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

A utility class for partitioning tensors. More...

#include <TensorPart.h>

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

Public Member Functions

 TensorPart (const TensorPart &)=delete
 
 TensorPart (TensorPart &&)=delete
 
TensorPartoperator= (const TensorPart &)=delete
 
TensorPartoperator= (TensorPart &&)=delete
 
 ~TensorPart ()
 

Static Public Member Functions

static std::vector< txeo::Tensor< T > > unstack (const txeo::Tensor< T > &tensor, size_t axis)
 Unstacks a tensor along a specified axis into a list of tensors.
 
static txeo::Tensor< Tslice (const txeo::Tensor< T > &tensor, size_t first_axis_begin, size_t first_axis_end)
 Returns a view of the tensor from a specified range of dimensions of the first axis.
 
static txeo::Tensor< Tincrease_dimension (const txeo::Tensor< T > &tensor, size_t axis, T value)
 Increments the dimension of the tensor at the specified axis.
 
static txeo::Tensor< T > & increase_dimension_by (txeo::Tensor< T > &tensor, size_t axis, T value)
 Increments the dimension of the tensor at the specified axis (in-place)
 
static txeo::Matrix< Tsub_matrix_cols (const txeo::Matrix< T > &matrix, const std::vector< size_t > &cols)
 Creates a submatrix containing specified columns.
 
static txeo::Matrix< Tsub_matrix_cols_exclude (const txeo::Matrix< T > &matrix, const std::vector< size_t > &cols)
 Creates a submatrix excluding the specified columns.
 
static txeo::Matrix< Tsub_matrix_rows (const txeo::Matrix< T > &matrix, const std::vector< size_t > &rows)
 Creates a submatrix containing specified rows.
 

Detailed Description

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

A utility class for partitioning tensors.

This class provides static methods for operations such as unstacking tensors along a specified axis and slicing tensors along the first axis.

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

Definition at line 24 of file TensorPart.h.

Constructor & Destructor Documentation

◆ TensorPart() [1/2]

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

◆ TensorPart() [2/2]

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

◆ ~TensorPart()

template<typename T >
txeo::TensorPart< T >::~TensorPart ( )

Member Function Documentation

◆ increase_dimension()

template<typename T >
static txeo::Tensor< T > txeo::TensorPart< T >::increase_dimension ( const txeo::Tensor< T > &  tensor,
size_t  axis,
T  value 
)
static

Increments the dimension of the tensor at the specified axis.

Parameters
tensorTensor which elements will generate the modified tensor
axisPosition where new dimension will be inserted
valueValue to fill the new dimension elements with
Returns
A new modified modified tensor

Example Usage:

// Add new dimension to 2x3 matrix making it 2x1x3
txeo::Tensor<float> t({2, 3}, {1,2,3,4,5,6});
// New shape: [2, 4]
// resp(0,2) == -1.0f, resp(1,2) == -1.0f
A container for managing training, evaluation, and test data splits.
Definition DataTable.h:24
static txeo::Tensor< T > increase_dimension(const txeo::Tensor< T > &tensor, size_t axis, T value)
Increments the dimension of the tensor at the specified axis.

◆ increase_dimension_by()

template<typename T >
static txeo::Tensor< T > & txeo::TensorPart< T >::increase_dimension_by ( txeo::Tensor< T > &  tensor,
size_t  axis,
T  value 
)
static

Increments the dimension of the tensor at the specified axis (in-place)

Parameters
tensorTensor which shape will be altered
axisPosition where new dimension will be inserted
valueValue to fill the new dimension elements with
Returns
Reference to the modified tensor

Example Usage:

// Add new dimension to 2x3 matrix making it 2x1x3
txeo::Tensor<float> t({2, 3}, {1,2,3,4,5,6});
// New shape: [2, 4]
// t(0,2) == -1.0f, t(1,2) == -1.0f
static txeo::Tensor< T > & increase_dimension_by(txeo::Tensor< T > &tensor, size_t axis, T value)
Increments the dimension of the tensor at the specified axis (in-place)

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ slice()

template<typename T >
static txeo::Tensor< T > txeo::TensorPart< T >::slice ( const txeo::Tensor< T > &  tensor,
size_t  first_axis_begin,
size_t  first_axis_end 
)
static

Returns a view of the tensor from a specified range of dimensions of the first axis.

This function creates a new tensor that views the content of the tensor according to the specified parameters. There is no element copying.

Parameters
first_axis_beginInitial index along the first axis (inclusive).
first_axis_endFinal index along the first axis (exclusive).
Returns
Tensor<T>

Example Usage:

