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

A utility class for performing operations on tensors and vectors. More...

#include <TensorOp.h>

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

Public Member Functions

 TensorOp (const TensorOp &)=delete
 
 TensorOp (TensorOp &&)=delete
 
TensorOpoperator= (const TensorOp &)=delete
 
TensorOpoperator= (TensorOp &&)=delete
 
 ~TensorOp ()=default
 

Static Public Member Functions

static txeo::Tensor< T > sum (const txeo::Tensor< T > &left, const txeo::Tensor< T > &right)
 Returns the sum of two tensors.
 
static txeo::Tensor< T > & sum_by (txeo::Tensor< T > &left, const txeo::Tensor< T > &right)
 Sums the left operand with the right operand (in-place)
 
static txeo::Tensor< T > sum (const txeo::Tensor< T > &left, const T &right)
 Element-wise sum of tensor and scalar (out-of-place)
 
static txeo::Tensor< T > & sum_by (txeo::Tensor< T > &left, const T &right)
 In-place element-wise addition of scalar to tensor.
 
static txeo::Tensor< T > subtract (const txeo::Tensor< T > &left, const txeo::Tensor< T > &right)
 Returns the subtraction of two tensors.
 
static txeo::Tensor< T > & subtract_by (txeo::Tensor< T > &left, const txeo::Tensor< T > &right)
 Subtracts the left operand by the right operand (in-place)
 
static txeo::Tensor< T > subtract (const txeo::Tensor< T > &left, const T &right)
 Element-wise subtraction of scalar from tensor (out-of-place)
 
static txeo::Tensor< T > & subtract_by (txeo::Tensor< T > &left, const T &right)
 In-place element-wise subtraction of scalar from tensor.
 
static txeo::Tensor< T > subtract (const T &left, const txeo::Tensor< T > &right)
 Element-wise subtraction of tensor from scalar (out-of-place)
 
static const T & subtract_by (const T &left, txeo::Tensor< T > &right)
 In-place element-wise subtraction of tensor from scalar.
 
static txeo::Tensor< T > multiply (const txeo::Tensor< T > &left, const T &right)
 Returns the multiplication of a tensor and a scalar.
 
static txeo::Tensor< T > & multiply_by (txeo::Tensor< T > &left, const T &right)
 Multiplies the tensor by a scalar (in-place)
 
static txeo::Tensor< T > divide (const txeo::Tensor< T > &left, const T &right)
 Element-wise division of tensor by scalar (out-of-place)
 
static txeo::Tensor< T > & divide_by (txeo::Tensor< T > &left, const T &right)
 In-place element-wise division of tensor by scalar.
 
static txeo::Tensor< T > divide (const T &left, const txeo::Tensor< T > &right)
 Element-wise division of scalar by tensor (out-of-place)
 
static txeo::Tensor< T > & divide_by (const T &scalar, txeo::Tensor< T > &tensor)
 In-place element-wise division of scalar by tensor elements.
 
static txeo::Tensor< T > hadamard_prod (const txeo::Tensor< T > &left, const txeo::Tensor< T > &right)
 Returns the element-wise product (Hadamard Product) of two tensors.
 
static txeo::Tensor< T > & hadamard_prod_by (txeo::Tensor< T > &left, const txeo::Tensor< T > &right)
 Performs element-wise multiplication of the left operand by the right operand (in-place)
 
static txeo::Tensor< T > hadamard_div (const txeo::Tensor< T > &left, const txeo::Tensor< T > &right)
 Element-wise Hadamard division (out-of-place)
 
static txeo::Tensor< T > & hadamard_div_by (txeo::Tensor< T > &left, const txeo::Tensor< T > &right)
 In-place element-wise Hadamard division.
 
static txeo::Matrix< T > product (const txeo::Matrix< T > &left, const txeo::Matrix< T > &right)
 Computes the matrix product of two matrices.
 
static T dot (const txeo::Vector< T > &left, const txeo::Vector< T > &right)
 Computes the dot product of two vectors.
 

Detailed Description

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

