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 <cstddef>
8#include <functional>
9
10namespace txeo {
11
21template <typename T>
22class TensorAgg {
23 public:
24 TensorAgg(const TensorAgg &) = delete;
25 TensorAgg(TensorAgg &&) = delete;
26 TensorAgg &operator=(const TensorAgg &) = delete;
28 ~TensorAgg() = default;
29
45 const std::vector<size_t> &axes);
46
62 const std::vector<size_t> &axes);
63
79 const std::vector<size_t> &axes);
80
96 const std::vector<size_t> &axes);
97
113 const std::vector<size_t> &axes);
114
130 const std::vector<size_t> &axes);
131
146 static txeo::Tensor<T> reduce_maximum_norm(const txeo::Tensor<T> &tensor, size_t axis);
147
162 static txeo::Tensor<T> reduce_variance(const txeo::Tensor<T> &tensor, size_t axis);
163
179
194 static txeo::Tensor<T> reduce_median(const txeo::Tensor<T> &tensor, size_t axis);
195
210 static txeo::Tensor<T> reduce_geometric_mean(const txeo::Tensor<T> &tensor, size_t axis);
211
227 const std::vector<size_t> &axes)
228 requires(std::convertible_to<T, bool>);
229
245 const std::vector<size_t> &axes)
246 requires(std::convertible_to<T, bool>);
247
262 static txeo::Tensor<T> cumulative_sum(const txeo::Tensor<T> &tensor, size_t axis);
263
278 static txeo::Tensor<T> cumulative_prod(const txeo::Tensor<T> &tensor, size_t axis);
279
294 static txeo::Tensor<size_t> arg_max(const txeo::Tensor<T> &tensor, size_t axis);
295
310 static txeo::Tensor<size_t> arg_min(const txeo::Tensor<T> &tensor, size_t axis);
311
326 static txeo::Tensor<size_t> count_non_zero(const txeo::Tensor<T> &tensor, size_t axis);
327
341 static T sum_all(const txeo::Tensor<T> &tensor);
342
343 private:
344 TensorAgg() = default;
345
346 static void verify_parameters(const txeo::Tensor<T> &tensor, const std::vector<size_t> &axes);
347
348 static txeo::Tensor<T> accumulate(const txeo::Tensor<T> &tensor, size_t axis,
349 std::function<T(std::vector<T> &)>);
350
351 static txeo::Tensor<size_t> count(const txeo::Tensor<T> &tensor, size_t axis,
352 std::function<size_t(std::vector<T> &)>);
353
354 static T median(std::vector<T> &values);
355 static T geometric_mean(std::vector<T> &values);
356 static T variance(std::vector<T> &values);
357 static T maximum_norm(std::vector<T> &values);
358 static size_t count_non_zero(std::vector<T> &values);
359};
360
365class TensorAggError : public std::runtime_error {
366 public:
367 using std::runtime_error::runtime_error;
368};
369
370} // namespace txeo
371
372#endif
Exceptions concerning txeo::TensorAgg.
Definition TensorAgg.h:365
A utility class for aggregation functions on tensors.
Definition TensorAgg.h:22
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.
Implements the mathematical concept of tensor, which is a magnitude of multiple order....
Definition Tensor.h:48
Definition Matrix.h:11