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

A utility class for aggregation functions on tensors. More...

#include <TensorAgg.h>

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

Public Member Functions

 TensorAgg (const TensorAgg &)=delete
 
 TensorAgg (TensorAgg &&)=delete
 
TensorAggoperator= (const TensorAgg &)=delete
 
TensorAggoperator= (TensorAgg &&)=delete
 
 ~TensorAgg ()=default
 

Static Public Member Functions

static txeo::Tensor< T > reduce_sum (const txeo::Tensor< T > &tensor, const std::vector< size_t > &axes)
 Computes the sum of tensor elements along the specified axes.
 
static txeo::Tensor< T > reduce_prod (const txeo::Tensor< T > &tensor, const std::vector< size_t > &axes)
 Computes the product of tensor elements along the specified axes.
 
static txeo::Tensor< T > reduce_mean (const txeo::Tensor< T > &tensor, const std::vector< size_t > &axes)
 Computes the mean of tensor elements along the specified axes.
 
static txeo::Tensor< T > reduce_max (const txeo::Tensor< T > &tensor, const std::vector< size_t > &axes)
 Computes the maximum of tensor elements along the specified axes.
 
static txeo::Tensor< T > reduce_min (const txeo::Tensor< T > &tensor, const std::vector< size_t > &axes)
 Computes the minimum of tensor elements along the specified axes.
 
static txeo::Tensor< T > reduce_euclidean_norm (const txeo::Tensor< T > &tensor, const std::vector< size_t > &axes)
 Computes the Euclidean norm of tensor elements along the specified axes.
 
static txeo::Tensor< T > reduce_maximum_norm (const txeo::Tensor< T > &tensor, size_t axis)
 Computes the maximum norm of tensor elements along the specified axis.
 
static txeo::Tensor< T > reduce_variance (const txeo::Tensor< T > &tensor, size_t axis)
 Computes the variance of tensor elements along the specified axis.
 
static txeo::Tensor< T > reduce_standard_deviation (const txeo::Tensor< T > &tensor, size_t axis)
 Computes the standard deviation of tensor elements along the specified axis.
 
static txeo::Tensor< T > reduce_median (const txeo::Tensor< T > &tensor, size_t axis)
 Computes the median of tensor elements along the specified axis.
 
static txeo::Tensor< T > reduce_geometric_mean (const txeo::Tensor< T > &tensor, size_t axis)
 Computes the geometric mean of tensor elements along the specified axis.
 
static txeo::Tensor< T > reduce_all (const txeo::Tensor< T > &tensor, const std::vector< size_t > &axes)
 Computes the logical AND (all) of tensor elements along the specified axes.
 
static txeo::Tensor< T > reduce_any (const txeo::Tensor< T > &tensor, const std::vector< size_t > &axes)
 Computes the logical OR (any) of tensor elements along the specified axes.
 
static txeo::Tensor< T > cumulative_sum (const txeo::Tensor< T > &tensor, size_t axis)
 Computes the cumulative sum of tensor elements along the specified axis.
 
static txeo::Tensor< T > cumulative_prod (const txeo::Tensor< T > &tensor, size_t axis)
 Computes the cumulative product of tensor elements along the specified axis.
 
static txeo::Tensor< size_t > arg_max (const txeo::Tensor< T > &tensor, size_t axis)
 Finds the indices of the maximum values along the specified axis.
 
static txeo::Tensor< size_t > arg_min (const txeo::Tensor< T > &tensor, size_t axis)
 Finds the indices of the minimum values along the specified axis.
 
static txeo::Tensor< size_t > count_non_zero (const txeo::Tensor< T > &tensor, size_t axis)
 Counts the number of non-zero elements along the specified axis.
 
static T sum_all (const txeo::Tensor< T > &tensor)
 Computes the sum of all elements in the tensor.
 

Detailed Description

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

A utility class for aggregation functions on tensors.

This class provides static methods for aggregation functions on tensors, such reduce_mean.

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

Definition at line 22 of file TensorAgg.h.

Constructor & Destructor Documentation

◆ TensorAgg() [1/2]

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

◆ TensorAgg() [2/2]

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

◆ ~TensorAgg()

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

Member Function Documentation

◆ arg_max()

template<typename T >
static txeo::Tensor< size_t > txeo::TensorAgg< T >::arg_max ( const txeo::Tensor< T > &  tensor,
size_t  axis 
)
static

Finds the indices of the maximum values along the specified axis.

Parameters
tensorThe input tensor.
axisThe axis along which to find the maximum indices.
Returns
A new tensor containing the indices of the maximum values along the specified axis.

Example Usage:

