1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
  
     | 
    
      /*
 * Copyright (c) 2019 Arm Limited.
 *
 * SPDX-License-Identifier: MIT
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to
 * deal in the Software without restriction, including without limitation the
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 * sell copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
#ifndef ARM_COMPUTE_TEST_SIMPLE_TENSOR_ACCESSOR_H
#define ARM_COMPUTE_TEST_SIMPLE_TENSOR_ACCESSOR_H
#include "SimpleTensor.h"
#include "tests/IAccessor.h"
namespace arm_compute
{
namespace test
{
/** Accessor implementation for @ref SimpleTensor objects. */
template <typename T>
class SimpleTensorAccessor : public IAccessor
{
public:
    /** Create an accessor for the given @p tensor.
     *
     * @param[in, out] tensor To be accessed tensor.
     */
    SimpleTensorAccessor(SimpleTensor<T> &tensor);
    /** Prevent instances of this class from being copy constructed */
    SimpleTensorAccessor(const SimpleTensorAccessor &) = delete;
    /** Prevent instances of this class from being copied */
    SimpleTensorAccessor &operator=(const SimpleTensorAccessor &) = delete;
    /** Allow instances of this class to be move constructed */
    SimpleTensorAccessor(SimpleTensorAccessor &&) = default;
    /** Allow instances of this class to be moved */
    SimpleTensorAccessor &operator=(SimpleTensorAccessor &&) = default;
    /** Get the tensor data.
     *
     * @return a constant pointer to the tensor data.
     */
    const void *data() const;
    /** Get the tensor data.
     *
     * @return a pointer to the tensor data.
     */
    void *data();
    // Inherited methods overridden:
    TensorShape      shape() const override;
    size_t           element_size() const override;
    size_t           size() const override;
    Format           format() const override;
    DataLayout       data_layout() const override;
    DataType         data_type() const override;
    int              num_channels() const override;
    int              num_elements() const override;
    PaddingSize      padding() const override;
    QuantizationInfo quantization_info() const override;
    const void *operator()(const Coordinates &coord) const override;
    void *operator()(const Coordinates &coord) override;
private:
    SimpleTensor<T> &_tensor;
};
template <typename T>
inline SimpleTensorAccessor<T>::SimpleTensorAccessor(SimpleTensor<T> &tensor)
    : _tensor{ tensor }
{
}
template <typename T>
inline TensorShape SimpleTensorAccessor<T>::shape() const
{
    return _tensor.shape();
}
template <typename T>
inline size_t SimpleTensorAccessor<T>::element_size() const
{
    return _tensor.element_size();
}
template <typename T>
inline size_t SimpleTensorAccessor<T>::size() const
{
    return _tensor.num_elements() * _tensor.element_size();
}
template <typename T>
inline Format SimpleTensorAccessor<T>::format() const
{
    return _tensor.format();
}
template <typename T>
inline DataLayout SimpleTensorAccessor<T>::data_layout() const
{
    return _tensor.data_layout();
}
template <typename T>
inline DataType SimpleTensorAccessor<T>::data_type() const
{
    return _tensor.data_type();
}
template <typename T>
inline int SimpleTensorAccessor<T>::num_channels() const
{
    return _tensor.num_channels();
}
template <typename T>
inline int SimpleTensorAccessor<T>::num_elements() const
{
    return _tensor.num_elements();
}
template <typename T>
inline PaddingSize SimpleTensorAccessor<T>::padding() const
{
    return _tensor.padding();
}
template <typename T>
inline QuantizationInfo SimpleTensorAccessor<T>::quantization_info() const
{
    return _tensor.quantization_info();
}
template <typename T>
inline const void *SimpleTensorAccessor<T>::data() const
{
    return _tensor.data();
}
template <typename T>
inline void *SimpleTensorAccessor<T>::data()
{
    return _tensor.data();
}
template <typename T>
inline const void *SimpleTensorAccessor<T>::operator()(const Coordinates &coord) const
{
    return _tensor(coord);
}
template <typename T>
inline void *SimpleTensorAccessor<T>::operator()(const Coordinates &coord)
{
    return _tensor(coord);
}
} // namespace test
} // namespace arm_compute
#endif /* ARM_COMPUTE_TEST_SIMPLE_TENSOR_ACCESSOR_H */
 
     |