#include <iostream>
#include "txeo/Tensor.h"
int main() {
txeo::Tensor<int> tensor{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
txeo::Tensor<int> sliced_tensor = TensorPart::slice(tensor, 0, 2);
std::cout << "Sliced Tensor: " << sliced_tensor << std::endl; // {{1, 2}, {4, 5}, {7, 8}}
return 0;
}
static txeo::Tensor< T > slice(const txeo::Tensor< T > &tensor, size_t first_axis_begin, size_t first_axis_end)
Returns a view of the tensor from a specified range of dimensions of the first axis.

◆ sub_matrix_cols()

template<typename T >
static txeo::Matrix< T > txeo::TensorPart< T >::sub_matrix_cols ( const txeo::Matrix< T > &  matrix,
const std::vector< size_t > &  cols 
)
static

Creates a submatrix containing specified columns.

Parameters
matrixSource matrix
colsVector of column indices to select
Returns
New matrix with selected columns
Exceptions
TensorPartError

Example Usage:

txeo::Matrix<double> mat(2, 3, {1.1, 2.2, 3.3, 4.4, 5.5, 6.6});
// Resulting 2x2 matrix:
// [1.1, 3.3]
// [4.4, 6.6]
static txeo::Matrix< T > sub_matrix_cols(const txeo::Matrix< T > &matrix, const std::vector< size_t > &cols)
Creates a submatrix containing specified columns.

◆ sub_matrix_cols_exclude()

template<typename T >
static txeo::Matrix< T > txeo::TensorPart< T >::sub_matrix_cols_exclude ( const txeo::Matrix< T > &  matrix,
const std::vector< size_t > &  cols 
)
static

Creates a submatrix excluding the specified columns.

Parameters
matrixSource matrix
colsVector of column indices to exclude
Returns
New matrix with excluded columns
Exceptions
TensorPartError

Example Usage:

txeo::Matrix<double> mat(2, 3, {1.1, 2.2, 3.3, 4.4, 5.5, 6.6});
// Resulting 2x1 matrix:
// [2.2]
// [5.5]
static txeo::Matrix< T > sub_matrix_cols_exclude(const txeo::Matrix< T > &matrix, const std::vector< size_t > &cols)
Creates a submatrix excluding the specified columns.

◆ sub_matrix_rows()

template<typename T >
static txeo::Matrix< T > txeo::TensorPart< T >::sub_matrix_rows ( const txeo::Matrix< T > &  matrix,
const std::vector< size_t > &  rows 
)
static

Creates a submatrix containing specified rows.

Parameters
matrixSource matrix
rowsVector of row indices to select
Returns
New matrix with selected rows
Exceptions
TensorPartError

Example Usage:

txeo::Matrix<int> mat(3, 2, {1,2,3,4,5,6});
// Resulting 2x2 matrix:
// [5, 6]
// [1, 2]
static txeo::Matrix< T > sub_matrix_rows(const txeo::Matrix< T > &matrix, const std::vector< size_t > &rows)
Creates a submatrix containing specified rows.

◆ unstack()

template<typename T >
static std::vector< txeo::Tensor< T > > txeo::TensorPart< T >::unstack ( const txeo::Tensor< T > &  tensor,
size_t  axis 
)
static

Unstacks a tensor along a specified axis into a list of tensors.

Template Parameters
TThe data type of the tensor elements.
Parameters
tensorThe input tensor to unstack.
axisThe axis along which to unstack the tensor. Must be a valid axis for the input tensor.
Returns
std::vector<txeo::Tensor<T>> A list of tensors resulting from the unstack operation.
Exceptions
txeo::TensorPartError

Example Usage:

#include "txeo/Tensor.h"
#include <iostream>
int main() {
// Create a 3D tensor with shape (2, 2, 3)
txeo::Tensor<int> tensor({{{1, 2, 3}, {4, 5, 6}}, {{7, 8, 9}, {10, 11, 12}}});
// Unstack the tensor along axis 0
auto unstacked_tensors = txeo::TensorPart<int>::unstack(tensor, 0);
// Print the unstacked tensors
for (size_t i = 0; i < unstacked_tensors.size(); ++i) {
std::cout << "Unstacked Tensor " << i << ":\n" << unstacked_tensors[i] << std::endl;
}
return 0;
}
static std::vector< txeo::Tensor< T > > unstack(const txeo::Tensor< T > &tensor, size_t axis)
Unstacks a tensor along a specified axis into a list of tensors.

Output:

[[1 2 3]
[4 5 6]]
[[7 8 9]
[10 11 12]]
Implements the mathematical concept of tensor, which is a magnitude of multiple order....
Definition Tensor.h:50

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