A utility class for performing operations on tensors and vectors.

This class provides static methods for common tensor and vector operations, such as dot product.

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

Definition at line 21 of file TensorOp.h.

Constructor & Destructor Documentation

◆ TensorOp() [1/2]

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

◆ TensorOp() [2/2]

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

◆ ~TensorOp()

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

Member Function Documentation

◆ divide() [1/2]

template<typename T >
static txeo::Tensor< T > txeo::TensorOp< T >::divide ( const T &  left,
const txeo::Tensor< T > &  right 
)
static

Element-wise division of scalar by tensor (out-of-place)

Parameters
leftScalar dividend
rightTensor divisor (shape NxMx...)
Returns
New tensor with same shape as input

Example Usage:

txeo::Tensor<int> A({3}, {2, 5, 10});
auto B = TensorOp<int>::divide(100, A);
// B contains [50, 20, 10], shape [3]
Implements the mathematical concept of tensor, which is a magnitude of multiple order....
Definition Tensor.h:48
static txeo::Tensor< T > divide(const txeo::Tensor< T > &left, const T &right)
Element-wise division of tensor by scalar (out-of-place)

◆ divide() [2/2]

template<typename T >
static txeo::Tensor< T > txeo::TensorOp< T >::divide ( const txeo::Tensor< T > &  left,
const T &  right 
)
static

Element-wise division of tensor by scalar (out-of-place)

Parameters
leftDividend tensor
rightScalar divisor
Returns
New tensor with division results

Example Usage:

txeo::Tensor<float> t({2, 2}, {10.0f, 20.0f, 30.0f, 40.0f});
auto result = TensorOp<float>::divide(t, 2.0f);
// result contains [5.0, 10.0, 15.0, 20.0]

◆ divide_by() [1/2]

template<typename T >
static txeo::Tensor< T > & txeo::TensorOp< T >::divide_by ( const T &  scalar,
txeo::Tensor< T > &  tensor 
)
static

In-place element-wise division of scalar by tensor elements.

Parameters
scalarScalar dividend
tensorTensor divisor (modified with results)

Example Usage:

txeo::Tensor<int> t({4}, {2, 5, 10, 25});
// t now contains [50, 20, 10, 4]
static txeo::Tensor< T > & divide_by(txeo::Tensor< T > &left, const T &right)
In-place element-wise division of tensor by scalar.

◆ divide_by() [2/2]

template<typename T >
static txeo::Tensor< T > & txeo::TensorOp< T >::divide_by ( txeo::Tensor< T > &  left,
const T &  right 
)
static

In-place element-wise division of tensor by scalar.

Parameters
leftTensor to modify (dividend)
rightScalar divisor

Example Usage:

txeo::Tensor<double> t({3}, {15.0, 30.0, 45.0});
// t now contains [5.0, 10.0, 15.0]

◆ dot()

template<typename T >
static T txeo::TensorOp< T >::dot ( const txeo::Vector< T > &  left,
const txeo::Vector< T > &  right 
)
static

Computes the dot product of two vectors.

Parameters
leftThe first vector.
rightThe second vector.
Returns
The dot product of the two vectors.
Exceptions
txeo::TensorOpError

Example Usage:

txeo::Vector<int> left({1, 2, 3}); // Vector [1, 2, 3]
txeo::Vector<int> right({4, 5, 6}); // Vector [4, 5, 6]
auto result = TensorOp<int>::dot(left, right);
// result = 1*4 + 2*5 + 3*6 = 32
static T dot(const txeo::Vector< T > &left, const txeo::Vector< T > &right)
Computes the dot product of two vectors.
A class representing a vector, derived from Tensor.
Definition Vector.h:42

◆ hadamard_div()

template<typename T >
static txeo::Tensor< T > txeo::TensorOp< T >::hadamard_div ( const txeo::Tensor< T > &  left,
const txeo::Tensor< T > &  right 
)
static

Element-wise Hadamard division (out-of-place)

