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
8#include <cstddef>
9#include <initializer_list>
10
11namespace txeo {
12
13namespace detail {
14class TensorHelper;
15}
16
17template <typename T>
18class Predictor;
19
20template <typename T>
21class TensorAgg;
22
23template <typename T>
24class TensorPart;
25
26template <typename T>
27class TensorOp;
28
29template <typename T>
30class TensorFunc;
31
41template <typename T>
42class Vector : public txeo::Tensor<T> {
43 public:
44 ~Vector() = default;
45
46 Vector(const Vector &Vector) : txeo::Tensor<T>{Vector} {};
47 Vector(Vector &&Vector) noexcept : txeo::Tensor<T>{std::move(Vector)} {};
48
51 return *this;
52 };
53
56 return *this;
57 };
58
70 explicit Vector(size_t dim) : txeo::Tensor<T>{txeo::TensorShape({dim})} {};
71
83 explicit Vector(size_t dim, const T &fill_value) : txeo::Tensor<T>({dim}, fill_value) {};
84
96 explicit Vector(size_t dim, const std::vector<T> &values) : txeo::Tensor<T>({dim}, values) {};
97
109 explicit Vector(size_t dim, const std::initializer_list<T> &values)
110 : txeo::Tensor<T>({dim}, std::vector<T>(values)) {};
111
122 explicit Vector(const std::initializer_list<T> &values)
123 : txeo::Tensor<T>({values.size()}, std::vector<T>(values)) {};
124
136 explicit Vector(txeo::Tensor<T> &&tensor);
137
139
140 void reshape(const std::vector<size_t> &shape) { this->reshape(txeo::TensorShape(shape)); };
141
142 void reshape(const std::initializer_list<size_t> &shape) {
143 this->reshape(std::vector<size_t>(shape));
144 };
145
164
180 static Vector<T> to_vector(const txeo::Tensor<T> &tensor);
181
196
210 static txeo::Tensor<T> to_tensor(const Vector<T> &vector);
211
212 private:
213 Vector() = default;
214
215 friend class txeo::Predictor<T>;
216 friend class txeo::TensorAgg<T>;
217 friend class txeo::TensorPart<T>;
218 friend class txeo::TensorOp<T>;
219 friend class txeo::TensorFunc<T>;
221};
222
227class VectorError : public std::runtime_error {
228 public:
229 using std::runtime_error::runtime_error;
230};
231
232} // namespace txeo
233
234#endif
Class that deals with the main tasks of prediction (inference)
Definition Predictor.h:45
A utility class for aggregation functions on tensors.
Definition TensorAgg.h:22
A utility class for common math functions on tensors.
Definition TensorFunc.h:23
Implements the mathematical concept of tensor, which is a magnitude of multiple order....
Definition Tensor.h:48
Tensor & operator=(const Tensor &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:21
A utility class for partitioning tensors.
Definition TensorPart.h:19
The shape of a tensor is an ordered collection of dimensions of mathematical vector spaces.
Definition TensorShape.h:30
Exceptions concerning txeo::Vector.
Definition Vector.h:227
A class representing a vector, derived from Tensor.
Definition Vector.h:42
void reshape(const std::vector< size_t > &shape)
Definition Vector.h:140
Vector(const std::initializer_list< T > &values)
Constructs a vector from an initializer list.
Definition Vector.h:122
Vector(size_t dim, const std::initializer_list< T > &values)
Constructs a vector with the specified dimension and initializer list.
Definition Vector.h:109
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
Vector(Vector &&Vector) noexcept
Definition Vector.h:47
friend class txeo::detail::TensorHelper
Definition Vector.h:220
void reshape(const std::initializer_list< size_t > &shape)
Definition Vector.h:142
Vector(size_t dim, const std::vector< T > &values)
Constructs a vector with the specified dimension and values.
Definition Vector.h:96
Vector(const Vector &Vector)
Definition Vector.h:46
Vector(size_t dim, const T &fill_value)
Constructs a vector with the specified dimension and fill value.
Definition Vector.h:83
Vector & operator=(const Vector &Vector)
Definition Vector.h:49
static txeo::Tensor< T > to_tensor(const Vector< T > &vector)
Creates a tensor from a vector (performs copy).
Vector & operator=(Vector &&Vector) noexcept
Definition Vector.h:54
Vector(size_t dim)
Constructs a vector with the specified dimension.
Definition Vector.h:70
void reshape(const txeo::TensorShape &shape)
Definition Matrix.h:11