ONE - On-device Neural Engine
Loading...
Searching...
No Matches
nnfw::cker::Tensor Struct Reference

#include <Tensor.h>

Public Member Functions

bool copyFrom (const Tensor &other, const Shape &new_shape)
 
template<typename T >
T * base () const
 
template<typename T , size_t NDIMS>
TTypes< T, NDIMS >::Tensor shaped (const std::vector< int32_t > &new_sizes)
 
template<typename T >
TTypes< T >::Flat flat ()
 
template<typename T , size_t NDIMS>
TTypes< T, NDIMS >::ConstTensor shaped (const std::vector< int32_t > new_sizes) const
 
template<typename T , size_t NDIMS>
TTypes< T, NDIMS >::Tensor shaped () const
 
template<typename T >
TTypes< T >::ConstFlat flat () const
 
template<typename T >
TTypes< T >::ConstScalar scalar () const
 
template<typename T >
TTypes< T >::Vec vec ()
 
template<typename T >
TTypes< T >::Matrix matrix ()
 

Data Fields

Shape shape
 
void * buffer
 

Detailed Description

Definition at line 94 of file Tensor.h.

Member Function Documentation

◆ base()

template<typename T >
T * nnfw::cker::Tensor::base ( ) const
inline

Definition at line 111 of file Tensor.h.

112 {
113 return buffer == nullptr ? nullptr : reinterpret_cast<T *>(buffer);
114 }

References buffer.

◆ copyFrom()

bool nnfw::cker::Tensor::copyFrom ( const Tensor other,
const Shape new_shape 
)
inline

Definition at line 100 of file Tensor.h.

101 {
102 if (other.shape.FlatSize() != new_shape.FlatSize())
103 return false;
104
105 this->shape.ReplaceWith(new_shape.DimensionsCount(), new_shape.DimsData());
106 this->buffer = other.buffer;
107
108 return true;
109 }
void ReplaceWith(int dimensions_count, const int32_t *dims_data)
Definition Shape.h:130

References buffer, nnfw::cker::Shape::DimensionsCount(), nnfw::cker::Shape::DimsData(), nnfw::cker::Shape::FlatSize(), nnfw::cker::Shape::ReplaceWith(), and shape.

◆ flat() [1/2]

template<typename T >
TTypes< T >::Flat nnfw::cker::Tensor::flat ( )
inline

Definition at line 127 of file Tensor.h.

127{ return shaped<T, 1>({shape.FlatSize()}); }
int FlatSize() const
Definition Shape.h:181

References nnfw::cker::Shape::FlatSize(), and shape.

Referenced by nnfw::cker::train::Adam(), and nnfw::cker::GenerateKey().

◆ flat() [2/2]

template<typename T >
TTypes< T >::ConstFlat nnfw::cker::Tensor::flat ( ) const
inline

Definition at line 151 of file Tensor.h.

152 {
153 return shaped<T, 1>({shape.FlatSize()});
154 }

References nnfw::cker::Shape::FlatSize(), and shape.

◆ matrix()

template<typename T >
TTypes< T >::Matrix nnfw::cker::Tensor::matrix ( )
inline

Definition at line 163 of file Tensor.h.

163{ return shaped<T, 2>(); }

Referenced by nnfw::cker::train::CategoricalCrossEntropyWithLogits().

◆ scalar()

template<typename T >
TTypes< T >::ConstScalar nnfw::cker::Tensor::scalar ( ) const
inline

Definition at line 156 of file Tensor.h.

157 {
158 return typename TTypes<T>::ConstScalar(base<T>());
159 }
Eigen::TensorMap< Eigen::TensorFixedSize< const T, Eigen::Sizes<>, Eigen::RowMajor, IndexType >, Eigen::Aligned > ConstScalar
Definition Tensor.h:51

Referenced by nnfw::cker::train::Adam(), nnfw::cker::BroadcastTo(), and nnfw::cker::train::GradientDescent().

◆ shaped() [1/3]

template<typename T , size_t NDIMS>
TTypes< T, NDIMS >::Tensor nnfw::cker::Tensor::shaped ( ) const
inline

Definition at line 141 of file Tensor.h.

142 {
143 Eigen::array<Eigen::DenseIndex, NDIMS> dims;
144 for (size_t d = 0; d < NDIMS; d++)
145 {
146 dims[d] = shape.Dims(d);
147 }
148 return typename TTypes<T, NDIMS>::Tensor(base<T>(), dims);
149 }
int32_t Dims(int i) const
Definition Shape.h:92
Eigen::TensorMap< Eigen::Tensor< T, NDIMS, Eigen::RowMajor, IndexType >, Eigen::Aligned > Tensor
Definition Tensor.h:32

References nnfw::cker::Shape::Dims(), and shape.

◆ shaped() [2/3]

template<typename T , size_t NDIMS>
TTypes< T, NDIMS >::Tensor nnfw::cker::Tensor::shaped ( const std::vector< int32_t > &  new_sizes)
inline

Definition at line 117 of file Tensor.h.

118 {
119 Eigen::array<Eigen::DenseIndex, NDIMS> dims;
120 for (size_t d = 0; d < NDIMS; d++)
121 {
122 dims[d] = new_sizes[d];
123 }
124 return typename TTypes<T, NDIMS>::Tensor(base<T>(), dims);
125 }

Referenced by nnfw::cker::FusedBatchNorm::operator()().

◆ shaped() [3/3]

template<typename T , size_t NDIMS>
TTypes< T, NDIMS >::ConstTensor nnfw::cker::Tensor::shaped ( const std::vector< int32_t >  new_sizes) const
inline

Definition at line 130 of file Tensor.h.

131 {
132 Eigen::array<Eigen::DenseIndex, NDIMS> dims;
133 for (size_t d = 0; d < NDIMS; d++)
134 {
135 dims[d] = new_sizes[d];
136 }
137 return typename TTypes<T, NDIMS>::ConstTensor(base<T>(), dims);
138 }
Eigen::TensorMap< Eigen::Tensor< const T, NDIMS, Eigen::RowMajor, IndexType >, Eigen::Aligned > ConstTensor
Definition Tensor.h:35

◆ vec()

template<typename T >
TTypes< T >::Vec nnfw::cker::Tensor::vec ( )
inline

Definition at line 161 of file Tensor.h.

161{ return shaped<T, 1>(); }

Referenced by nnfw::cker::train::CategoricalCrossEntropyWithLogits().

Field Documentation

◆ buffer

◆ shape


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