ONE - On-device Neural Engine
Loading...
Searching...
No Matches
nnfw::misc::tensor Namespace Reference

Data Structures

class  Comparator
 Class to compare two tensors (expected and obtained to compare) More...
 
struct  Diff
 Struct to have information after comparing two elements of two tensors. More...
 
struct  Index
 Struct to represent index of each dimension of a tensor. More...
 
class  IndexEnumerator
 Class to enumerate index of a tensor. More...
 
class  IndexFormatter
 Class to send Index object to output stream. More...
 
class  IndexIterator
 Class to iterate indexes available for given shape. More...
 
class  NonIncreasingStride
 Class to represent strides where stride[N-1] >= stride[N] holds for all N < rank. More...
 
class  Object
 Class to build a tensor using specific generator. More...
 
struct  Reader
 Struct to read element of tensor. More...
 
class  Shape
 Class to represent shape of a tensor. More...
 
class  Zipper
 Class to apply a function with three params: Index, elements of a tensor at passed index read by Reader objects. More...
 

Functions

std::ostream & operator<< (std::ostream &os, const IndexFormatter &fmt)
 Send IndexFormatter object to output stream.
 
IndexIterator iterate (const Shape &shape)
 Get an IndexItator object.
 
template<typename Callable >
IndexIteratoroperator<< (IndexIterator &&it, Callable cb)
 Iterate all indexes and apply a function.
 
bool operator== (const Shape &, const Shape &)
 Check equality of two Shape.
 
std::ostream & operator<< (std::ostream &os, const Shape &shape)
 Send Shape to std::ostream.
 
template<typename T , typename Callable >
const Zipper< T > & operator<< (const Zipper< T > &zipper, Callable cb)
 Apply cb by using lhs and rhs passed to the constructor of zipper.
 
template<typename T >
Zipper< T > zip (const Shape &shape, const Reader< T > &lhs, const Reader< T > &rhs)
 Get Zipper object constructed using passed params.
 

Function Documentation

◆ iterate()

IndexIterator nnfw::misc::tensor::iterate ( const Shape shape)
inline

Get an IndexItator object.

Parameters
[in]shapeShape of tensor of which index will be iterated
Returns
IndexIterator object

Definition at line 89 of file IndexIterator.h.

89{ return IndexIterator{shape}; }
Class to iterate indexes available for given shape.

Referenced by nnfw::misc::tensor::Object< T >::Object(), and nnfw::misc::tensor::Zipper< T >::zip().

◆ operator<<() [1/4]

template<typename T , typename Callable >
const Zipper< T > & nnfw::misc::tensor::operator<< ( const Zipper< T > &  zipper,
Callable  cb 
)

Apply cb by using lhs and rhs passed to the constructor of zipper.

Parameters
[in]zipperZipper object
[in]cbFunction to zpply using zip function
Returns
zipper object after applying cb to zipper

Definition at line 82 of file Zipper.h.

83{
84 zipper.zip(cb);
85 return zipper;
86}
void zip(Callable cb) const
Apply cb to all elements of tensors. Elements of two tensors at passed index are read by lhs and rhs.
Definition Zipper.h:63

References nnfw::misc::tensor::Zipper< T >::zip().

◆ operator<<() [2/4]

template<typename Callable >
IndexIterator & nnfw::misc::tensor::operator<< ( IndexIterator &&  it,
Callable  cb 
)

Iterate all indexes and apply a function.

Parameters
[in]itIndexIterator object that is constructed with a tensor shape
[in]cbA function that will receive a specific index. Inside the function, the index is used to manipulate tensor element.
Returns
IndexIterator object

Definition at line 98 of file IndexIterator.h.

99{
100 return it.iter(cb);
101}
IndexIterator & iter(Callable fn)
Iterate all available indexes and run a function for each index.

References nnfw::misc::tensor::IndexIterator::iter().

◆ operator<<() [3/4]

std::ostream & nnfw::misc::tensor::operator<< ( std::ostream &  os,
const IndexFormatter fmt 
)

Send IndexFormatter object to output stream.

Parameters
[in]osOutput stream
[in]fmtIndexFormatter object that is sent to output stream
Returns
Output stream

Definition at line 28 of file IndexFormatter.cpp.

29{
30 const auto rank = fmt.index().rank();
31
32 assert(rank > 0);
33
34 os << fmt.index().at(0);
35
36 if (rank > 1)
37 {
38 for (uint32_t axis = 1; axis < rank; ++axis)
39 {
40 os << ", " << fmt.index().at(axis);
41 }
42 }
43
44 return os;
45}

◆ operator<<() [4/4]

std::ostream & nnfw::misc::tensor::operator<< ( std::ostream &  os,
const Shape shape 
)

Send Shape to std::ostream.

Parameters
[in]osstd::ostream to process this Shape
[in]shapeShape to send to ostream
Returns
Reference of std::ostream

Definition at line 90 of file Shape.cpp.

91{
92 if (shape.rank() > 0)
93 {
94 os << shape.dim(0);
95
96 for (uint32_t axis = 1; axis < shape.rank(); ++axis)
97 {
98 os << "," << shape.dim(axis);
99 }
100 }
101
102 return os;
103}
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

References nnfw::misc::tensor::Shape::dim(), and nnfw::misc::tensor::Shape::rank().

◆ operator==()

bool nnfw::misc::tensor::operator== ( const Shape lhs,
const Shape rhs 
)

Check equality of two Shape.

Parameters
[in]ShapeFirst shape to compare
[in]ShapeSecond shape to compare
Returns
true if both shapes are equal, otherwise false

Definition at line 30 of file Shape.cpp.

31{
32 if (lhs.rank() != rhs.rank())
33 {
34 return false;
35 }
36
37 for (uint32_t axis = 0; axis < lhs.rank(); ++axis)
38 {
39 if (lhs.dim(axis) != rhs.dim(axis))
40 {
41 return false;
42 }
43 }
44
45 return true;
46}

References nnfw::misc::tensor::Shape::dim(), and nnfw::misc::tensor::Shape::rank().

◆ zip()

template<typename T >
Zipper< T > nnfw::misc::tensor::zip ( const Shape shape,
const Reader< T > &  lhs,
const Reader< T > &  rhs 
)

Get Zipper object constructed using passed params.

Parameters
shapeShape of lhs and rhs
lhsReader object of a tensor
rhsReader object of a tensor
Returns
Zipper object

Definition at line 95 of file Zipper.h.

96{
97 return Zipper<T>{shape, lhs, rhs};
98}
Class to apply a function with three params: Index, elements of a tensor at passed index read by Read...
Definition Zipper.h:42

Referenced by nnfw::misc::tensor::Comparator::compare().