13#include <initializer_list>
25concept c_numeric = std::is_arithmetic_v<T> && !std::is_same_v<T, bool>;
386 explicit Tensor(
const std::initializer_list<std::initializer_list<T>> &
values);
416 const std::initializer_list<std::initializer_list<std::initializer_list<T>>> &
values);
430 constexpr std::type_identity_t<T>
type()
const;
523 template <
typename U>
525 return this->
shape() == other.shape();
561 template <
typename...
Args>
562 requires(std::convertible_to<Args, size_t> && ...)
840 const size_t &
seed2);
1058 template <
typename U>
1061 template <
typename U>
1081 template <
typename U>
1099 template <
typename U>
1117 template <
typename U>
1134 template <
typename U>
1137 template <
typename U>
1154 template <
typename U>
1172 template <
typename U>
1199 template <
typename P>
1206 const std::initializer_list<std::initializer_list<std::initializer_list<T>>> &
list,
1218 using std::runtime_error::runtime_error;
1221template <
typename T>
1222template <
typename...
Args>
1223 requires(std::convertible_to<Args, size_t> && ...)
1225 size_t indexes[] = {
static_cast<size_t>(
args)...};
1226 size_t size = this->order();
1227 auto *stride = this->shape().stride().data();
1230 for (
size_t i = 0;
i < size - 1; ++
i)
1236template <
typename T>
1237template <
typename...
Args>
1238 requires(std::convertible_to<Args, size_t> && ...)
1240 size_t indexes[] = {
static_cast<size_t>(
args)...};
1241 size_t size = this->order();
1242 auto *stride = this->shape().stride().data();
1245 for (
size_t i = 0;
i < size - 1; ++
i)
1251template <
typename T>
1252template <
typename...
Args>
1253 requires(std::convertible_to<Args, size_t> && ...)
1255 if (this->order() !=
sizeof...(Args))
1256 throw TensorError(
"The number of axes specified and the order of this tensor do no match.");
1258 check_indexes({
static_cast<size_t>(
args)...});
1259 }
catch (std::exception
e) {
1263 return (*
this)(
args...);
1266template <
typename T>
1267template <
typename...
Args>
1268 requires(std::convertible_to<Args, size_t> && ...)
1270 if (this->order() !=
sizeof...(Args))
1271 throw TensorError(
"The number of axes specified and the order of this tensor do no match.");
1273 check_indexes({
static_cast<size_t>(
args)...});
1274 }
catch (std::exception
e) {
1278 return (*
this)(
args...);
1281template <
typename T>
1283 std::vector<T> &
flat_data, std::vector<size_t> &shape) {
1285 shape.emplace_back(
list.size());
1286 std::vector<std::initializer_list<T>>
v_list(
list);
1287 for (
size_t i{1};
i <
v_list.size(); ++
i)
1291 shape.emplace_back(
v_list[0].size());
1297template <
typename T>
1299 const std::initializer_list<std::initializer_list<std::initializer_list<T>>> &
list,
1300 std::vector<T> &
flat_data, std::vector<size_t> &shape) {
1301 shape.emplace_back(
list.size());
1302 std::vector<std::initializer_list<std::initializer_list<T>>>
v_list(
list);
1303 for (
size_t i{1};
i <
v_list.size(); ++
i)
1307 shape.emplace_back(
v_list[0].size());
1309 for (
size_t i{0};
i <
v_list.size(); ++
i) {
1316 shape.emplace_back(
v_sublist[0].size());
A container for managing training, evaluation, and test data splits.
Class that deals with the main tasks of prediction (inference)
A utility class for aggregation functions on tensors.
Exceptions concerning txeo::Tensor.
A utility class for common math functions on tensors.
Implements the mathematical concept of tensor, which is a magnitude of multiple order....
friend txeo::Tensor< U > operator*(const U &scalar, const txeo::Tensor< U > &tensor)
Tensor(Tensor &&tensor) noexcept
Tensor< T > & permute(const std::vector< size_t > &axes)
Permutes tensor dimensions according to specified axis order.
Tensor(txeo::TensorShape &&shape)
Constructs a Tensor from a specified txeo::TensorShape.
Tensor(const std::vector< size_t > &shape, const T &fill_value)
Constructs a Tensor from a specified shape std::vector and fills it with a value.
friend std::ostream & operator<<(std::ostream &os, const Tensor< U > &tensor)
friend txeo::Tensor< U > operator+(const txeo::Tensor< U > &left, const U &right)
Tensor< T > clone() const
Returns a clone of this tensor.
T * data()
Acesses the raw data of this tensor.
void fill_with_uniform_random(const T &min, const T &max)
Fills the tensor with uniformly distributed random values ranging according to the specified interval...
Tensor< T > & increase_dimension(size_t axis, T value)
Increments the dimension of the specified axis.
Tensor< T > & operator/=(const T &scalar)
bool operator!=(const Tensor &tensor)
Tensor(std::vector< size_t > &&shape, const T &fill_value)
Constructs a Tensor from a specified shape std::vector and fills it with a value.
Tensor & operator=(const Tensor &tensor)
void squeeze()
Reshapes this tensor by removing all the axes of dimension one.
Tensor(const std::initializer_list< std::initializer_list< std::initializer_list< T > > > &values)
Constructs a third order Tensor from a nested std::initializer_list.
std::unique_ptr< Impl > _impl
bool operator==(const Tensor &tensor)
Tensor & operator=(Tensor &&tensor) noexcept
friend txeo::Tensor< U > operator-(const txeo::Tensor< U > &left, const U &right)
Element-wise tensor-scalar addition operator.
T inner(const Tensor< T > &tensor) const
Computes inner product with another tensor.
void create_from_shape(P &&shape)
Tensor< T > flatten() const
Returns a first order reshaped view of this tensor.
Tensor< T > & operator+=(const Tensor< T > &tensor)
constexpr std::type_identity_t< T > type() const
Returns the data type of this tensor.
void shuffle()
Shuffles the elements of this tensor.
Tensor(const txeo::TensorShape &shape, const std::vector< T > &values)
Constructs a Tensor object from a specified txeo::TensorShape and fills it with a std::vector of valu...
Tensor< T > & operator-=(const Tensor< T > &tensor)
friend class txeo::detail::TensorHelper
Tensor(const std::initializer_list< size_t > &shape, const T &fill_value)
Constructs a Tensor from a specified initializer list and fills it with a value.
Tensor< T > & operator*=(const T &scalar)
bool is_equal_shape(const Tensor< U > &other) const
Compares the shape of this tensor with the shape of the specified tensor.
friend txeo::Tensor< U > operator+(const txeo::Tensor< U > &left, const txeo::Tensor< U > &right)
Returns the sum of two tensors.
txeo::TensorIterator< const T > begin() const
Tensor< T > & abs()
Computes absolute value of all tensor elements in-place.
friend txeo::Tensor< U > operator/(const txeo::Tensor< U > &left, const U &right)
Element-wise division operator (tensor / scalar)
Tensor< T > & normalize(size_t axis, txeo::NormalizationType type)
Normalizes tensor along specified axis.
Tensor(const std::initializer_list< std::initializer_list< T > > &values)
Constructs a second order Tensor from a nested std::initializer_list.
Tensor(const std::initializer_list< size_t > &shape)
Constructs a Tensor from a specified shape std::vector.
Tensor< T > & sqrt()
Computes square root of all tensor elements in-place.
Tensor< T > & square()
Squares all tensor elements in-place.
friend txeo::Tensor< U > operator-(const txeo::Tensor< U > &left, const txeo::Tensor< U > &right)
Returns the subtraction of two tensors.
Tensor(std::vector< size_t > &&shape)
Constructs a Tensor from a specified shape std::vector.
Tensor(const txeo::TensorShape &shape, const T &fill_value)
Constructs a Tensor from a specified txeo::TensorShape and fills it with a value.
friend txeo::Tensor< U > operator/(const U &left, const txeo::Tensor< U > &right)
Element-wise scalar-tensor division operator.
txeo::TensorIterator< T > end()
const T * data() const
Reads the raw data of this tensor.
void fill(const T &value)
Fills this tensor with the specified value.
Tensor< T > & operator=(const T &value)
Assigns a specified value to this tensor elements.
Tensor(txeo::TensorShape &&shape, const T &fill_value)
Constructs a Tensor from a specified txeo::TensorShape and fills it with a value.
void reshape(const txeo::TensorShape &shape)
Reshapes this tensor if the specified shape defines a number of elements equal to this tensor order.
Tensor< T > & power(const T &exponent)
Raises all tensor elements to the specified power.
txeo::TensorIterator< const T > end() const
Tensor(const Tensor &tensor)
T & operator()()
Accesses the value of this tensor if it is a scalar (order zero).
Tensor(const std::initializer_list< size_t > &shape, const std::vector< T > &values)
Constructs a Tensor object from a specified initializer list and fills it with a std::vector of value...
friend txeo::Tensor< U > operator*(const txeo::Tensor< U > &tensor, const U &scalar)
Returns the scalar multiplication of a tensor.
Tensor< T > & normalize(txeo::NormalizationType type)
Normalizes entire tensor.
Tensor< T > & operator+=(const T &tensor)
Tensor< T > & operator-=(const T &tensor)
Tensor(const std::vector< size_t > &shape)
Constructs a Tensor from a specified shape std::vector.
const txeo::TensorShape & shape() const
Returns the shape of this tensor.
void view_of(const Tensor< T > &tensor, const txeo::TensorShape &shape)
Views the content of the specified tensor according to the specified shape. There is no element copyi...
txeo::TensorIterator< T > begin()
void fill_with_uniform_random(const T &min, const T &max, const size_t &seed1, const size_t &seed2)
Fills the tensor with uniformly distributed random values ranging according to the specified interval...
size_t memory_size() const
Returns the number of bytes occupied by this tensor.
void check_indexes(const std::vector< size_t > &indexes)
Tensor(const txeo::TensorShape &shape)
Constructs a tensor from a specified txeo::TensorShape.
T & at()
Accesses the value of this tensor if it is a scalar (order zero).
Tensor(const std::vector< size_t > &shape, const std::vector< T > &values)
Constructs a Tensor object from a specified std::vector<size_t> and fills it with a std::vector of va...
size_t dim() const
Returns the dimension of this tensor.
friend txeo::Tensor< U > operator-(const U &left, const txeo::Tensor< U > &right)
Element-wise scalar-tensor subtraction operator.
size_t number_of_elements() const
Returns the number of elements of this tensor, which corresponds to the dimension of this tensor.
Tensor< T > slice(size_t first_axis_begin, size_t first_axis_end) const
Returns a view ot this tensor from a specified range of dimensions of the first axis.
int order() const
Returns the order of this tensor.
void fill_data_shape(const std::initializer_list< std::initializer_list< T > > &list, std::vector< T > &flat_data, std::vector< size_t > &shape)
A utility class for performing operations on tensors and vectors.
A utility class for partitioning tensors.
The shape of a tensor is an ordered collection of dimensions of mathematical vector spaces.
NormalizationType
Normalization types to be used in normalization functions.