Txeo v0.1
A Developer-Friendly TensorFlow C++ Wrapper
Loading...
Searching...
No Matches
Matrix.h
Go to the documentation of this file.
1#ifndef MATRIX_H
2#define MATRIX_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 Matrix : public txeo::Tensor<T> {
43 public:
44 ~Matrix() = default;
45
46 Matrix(const Matrix &matrix) : txeo::Tensor<T>{matrix} {};
47 Matrix(Matrix &&matrix) noexcept : txeo::Tensor<T>{std::move(matrix)} {};
48
49 Matrix &operator=(const Matrix &matrix) {
51 return *this;
52 };
53
54 Matrix &operator=(Matrix &&matrix) noexcept {
55 txeo::Tensor<T>::operator=(std::move(matrix));
56 return *this;
57 };
58
72 explicit Matrix(size_t row_size, size_t col_size)
73 : txeo::Tensor<T>{txeo::TensorShape({row_size, col_size})} {};
74
87 explicit Matrix(size_t row_size, size_t col_size, const T &fill_value)
88 : txeo::Tensor<T>({row_size, col_size}, fill_value) {};
89
103 explicit Matrix(size_t row_size, size_t col_size, const std::vector<T> &values)
104 : txeo::Tensor<T>({row_size, col_size}, values) {};
105
119 explicit Matrix(size_t row_size, size_t col_size, const std::initializer_list<T> &values)
120 : txeo::Tensor<T>({row_size, col_size}, std::vector<T>(values)) {};
121
133 explicit Matrix(const std::initializer_list<std::initializer_list<T>> &values)
134 : txeo::Tensor<T>(values) {};
135
147 explicit Matrix(txeo::Tensor<T> &&tensor);
148
160 [[nodiscard]] size_t size() const { return txeo::Tensor<T>::dim(); };
161
163
164 void reshape(const std::vector<size_t> &shape) { this->reshape(txeo::TensorShape(shape)); };
165
166 void reshape(const std::initializer_list<size_t> &shape) {
167 this->reshape(std::vector<size_t>(shape));
168 };
169
186
202 static Matrix<T> to_matrix(const txeo::Tensor<T> &tensor);
203
220
236 static txeo::Tensor<T> to_tensor(const Matrix<T> &matrix);
237
238 private:
239 Matrix() = default;
240
241 friend class txeo::Predictor<T>;
242 friend class txeo::TensorAgg<T>;
243 friend class txeo::TensorPart<T>;
244 friend class txeo::TensorOp<T>;
245 friend class txeo::TensorFunc<T>;
247};
248
253class MatrixError : public std::runtime_error {
254 public:
255 using std::runtime_error::runtime_error;
256};
257
258} // namespace txeo
259#endif
Exceptions concerning txeo::Matrix.
Definition Matrix.h:253
A class representing a matrix, derived from Tensor.
Definition Matrix.h:42
Matrix(Matrix &&matrix) noexcept
Definition Matrix.h:47
Matrix(size_t row_size, size_t col_size, const std::vector< T > &values)
Constructs a matrix with the specified row and column sizes and values.
Definition Matrix.h:103
Matrix & operator=(const Matrix &matrix)
Definition Matrix.h:49
void reshape(const std::vector< size_t > &shape)
Definition Matrix.h:164
static Matrix< T > to_matrix(txeo::Tensor< T > &&tensor)
Converts a tensor to a matrix by moving data.
size_t size() const
Returns the size of the matrix.
Definition Matrix.h:160
friend class txeo::detail::TensorHelper
Definition Matrix.h:246
Matrix(size_t row_size, size_t col_size, const std::initializer_list< T > &values)
Constructs a matrix with the specified row and column sizes and initializer list.
Definition Matrix.h:119
static Matrix< T > to_matrix(const txeo::Tensor< T > &tensor)
Creates a matrix from a tensor (preforms copy).
Matrix(const std::initializer_list< std::initializer_list< T > > &values)
Constructs a matrix from a nested initializer list.
Definition Matrix.h:133
Matrix(txeo::Tensor< T > &&tensor)
Constructs a matrix by moving data from a Tensor.
Matrix(size_t row_size, size_t col_size, const T &fill_value)
Constructs a matrix with the specified row and column sizes and a fill value.
Definition Matrix.h:87
Matrix(const Matrix &matrix)
Definition Matrix.h:46
static txeo::Tensor< T > to_tensor(Matrix< T > &&matrix)
Converts a matrix to a tensor by moving data.
void reshape(const std::initializer_list< size_t > &shape)
Definition Matrix.h:166
Matrix(size_t row_size, size_t col_size)
Constructs a matrix with the specified row and column sizes.
Definition Matrix.h:72
Matrix & operator=(Matrix &&matrix) noexcept
Definition Matrix.h:54
static txeo::Tensor< T > to_tensor(const Matrix< T > &matrix)
Creates a tensor from a matrix (performs copy).
~Matrix()=default
void reshape(const txeo::TensorShape &shape)
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
Definition Matrix.h:11