Parameters
leftDividend tensor (shape NxMx...)
rightDivisor tensor (must match left's shape)
Returns
New tensor with same shape as inputs

Example Usage:

txeo::Tensor<float> A({2}, {10.0f, 20.0f});
txeo::Tensor<float> B({2}, {2.0f, 5.0f});
// C contains [5.0, 4.0], shape [2]
static txeo::Tensor< T > hadamard_div(const txeo::Tensor< T > &left, const txeo::Tensor< T > &right)
Element-wise Hadamard division (out-of-place)

◆ hadamard_div_by()

template<typename T >
static txeo::Tensor< T > & txeo::TensorOp< T >::hadamard_div_by ( txeo::Tensor< T > &  left,
const txeo::Tensor< T > &  right 
)
static

In-place element-wise Hadamard division.

Parameters
leftDividend tensor (modified with results)
rightDivisor tensor

Example Usage:

txeo::Tensor<float> a({3}, {10.0f, 20.0f, 30.0f});
txeo::Tensor<float> b({3}, {2.0f, 5.0f, 10.0f});
// a now contains [5.0, 4.0, 3.0]
static txeo::Tensor< T > & hadamard_div_by(txeo::Tensor< T > &left, const txeo::Tensor< T > &right)
In-place element-wise Hadamard division.

◆ hadamard_prod()

template<typename T >
static txeo::Tensor< T > txeo::TensorOp< T >::hadamard_prod ( const txeo::Tensor< T > &  left,
const txeo::Tensor< T > &  right 
)
static

Returns the element-wise product (Hadamard Product) of two tensors.

Parameters
leftLeft operand
rightRight operand
Returns
txeo::Tensor<T> Result
Exceptions
TensorOpErrorThrown if shapes mismatch

Example Usage:

txeo::Tensor<float> a({2,2}, {1.0f, 2.0f, 3.0f, 4.0f});
txeo::Tensor<float> b({2,2}, {2.0f, 3.0f, 4.0f, 5.0f});
auto c = TensorOp<float>::hadamard_prod(a, b); // Result: [[2,6],[12,20]]
static txeo::Tensor< T > hadamard_prod(const txeo::Tensor< T > &left, const txeo::Tensor< T > &right)
Returns the element-wise product (Hadamard Product) of two tensors.

◆ hadamard_prod_by()

template<typename T >
static txeo::Tensor< T > & txeo::TensorOp< T >::hadamard_prod_by ( txeo::Tensor< T > &  left,
const txeo::Tensor< T > &  right 
)
static

Performs element-wise multiplication of the left operand by the right operand (in-place)

Parameters
leftOperand to be modified
rightOperand to multiply with
Exceptions
TensorOpErrorThrown if shapes mismatch

Example Usage:

txeo::Tensor<double> a({3}, {2.0, 3.0, 4.0});
txeo::Tensor<double> b({3}, {5.0, 6.0, 7.0});
TensorOp<double>::hadamard_prod_by(a, b); // a becomes [10.0, 18.0, 28.0]
static txeo::Tensor< T > & hadamard_prod_by(txeo::Tensor< T > &left, const txeo::Tensor< T > &right)
Performs element-wise multiplication of the left operand by the right operand (in-place)

◆ multiply()

template<typename T >
static txeo::Tensor< T > txeo::TensorOp< T >::multiply ( const txeo::Tensor< T > &  left,
const T &  right 
)
static

Returns the multiplication of a tensor and a scalar.

Parameters
leftTensor operand
rightScalar multiplier
Returns
txeo::Tensor<T> Result

Example Usage:

txeo::Tensor<double> a({3}, {1.5, 2.5, 3.5});
auto b = TensorOp<double>::multiply(a, 2.0); // Result: [3.0, 5.0, 7.0]
static txeo::Tensor< T > multiply(const txeo::Tensor< T > &left, const T &right)
Returns the multiplication of a tensor and a scalar.

◆ multiply_by()

template<typename T >
static txeo::Tensor< T > & txeo::TensorOp< T >::multiply_by ( txeo::Tensor< T > &  left,
const T &  right 
)
static

Multiplies the tensor by a scalar (in-place)

Parameters
leftOperand to be modified
rightScalar multiplier

Example Usage:

txeo::Tensor<int> a({2,2}, {1, 2, 3, 4});
TensorOp<int>::multiply_by(a, 3); // a becomes [[3,6],[9,12]]
static txeo::Tensor< T > & multiply_by(txeo::Tensor< T > &left, const T &right)
Multiplies the tensor by a scalar (in-place)

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ product()

template<typename T >
static txeo::Matrix< T > txeo::TensorOp< T >::product ( const txeo::Matrix< T > &  left,
const txeo::Matrix< T > &  right 
)
static

Computes the matrix product of two matrices.

Parameters
leftThe left matrix (m x n).
rightThe right matrix (n x p).
Returns
A new matrix (m x p) containing the result of the matrix product.
Exceptions
txeo::TensorOpError

Example Usage:

txeo::Matrix<int> left(2, 3, {1, 2, 3, 4, 5, 6}); // 2x3 matrix
txeo::Matrix<int> right(3, 2, {7, 8, 9, 10, 11, 12}); // 3x2 matrix
auto result = TensorOp<int>::product(left, right);
// result = [ [58, 64], [139, 154] ]
A class representing a matrix, derived from Tensor.
Definition Matrix.h:42
static txeo::Matrix< T > product(const txeo::Matrix< T > &left, const txeo::Matrix< T > &right)
Computes the matrix product of two matrices.

◆ subtract() [1/3]

template<typename T >
static txeo::Tensor< T > txeo::TensorOp< T >::subtract ( const T &  left,
const txeo::Tensor< T > &  right 
)
static

Element-wise subtraction of tensor from scalar (out-of-place)

Parameters
leftScalar value
rightTensor to subtract
Returns
New tensor where each element = left - right[i]

Example Usage:

txeo::Tensor<double> t({2}, {1.5, 3.0});
auto result = TensorOp<double>::subtract(10.0, t);
// result contains [8.5, 7.0] with shape [2]
static txeo::Tensor< T > subtract(const txeo::Tensor< T > &left, const txeo::Tensor< T > &right)
Returns the subtraction of two tensors.

◆ subtract() [2/3]

template<typename T >
static txeo::Tensor< T > txeo::TensorOp< T >::subtract ( const txeo::Tensor< T > &  left,
const T &  right 
)
static

Element-wise subtraction of scalar from tensor (out-of-place)

Parameters
leftInput tensor (shape NxMx...)
rightScalar value to subtract
Returns
New tensor with same shape as input

Example Usage:

txeo::Tensor<int> A({2, 2}, {10, 20, 30, 40});
auto B = TensorOp<int>::subtract(A, 5);
// B contains [5, 15, 25, 35], shape [2,2]

◆ subtract() [3/3]

template<typename T >
static txeo::Tensor< T > txeo::TensorOp< T >::subtract ( const txeo::Tensor< T > &  left,
const txeo::Tensor< T > &  right 
)
static

Returns the subtraction of two tensors.

Parameters
leftLeft operand
rightRight operand
Returns
txeo::Tensor<T> Result
Exceptions
TensorOpErrorThrown if shapes mismatch

Example Usage:

txeo::Tensor<int> a({2}, {10, 20});
txeo::Tensor<int> b({2}, {3, 5});
auto c = TensorOp<int>::subtract(a, b); // Result: [7, 15]

◆ subtract_by() [1/3]

template<typename T >
static const T & txeo::TensorOp< T >::subtract_by ( const T &  left,
txeo::Tensor< T > &  right 
)
static

In-place element-wise subtraction of tensor from scalar.

Parameters
leftScalar value (minuend)
rightTensor to modify (subtrahend)

Example Usage:

txeo::Tensor<int> t({3}, {2, 3, 4});
// t now contains [8, 7, 6]
static txeo::Tensor< T > & subtract_by(txeo::Tensor< T > &left, const txeo::Tensor< T > &right)
Subtracts the left operand by the right operand (in-place)

◆ subtract_by() [2/3]

template<typename T >
static txeo::Tensor< T > & txeo::TensorOp< T >::subtract_by ( txeo::Tensor< T > &  left,
const T &  right 
)
static

In-place element-wise subtraction of scalar from tensor.

Parameters
leftTensor to modify
rightScalar to subtract

Example Usage:

txeo::Tensor<float> t({3}, {5.5f, 6.6f, 7.7f});
// t now contains [3.3, 4.4, 5.5]

◆ subtract_by() [3/3]

template<typename T >
static txeo::Tensor< T > & txeo::TensorOp< T >::subtract_by ( txeo::Tensor< T > &  left,
const txeo::Tensor< T > &  right 
)
static

Subtracts the left operand by the right operand (in-place)

Parameters
leftOperand to be modified
rightOperand to subtract
Exceptions
TensorOpErrorThrown if shapes mismatch

Example Usage:

txeo::Tensor<float> a({2,2}, {5.0f, 10.0f, 15.0f, 20.0f});
txeo::Tensor<float> b({2,2}, {1.0f, 2.0f, 3.0f, 4.0f});
TensorOp<float>::subtract_by(a, b); // a becomes [[4,8],[12,16]]

◆ sum() [1/2]

template<typename T >
static txeo::Tensor< T > txeo::TensorOp< T >::sum ( const txeo::Tensor< T > &  left,
const T &  right 
)
static

Element-wise sum of tensor and scalar (out-of-place)

Parameters
leftInput tensor (shape NxMx...)
rightScalar value to add
Returns
New tensor with same shape as input

Example Usage:

txeo::Tensor<float> A({3}, {1.0f, 2.0f, 3.0f});
auto B = TensorOp<float>::sum(A, 5.0f);
// B contains [6.0, 7.0, 8.0], shape [3]
static txeo::Tensor< T > sum(const txeo::Tensor< T > &left, const txeo::Tensor< T > &right)
Returns the sum of two tensors.

◆ sum() [2/2]

template<typename T >
static txeo::Tensor< T > txeo::TensorOp< T >::sum ( const txeo::Tensor< T > &  left,
const txeo::Tensor< T > &  right 
)
static

Returns the sum of two tensors.

Parameters
leftLeft operand
rightRight operand
Returns
txeo::Tensor<T> Result
Exceptions
TensorOpErrorThrown if shapes mismatch

Example Usage:

txeo::Tensor<float> a({2,2}, {1.0f, 2.0f, 3.0f, 4.0f});
txeo::Tensor<float> b({2,2}, {5.0f, 6.0f, 7.0f, 8.0f});
auto c = TensorOp<float>::sum(a, b); // Result: [[6,8],[10,12]]

◆ sum_by() [1/2]

template<typename T >
static txeo::Tensor< T > & txeo::TensorOp< T >::sum_by ( txeo::Tensor< T > &  left,
const T &  right 
)
static

In-place element-wise addition of scalar to tensor.

Parameters
leftTensor to modify
rightScalar to add

Example Usage:

txeo::Tensor<int> t({2, 2}, {1, 2, 3, 4});
// t now contains [6, 7, 8, 9] with shape [2,2]
static txeo::Tensor< T > & sum_by(txeo::Tensor< T > &left, const txeo::Tensor< T > &right)
Sums the left operand with the right operand (in-place)

◆ sum_by() [2/2]

template<typename T >
static txeo::Tensor< T > & txeo::TensorOp< T >::sum_by ( txeo::Tensor< T > &  left,
const txeo::Tensor< T > &  right 
)
static

Sums the left operand with the right operand (in-place)

Parameters
leftOperand to be modified
rightOperand to add
Exceptions
TensorOpErrorThrown if shapes mismatch

Example Usage:

txeo::Tensor<double> a({3}, {1.0, 2.0, 3.0});
txeo::Tensor<double> b({3}, {4.0, 5.0, 6.0});
TensorOp<double>::sum_by(a, b); // a becomes [5.0, 7.0, 9.0]

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