Txeo v0.1
A Developer-Friendly TensorFlow C++ Wrapper
Loading...
Searching...
No Matches
Vector.h
Go to the documentation of this file.
1#ifndef VECTOR_H
2#define VECTOR_H
3#pragma once
4
5#include "txeo/Tensor.h"
6#include "txeo/TensorShape.h"
7#include "txeo/types.h"
8
9#include <cstddef>
10#include <initializer_list>
11#include <stdexcept>
12#include <utility>
13#include <vector>
14
15namespace txeo {
16
17namespace detail {
18class TensorHelper;
19}
20
21enum class NormalizationType;
22template <typename T>
23class Predictor;
24template <typename T>
25class TensorAgg;
26template <typename T>
27class TensorFunc;
28template <typename T>
29class TensorOp;
30template <typename T>
31class TensorPart;
32
42template <typename T>
43class Vector : public txeo::Tensor<T> {
44 public:
45 explicit Vector();
46 ~Vector() = default;
47
50
53 return *this;
54 };
55
58 return *this;
59 };
60
72 explicit Vector(size_t dim) : txeo::Tensor<T>{txeo::TensorShape({dim})} {};
73
85 explicit Vector(size_t dim, const T &fill_value) : txeo::Tensor<T>({dim}, fill_value) {};
86
98 explicit Vector(size_t dim, const std::vector<T> &values) : txeo::Tensor<T>({dim}, values) {};
99
111 explicit Vector(size_t dim, const std::initializer_list<T> &values)
112 : txeo::Tensor<T>({dim}, std::vector<T>(values)) {};
113
124 explicit Vector(const std::initializer_list<T> &values)
125 : txeo::Tensor<T>({values.size()}, std::vector<T>(values)) {};
126
139
160
162
163 void reshape(const std::vector<size_t> &shape) { this->reshape(txeo::TensorShape(shape)); };
164
165 void reshape(const std::initializer_list<size_t> &shape) {
166 this->reshape(std::vector<size_t>(shape));
167 };
168
180 [[nodiscard]] size_t size() const { return this->dim(); }
181
200
217
232
247
248 template <typename U>
250
251 template <typename U>
253
254 template <typename U>
256
257 template <typename U>
259
260 template <typename U>
262
263 template <typename U>
265
266 template <typename U>
268
269 template <typename U>
271
272 template <typename U>
274
275 private:
276 friend class txeo::Predictor<T>;
277 friend class txeo::TensorAgg<T>;
278 friend class txeo::TensorPart<T>;
279 friend class txeo::TensorOp<T>;
280 friend class txeo::TensorFunc<T>;
282};
283
288class VectorError : public std::runtime_error {
289 public:
290 using std::runtime_error::runtime_error;
291};
292
293} // namespace txeo
294
295#endif
A container for managing training, evaluation, and test data splits.
Definition DataTable.h:24
Class that deals with the main tasks of prediction (inference)
Definition Predictor.h:24
A utility class for aggregation functions on tensors.
Definition TensorAgg.h:25
A utility class for common math functions on tensors.
Definition TensorFunc.h:27
Implements the mathematical concept of tensor, which is a magnitude of multiple order....
Definition Tensor.h:50
Tensor & operator=(const Tensor &tensor)
constexpr std::type_identity_t< T > type() const
Returns the data type of this tensor.
const txeo::TensorShape & shape() const
Returns the shape of this tensor.
size_t dim() const
Returns the dimension of this tensor.
A utility class for performing operations on tensors and vectors.
Definition TensorOp.h:25
A utility class for partitioning tensors.
Definition TensorPart.h:24
The shape of a tensor is an ordered collection of dimensions of mathematical vector spaces.
Definition TensorShape.h:31
Exceptions concerning txeo::Vector.
Definition Vector.h:288
A class representing a vector, derived from Tensor.
Definition Vector.h:43
void reshape(const std::vector< size_t > &shape)
Definition Vector.h:163
Vector(const std::initializer_list< T > &values)
Constructs a vector from an initializer list.
Definition Vector.h:124
Vector(size_t dim, const std::initializer_list< T > &values)
Constructs a vector with the specified dimension and initializer list.
Definition Vector.h:111
static Vector< T > to_vector(txeo::Tensor< T > &&tensor)
Converts a tensor to a vector by moving data.
static txeo::Tensor< T > to_tensor(Vector< T > &&vector)
Converts a vector to a tensor by moving data.
Vector(txeo::Tensor< T > &&tensor)
Constructs a vector by moving data from a Tensor.
static Vector< T > to_vector(const txeo::Tensor< T > &tensor)
Creates a vector from a tensor (performs copy).
~Vector()=default
void normalize(txeo::NormalizationType type)
Normalizes the vector in-place using specified normalization method.
friend txeo::Vector< U > operator-(const txeo::Vector< U > &left, const txeo::Vector< U > &right)
Vector(Vector &&Vector) noexcept
Definition Vector.h:49
friend class txeo::detail::TensorHelper
Definition Vector.h:281
void reshape(const std::initializer_list< size_t > &shape)
Definition Vector.h:165
Vector(size_t dim, const std::vector< T > &values)
Constructs a vector with the specified dimension and values.
Definition Vector.h:98
Vector(const Vector &Vector)
Definition Vector.h:48
friend txeo::Vector< U > operator+(const txeo::Vector< U > &left, const txeo::Vector< U > &right)
friend txeo::Vector< U > operator*(const txeo::Vector< U > &vector, const U &scalar)
Vector(size_t dim, const T &fill_value)
Constructs a vector with the specified dimension and fill value.
Definition Vector.h:85
Vector & operator=(const Vector &Vector)
Definition Vector.h:51
static txeo::Tensor< T > to_tensor(const Vector< T > &vector)
Creates a tensor from a vector (performs copy).
friend txeo::Vector< U > operator/(const txeo::Vector< U > &left, const U &right)
friend txeo::Vector< U > operator-(const U &left, const txeo::Vector< U > &right)
size_t size() const
Returns the size of the vector.
Definition Vector.h:180
friend txeo::Vector< U > operator/(const U &left, const txeo::Vector< U > &right)
Vector & operator=(Vector &&Vector) noexcept
Definition Vector.h:56
friend txeo::Vector< U > operator-(const txeo::Vector< U > &left, const U &right)
Vector(size_t dim)
Constructs a vector with the specified dimension.
Definition Vector.h:72
void reshape(const txeo::TensorShape &shape)
friend txeo::Vector< U > operator+(const txeo::Vector< U > &left, const U &right)
friend txeo::Vector< U > operator*(const U &scalar, const txeo::Vector< U > &vector)
NormalizationType
Normalization types to be used in normalization functions.
Definition types.h:38