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

A utility class for common math functions on tensors. More...

#include <TensorFunc.h>

Collaboration diagram for txeo::TensorFunc< T >:
Collaboration graph

Public Member Functions

 TensorFunc (const TensorFunc &)=delete
 
 TensorFunc (TensorFunc &&)=delete
 
TensorFuncoperator= (const TensorFunc &)=default
 
TensorFuncoperator= (TensorFunc &&)=delete
 
 ~TensorFunc ()=default
 

Static Public Member Functions

static txeo::Tensor< T > power_elem (const txeo::Tensor< T > &tensor, const T &exponent)
 Returns the element-wise potentiation of a tensor.
 
static txeo::Tensor< T > power_elem_by (txeo::Tensor< T > &tensor, const T &exponent)
 Performs element-wise potentiation of the tensor (in-place)
 
static txeo::Tensor< T > square (const txeo::Tensor< T > &tensor)
 Computes the element-wise square of a tensor.
 
static txeo::Tensor< T > & square_by (txeo::Tensor< T > &tensor)
 Computes the element-wise square of a tensor in-place.
 
static txeo::Tensor< T > sqrt (const txeo::Tensor< T > &tensor)
 Computes the element-wise square root of a tensor.
 
static txeo::Tensor< T > & sqrt_by (txeo::Tensor< T > &tensor)
 Computes the element-wise square root of a tensor in-place.
 
static txeo::Tensor< T > abs (const txeo::Tensor< T > &tensor)
 Computes the element-wise absolute value of a tensor.
 
static txeo::Tensor< T > & abs_by (txeo::Tensor< T > &tensor)
 Computes the element-wise absolute value of a tensor in-place.
 
static txeo::Tensor< T > permute (const txeo::Tensor< T > &tensor, const std::vector< size_t > &axes)
 Permutes the axes of a tensor.
 
static txeo::Tensor< T > & permute_by (txeo::Tensor< T > &tensor, const std::vector< size_t > &axes)
 Permutes the axes of a tensor in-place.
 
static txeo::Matrix< T > transpose (const txeo::Matrix< T > &matrix)
 Transposes a matrix.
 
static txeo::Matrix< T > & transpose_by (txeo::Matrix< T > &matrix)
 Transposes a matrix in-place.
 

Detailed Description

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

A utility class for common math functions on tensors.

This class provides static methods for common tensor functions, such as square.

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

Definition at line 23 of file TensorFunc.h.

Constructor & Destructor Documentation

◆ TensorFunc() [1/2]

template<typename T >
txeo::TensorFunc< T >::TensorFunc ( const TensorFunc< T > &  )
delete

◆ TensorFunc() [2/2]

template<typename T >
txeo::TensorFunc< T >::TensorFunc ( TensorFunc< T > &&  )
delete

◆ ~TensorFunc()

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

Member Function Documentation

◆ abs()

template<typename T >
static txeo::Tensor< T > txeo::TensorFunc< T >::abs ( const txeo::Tensor< T > &  tensor)
static

Computes the element-wise absolute value of a tensor.

Parameters
tensorThe input tensor to be modified.

Example Usage:

txeo::Tensor<int> tensor({3}, {-1, 2, -3});
TensorOp<int>::abs_by(tensor);
// tensor = [1, 2, 3]
Implements the mathematical concept of tensor, which is a magnitude of multiple order....
Definition Tensor.h:48

◆ abs_by()

template<typename T >
static txeo::Tensor< T > & txeo::TensorFunc< T >::abs_by ( txeo::Tensor< T > &  tensor)
static

Computes the element-wise absolute value of a tensor in-place.

Parameters
tensorThe input tensor to be modified.

Example Usage:

txeo::Tensor<int> tensor({3}, {-1, 2, -3});
TensorOp<int>::abs_by(tensor);
// tensor = [1, 2, 3]

◆ operator=() [1/2]

template<typename T >
TensorFunc & txeo::TensorFunc< T >::operator= ( const TensorFunc< T > &  )
default

◆ operator=() [2/2]

template<typename T >
TensorFunc & txeo::TensorFunc< T >::operator= ( TensorFunc< T > &&  )
delete

◆ permute()

template<typename T >
static txeo::Tensor< T > txeo::TensorFunc< T >::permute ( const txeo::Tensor< T > &  tensor,
const std::vector< size_t > &  axes 
)
static

Permutes the axes of a tensor.

Parameters
tensorThe input tensor.
axesThe new order of the tensor axes. Must be a valid permutation of the tensor's dimensions.
Returns
A new tensor with the axes permuted.
Exceptions
std::invalid_argumentIf the axes are invalid (e.g., size mismatch or out of range).

Example Usage:

txeo::Tensor<int> tensor({2, 3, 4}, {
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24
});
// The new postion of axis 1 is zero, of axis 2 is one and of axis zero is 2
auto result = TensorFunc<int>::permute(tensor, {1, 2, 0});
// result shape: (3, 4, 2)
static txeo::Tensor< T > permute(const txeo::Tensor< T > &tensor, const std::vector< size_t > &axes)
Permutes the axes of a tensor.

◆ permute_by()

