telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
David Beck | ecb56cd | 2018-09-05 12:52:57 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 4 | // |
| 5 | |
| 6 | #include <armnn/Tensor.hpp> |
| 7 | |
| 8 | #include <boost/assert.hpp> |
| 9 | |
| 10 | namespace armnn |
| 11 | { |
| 12 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 13 | // Utility class providing access to raw tensor memory based on indices along each dimension. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 14 | template <typename DataType> |
| 15 | class TensorBufferArrayView |
| 16 | { |
| 17 | public: |
| 18 | TensorBufferArrayView(const TensorShape& shape, DataType* data) |
| 19 | : m_Shape(shape) |
| 20 | , m_Data(data) |
| 21 | { |
| 22 | } |
| 23 | |
| 24 | DataType& Get(unsigned int b, unsigned int c, unsigned int h, unsigned int w) const |
| 25 | { |
| 26 | BOOST_ASSERT( b < m_Shape[0] || (m_Shape[0] == 0 && b == 0) ); |
| 27 | BOOST_ASSERT( c < m_Shape[1] || (m_Shape[1] == 0 && c == 0) ); |
| 28 | BOOST_ASSERT( h < m_Shape[2] || (m_Shape[2] == 0 && h == 0) ); |
| 29 | BOOST_ASSERT( w < m_Shape[3] || (m_Shape[3] == 0 && w == 0) ); |
| 30 | |
| 31 | return m_Data[b * m_Shape[1] * m_Shape[2] * m_Shape[3] |
| 32 | + c * m_Shape[2] * m_Shape[3] |
| 33 | + h * m_Shape[3] |
| 34 | + w]; |
| 35 | } |
| 36 | |
| 37 | private: |
| 38 | const TensorShape m_Shape; |
| 39 | DataType* m_Data; |
| 40 | }; |
| 41 | |
| 42 | } //namespace armnn |