blob: e19810ca87aefbbd209da504029aa652e7da4640 [file] [log] [blame]
telsoa014fcda012018-03-09 14:13:49 +00001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
David Beckecb56cd2018-09-05 12:52:57 +01003// SPDX-License-Identifier: MIT
telsoa014fcda012018-03-09 14:13:49 +00004//
5
6#include <armnn/Tensor.hpp>
7
8#include <boost/assert.hpp>
9
10namespace armnn
11{
12
telsoa01c577f2c2018-08-31 09:22:23 +010013// Utility class providing access to raw tensor memory based on indices along each dimension.
telsoa014fcda012018-03-09 14:13:49 +000014template <typename DataType>
15class TensorBufferArrayView
16{
17public:
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
37private:
38 const TensorShape m_Shape;
39 DataType* m_Data;
40};
41
42} //namespace armnn