template<typename T >
static txeo::Tensor< T > & txeo::TensorFunc< T >::permute_by ( txeo::Tensor< T > &  tensor,
const std::vector< size_t > &  axes 
)
static

Permutes the axes of a tensor in-place.

Parameters
tensorThe input tensor to be modified.
axesThe new order of axes. Must be a valid permutation of the tensor's dimensions.
Returns
A reference to the modified tensor.
Exceptions
std::invalid_argumentIf the axes are invalid (e.g., size mismatch or out of range).

Example Usage:

txeo::Tensor<int> tensor({2, 3, 4}, {
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24
});
// The new postion of axis 1 is zero, of axis 2 is one and of axis zero is 2
TensorFunc<int>::permute_by(tensor, {1, 2, 0});
// tensor shape after permutation: (3, 4, 2)
static txeo::Tensor< T > & permute_by(txeo::Tensor< T > &tensor, const std::vector< size_t > &axes)
Permutes the axes of a tensor in-place.

◆ power_elem()

template<typename T >
static txeo::Tensor< T > txeo::TensorFunc< T >::power_elem ( const txeo::Tensor< T > &  tensor,
const T &  exponent 
)
static

Returns the element-wise potentiation of a tensor.

Parameters
tensorTensor to be powered
exponentExponent of the potentiation
Returns
txeo::Tensor<T> Result

Example Usage:

txeo::Tensor<float> a({3}, {2.0f, 3.0f, 4.0f});
auto b = TensorOp<float>::power_elem(a, 2.0f); // Result: [4.0f, 9.0f, 16.0f]

◆ power_elem_by()

template<typename T >
static txeo::Tensor< T > txeo::TensorFunc< T >::power_elem_by ( txeo::Tensor< T > &  tensor,
const T &  exponent 
)
static

Performs element-wise potentiation of the tensor (in-place)

Parameters
tensorTensor to be modified
exponentExponent of the potentiation

Example Usage:

txeo::Tensor<double> a({2}, {3.0, 4.0});
TensorOp<double>::power_elem_by(a, 3.0); // a becomes [27.0, 64.0]

◆ sqrt()

template<typename T >
static txeo::Tensor< T > txeo::TensorFunc< T >::sqrt ( const txeo::Tensor< T > &  tensor)
static

Computes the element-wise square root of a tensor.

Parameters
tensorThe input tensor.
Returns
A new tensor containing the square root values.

Example Usage:

txeo::Tensor<double> tensor({3}, {1.0, 4.0, 9.0});
auto result = TensorOp<double>::sqrt(tensor);
// result = [1.0, 2.0, 3.0]

◆ sqrt_by()

template<typename T >
static txeo::Tensor< T > & txeo::TensorFunc< T >::sqrt_by ( txeo::Tensor< T > &  tensor)
static

Computes the element-wise square root of a tensor in-place.

Parameters
tensorThe input tensor to be modified.

Example Usage:

txeo::Tensor<double> tensor({3}, {1.0, 4.0, 9.0});
TensorOp<double>::sqrt_by(tensor);
// tensor = [1.0, 2.0, 3.0]

◆ square()

template<typename T >
static txeo::Tensor< T > txeo::TensorFunc< T >::square ( const txeo::Tensor< T > &  tensor)
static

Computes the element-wise square of a tensor.

Parameters
tensorThe input tensor.
Returns
A new tensor containing the squared values.

Example Usage:

txeo::Tensor<int> tensor({3}, {1, 2, 3});
auto result = TensorOp<int>::square(tensor);
// result = [1, 4, 9]

◆ square_by()

template<typename T >
static txeo::Tensor< T > & txeo::TensorFunc< T >::square_by ( txeo::Tensor< T > &  tensor)
static

Computes the element-wise square of a tensor in-place.

Parameters
tensorThe input tensor to be modified.

Example Usage:

txeo::Tensor<int> tensor({3}, {1, 2, 3});
TensorOp<int>::square_by(tensor);
// tensor = [1, 4, 9]

◆ transpose()

template<typename T >
static txeo::Matrix< T > txeo::TensorFunc< T >::transpose ( const txeo::Matrix< T > &  matrix)
static

Transposes a matrix.

Parameters
matrixThe input matrix.
Returns
A new matrix that is the transpose of the input matrix.

Example Usage:

txeo::Matrix<int> matrix(2, 3, {1, 2, 3, 4, 5, 6});
auto result = TensorFunc<int>::transpose(matrix);
// result shape: (3, 2)
A class representing a matrix, derived from Tensor.
Definition Matrix.h:42
static txeo::Matrix< T > transpose(const txeo::Matrix< T > &matrix)
Transposes a matrix.

◆ transpose_by()

template<typename T >
static txeo::Matrix< T > & txeo::TensorFunc< T >::transpose_by ( txeo::Matrix< T > &  matrix)
static

Transposes a matrix in-place.

Parameters
matrixThe input matrix to be modified.
Returns
A reference to the modified matrix.

Example Usage:

txeo::Matrix<int> matrix(2, 3, {1, 2, 3, 4, 5, 6});
// matrix shape after transpose: (3, 2)
static txeo::Matrix< T > & transpose_by(txeo::Matrix< T > &matrix)
Transposes a matrix in-place.

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