Txeo v0.1
A Developer-Friendly TensorFlow C++ Wrapper
Loading...
Searching...
No Matches
txeo::Vector< T > Class Template Reference

A class representing a vector, derived from Tensor. More...

#include <Vector.h>

Inheritance diagram for txeo::Vector< T >:
Inheritance graph
Collaboration diagram for txeo::Vector< T >:
Collaboration graph

Public Member Functions

 ~Vector ()=default
 
 Vector (const Vector &Vector)
 
 Vector (Vector &&Vector) noexcept
 
Vectoroperator= (const Vector &Vector)
 
Vectoroperator= (Vector &&Vector) noexcept
 
 Vector (size_t dim)
 Constructs a vector with the specified dimension.
 
 Vector (size_t dim, const T &fill_value)
 Constructs a vector with the specified dimension and fill value.
 
 Vector (size_t dim, const std::vector< T > &values)
 Constructs a vector with the specified dimension and values.
 
 Vector (size_t dim, const std::initializer_list< T > &values)
 Constructs a vector with the specified dimension and initializer list.
 
 Vector (const std::initializer_list< T > &values)
 Constructs a vector from an initializer list.
 
 Vector (txeo::Tensor< T > &&tensor)
 Constructs a vector by moving data from a Tensor.
 
void reshape (const txeo::TensorShape &shape)
 
void reshape (const std::vector< size_t > &shape)
 
void reshape (const std::initializer_list< size_t > &shape)
 
- Public Member Functions inherited from txeo::Tensor< T >
 Tensor (const Tensor &tensor)
 
 Tensor (Tensor &&tensor) noexcept
 
 ~Tensor ()
 
Tensoroperator= (const Tensor &tensor)
 
