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< 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.
 

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 19 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

◆ 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;
}
Implements the mathematical concept of tensor, which is a magnitude of multiple order....
Definition Tensor.h:48
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.

◆ 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:

Unstacked Tensor 0:
[[1 2 3]
[4 5 6]]
Unstacked Tensor 1:
[[7 8 9]
[10 11 12]]

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