Txeo v0.1
A Developer-Friendly TensorFlow C++ Wrapper
|
Implements the mathematical concept of tensor, which is a magnitude of multiple order. A tensor of order zero is defined to be a scalar, of order one a vector, of order two a matrix and so on. Each order of the tensor has a dimension. Elements are addressed via multidimensional indexing. More...
#include <Tensor.h>
Public Member Functions | |
Tensor (const Tensor &tensor) | |
Tensor (Tensor &&tensor) noexcept | |
~Tensor () | |
Tensor & | operator= (const Tensor &tensor) |
Tensor & | operator= (Tensor &&tensor) noexcept |
bool | operator== (const Tensor &tensor) |
bool | operator!= (const Tensor &tensor) |
Tensor (const txeo::TensorShape &shape) | |
Constructs a tensor from a specified txeo::TensorShape. | |
Tensor (txeo::TensorShape &&shape) | |
Constructs a Tensor from a specified txeo::TensorShape. | |
Tensor (const std::vector< size_t > &shape) | |
Constructs a Tensor from a specified shape std::vector. | |
Tensor (std::vector< size_t > &&shape) | |
Constructs a Tensor from a specified shape std::vector. | |
Tensor (const std::initializer_list< size_t > &shape) | |
Constructs a Tensor from a specified shape std::vector. | |
Tensor (const txeo::TensorShape &shape, const T &fill_value) | |
Constructs a Tensor from a specified txeo::TensorShape and fills it with a value. | |
Tensor (txeo::TensorShape &&shape, const T &fill_value) | |
Constructs a Tensor from a specified txeo::TensorShape and fills it with a value. | |
Tensor (const std::vector< size_t > &shape, const T &fill_value) | |
Constructs a Tensor from a specified shape std::vector and fills it with a value. | |
Tensor (std::vector< size_t > &&shape, const T &fill_value) | |
Constructs a Tensor from a specified shape std::vector and fills it with a value. | |
Tensor (const std::initializer_list< size_t > &shape, const T &fill_value) | |
Constructs a Tensor from a specified initializer list and fills it with a value. | |
Tensor (const txeo::TensorShape &shape, const std::vector< T > &values) | |
Constructs a Tensor object from a specified txeo::TensorShape and fills it with a std::vector of values in a row-major scheme. | |
Tensor (const std::vector< size_t > &shape, const std::vector< T > &values) | |
Constructs a Tensor object from a specified std::vector<size_t> and fills it with a std::vector of values in a row-major scheme. | |
Tensor (const std::initializer_list< size_t > &shape, const std::vector< T > &values) | |
Constructs a Tensor object from a specified initializer list and fills it with a std::vector of values in a row-major scheme. | |
Tensor (const std::initializer_list< std::initializer_list< T > > &values) | |
Constructs a second order Tensor from a nested std::initializer_list. | |
Tensor (const std::initializer_list< std::initializer_list< std::initializer_list< T > > > &values) | |
Constructs a third order Tensor from a nested std::initializer_list. | |
const txeo::TensorShape & | shape () const |
Returns the shape of this tensor. | |
constexpr std::type_identity_t< T > | type () const |
Returns the data type of this tensor. | |
int | order () const |
Returns the order of this tensor. | |
size_t | dim () const |
Returns the dimension of this tensor. | |
size_t | number_of_elements () const |
Returns the number of elements of this tensor, which corresponds to the dimension of this tensor. | |
size_t | memory_size () const |
Returns the number of bytes occupied by this tensor. | |
Tensor< T > | slice (size_t first_axis_begin, size_t first_axis_end) const |
Returns a view ot this tensor from a specified range of dimensions of the first axis. | |
void | view_of (const Tensor< T > &tensor, const txeo::TensorShape &shape) |
Views the content of the specified tensor according to the specified shape. There is no element copying. | |
template<typename U > | |
bool | is_equal_shape (const Tensor< U > &other) const |
Compares the shape of this tensor with the shape of the specified tensor. | |
T & | operator() () |
Accesses the value of this tensor if it is a scalar (order zero). | |
template<typename... Args> requires (std::convertible_to<Args, size_t> && ...) | |
T & | operator() (Args... args) |
Accesses an element of this tensor according to the specified indexes. | |
T & | at () |
Accesses the value of this tensor if it is a scalar (order zero). | |
template<typename... Args> requires (std::convertible_to<Args, size_t> && ...) | |
T & | at (Args... args) |
Accesses an element of this tensor according to the specified indexes. | |
const T & | operator() () const |
Reads the value of this tensor if it is a scalar (order zero). | |
template<typename... Args> requires (std::convertible_to<Args, size_t> && ...) | |
const T & | operator() (Args... args) const |
Reads an element of this tensor according to the specified indexes. | |
const T & | at () const |
Reads the value of this tensor if it is a scalar (order zero). Order checking is performed. | |
template<typename... Args> requires (std::convertible_to<Args, size_t> && ...) | |
const T & | at (Args... args) const |
Reads an element of this tensor according to the specified indexes. | |
void | reshape (const txeo::TensorShape &shape) |
Reshapes this tensor if the specified shape defines a number of elements equal to this tensor order. | |
void | reshape (const std::vector< size_t > &shape) |
Reshapes this tensor if the specified shape vector defines a number of elements equal to this tensor order. | |
void | reshape (const std::initializer_list< size_t > &shape) |
Reshapes this tensor if the specified shape vector defines a number of elements equal to this tensor order. | |
Tensor< T > | flatten () const |
Returns a first order reshaped view of this tensor. | |
void | fill (const T &value) |
Fills this tensor with the specified value. | |
void | fill_with_uniform_random (const T &min, const T &max) |
Fills the tensor with uniformly distributed random values ranging according to the specified interval. | |
void | fill_with_uniform_random (const T &min, const T &max, const size_t &seed1, const size_t &seed2) |
Fills the tensor with uniformly distributed random values ranging according to the specified interval. | |
void | shuffle () |
Shuffles the elements of this tensor. | |
void | squeeze () |
Reshapes this tensor by removing all the axes of dimension one. | |
Tensor< T > & | operator= (const T &value) |
Assigns a specified value to this tensor elements. | |
T * | data () |
Acesses the raw data of this tensor. | |
const T * | data () const |
Reads the raw data of this tensor. | |
Tensor< T > | clone () const |
Returns a clone of this tensor. | |
Tensor< T > & | operator+= (const Tensor< T > &tensor) |
Tensor< T > & | operator+= (const T &tensor) |
Tensor< T > & | operator-= (const Tensor< T > &tensor) |
Tensor< T > & | operator-= (const T &tensor) |
Tensor< T > & | operator*= (const T &scalar) |
Tensor< T > & | operator/= (const T &scalar) |
txeo::TensorIterator< T > | begin () |
txeo::TensorIterator< T > | end () |
txeo::TensorIterator< const T > | begin () const |
txeo::TensorIterator< const T > | end () const |
Protected Member Functions | |
template<typename P > | |
void | create_from_shape (P &&shape) |
void | fill_data_shape (const std::initializer_list< std::initializer_list< T > > &list, std::vector< T > &flat_data, std::vector< size_t > &shape) |
void | fill_data_shape (const std::initializer_list< std::initializer_list< std::initializer_list< T > > > &list, std::vector< T > &flat_data, std::vector< size_t > &shape) |
void | check_indexes (const std::vector< size_t > &indexes) |
Tensor () | |
Protected Attributes | |
std::unique_ptr< Impl > | _impl {nullptr} |
Friends | |
class | txeo::Predictor< T > |
class | txeo::TensorAgg< T > |
class | txeo::TensorPart< T > |
class | txeo::TensorOp< T > |
class | txeo::TensorFunc< T > |
class | txeo::detail::TensorHelper |
template<typename U > | |
std::ostream & | operator<< (std::ostream &os, const Tensor< U > &tensor) |
template<typename U > | |
txeo::Tensor< U > | operator+ (const txeo::Tensor< U > &left, const txeo::Tensor< U > &right) |
Returns the sum of two tensors. | |
template<typename U > | |
txeo::Tensor< U > | operator+ (const txeo::Tensor< U > &left, const U &right) |
template<typename U > | |
txeo::Tensor< U > | operator- (const txeo::Tensor< U > &left, const txeo::Tensor< U > &right) |
Returns the subtraction of two tensors. | |
template<typename U > | |
txeo::Tensor< U > | operator- (const txeo::Tensor< U > &left, const U &right) |
Element-wise tensor-scalar addition operator. | |
template<typename U > | |
txeo::Tensor< U > | operator- (const U &left, const txeo::Tensor< U > &right) |
Element-wise scalar-tensor subtraction operator. | |
template<typename U > | |
txeo::Tensor< U > | operator* (const txeo::Tensor< U > &tensor, const U &scalar) |
Returns the scalar multiplication of a tensor. | |
template<typename U > | |
txeo::Tensor< U > | operator/ (const txeo::Tensor< U > &left, const U &right) |
Element-wise division operator (tensor / scalar) | |
template<typename U > | |
txeo::Tensor< U > | operator/ (const U &left, const txeo::Tensor< U > &right) |
Element-wise scalar-tensor division operator. | |
Implements the mathematical concept of tensor, which is a magnitude of multiple order. A tensor of order zero is defined to be a scalar, of order one a vector, of order two a matrix and so on. Each order of the tensor has a dimension. Elements are addressed via multidimensional indexing.
txeo::Tensor< T >::Tensor | ( | const Tensor< T > & | tensor | ) |
|
noexcept |
txeo::Tensor< T >::~Tensor | ( | ) |
|
explicit |
Constructs a tensor from a specified txeo::TensorShape.
shape | Shape of the constructed tensor |
Example Usage:
|
explicit |
Constructs a Tensor from a specified txeo::TensorShape.
shape | Shape of the constructed tensor |
Example Usage:
|
explicit |
Constructs a Tensor from a specified shape std::vector.
shape | Vector of dimensions |
Example Usage:
|
explicit |
Constructs a Tensor from a specified shape std::vector.
shape | Vector of dimensions |
Example Usage:
|
inlineexplicit |
Constructs a Tensor from a specified shape std::vector.
shape | Vector of dimensions |
Example Usage:
Definition at line 172 of file Tensor.h.
|
explicit |
Constructs a Tensor from a specified txeo::TensorShape and fills it with a value.
shape | Shape of the constructed tensor |
fill_value | Value of the elements of the constructed tensor |
Example Usage:
|
explicit |
Constructs a Tensor from a specified txeo::TensorShape and fills it with a value.
shape | Shape of the constructed tensor |
fill_value | Value of the elements of the constructed tensor |
Example Usage:
|
explicit |
Constructs a Tensor from a specified shape std::vector and fills it with a value.
shape | Shape of the constructed tensor |
fill_value | Value of the elements of the constructed tensor |
Example Usage:
|
explicit |
Constructs a Tensor from a specified shape std::vector and fills it with a value.
shape | Shape of the constructed tensor |
fill_value | Value of the elements of the constructed tensor |
Example Usage:
|
inlineexplicit |
Constructs a Tensor from a specified initializer list and fills it with a value.
shape | Shape of the constructed tensor |
fill_value | Value of the elements of the constructed tensor |
Example Usage:
|
explicit |
Constructs a Tensor object from a specified txeo::TensorShape and fills it with a std::vector of values in a row-major scheme.
shape | Shape of the constructed tensor |
values | Elements of the constructed tensor |
txeo::TensorError |
Example Usage:
|
explicit |
Constructs a Tensor object from a specified std::vector<size_t> and fills it with a std::vector of values in a row-major scheme.
shape | Shape of the constructed tensor |
values | Elements of the constructed tensor |
txeo::TensorError |
Example Usage:
|
inlineexplicit |
Constructs a Tensor object from a specified initializer list and fills it with a std::vector of values in a row-major scheme.
shape | Shape of the constructed tensor |
values | Elements of the constructed tensor |
txeo::TensorError |
Example Usage:
|
explicit |
Constructs a second order Tensor from a nested std::initializer_list.
values | Nested initializer list |
txeo::TensorError |
Example Usage:
|
explicit |
Constructs a third order Tensor from a nested std::initializer_list.
values | Nested initializer list |
txeo::TensorError |
Example Usage:
|
explicitprotected |
T & txeo::Tensor< T >::at | ( | ) |
Accesses the value of this tensor if it is a scalar (order zero).
txeo::TensorError |
const T & txeo::Tensor< T >::at | ( | ) | const |
Reads the value of this tensor if it is a scalar (order zero). Order checking is performed.
txeo::TensorError |
|
inline |
Accesses an element of this tensor according to the specified indexes.
Args | A variadic list of indices that must be convertible to size_t . |
args | The indices specifying the position of the element. |
txeo::TensorError |
Example Usage:
Definition at line 1107 of file Tensor.h.
|
inline |
Reads an element of this tensor according to the specified indexes.
Args | A variadic list of indices that must be convertible to size_t . |
args | The indices specifying the position of the element. |
txeo::TensorError |
Example Usage:
Definition at line 1122 of file Tensor.h.
txeo::TensorIterator< T > txeo::Tensor< T >::begin | ( | ) |
txeo::TensorIterator< const T > txeo::Tensor< T >::begin | ( | ) | const |
|
protected |
Tensor< T > txeo::Tensor< T >::clone | ( | ) | const |
Returns a clone of this tensor.
|
protected |
T * txeo::Tensor< T >::data | ( | ) |
Acesses the raw data of this tensor.
const T * txeo::Tensor< T >::data | ( | ) | const |
Reads the raw data of this tensor.
size_t txeo::Tensor< T >::dim | ( | ) | const |
Returns the dimension of this tensor.
txeo::TensorIterator< T > txeo::Tensor< T >::end | ( | ) |
txeo::TensorIterator< const T > txeo::Tensor< T >::end | ( | ) | const |
void txeo::Tensor< T >::fill | ( | const T & | value | ) |
Fills this tensor with the specified value.
value | Value to fill this tensor |
|
protected |
Definition at line 1151 of file Tensor.h.
|
protected |
Definition at line 1135 of file Tensor.h.
void txeo::Tensor< T >::fill_with_uniform_random | ( | const T & | min, |
const T & | max | ||
) |
Fills the tensor with uniformly distributed random values ranging according to the specified interval.
T | The data type of the tensor elements. |
min | The minimum possible random value. |
max | The maximum possible random value. |
txeo::TensorError |
Example Usage:
void txeo::Tensor< T >::fill_with_uniform_random | ( | const T & | min, |
const T & | max, | ||
const size_t & | seed1, | ||
const size_t & | seed2 | ||
) |
Fills the tensor with uniformly distributed random values ranging according to the specified interval.
T | The data type of the tensor elements. |
min | The minimum possible random value. |
max | The maximum possible random value. |
seed1 | The first seed for random number generation (in order to enable reproducibility). |
seed2 | The second seed for random number generation (in order to enable reproducibility). |
txeo::TensorError |
Example Usage:
Tensor< T > txeo::Tensor< T >::flatten | ( | ) | const |
Returns a first order reshaped view of this tensor.
txeo::TensorError |
|
inline |
Compares the shape of this tensor with the shape of the specified tensor.
U | Data type of the specfied tensor |
other | The tensor to compare |
Example Usage:
Definition at line 519 of file Tensor.h.
size_t txeo::Tensor< T >::memory_size | ( | ) | const |
Returns the number of bytes occupied by this tensor.
|
inline |
bool txeo::Tensor< T >::operator!= | ( | const Tensor< T > & | tensor | ) |
T & txeo::Tensor< T >::operator() | ( | ) |
Accesses the value of this tensor if it is a scalar (order zero).
Since this function does not perform any checking, it accesses the first value of this tensor if it has order greater than zero.
const T & txeo::Tensor< T >::operator() | ( | ) | const |
Reads the value of this tensor if it is a scalar (order zero).
|
inline |
Accesses an element of this tensor according to the specified indexes.
Args | A variadic list of indices that must be convertible to size_t . |
args | The indices specifying the position of the element. |
Example Usage:
Definition at line 1077 of file Tensor.h.
|
inline |
Reads an element of this tensor according to the specified indexes.
Args | A variadic list of indices that must be convertible to size_t . |
args | The indices specifying the position of the element. |
Example Usage:
Definition at line 1092 of file Tensor.h.
Tensor< T > & txeo::Tensor< T >::operator*= | ( | const T & | scalar | ) |
Tensor< T > & txeo::Tensor< T >::operator+= | ( | const T & | tensor | ) |
Tensor< T > & txeo::Tensor< T >::operator+= | ( | const Tensor< T > & | tensor | ) |
Tensor< T > & txeo::Tensor< T >::operator-= | ( | const T & | tensor | ) |
Tensor< T > & txeo::Tensor< T >::operator-= | ( | const Tensor< T > & | tensor | ) |
Tensor< T > & txeo::Tensor< T >::operator/= | ( | const T & | scalar | ) |
Tensor< T > & txeo::Tensor< T >::operator= | ( | const T & | value | ) |
Assigns a specified value to this tensor elements.
value | Value to be assigned |
Tensor & txeo::Tensor< T >::operator= | ( | const Tensor< T > & | tensor | ) |
|
noexcept |
bool txeo::Tensor< T >::operator== | ( | const Tensor< T > & | tensor | ) |
int txeo::Tensor< T >::order | ( | ) | const |
Returns the order of this tensor.
|
inline |
Reshapes this tensor if the specified shape vector defines a number of elements equal to this tensor order.
shape | New shape vector for this tensor |
txeo::TensorError |
Example Usage:
Definition at line 756 of file Tensor.h.
void txeo::Tensor< T >::reshape | ( | const std::vector< size_t > & | shape | ) |
Reshapes this tensor if the specified shape vector defines a number of elements equal to this tensor order.
shape | New shape vector for this tensor |
txeo::TensorError |
Example Usage:
void txeo::Tensor< T >::reshape | ( | const txeo::TensorShape & | shape | ) |
Reshapes this tensor if the specified shape defines a number of elements equal to this tensor order.
shape | New shape for this tensor |
txeo::TensorError |
Example Usage:
const txeo::TensorShape & txeo::Tensor< T >::shape | ( | ) | const |
Returns the shape of this tensor.
void txeo::Tensor< T >::shuffle | ( | ) |
Shuffles the elements of this tensor.
Tensor< T > txeo::Tensor< T >::slice | ( | size_t | first_axis_begin, |
size_t | first_axis_end | ||
) | const |
Returns a view ot this tensor from a specified range of dimensions of the first axis.
This function creates a new tensor that views the content of this tensor according to the specified parameters. There is no element copying.
first_axis_begin | Initial index along the first axis (inclusive). |
first_axis_end | Final index along the first axis (exclusive). |
Example Usage:
void txeo::Tensor< T >::squeeze | ( | ) |
Reshapes this tensor by removing all the axes of dimension one.
Example Usage:
|
constexpr |
Returns the data type of this tensor.
void txeo::Tensor< T >::view_of | ( | const Tensor< T > & | tensor, |
const txeo::TensorShape & | shape | ||
) |
Views the content of the specified tensor according to the specified shape. There is no element copying.
tensor | Viewed tensor |
shape | New shape of this tensor |
|
friend |
Returns the scalar multiplication of a tensor.
U | type of the tensor involved |
tensor | Operand to be multiplied |
scalar | Operand that multiplies |
Example Usage:
|
friend |
Returns the sum of two tensors.
U | type of the tensors involved |
left | Left operand |
right | Right operand |
txeo::TensorOpError |
Example Usage:
|
friend |
|
friend |
Returns the subtraction of two tensors.
U | type of the tensors involved |
left | Left operand |
right | Right operand |
txeo::TensorOpError |
Example Usage:
|
friend |
Element-wise tensor-scalar addition operator.
U | Numeric type of tensor elements |
left | Input tensor |
right | Scalar to add |
Example Usage:
|
friend |
Element-wise scalar-tensor subtraction operator.
U | Numeric type of tensor elements |
left | Scalar value |
right | Input tensor |
Example Usage:
|
friend |
Element-wise division operator (tensor / scalar)
left | Input tensor |
right | Divisor value |
Example Usage:
|
friend |
Element-wise scalar-tensor division operator.
U | Numeric type of tensor elements |
left | Scalar dividend |
right | Tensor divisor |
Example Usage:
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
protected |