Txeo v0.1
A Developer-Friendly TensorFlow C++ Wrapper
Loading...
Searching...
No Matches
TensorAgg.h
Go to the documentation of this file.
1#ifndef TENSORAGG_H
2#define TENSORAGG_H
3#pragma once
4
5#include "txeo/Tensor.h"
6
7#include <concepts>
8#include <cstddef>
9#include <functional>
10#include <stdexcept>
11#include <vector>
12
13namespace txeo {
14
24template <typename T>
25class TensorAgg {
26 public:
27 TensorAgg(const TensorAgg &) = delete;
28 TensorAgg(TensorAgg &&) = delete;
29 TensorAgg &operator=(const TensorAgg &) = delete;
31 ~TensorAgg() = default;
32
48 const std::vector<size_t> &axes);
49
65 const std::vector<size_t> &axes);
66
82 const std::vector<size_t> &axes);
83
99 const std::vector<size_t> &axes);
100
116 const std::vector<size_t> &axes);
117
133 const std::vector<size_t> &axes);
134
150
166
182
198
214
230 const std::vector<size_t> &axes)
231 requires(std::convertible_to<T, bool>);
232
248 const std::vector<size_t> &axes)
249 requires(std::convertible_to<T, bool>);
250
266
282
298
314
330
345
346 private:
347 TensorAgg() = default;
348
349 static void verify_parameters(const txeo::Tensor<T> &tensor, const std::vector<size_t> &axes);
350
351 static txeo::Tensor<T> accumulate(const txeo::Tensor<T> &tensor, size_t axis,
352 std::function<T(std::vector<T> &)>);
353
354 static txeo::Tensor<size_t> count(const txeo::Tensor<T> &tensor, size_t axis,
355 std::function<size_t(std::vector<T> &)>);
356
357 static T median(std::vector<T> &values);
358 static T geometric_mean(std::vector<T> &values);
359 static T variance(std::vector<T> &values);
360 static T maximum_norm(std::vector<T> &values);
361 static size_t count_non_zero(std::vector<T> &values);
362};
363
368class TensorAggError : public std::runtime_error {
369 public:
370 using std::runtime_error::runtime_error;
371};
372
373} // namespace txeo
374
375#endif
A container for managing training, evaluation, and test data splits.
Definition DataTable.h:24
Exceptions concerning txeo::TensorAgg.
Definition TensorAgg.h:368
A utility class for aggregation functions on tensors.
Definition TensorAgg.h:25
static T sum_all(const txeo::Tensor< T > &tensor)
Computes the sum of all elements in the tensor.
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.
~TensorAgg()=default
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< 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< 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 > 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_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_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_mean(const txeo::Tensor< T > &tensor, const std::vector< size_t > &axes)
Computes the mean of tensor elements along the specified axes.
TensorAgg & operator=(TensorAgg &&)=delete
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 > count_non_zero(const txeo::Tensor< T > &tensor, size_t axis)
Counts the number of non-zero elements along the specified axis.
TensorAgg(TensorAgg &&)=delete
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< 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< 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_variance(const txeo::Tensor< T > &tensor, size_t axis)
Computes the variance of tensor elements along the specified axis.
TensorAgg & operator=(const TensorAgg &)=delete
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.
TensorAgg(const TensorAgg &)=delete
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_all(const txeo::Tensor< T > &tensor, const std::vector< size_t > &axes)
Computes the logical AND (all) of tensor elements along the specified axes.