txeo::Tensor<int> tensor({2, 3}, {1, 2, 3, 4, 5, 6});
auto result = TensorAgg<int>::arg_max(tensor, 1);
// result = [2, 2] (indices of max values along axis 1)
static txeo::Tensor< size_t > arg_max(const txeo::Tensor< T > &tensor, size_t axis)
Finds the indices of the maximum values along the specified axis.
Implements the mathematical concept of tensor, which is a magnitude of multiple order....
Definition Tensor.h:48

◆ arg_min()

template<typename T >
static txeo::Tensor< size_t > txeo::TensorAgg< T >::arg_min ( const txeo::Tensor< T > &  tensor,
size_t  axis 
)
static

Finds the indices of the minimum values along the specified axis.

Parameters
tensorThe input tensor.
axisThe axis along which to find the minimum indices.
Returns
A new tensor containing the indices of the minimum values along the specified axis.

Example Usage:

txeo::Tensor<int> tensor({2, 3}, {1, 2, 3, 4, 5, 6});
auto result = TensorAgg<int>::arg_min(tensor, 1);
// result = [0, 0] (indices of min values along axis 1)
static txeo::Tensor< size_t > arg_min(const txeo::Tensor< T > &tensor, size_t axis)
Finds the indices of the minimum values along the specified axis.

◆ count_non_zero()

template<typename T >
static txeo::Tensor< size_t > txeo::TensorAgg< T >::count_non_zero ( const txeo::Tensor< T > &  tensor,
size_t  axis 
)
static

Counts the number of non-zero elements along the specified axis.

Parameters
tensorThe input tensor.
axisThe axis along which to count non-zero elements.
Returns
A new tensor containing the count of non-zero elements along the specified axis.

Example Usage:

txeo::Tensor<int> tensor({2, 3}, {1, 0, 3, 0, 5, 0});
auto result = TensorAgg<int>::count_non_zero(tensor, 1);
// result = [2, 1] (count of non-zero elements along axis 1)
static txeo::Tensor< size_t > count_non_zero(const txeo::Tensor< T > &tensor, size_t axis)
Counts the number of non-zero elements along the specified axis.

◆ cumulative_prod()

template<typename T >
static txeo::Tensor< T > txeo::TensorAgg< T >::cumulative_prod ( const txeo::Tensor< T > &  tensor,
size_t  axis 
)
static

Computes the cumulative product of tensor elements along the specified axis.

Parameters
tensorThe input tensor.
axisThe axis along which to compute the cumulative product.
Returns
A new tensor containing the cumulative product along the specified axis.

Example Usage:

txeo::Tensor<int> tensor({2, 3}, {1, 2, 3, 4, 5, 6});
auto result = TensorAgg<int>::cumulative_prod(tensor, 1);
// result = [ [1, 2, 6], [4, 20, 120] ] (cumulative product along axis 1)
static txeo::Tensor< T > cumulative_prod(const txeo::Tensor< T > &tensor, size_t axis)
Computes the cumulative product of tensor elements along the specified axis.

◆ cumulative_sum()

template<typename T >
static txeo::Tensor< T > txeo::TensorAgg< T >::cumulative_sum ( const txeo::Tensor< T > &  tensor,
size_t  axis 
)
static

Computes the cumulative sum of tensor elements along the specified axis.

Parameters
tensorThe input tensor.
axisThe axis along which to compute the cumulative sum.
Returns
A new tensor containing the cumulative sum along the specified axis.

Example Usage:

txeo::Tensor<int> tensor({2, 3}, {1, 2, 3, 4, 5, 6});
auto result = TensorAgg<int>::cumulative_sum(tensor, 1);
// result = [ [1, 3, 6], [4, 9, 15] ] (cumulative sum along axis 1)
static txeo::Tensor< T > cumulative_sum(const txeo::Tensor< T > &tensor, size_t axis)
Computes the cumulative sum of tensor elements along the specified axis.

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ reduce_all()

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

Computes the logical AND (all) of tensor elements along the specified axes.

Parameters
tensorThe input tensor.
axesThe axes along which to compute the logical AND.
Returns
A new tensor containing the logical AND along the specified axes.

Example Usage:

txeo::Tensor<bool> tensor({2, 3}, {true, false, true, true, true, false});
auto result = TensorAgg<bool>::reduce_all(tensor, {1});
// result = [false, false] (logical AND along axis 1)
static txeo::Tensor< T > reduce_all(const txeo::Tensor< T > &tensor, const std::vector< size_t > &axes)
Computes the logical AND (all) of tensor elements along the specified axes.

◆ reduce_any()

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

Computes the logical OR (any) of tensor elements along the specified axes.

