Txeo v0.1
A Developer-Friendly TensorFlow C++ Wrapper
Loading...
Searching...
No Matches
TensorFunc.h
Go to the documentation of this file.
1#ifndef TENSORFUNC_H
2#define TENSORFUNC_H
3#pragma once
4
5#include "txeo/Matrix.h"
6#include "txeo/Tensor.h"
7#include "txeo/types.h"
8
9#include <cstddef>
10#include <functional>
11#include <stdexcept>
12#include <vector>
13
14namespace txeo {
15enum class NormalizationType;
16
26template <typename T>
28 public:
29 TensorFunc(const TensorFunc &) = delete;
30 TensorFunc(TensorFunc &&) = delete;
31 TensorFunc &operator=(const TensorFunc &) = default;
33 ~TensorFunc() = default;
34
49
63
78
92
107
121
135
149
172 static txeo::Tensor<T> permute(const txeo::Tensor<T> &tensor, const std::vector<size_t> &axes);
173
194 static txeo::Tensor<T> &permute_by(txeo::Tensor<T> &tensor, const std::vector<size_t> &axes);
195
218
239
252 static std::vector<std::function<T(const T &)>>
255
274
293
305 static std::function<T(const T &)> make_normalize_function(const txeo::Tensor<T> &tensor,
307
322
337
376
377 private:
378 TensorFunc() = default;
379
380 static void
381 axis_func(txeo::Tensor<T> &tensor, size_t axis,
382 std::function<void(const std::vector<T> &, const std::vector<T *> &)> func);
383 static std::vector<std::function<T(const T &)>>
384 new_axis_func(const txeo::Tensor<T> &tensor, size_t axis,
385 std::function<void(const std::vector<T> &, T &, T &)> func);
386
387 static void min_max_normalize(const std::vector<T> &values, const std::vector<T *> &adresses);
388 static void z_score_normalize(const std::vector<T> &values, const std::vector<T *> &adresses);
389
390 static void new_min_max_normalize(const std::vector<T> &values,
391 const std::vector<T *> &adresses, T &subtractor,
392 T &denominator);
393 static void new_z_score_normalize(const std::vector<T> &values,
394 const std::vector<T *> &adresses, T &subtractor,
395 T &denominator);
396
397 static void min_max_normalize(const txeo::Tensor<T> &tensor, T &subtractor, T &denominator);
398 static void z_score_normalize(const txeo::Tensor<T> &tensor, T &subtractor, T &denominator);
399
400 static void min_max_subtractor_denominator(const std::vector<T> &values, T &subtractor,
401 T &denominator);
402
403 static void z_score_subtractor_denominator(const std::vector<T> &values, T &subtractor,
404 T &denominator);
405};
406
411class TensorFuncError : public std::runtime_error {
412 public:
413 using std::runtime_error::runtime_error;
414};
415
416} // namespace txeo
417
418#endif
A container for managing training, evaluation, and test data splits.
Definition DataTable.h:24
Exceptions concerning txeo::TensorOp.
Definition TensorFunc.h:411
A utility class for common math functions on tensors.
Definition TensorFunc.h:27
static txeo::Tensor< T > & square_by(txeo::Tensor< T > &tensor)
Computes the element-wise square of a tensor in-place.
static txeo::Tensor< T > power_elem(const txeo::Tensor< T > &tensor, const T &exponent)
Returns the element-wise potentiation of a tensor.
static txeo::Tensor< T > normalize(const txeo::Tensor< T > &tensor, size_t axis, txeo::NormalizationType type)
Creates a normalized copy of the input tensor along a specified axis.
TensorFunc & operator=(TensorFunc &&)=delete
static txeo::Tensor< T > normalize(const txeo::Tensor< T > &tensor, txeo::NormalizationType type)
Creates a normalized copy of the entire tensor (global normalization)
static std::vector< std::function< T(const T &)> > make_normalize_functions(const txeo::Tensor< T > &tensor, size_t axis, txeo::NormalizationType type)
Construct the normalization functions for each dimension of the specified axis.
static txeo::Tensor< T > sqrt(const txeo::Tensor< T > &tensor)
Computes the element-wise square root of a tensor.
static txeo::Tensor< T > permute(const txeo::Tensor< T > &tensor, const std::vector< size_t > &axes)
Permutes the axes of a tensor.
static txeo::Matrix< T > & transpose_by(txeo::Matrix< T > &matrix)
Transposes a matrix in-place.
TensorFunc(const TensorFunc &)=delete
static txeo::Tensor< T > & sqrt_by(txeo::Tensor< T > &tensor)
Computes the element-wise square root of a tensor in-place.
static Tensor< T > & normalize_by(txeo::Tensor< T > &tensor, txeo::NormalizationType type)
Normalizes the entire tensor in-place (global normalization)
static txeo::Tensor< T > & abs_by(txeo::Tensor< T > &tensor)
Computes the element-wise absolute value of a tensor in-place.
~TensorFunc()=default
static txeo::Matrix< T > transpose(const txeo::Matrix< T > &matrix)
Transposes a matrix.
TensorFunc & operator=(const TensorFunc &)=default
static txeo::Tensor< T > & normalize_by(txeo::Tensor< T > &tensor, size_t axis, txeo::NormalizationType type)
Normalizes the input tensor along a specified axis in-place.
static txeo::Tensor< T > & power_elem_by(txeo::Tensor< T > &tensor, const T &exponent)
Performs element-wise potentiation of the tensor (in-place)
static std::function< T(const T &)> make_normalize_function(const txeo::Tensor< T > &tensor, txeo::NormalizationType type)
Construct the normalization function for the elements of the specified tensor.
static txeo::Tensor< T > square(const txeo::Tensor< T > &tensor)
Computes the element-wise square of a tensor.
static txeo::Tensor< T > abs(const txeo::Tensor< T > &tensor)
Computes the element-wise absolute value of a tensor.
TensorFunc(TensorFunc &&)=delete
static txeo::Tensor< T > & permute_by(txeo::Tensor< T > &tensor, const std::vector< size_t > &axes)
Permutes the axes of a tensor in-place.
static txeo::Matrix< T > compute_gram_matrix(const txeo::Matrix< T > &matrix)
Computes the Gram matrix ( ) of the input matrix.
NormalizationType
Normalization types to be used in normalization functions.
Definition types.h:38