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

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

#include <Matrix.h>

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

Public Member Functions

 Matrix ()
 
 ~Matrix ()=default
 
 Matrix (const Matrix &matrix)
 
 Matrix (Matrix &&matrix) noexcept
 
Matrixoperator= (const Matrix &matrix)
 
Matrixoperator= (Matrix &&matrix) noexcept
 
 Matrix (size_t row_size, size_t col_size)
 Constructs a matrix with the specified row and column sizes.
 
 Matrix (size_t row_size, size_t col_size, const T &fill_value)
 Constructs a matrix with the specified row and column sizes and a fill value.
 
 Matrix (size_t row_size, size_t col_size, const std::vector< T > &values)
 Constructs a matrix with the specified row and column sizes and values.
 
 Matrix (size_t row_size, size_t col_size, const std::initializer_list< T > &values)
 Constructs a matrix with the specified row and column sizes and initializer list.
 
 Matrix (const std::initializer_list< std::initializer_list< T > > &values)
 Constructs a matrix from a nested initializer list.
 
 Matrix (txeo::Tensor< T > &&tensor)
 Constructs a matrix by moving data from a Tensor.
 
size_t size () const
 Returns the size of the matrix.
 
size_t row_size () const
 Returns the row size of the matrix.
 
size_t col_size () const
 Returns the column size of the matrix.
 
void normalize_columns (txeo::NormalizationType type)
 Normalizes matrix columns in-place using specified normalization method.
 
void normalize_rows (txeo::NormalizationType type)
 Normalizes matrix rows in-place using specified normalization method.
 
void reshape (const txeo::TensorShape &shape)
 
void reshape (const std::vector< size_t > &shape)
 
void reshape (const std::initializer_list< size_t > &shape)
 
Matrix< T > & transpose ()
 Transposes the matrix (swaps rows and columns) in-place.
 
Matrix< Tdot (const Matrix< T > &matrix) const
 Performs matrix multiplication with another matrix.
 
Tensor< Tdot (const txeo::Vector< T > &vector) const
 Performs matrix-vector multiplication.
 
Matrix< Tclone () const
 
- Public Member Functions inherited from txeo::Tensor< T >
 Tensor ()
 
 Tensor (const Tensor &tensor)
 
 Tensor (Tensor &&tensor) noexcept
 
virtual ~Tensor ()
 
Tensoroperator= (const Tensor &tensor)
 