Parameters
tensorThe input tensor.
axesThe axes along which to compute the logical OR.
Returns
A new tensor containing the logical OR along the specified axes.

Example Usage:

txeo::Tensor<bool> tensor({2, 3}, {true, false, true, true, true, false});
auto result = TensorAgg<bool>::reduce_any(tensor, {1});
// result = [true, true] (logical OR along axis 1)
static txeo::Tensor< T > reduce_any(const txeo::Tensor< T > &tensor, const std::vector< size_t > &axes)
Computes the logical OR (any) of tensor elements along the specified axes.

◆ reduce_euclidean_norm()

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

Computes the Euclidean norm of tensor elements along the specified axes.

Parameters
tensorThe input tensor.
axesThe axes along which to compute the Euclidean norm.
Returns
A new tensor containing the Euclidean norm along the specified axes.

Example Usage:

txeo::Tensor<double> tensor({2, 3}, {1.0, 2.0, 3.0, 4.0, 5.0, 6.0});
auto result = TensorAgg<double>::reduce_euclidean_norm(tensor, {1});
// result = [sqrt(1^2 + 2^2 + 3^2), sqrt(4^2 + 5^2 + 6^2)] = [3.74166, 8.77496]
static txeo::Tensor< T > reduce_euclidean_norm(const txeo::Tensor< T > &tensor, const std::vector< size_t > &axes)
Computes the Euclidean norm of tensor elements along the specified axes.

◆ reduce_geometric_mean()

template<typename T >
static txeo::Tensor< T > txeo::TensorAgg< T >::reduce_geometric_mean ( const txeo::Tensor< T > &  tensor,
size_t  axis 
)
static

Computes the geometric mean of tensor elements along the specified axis.

Parameters
tensorThe input tensor.
axisThe axis along which to compute the geometric mean.
Returns
A new tensor containing the geometric mean along the specified axis.

Example Usage:

txeo::Tensor<double> tensor({2, 3}, {1.0, 2.0, 3.0, 4.0, 5.0, 6.0});
// result = [1.81712, 4.93242] (geometric mean along axis 1)
static txeo::Tensor< T > reduce_geometric_mean(const txeo::Tensor< T > &tensor, size_t axis)
Computes the geometric mean of tensor elements along the specified axis.

◆ reduce_max()

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

Computes the maximum of tensor elements along the specified axes.

Parameters
tensorThe input tensor.
axesThe axes along which to compute the maximum.
Returns
A new tensor containing the maximum along the specified axes.

Example Usage:

txeo::Tensor<int> tensor({2, 3}, {1, 2, 3, 4, 5, 6});
auto result = TensorAgg<int>::reduce_max(tensor, {1});
// result = [3, 6] (max along axis 1)
static txeo::Tensor< T > reduce_max(const txeo::Tensor< T > &tensor, const std::vector< size_t > &axes)
Computes the maximum of tensor elements along the specified axes.

◆ reduce_maximum_norm()

template<typename T >
static txeo::Tensor< T > txeo::TensorAgg< T >::reduce_maximum_norm ( const txeo::Tensor< T > &  tensor,
size_t  axis 
)
static

Computes the maximum norm of tensor elements along the specified axis.

Parameters
tensorThe input tensor.
axisThe axis along which to compute the maximum norm.
Returns
A new tensor containing the maximum norm along the specified axis.

Example Usage:

txeo::Tensor<int> tensor({2, 3}, {1, -2, 3, -4, 5, -6});
auto result = TensorAgg<int>::reduce_maximum_norm(tensor, 1);
// result = [3, 6] (max norm along axis 1)
static txeo::Tensor< T > reduce_maximum_norm(const txeo::Tensor< T > &tensor, size_t axis)
Computes the maximum norm of tensor elements along the specified axis.

◆ reduce_mean()

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

Computes the mean of tensor elements along the specified axes.

Parameters
tensorThe input tensor.
axesThe axes along which to compute the mean.
Returns
A new tensor containing the mean along the specified axes.

Example Usage:

txeo::Tensor<double> tensor({2, 3}, {1.0, 2.0, 3.0, 4.0, 5.0, 6.0});
auto result = TensorAgg<double>::reduce_mean(tensor, {1});
// result = [2.0, 5.0] (mean along axis 1)
static txeo::Tensor< T > reduce_mean(const txeo::Tensor< T > &tensor, const std::vector< size_t > &axes)
Computes the mean of tensor elements along the specified axes.

◆ reduce_median()

template<typename T >
static txeo::Tensor< T > txeo::TensorAgg< T >::reduce_median ( const txeo::Tensor< T > &  tensor,
size_t  axis 
)
static

Computes the median of tensor elements along the specified axis.

