blob: 5c370e5eba6dde4b575049d07dddd10decf522d5 [file] [log] [blame]
Kaizen8938bd32017-09-28 14:38:23 +01001/*
2 * Copyright (c) 2017 ARM Limited.
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24#ifndef __ARM_COMPUTE_GRAPH_UTILS_H__
25#define __ARM_COMPUTE_GRAPH_UTILS_H__
26
Kaizenbf8b01d2017-10-12 14:26:51 +010027#include "arm_compute/core/PixelValue.h"
Kaizen8938bd32017-09-28 14:38:23 +010028#include "arm_compute/graph/ITensorAccessor.h"
29#include "arm_compute/graph/Types.h"
30
Kaizenbf8b01d2017-10-12 14:26:51 +010031#include <random>
32
Kaizen8938bd32017-09-28 14:38:23 +010033namespace arm_compute
34{
35namespace graph_utils
36{
37/** PPM writer class */
38class PPMWriter : public graph::ITensorAccessor
39{
40public:
41 /** Constructor
42 *
43 * @param[in] name PPM file name
44 * @param[in] maximum Maximum elements to access
45 */
46 PPMWriter(std::string name, unsigned int maximum = 1);
47 /** Allows instances to move constructed */
48 PPMWriter(PPMWriter &&) = default;
49
50 // Inherited methods overriden:
51 bool access_tensor(ITensor &tensor) override;
52
53private:
54 const std::string _name;
55 unsigned int _iterator;
56 unsigned int _maximum;
57};
58
59/** Dummy accessor class */
Kaizenbf8b01d2017-10-12 14:26:51 +010060class DummyAccessor final : public graph::ITensorAccessor
Kaizen8938bd32017-09-28 14:38:23 +010061{
62public:
63 /** Constructor
64 *
65 * @param[in] maximum Maximum elements to write
66 */
67 DummyAccessor(unsigned int maximum = 1);
68 /** Allows instances to move constructed */
69 DummyAccessor(DummyAccessor &&) = default;
70
71 // Inherited methods overriden:
72 bool access_tensor(ITensor &tensor) override;
73
74private:
75 unsigned int _iterator;
76 unsigned int _maximum;
77};
78
Kaizenbf8b01d2017-10-12 14:26:51 +010079/** Random accessor class */
80class RandomAccessor final : public graph::ITensorAccessor
81{
82public:
83 /** Constructor
84 *
85 * @param[in] lower Lower bound value.
86 * @param[in] upper Upper bound value.
87 * @param[in] seed (Optional) Seed used to initialise the random number generator.
88 */
89 RandomAccessor(PixelValue lower, PixelValue upper, const std::random_device::result_type seed = 0);
90 /** Allows instances to move constructed */
91 RandomAccessor(RandomAccessor &&) = default;
92
93 // Inherited methods overriden:
94 bool access_tensor(ITensor &tensor) override;
95
96private:
97 template <typename T, typename D>
98 void fill(ITensor &tensor, D &&distribution);
99 PixelValue _lower;
100 PixelValue _upper;
101 std::random_device::result_type _seed;
102};
103
Kaizen8938bd32017-09-28 14:38:23 +0100104/** Numpy Binary loader class*/
Kaizenbf8b01d2017-10-12 14:26:51 +0100105class NumPyBinLoader final : public graph::ITensorAccessor
Kaizen8938bd32017-09-28 14:38:23 +0100106{
107public:
108 /** Default Constructor
109 *
110 * @param filename Binary file name
111 */
112 NumPyBinLoader(std::string filename);
113 /** Allows instances to move constructed */
114 NumPyBinLoader(NumPyBinLoader &&) = default;
115
116 // Inherited methods overriden:
117 bool access_tensor(ITensor &tensor) override;
118
119private:
120 const std::string _filename;
121};
Kaizenbf8b01d2017-10-12 14:26:51 +0100122} // namespace graph_utils
Kaizen8938bd32017-09-28 14:38:23 +0100123} // namespace arm_compute
124
125#endif /* __ARM_COMPUTE_GRAPH_UTILS_H__ */