ONE - On-device Neural Engine
Loading...
Searching...
No Matches
nnfw::misc::tensor::Object< T > Class Template Referencefinal

Class to build a tensor using specific generator. More...

#include <Object.h>

Collaboration diagram for nnfw::misc::tensor::Object< T >:

Public Types

using Generator = std::function< T(const Shape &shape, const Index &index)>
 Function to generate tensor element.
 

Public Member Functions

 Object (const Shape &shape, const Generator &fn)
 Construct a new Object object.
 
const Shapeshape (void) const
 Get reference of shape.
 
at (const Index &index) const override
 Get and element of tensor.
 
- Public Member Functions inherited from nnfw::misc::tensor::Reader< T >
virtual ~Reader ()=default
 Destroy the Reader object.
 

Detailed Description

template<typename T>
class nnfw::misc::tensor::Object< T >

Class to build a tensor using specific generator.

Template Parameters
TType of tensor element

Definition at line 46 of file Object.h.

Member Typedef Documentation

◆ Generator

template<typename T >
using nnfw::misc::tensor::Object< T >::Generator = std::function<T(const Shape &shape, const Index &index)>

Function to generate tensor element.

Definition at line 52 of file Object.h.

Constructor & Destructor Documentation

◆ Object()

template<typename T >
nnfw::misc::tensor::Object< T >::Object ( const Shape shape,
const Generator fn 
)
inline

Construct a new Object object.

Parameters
[in]shapeTensor shape
[in]fnFunction to generate tensor elements

Definition at line 60 of file Object.h.

60 : _shape{shape}
61 {
62 // Set 'stride'
63 _stride.init(shape);
64
65 // Handle scalar object
66 if (shape.rank() == 0)
67 {
68 _values.resize(1);
69 _values.at(0) = fn(_shape, 0);
70 }
71 else
72 {
73 // Pre-allocate buffer
74 _values.resize(_shape.dim(0) * _stride.at(0));
75
76 // Set 'value'
77 iterate(_shape) <<
78 [this, &fn](const Index &index) { _values.at(_stride.offset(index)) = fn(_shape, index); };
79 }
80 }
uint32_t at(uint32_t axis) const
Get an stride value for specific axis.
void init(const Shape &shape)
Initialize the stride data using Shape.
uint32_t offset(const Index &index) const
Get the 1-D offset of specified index for n-D tensor.
const Shape & shape(void) const
Get reference of shape.
Definition Object.h:87
int32_t dim(uint32_t n) const
Get specific dimension.
Definition Shape.h:100
uint32_t rank(void) const
Get the rank of this shape.
Definition Shape.h:92
loco::GraphInputIndex index(const TFPlaceholder *node)
Definition TFNode.cpp:54
IndexIterator iterate(const Shape &shape)
Get an IndexItator object.

References nnfw::misc::tensor::NonIncreasingStride::at(), nnfw::misc::tensor::Shape::dim(), nnfw::misc::tensor::NonIncreasingStride::init(), nnfw::misc::tensor::iterate(), nnfw::misc::tensor::NonIncreasingStride::offset(), nnfw::misc::tensor::Shape::rank(), and nnfw::misc::tensor::Object< T >::shape().

Member Function Documentation

◆ at()

template<typename T >
T nnfw::misc::tensor::Object< T >::at ( const Index index) const
inlineoverridevirtual

Get and element of tensor.

Parameters
[in]indexIndex of a tensor element
Returns
Value of tensor element

Implements nnfw::misc::tensor::Reader< T >.

Definition at line 95 of file Object.h.

95{ return _values.at(_stride.offset(index)); }

References nnfw::misc::tensor::NonIncreasingStride::offset().

◆ shape()

template<typename T >
const Shape & nnfw::misc::tensor::Object< T >::shape ( void  ) const
inline

The documentation for this class was generated from the following file: