ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Tensor Class Reference

Public Member Functions

 Tensor (const vector< hsize_t > &shape)
 
 ~Tensor ()
 
int rank () const
 
int dim (int d) const
 
float * data ()
 
float numElems () const
 
float & at (const vector< int > &coords)
 
Tensor transpose (const vector< hsize_t > &reshape)
 

Detailed Description

Definition at line 31 of file tensor_gen.cpp.

Constructor & Destructor Documentation

◆ Tensor()

Tensor::Tensor ( const vector< hsize_t > &  shape)
inlineexplicit

Definition at line 34 of file tensor_gen.cpp.

34 : _shape(shape), _data(0), _num_elems(1)
35 {
36 _strides.resize(shape.size());
37
38 for (int i = _shape.size() - 1; i >= 0; --i)
39 {
40 _strides[i] = _num_elems;
41 _num_elems *= _shape[i];
42 }
43
44 _data = new float[_num_elems];
45 }

◆ ~Tensor()

Tensor::~Tensor ( )
inline

Definition at line 47 of file tensor_gen.cpp.

47{ delete[] _data; }

Member Function Documentation

◆ at()

float & Tensor::at ( const vector< int > &  coords)
inline

Definition at line 53 of file tensor_gen.cpp.

54 {
55 int offset = 0;
56
57 for (auto i = 0; i < coords.size(); ++i)
58 offset += coords[i] * _strides[i];
59
60 return _data[offset];
61 }
Array< CornerBox > coords
__global uchar * offset(const Image *img, int x, int y)
Definition helpers.h:540

References coords, and offset().

Referenced by TEST(), and transpose().

◆ data()

float * Tensor::data ( )
inline

Definition at line 50 of file tensor_gen.cpp.

50{ return _data; }

◆ dim()

int Tensor::dim ( int  d) const
inline

Definition at line 49 of file tensor_gen.cpp.

49{ return _shape[d]; }

◆ numElems()

float Tensor::numElems ( ) const
inline

Definition at line 51 of file tensor_gen.cpp.

51{ return _num_elems; }

◆ rank()

int Tensor::rank ( ) const
inline

Definition at line 48 of file tensor_gen.cpp.

48{ return _shape.size(); }

Referenced by transpose().

◆ transpose()

Tensor Tensor::transpose ( const vector< hsize_t > &  reshape)
inline

Definition at line 63 of file tensor_gen.cpp.

64 {
65 vector<hsize_t> tr_shape(_shape.size());
66
67 for (auto i = 0; i < _shape.size(); ++i)
68 tr_shape[i] = _shape[reshape[i]];
69
70 Tensor result(tr_shape);
71 auto on_loop = [this, &reshape, &result](vector<int> &coords) {
72 vector<int> tr_coords(_shape.size());
73
74 for (int i = 0; i < rank(); ++i)
75 tr_coords[i] = coords[reshape[i]];
76
77 result.at(tr_coords) = at(coords);
78 };
79 iterate(*this, on_loop);
80 return result;
81 }
float & at(const vector< int > &coords)
int rank() const
result
Definition infer.py:103

References at(), coords, and rank().

Referenced by main().


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