Parameters
tensorThe input tensor.
axisThe axis along which to compute the median.
Returns
A new tensor containing the median along the specified axis.

Example Usage:

txeo::Tensor<int> tensor({2, 3}, {1, 2, 3, 4, 5, 6});
auto result = TensorAgg<int>::reduce_median(tensor, 1);
// result = [2, 5] (median along axis 1)
static txeo::Tensor< T > reduce_median(const txeo::Tensor< T > &tensor, size_t axis)
Computes the median of tensor elements along the specified axis.

◆ reduce_min()

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

Computes the minimum of tensor elements along the specified axes.

Parameters
tensorThe input tensor.
axesThe axes along which to compute the minimum.
Returns
A new tensor containing the minimum along the specified axes.

Example Usage:

txeo::Tensor<int> tensor({2, 3}, {1, 2, 3, 4, 5, 6});
auto result = TensorAgg<int>::reduce_min(tensor, {1});
// result = [1, 4] (min along axis 1)
static txeo::Tensor< T > reduce_min(const txeo::Tensor< T > &tensor, const std::vector< size_t > &axes)
Computes the minimum of tensor elements along the specified axes.

◆ reduce_prod()

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

Computes the product of tensor elements along the specified axes.

Parameters
tensorThe input tensor.
axesThe axes along which to compute the product.
Returns
A new tensor containing the product along the specified axes.

Example Usage:

txeo::Tensor<int> tensor({2, 3}, {1, 2, 3, 4, 5, 6});
auto result = TensorAgg<int>::reduce_prod(tensor, {1});
// result = [6, 120] (product along axis 1)
static txeo::Tensor< T > reduce_prod(const txeo::Tensor< T > &tensor, const std::vector< size_t > &axes)
Computes the product of tensor elements along the specified axes.

◆ reduce_standard_deviation()

template<typename T >
static txeo::Tensor< T > txeo::TensorAgg< T >::reduce_standard_deviation ( const txeo::Tensor< T > &  tensor,
size_t  axis 
)
static

Computes the standard deviation of tensor elements along the specified axis.

Parameters
tensorThe input tensor.
axisThe axis along which to compute the standard deviation.
Returns
A new tensor containing the standard deviation along the specified axis.

Example Usage:

txeo::Tensor<double> tensor({2, 3}, {1.0, 2.0, 3.0, 4.0, 5.0, 6.0});
// result = [1.0, 1.0] (standard deviation along axis 1)
static txeo::Tensor< T > reduce_standard_deviation(const txeo::Tensor< T > &tensor, size_t axis)
Computes the standard deviation of tensor elements along the specified axis.

◆ reduce_sum()

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

Computes the sum of tensor elements along the specified axes.

Parameters
tensorThe input tensor.
axesThe axes along which to compute the sum.
Returns
A new tensor containing the sum along the specified axes.

Example Usage:

txeo::Tensor<int> tensor({2, 3}, {1, 2, 3, 4, 5, 6});
auto result = TensorAgg<int>::reduce_sum(tensor, {1});
// result = [6, 15] (sum along axis 1)
static txeo::Tensor< T > reduce_sum(const txeo::Tensor< T > &tensor, const std::vector< size_t > &axes)
Computes the sum of tensor elements along the specified axes.

◆ reduce_variance()

template<typename T >
static txeo::Tensor< T > txeo::TensorAgg< T >::reduce_variance ( const txeo::Tensor< T > &  tensor,
size_t  axis 
)
static

Computes the variance of tensor elements along the specified axis.

Parameters
tensorThe input tensor.
axisThe axis along which to compute the variance.
Returns
A new tensor containing the variance along the specified axis.

Example Usage:

txeo::Tensor<double> tensor({2, 3}, {1.0, 2.0, 3.0, 4.0, 5.0, 6.0});
auto result = TensorAgg<double>::reduce_variance(tensor, 1);
// result = [1.0, 1.0] (variance along axis 1)
static txeo::Tensor< T > reduce_variance(const txeo::Tensor< T > &tensor, size_t axis)
Computes the variance of tensor elements along the specified axis.

◆ sum_all()

template<typename T >
static T txeo::TensorAgg< T >::sum_all ( const txeo::Tensor< T > &  tensor)
static

Computes the sum of all elements in the tensor.

Parameters
tensorThe input tensor.
Returns
The sum of all elements in the tensor.

Example Usage:

txeo::Tensor<int> tensor({2, 3}, {1, 2, 3, 4, 5, 6});
auto result = TensorAgg<int>::sum_all(tensor);
// result = 21 (sum of all elements)
static T sum_all(const txeo::Tensor< T > &tensor)
Computes the sum of all elements in the tensor.

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