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 () | |
Tensor (const Tensor &tensor) | |
Tensor (Tensor &&tensor) noexcept | |
virtual | ~Tensor () |
Tensor & | operator= (const Tensor &tensor) |
Tensor & | operator= (Tensor &&tensor) noexcept |
bool | operator== (const Tensor &tensor) |
bool | operator!= (const Tensor &tensor) |
Tensor (txeo::TensorShape &&shape) | |
Constructs a Tensor from a specified txeo::TensorShape. | |
Tensor (const txeo::TensorShape &shape) | |
Constructs a tensor from a specified txeo::TensorShape. | |
Tensor (std::vector< size_t > &&shape) | |
Constructs a Tensor from a specified shape std::vector. | |
Tensor (const 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 (txeo::TensorShape &&shape, const T &fill_value) | |
Constructs a Tensor from a specified txeo::TensorShape and fills it with a value. | |
Tensor (const txeo::TensorShape &shape, const T &fill_value) | |
Constructs a Tensor from a specified txeo::TensorShape 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::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 > & | increase_dimension (size_t axis, T value) |
Increments the dimension of the specified axis. | |
Tensor< T > & | power (const T &exponent) |
Raises all tensor elements to the specified power. | |
Tensor< T > & | square () |
Squares all tensor elements in-place. | |
Tensor< T > & | sqrt () |
Computes square root of all tensor elements in-place. | |
Tensor< T > & | abs () |
Computes absolute value of all tensor elements in-place. | |
Tensor< T > & | permute (const std::vector< size_t > &axes) |
Permutes tensor dimensions according to specified axis order. | |
Tensor< T > & | normalize (size_t axis, txeo::NormalizationType type) |
Normalizes tensor along specified axis. | |
Tensor< T > & | normalize (txeo::NormalizationType type) |
Normalizes entire tensor. | |
T | inner (const Tensor< T > &tensor) const |
Computes inner product with another tensor. | |
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) |
Protected Attributes | |
std::unique_ptr< Impl > | _impl {nullptr} |
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.
|
explicit |
|
explicit |
Constructs a Tensor from a specified txeo::TensorShape.
shape | Shape of the constructed tensor |
Example Usage:
|
inlineexplicit |
Constructs a tensor from a specified txeo::TensorShape.
shape | Shape of the constructed tensor |
Example Usage:
Definition at line 113 of file Tensor.h.
|
explicit |
Constructs a Tensor from a specified shape std::vector.
shape | Vector of dimensions |
Example Usage:
|
inlineexplicit |
|
inlineexplicit |
Constructs a Tensor from a specified shape std::vector.
shape | Vector of dimensions |
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:
|
inlineexplicit |
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:
|
inlineexplicit |
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:
Computes absolute value of all tensor elements in-place.
Example Usage:
T & txeo::Tensor< T >::at | ( | ) |
Accesses the value of this tensor if it is a scalar (order zero).
txeo::TensorError |
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 1254 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 1269 of file Tensor.h.
txeo::TensorIterator< T > txeo::Tensor< T >::begin | ( | ) |
txeo::TensorIterator< const T > txeo::Tensor< T >::begin | ( | ) | const |
|
protected |
Returns a clone of this tensor.
|
protected |
T * txeo::Tensor< T >::data | ( | ) |
Acesses the raw data of this tensor.
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 |
Fills this tensor with the specified value.
value | Value to fill this tensor |
|
protected |
Definition at line 1298 of file Tensor.h.
|
protected |
Definition at line 1282 of file Tensor.h.
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:
Returns a first order reshaped view of this tensor.
txeo::TensorError |
Increments the dimension of the specified axis.
axis | Position where new dimension will be inserted |
value | Value to fill the new dimension elements with |
Example Usage:
Computes inner product with another tensor.
tensor | Right-hand operand for dot product |
TensorOpError |
Example Usage:
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 524 of file Tensor.h.
size_t txeo::Tensor< T >::memory_size | ( | ) | const |
Returns the number of bytes occupied by this tensor.
Tensor< T > & txeo::Tensor< T >::normalize | ( | size_t | axis, |
txeo::NormalizationType | type | ||
) |
Normalizes tensor along specified axis.
axis | Axis to normalize along |
type | Normalization type (MIN_MAX or Z_SCORE) |
Example Usage:
Tensor< T > & txeo::Tensor< T >::normalize | ( | txeo::NormalizationType | type | ) |
Normalizes entire tensor.
type | Normalization type (MIN_MAX or Z_SCORE) |
|
inline |
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.
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 1224 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 1239 of file Tensor.h.
Assigns a specified value to this tensor elements.
value | Value to be assigned |
int txeo::Tensor< T >::order | ( | ) | const |
Returns the order of this tensor.
Permutes tensor dimensions according to specified axis order.
axes | New axis order (must be valid permutation of existing axes) |
TensorFuncError | for invalid permutation |
Example Usage:
Raises all tensor elements to the specified power.
exponent | Power to raise elements to |
Example Usage:
|
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 761 of file Tensor.h.
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.
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:
Computes square root of all tensor elements in-place.
Example Usage:
Squares all tensor elements in-place.
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 |
|
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: