![]() |
ImFusion SDK 4.3
|
#include <ImFusion/ML/Tensor.h>
Implementation of a Tensor class; used in TensorDataElement to directly present data to a neural network. More...
Implementation of a Tensor class; used in TensorDataElement to directly present data to a neural network.
Currently suppports three datatypes: Float, Int (int64_t) and uint8_t.
Public Member Functions | |
Tensor () | |
Create empty Tensor. | |
Tensor (Tensor const &other)=default | |
Copy constructor. | |
Tensor & | operator= (const Tensor &other)=default |
Copy assignement. | |
Tensor (Tensor &&other) noexcept | |
Move constructor. | |
Tensor & | operator= (Tensor &&other) noexcept |
Move assignement. | |
Tensor (std::vector< size_t > shape, float const *data) | |
Create a tensor with shape 'shape' and type Float, initialized from data. | |
Tensor (std::vector< size_t > shape, int64_t const *data) | |
Create a tensor with shape 'shape' and type Int, initialized from data. | |
Tensor (std::vector< size_t > shape, uint8_t const *data) | |
Create a tensor with shape 'shape' and type uint8_t, initialized from data. | |
Tensor (std::vector< size_t > shape, PixelType type, uint8_t const *raw_data=nullptr) | |
Create a tensor with shape 'shape' and type 'type', initialized from data. | |
size_t | order () const |
Rank of the tensor. | |
std::vector< size_t > const & | shape () const |
Returns the shape of the tensor. | |
size_t | numElements () const |
Returns the number of elements in this tensor's storage buffer. | |
size_t | byteSize () const |
Returns the number of bytes in this tensor's storage buffer. | |
bool | serialize (std::ostream &out) const |
Writes the tensor content into the given stream. | |
bool | deserialize (std::istream &in) |
Clears the tensor and reads new content from the given stream. | |
bool | operator== (Tensor const &other) const |
std::vector< uint64_t > const & | byteData () const |
Return the raw underlying data as bytes. | |
PixelType | dataType () const |
std::optional< std::vector< float > > | toFloatVector () const |
Create a copy of underlying data into a float vector, of size numElements(). | |
std::optional< std::vector< int64_t > > | toIntVector () const |
Create a copy of underlying data into a int64_t vector, of size numElements(). | |
std::optional< std::vector< uint8_t > > | toUByteVector () const |
Create a copy of underlying data into a uint8_t vector, of size numElements(). | |
uint8_t const * | bytePtr () const |
Access to raw byte data. | |
uint8_t * | bytePtr () |
Protected Member Functions | |
void | swapWith (Tensor &other) |
|
explicit |
Create a tensor with shape 'shape' and type Float, initialized from data.
Makes a copy of the data, does not take ownership.
|
explicit |
Create a tensor with shape 'shape' and type Int, initialized from data.
Makes a copy of the data, does not take ownership.
|
explicit |
Create a tensor with shape 'shape' and type uint8_t, initialized from data.
Makes a copy of the data, does not take ownership.
|
explicit |
Create a tensor with shape 'shape' and type 'type', initialized from data.
Makes a copy of the raw_data if supplied, otherwise initialize as 0. Does not take ownership.
std::optional< std::vector< float > > toFloatVector | ( | ) | const |
Create a copy of underlying data into a float vector, of size numElements().
Element ordering follows Torch ordering (lowest dimension is last shape dimension). Returns null optional if data is not of float type.
std::optional< std::vector< int64_t > > toIntVector | ( | ) | const |
Create a copy of underlying data into a int64_t vector, of size numElements().
Element ordering follows Torch ordering (lowest dimension is last shape dimension). Returns null optional if data is not of int64_t type.
std::optional< std::vector< uint8_t > > toUByteVector | ( | ) | const |
Create a copy of underlying data into a uint8_t vector, of size numElements().
Element ordering follows Torch ordering (lowest dimension is last shape dimension). Returns null optional if data is not of uint8_t type.