Tensoroperator= (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::TensorShapeshape () const
 Returns the shape of this tensor.
 
constexpr std::type_identity_t< Ttype () 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< Tslice (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.
 
Toperator() ()
 Accesses the value of this tensor if it is a scalar (order zero).
 
template<typename... Args>
requires (std::convertible_to<Args, size_t> && ...)
Toperator() (Args... args)
 Accesses an element of this tensor according to the specified indexes.
 
Tat ()
 Accesses the value of this tensor if it is a scalar (order zero).
 
template<typename... Args>
requires (std::convertible_to<Args, size_t> && ...)
Tat (Args... args)
 Accesses an element of this tensor according to the specified indexes.
 
const Toperator() () 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 Toperator() (Args... args) const
 Reads an element of this tensor according to the specified indexes.
 
const Tat () 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 Tat (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< Tflatten () 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.
 
Tdata ()
 Acesses the raw data of this tensor.
 
const Tdata () const
 Reads the raw data of this tensor.
 
Tensor< Tclone () 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< Tbegin ()
 
txeo::TensorIterator< Tend ()
 
txeo::TensorIterator< const Tbegin () const
 
txeo::TensorIterator< const Tend () const
 

Static Public Member Functions

static Matrix< Tto_matrix (txeo::Tensor< T > &&tensor)
 Converts a tensor to a matrix by moving data.
 
static Matrix< Tto_matrix (const txeo::Tensor< T > &tensor)
 Creates a matrix from a tensor (preforms copy).
 
static txeo::Tensor< Tto_tensor (Matrix< T > &&matrix)
 Converts a matrix to a tensor by moving data.
 
static txeo::Tensor< Tto_tensor (const Matrix< T > &matrix)
 Creates a tensor from a matrix (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
 
template<typename U >
Matrix< Uoperator+ (const Matrix< U > &left, const Matrix< U > &right)
 
template<typename U >
Matrix< Uoperator+ (const Matrix< U > &left, const U &right)
 
template<typename U >
Matrix< Uoperator- (const Matrix< U > &left, const Matrix< U > &right)
 
template<typename U >
Matrix< Uoperator- (const Matrix< U > &left, const U &right)
 
template<typename U >
Matrix< Uoperator- (const U &left, const Matrix< U > &right)
 
template<typename U >
Matrix< Uoperator* (const Matrix< U > &matrix, const U &scalar)
 
template<typename U >
Matrix< Uoperator* (const U &scalar, const Matrix< U > &matrix)
 
template<typename U >
Matrix< Uoperator/ (const Matrix< U > &left, const U &right)
 
template<typename U >
Matrix< Uoperator/ (const U &left, const Matrix< U > &right)
 

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)
 
- Protected Attributes inherited from txeo::Tensor< T >
std::unique_ptr< Impl_impl {nullptr}
 

Detailed Description

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

A class representing a matrix, derived from Tensor.

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

Template Parameters
TThe data type of the matrix elements (e.g., int, double).
Examples
/opt/build/repo/include/txeo/DataTable.h.

Definition at line 46 of file Matrix.h.

Constructor & Destructor Documentation

◆ Matrix() [1/9]

template<typename T >
txeo::Matrix< T >::Matrix ( )
explicit

◆ ~Matrix()

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

◆ Matrix() [2/9]

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

Definition at line 51 of file Matrix.h.

51: txeo::Tensor<T>{matrix} {};
A container for managing training, evaluation, and test data splits.
Definition DataTable.h:24

◆ Matrix() [3/9]

template<typename T >
txeo::Matrix< T >::Matrix ( Matrix< T > &&  matrix)
inlinenoexcept

Definition at line 52 of file Matrix.h.

52: txeo::Tensor<T>{std::move(matrix)} {};

◆ Matrix() [4/9]

template<typename T >
txeo::Matrix< T >::Matrix ( size_t  row_size,
size_t  col_size 
)
inlineexplicit

Constructs a matrix with the specified row and column sizes.

This constructor creates a matrix of the specified row and column sizes, with uninitialized elements.

Parameters
row_sizeThe number of rows in the matrix.
col_sizeThe number of columns in the matrix.
txeo::Matrix<int> matrix(2, 3); // Creates a 2x3 matrix

Definition at line 77 of file Matrix.h.

size_t row_size() const
Returns the row size of the matrix.
Definition Matrix.h:178
size_t col_size() const
Returns the column size of the matrix.
Definition Matrix.h:191
The shape of a tensor is an ordered collection of dimensions of mathematical vector spaces.
Definition TensorShape.h:31
Here is the call graph for this function:

◆ Matrix() [5/9]

template<typename T >
txeo::Matrix< T >::Matrix ( size_t  row_size,
size_t  col_size,
const T fill_value 
)
inlineexplicit

Constructs a matrix with the specified row and column sizes and a fill value.

Parameters
row_sizeThe number of rows in the matrix.
col_sizeThe number of columns in the matrix.
fill_valueThe value to fill the matrix with.

Example Usage:

txeo::Matrix<int> matrix(2, 3, 5); // Creates a 2x3 matrix filled with 5

Definition at line 92 of file Matrix.h.

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

◆ Matrix() [6/9]

template<typename T >
txeo::Matrix< T >::Matrix ( size_t  row_size,
size_t  col_size,
const std::vector< T > &  values 
)
inlineexplicit

Constructs a matrix with the specified row and column sizes and values.

Parameters
row_sizeThe number of rows in the matrix.
col_sizeThe number of columns in the matrix.
valuesThe values to initialize the matrix with.

Example Usage:

txeo::Matrix<int> matrix(2, 3, {1, 2, 3, 4, 5, 6}); // Creates a 2x3 matrix with values [1,
2, 3, 4, 5, 6]

Definition at line 108 of file Matrix.h.

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

◆ Matrix() [7/9]

template<typename T >
txeo::Matrix< T >::Matrix ( size_t  row_size,
size_t  col_size,
const std::initializer_list< T > &  values 
)
inlineexplicit

Constructs a matrix with the specified row and column sizes and initializer list.

Parameters
row_sizeThe number of rows in the matrix.
col_sizeThe number of columns in the matrix.
valuesThe values to initialize the matrix with.

Example Usage:

txeo::Matrix<int> matrix(2, 3, {1, 2, 3, 4, 5, 6}); // Creates a 2x3 matrix with values [1,
2, 3, 4, 5, 6]

Definition at line 124 of file Matrix.h.

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

◆ Matrix() [8/9]

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

Constructs a matrix from a nested initializer list.

Parameters
valuesThe values to initialize the matrix with.

Example Usage:

txeo::Matrix<int> matrix({{1, 2, 3}, {4, 5, 6}});
// Creates a 2x3 matrix with values [1, 2, 3, 4, 5, 6]

Definition at line 138 of file Matrix.h.

139 : txeo::Tensor<T>(values) {};

◆ Matrix() [9/9]

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

Constructs a matrix by moving data from a Tensor.

Parameters
tensorThe Tensor to move data from.

Example Usage:

txeo::Tensor<int> tensor({2, 3}, {1, 2, 3, 4, 5, 6});
txeo::Matrix<int> matrix(std::move(tensor)); // Moves data from tensor to matrix

Member Function Documentation

◆ clone()

template<typename T >
Matrix< T > txeo::Matrix< T >::clone ( ) const

◆ col_size()

template<typename T >
size_t txeo::Matrix< T >::col_size ( ) const
inline

Returns the column size of the matrix.

Returns
The number of columns in the matrix.

Example Usage:

size_t size = matrix.col_size(); // size = 3
size_t size() const
Returns the size of the matrix.
Definition Matrix.h:165

Definition at line 191 of file Matrix.h.

191{ return this->shape().axis_dim(1); };
const txeo::TensorShape & shape() const
Returns the shape of this tensor.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dot() [1/2]

template<typename T >
Matrix< T > txeo::Matrix< T >::dot ( const Matrix< T > &  matrix) const

Performs matrix multiplication with another matrix.

Parameters
matrixThe right-hand side matrix for multiplication
Returns
New matrix resulting from the matrix product
Exceptions
MatrixError

Example Usage:

// Matrix-matrix multiplication
txeo::Matrix<int> a(2, 3, {1, 2, 3, 4, 5, 6}); // 2x3
txeo::Matrix<int> b(3, 2, {7, 8, 9, 10, 11, 12}); // 3x2
txeo::Matrix<int> c = a.dot(b); // Resulting 2x2 matrix:
// [58, 64]
// [139, 154]
// Identity matrix multiplication
txeo::Matrix<double> identity(2, 2, {1, 0, 0, 1});
txeo::Matrix<double> mat(2, 3, {5, 6, 7, 8, 9, 10});
auto result = identity.dot(mat); // Returns unchanged mat

◆ dot() [2/2]

template<typename T >
Tensor< T > txeo::Matrix< T >::dot ( const txeo::Vector< T > &  vector) const

Performs matrix-vector multiplication.

Parameters
vectorThe right-hand side vector for multiplication
Returns
New tensor (n x 1) resulting from the product
Exceptions
MatrixErrorif dimensions are incompatible

Example Usage:

// Matrix-vector multiplication
txeo::Matrix<int> mat(2, 3, {1, 2, 3, 4, 5, 6});
txeo::Tensor<int> result = mat.dot(vec); // Result: [[50][122]]

◆ normalize_columns()

template<typename T >
void txeo::Matrix< T >::normalize_columns ( txeo::NormalizationType  type)

Normalizes matrix columns in-place using specified normalization method.

Parameters
typeNormalization type to apply (MIN_MAX or Z_SCORE)

Example Usage:

// Example: Min-max normalize columns
Matrix<double> mat({{10.0, 20.0}, // Column 1: [10, 30]
{30.0, 40.0}}); // Column 2: [20, 40]
mat.normalize_columns(txeo::NormalizationType::MIN_MAX);
// Column 1 becomes [0.0, 1.0]
// Column 2 becomes [0.0, 1.0]
// Example: Z-score normalize columns
Matrix<float> m({{1.0f, 4.0f}, // Column 1: μ=2.0, σ=1.414
{3.0f, 6.0f}}); // Column 2: μ=5.0, σ=1.414
m.normalize_columns(txeo::NormalizationType::Z_SCORE);
// Column 1 becomes [-0.707, 0.707]
// Column 2 becomes [-0.707, 0.707]

◆ normalize_rows()

template<typename T >
void txeo::Matrix< T >::normalize_rows ( txeo::NormalizationType  type)

Normalizes matrix rows in-place using specified normalization method.

Parameters
typeNormalization type to apply (MIN_MAX or Z_SCORE)

Example Usage:

// Example: Min-max normalize rows
Matrix<double> mat({{10.0, 20.0, 30.0}, // Row 1: [10, 20, 30]
{5.0, 10.0, 15.0}}); // Row 2: [5, 10, 15]
// Row 1 becomes [0.0, 0.5, 1.0]
// Row 2 becomes [0.0, 0.5, 1.0]
// Example: Z-score normalize rows
Matrix<float> m({{2.0f, 4.0f}, // Row 1: μ=3.0, σ=1.414
{6.0f, 8.0f}}); // Row 2: μ=7.0, σ=1.414
// Row 1 becomes [-0.707, 0.707]
// Row 2 becomes [-0.707, 0.707]

◆ operator=() [1/2]

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

Definition at line 54 of file Matrix.h.

54 {
56 return *this;
57 };
Tensor & operator=(const Tensor &tensor)
Here is the call graph for this function:

◆ operator=() [2/2]

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

Definition at line 59 of file Matrix.h.

59 {
60 txeo::Tensor<T>::operator=(std::move(matrix));
61 return *this;
62 };
Here is the call graph for this function:

◆ reshape() [1/3]

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

Definition at line 243 of file Matrix.h.

243 {
244 this->reshape(std::vector<size_t>(shape));
245 };
void reshape(const txeo::TensorShape &shape)
Here is the call graph for this function:

◆ reshape() [2/3]

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

Definition at line 241 of file Matrix.h.

241{ 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::Matrix< T >::reshape ( const txeo::TensorShape shape)
Here is the caller graph for this function:

◆ row_size()

template<typename T >
size_t txeo::Matrix< T >::row_size ( ) const
inline

Returns the row size of the matrix.

Returns
The number of rows in the matrix.

Example Usage:

size_t size = matrix.row_size(); // size = 2
size_t row_size() const
Returns the number of training rows.

Definition at line 178 of file Matrix.h.

178{ return this->shape().axis_dim(0); };
Here is the call graph for this function:
Here is the caller graph for this function:

◆ size()

template<typename T >
size_t txeo::Matrix< T >::size ( ) const
inline

Returns the size of the matrix.

Returns
The total number of elements in the matrix.

Example Usage:

size_t size = matrix.size(); // size = 6

Definition at line 165 of file Matrix.h.

165{ return txeo::Tensor<T>::dim(); };
size_t dim() const
Returns the dimension of this tensor.
Here is the call graph for this function:

◆ to_matrix() [1/2]

template<typename T >
static Matrix< T > txeo::Matrix< T >::to_matrix ( const txeo::Tensor< T > &  tensor)
static

Creates a matrix from a tensor (preforms copy).

Parameters
tensorThe input tensor to copied. Must be 2-dimensional.
Returns
A matrix created from the input tensor.
Exceptions
std::MatrixError

Example Usage:

txeo::Tensor<int> tensor({2, 3}, {1, 2, 3, 4, 5, 6}); // 2D tensor with shape (2, 3)
auto matrix = Matrix<int>::to_matrix(std::move(tensor)); //
// matrix shape: (2, 3)
static Matrix< T > to_matrix(txeo::Tensor< T > &&tensor)
Converts a tensor to a matrix by moving data.

◆ to_matrix() [2/2]

template<typename T >
static Matrix< T > txeo::Matrix< T >::to_matrix ( txeo::Tensor< T > &&  tensor)
static

Converts a tensor to a matrix by moving data.

Parameters
tensorThe input tensor to convert. Must be 2-dimensional.
Returns
A matrix created from the input tensor.
Exceptions
std::MatrixError

Example Usage:

txeo::Tensor<int> tensor({2, 3}, {1, 2, 3, 4, 5, 6}); // 2D tensor with shape (2, 3)
auto matrix = Matrix<int>::to_matrix(std::move(tensor)); // Convert to matrix
// matrix shape: (2, 3)

◆ to_tensor() [1/2]

template<typename T >
static txeo::Tensor< T > txeo::Matrix< T >::to_tensor ( const Matrix< T > &  matrix)
static

Creates a tensor from a matrix (performs copy).

Parameters
matrixThe input matrix to copy. Must be second order.
Returns
A tensor created from the input matrix.
Exceptions
std::MatrixError

Example Usage:

txeo::Matrix<int> matrix(2, 3, {1, 2, 3, 4, 5, 6}); // 2x3 matrix
auto tensor = Matrix<int>::to_tensor(matrix); // Convert to tensor
// tensor shape: (2, 3)
static txeo::Tensor< T > to_tensor(Matrix< T > &&matrix)
Converts a matrix to a tensor by moving data.

◆ to_tensor() [2/2]

template<typename T >
static txeo::Tensor< T > txeo::Matrix< T >::to_tensor ( Matrix< T > &&  matrix)
static

Converts a matrix to a tensor by moving data.

Parameters
matrixThe input matrix to convert. Must be second order.
Returns
A tensor created from the input matrix.
Exceptions
std::MatrixError

Example Usage:

txeo::Matrix<int> matrix(2, 3, {1, 2, 3, 4, 5, 6}); // 2x3 matrix
auto tensor = Matrix<int>::to_tensor(std::move(matrix)); // Convert to tensor
// tensor shape: (2, 3)

◆ transpose()

template<typename T >
Matrix< T > & txeo::Matrix< T >::transpose ( )

Transposes the matrix (swaps rows and columns) in-place.

Returns
Reference to this matrix

Example Usage:

// Transpose a 2x3 matrix
txeo::Matrix<int> mat(2, 3, {1, 2, 3, 4, 5, 6});
mat.transpose();
// mat becomes 3x2 matrix:
// [1, 4]
// [2, 5]
// [3, 6]
// Transpose a square matrix
txeo::Matrix<double> square_mat({{1.5, 2.5}, {3.5, 4.5}});
square_mat.transpose();
// Result:
// [1.5, 3.5]
// [2.5, 4.5]

Friends And Related Symbol Documentation

◆ operator* [1/2]

template<typename T >
template<typename U >
Matrix< U > operator* ( const Matrix< U > &  matrix,
const U scalar 
)
friend

◆ operator* [2/2]

template<typename T >
template<typename U >
Matrix< U > operator* ( const U scalar,
const Matrix< U > &  matrix 
)
friend

◆ operator+ [1/2]

template<typename T >
template<typename U >
Matrix< U > operator+ ( const Matrix< U > &  left,
const Matrix< U > &  right 
)
friend

◆ operator+ [2/2]

template<typename T >
template<typename U >
Matrix< U > operator+ ( const Matrix< U > &  left,
const U right 
)
friend

◆ operator- [1/3]

template<typename T >
template<typename U >
Matrix< U > operator- ( const Matrix< U > &  left,
const Matrix< U > &  right 
)
friend

◆ operator- [2/3]

template<typename T >
template<typename U >
Matrix< U > operator- ( const Matrix< U > &  left,
const U right 
)
friend

◆ operator- [3/3]

template<typename T >
template<typename U >
Matrix< U > operator- ( const U left,
const Matrix< U > &  right 
)
friend

◆ operator/ [1/2]

template<typename T >
template<typename U >
Matrix< U > operator/ ( const Matrix< U > &  left,
const U right 
)
friend

◆ operator/ [2/2]

template<typename T >
template<typename U >
Matrix< U > operator/ ( const U left,
const Matrix< U > &  right 
)
friend

◆ txeo::detail::TensorHelper

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

Definition at line 414 of file Matrix.h.

◆ txeo::Predictor< T >

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

Definition at line 406 of file Matrix.h.

◆ txeo::TensorAgg< T >

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

Definition at line 406 of file Matrix.h.

◆ txeo::TensorFunc< T >

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

Definition at line 406 of file Matrix.h.

◆ txeo::TensorOp< T >

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

Definition at line 406 of file Matrix.h.

◆ txeo::TensorPart< T >

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

Definition at line 406 of file Matrix.h.


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