Tensoroperator= (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::TensorShapeshape () 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
 

Static Public Member Functions

static Vector< T > to_vector (txeo::Tensor< T > &&tensor)
 Converts a tensor to a vector by moving data.
 
static Vector< T > to_vector (const txeo::Tensor< T > &tensor)
 Creates a vector from a tensor (performs copy).
 
static txeo::Tensor< T > to_tensor (Vector< T > &&vector)
 Converts a vector to a tensor by moving data.
 
static txeo::Tensor< T > to_tensor (const Vector< T > &vector)
 Creates a tensor from a vector (performs copy).
 

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
 

Additional Inherited Members

- Protected Member Functions inherited from txeo::Tensor< T >
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 inherited from txeo::Tensor< T >
std::unique_ptr< Impl > _impl {nullptr}
 

Detailed Description

template<typename T>
class txeo::Vector< T >

A class representing a vector, derived from Tensor.

This class provides constructors for creating vectors with various initialization methods. It inherits from txeo::Tensor<T> and specializes it for order one data.

Template Parameters
TThe data type of the vector elements (e.g., int, double).

Definition at line 42 of file Vector.h.

Constructor & Destructor Documentation

◆ ~Vector()

template<typename T >
txeo::Vector< T >::~Vector ( )
default

◆ Vector() [1/8]

template<typename T >
txeo::Vector< T >::Vector ( const Vector< T > &  Vector)
inline

Definition at line 46 of file Vector.h.

Implements the mathematical concept of tensor, which is a magnitude of multiple order....
Definition Tensor.h:48
Vector(const Vector &Vector)
Definition Vector.h:46

◆ Vector() [2/8]

template<typename T >
txeo::Vector< T >::Vector ( Vector< T > &&  Vector)
inlinenoexcept

Definition at line 47 of file Vector.h.

47: txeo::Tensor<T>{std::move(Vector)} {};

◆ Vector() [3/8]

template<typename T >
txeo::Vector< T >::Vector ( size_t  dim)
inlineexplicit

Constructs a vector with the specified dimension.

Parameters
dimThe dimension (size) of the vector.

Example Usage:

txeo::Vector<int> vector(3); // Creates a vector of size 3
A class representing a vector, derived from Tensor.
Definition Vector.h:42

Definition at line 70 of file Vector.h.

size_t dim() const
Returns the dimension of this tensor.
The shape of a tensor is an ordered collection of dimensions of mathematical vector spaces.
Definition TensorShape.h:30
Here is the call graph for this function:

◆ Vector() [4/8]

template<typename T >
txeo::Vector< T >::Vector ( size_t  dim,
const T &  fill_value 
)
inlineexplicit

Constructs a vector with the specified dimension and fill value.

Parameters
dimThe dimension (size) of the vector.
fill_valueThe value to fill the vector with.

Example Usage:

txeo::Vector<int> vector(3, 5); // Creates a vector of size 3 filled with 5

Definition at line 83 of file Vector.h.

83: txeo::Tensor<T>({dim}, fill_value) {};
Here is the call graph for this function:

◆ Vector() [5/8]

template<typename T >
txeo::Vector< T >::Vector ( size_t  dim,
const std::vector< T > &  values 
)
inlineexplicit

Constructs a vector with the specified dimension and values.

Parameters
dimThe dimension (size) of the vector.
valuesThe values to initialize the vector with.

Example Usage:

txeo::Vector<int> vector(3, {1, 2, 3}); // Creates a vector of size 3 with values [1, 2, 3]

Definition at line 96 of file Vector.h.

96: txeo::Tensor<T>({dim}, values) {};
Here is the call graph for this function:

◆ Vector() [6/8]

template<typename T >
txeo::Vector< T >::Vector ( size_t  dim,
const std::initializer_list< T > &  values 
)
inlineexplicit

Constructs a vector with the specified dimension and initializer list.

Parameters
dimThe dimension (size) of the vector.
valuesThe values to initialize the vector with.

Example Usage:

txeo::Vector<int> vector(3, {1, 2, 3}); // Creates a vector of size 3 with values [1, 2, 3]

Definition at line 109 of file Vector.h.

110 : txeo::Tensor<T>({dim}, std::vector<T>(values)) {};
Here is the call graph for this function:

◆ Vector() [7/8]

template<typename T >
txeo::Vector< T >::Vector ( const std::initializer_list< T > &  values)
inlineexplicit

Constructs a vector from an initializer list.

Parameters
valuesThe values to initialize the vector with.

Example Usage:

txeo::Vector<int> vector({1, 2, 3}); // Creates a vector of size 3 with values [1, 2, 3]

Definition at line 122 of file Vector.h.

123 : txeo::Tensor<T>({values.size()}, std::vector<T>(values)) {};

◆ Vector() [8/8]

template<typename T >
txeo::Vector< T >::Vector ( txeo::Tensor< T > &&  tensor)
explicit

Constructs a vector by moving data from a Tensor.

Parameters
tensorThe Tensor to move data from.

Example Usage:

txeo::Tensor<int> tensor({3}, {1, 2, 3});
txeo::Vector<int> vector(std::move(tensor)); // Moves data from tensor to vector

Member Function Documentation

◆ operator=() [1/2]

template<typename T >
Vector & txeo::Vector< T >::operator= ( const Vector< T > &  Vector)
inline

Definition at line 49 of file Vector.h.

49 {
51 return *this;
52 };
Tensor & operator=(const Tensor &tensor)
Here is the call graph for this function:

◆ operator=() [2/2]

template<typename T >
Vector & txeo::Vector< T >::operator= ( Vector< T > &&  Vector)
inlinenoexcept

Definition at line 54 of file Vector.h.

54 {
55 txeo::Tensor<T>::operator=(std::move(Vector));
56 return *this;
57 };
Here is the call graph for this function:

◆ reshape() [1/3]

template<typename T >
void txeo::Vector< T >::reshape ( const std::initializer_list< size_t > &  shape)
inline

Definition at line 142 of file Vector.h.

142 {
143 this->reshape(std::vector<size_t>(shape));
144 };
const txeo::TensorShape & shape() const
Returns the shape of this tensor.
void reshape(const txeo::TensorShape &shape)
Here is the call graph for this function:

◆ reshape() [2/3]

template<typename T >
void txeo::Vector< T >::reshape ( const std::vector< size_t > &  shape)
inline

Definition at line 140 of file Vector.h.

140{ this->reshape(txeo::TensorShape(shape)); };
Here is the call graph for this function:
Here is the caller graph for this function:

◆ reshape() [3/3]

template<typename T >
void txeo::Vector< T >::reshape ( const txeo::TensorShape shape)
Here is the caller graph for this function:

◆ to_tensor() [1/2]

template<typename T >
static txeo::Tensor< T > txeo::Vector< T >::to_tensor ( const Vector< T > &  vector)
static

Creates a tensor from a vector (performs copy).

Parameters
vectorThe input vector to copy.
Returns
A tensor created from the input vector.

Example Usage:

txeo::Vector<int> vector({1, 2, 3, 4}); // Vector with 4 elements
auto tensor = Vector<int>::to_tensor(vector); // Convert to tensor
// tensor shape: (4)
static txeo::Tensor< T > to_tensor(Vector< T > &&vector)
Converts a vector to a tensor by moving data.

◆ to_tensor() [2/2]

template<typename T >
static txeo::Tensor< T > txeo::Vector< T >::to_tensor ( Vector< T > &&  vector)
static

Converts a vector to a tensor by moving data.

Parameters
vectorThe input vector to convert.
Returns
A tensor created from the input vector.

Example Usage:

txeo::Vector<int> vector({1, 2, 3, 4}); // Vector with 4 elements
auto tensor = Vector<int>::to_tensor(std::move(vector)); // Convert to tensor
// tensor shape: (4)

◆ to_vector() [1/2]

template<typename T >
static Vector< T > txeo::Vector< T >::to_vector ( const txeo::Tensor< T > &  tensor)
static

Creates a vector from a tensor (performs copy).

Parameters
tensorThe input tensor to copy. Must be first order.
Returns
A vector created from the input tensor.
Exceptions
std::VectorError.

Example Usage:

txeo::Tensor<int> tensor({4}, {1, 2, 3, 4}); // 1D tensor with shape (4)
auto vector = Vector<int>::to_vector(tensor); // Convert to vector
// vector contains [1, 2, 3, 4]
static Vector< T > to_vector(txeo::Tensor< T > &&tensor)
Converts a tensor to a vector by moving data.

◆ to_vector() [2/2]

template<typename T >
static Vector< T > txeo::Vector< T >::to_vector ( txeo::Tensor< T > &&  tensor)
static

Converts a tensor to a vector by moving data.

This function moves the data from the input tensor to a new vector.

Parameters
tensorThe input tensor to convert. Must be 1-dimensional.
Returns
A vector created from the input tensor.
Exceptions
std::VectorErrorif the tensor is not 1-dimensional.

Example Usage:

txeo::Tensor<int> tensor({4}, {1, 2, 3, 4}); // 1D tensor with shape (4)
auto vector = Vector<int>::to_vector(std::move(tensor)); // Convert to vector
// vector contains [1, 2, 3, 4]

Friends And Related Symbol Documentation

◆ txeo::detail::TensorHelper

template<typename T >
friend class txeo::detail::TensorHelper
friend

Definition at line 220 of file Vector.h.

◆ txeo::Predictor< T >

template<typename T >
friend class txeo::Predictor< T >
friend

Definition at line 213 of file Vector.h.

◆ txeo::TensorAgg< T >

template<typename T >
friend class txeo::TensorAgg< T >
friend

Definition at line 213 of file Vector.h.

◆ txeo::TensorFunc< T >

template<typename T >
friend class txeo::TensorFunc< T >
friend

Definition at line 213 of file Vector.h.

◆ txeo::TensorOp< T >

template<typename T >
friend class txeo::TensorOp< T >
friend

Definition at line 213 of file Vector.h.

◆ txeo::TensorPart< T >

template<typename T >
friend class txeo::TensorPart< T >
friend

Definition at line 213 of file Vector.h.


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