Txeo v0.1
A Developer-Friendly TensorFlow C++ Wrapper
Loading...
Searching...
No Matches
TensorShape.h
Go to the documentation of this file.
1#ifndef TENSOR_SHAPE_H
2#define TENSOR_SHAPE_H
3#pragma once
4
5#include <cstddef>
6#include <cstdint>
7#include <memory>
8#include <ostream>
9#include <stdexcept>
10#include <vector>
11
12namespace txeo {
13
14namespace detail {
15class TensorHelper;
16}
17
31 public:
32 TensorShape(const TensorShape &shape);
33 TensorShape(TensorShape &&shape) noexcept;
35
37 TensorShape &operator=(TensorShape &&shape) noexcept;
38 bool operator==(const TensorShape &shape) const;
39 bool operator!=(const TensorShape &shape) const;
40
41 friend std::ostream &operator<<(std::ostream &os, const TensorShape &shape);
42
64 explicit TensorShape(int number_of_axes, size_t dim);
65
85 explicit TensorShape(const std::vector<size_t> &shape);
86
104 explicit TensorShape(std::vector<size_t> &&shape);
105
123 explicit TensorShape(const std::initializer_list<size_t> &shape)
124 : TensorShape(std::vector<size_t>(shape)) {}
125
131 [[nodiscard]] int number_of_axes() const noexcept;
132
138 [[nodiscard]] int size() const noexcept { return this->number_of_axes(); };
139
149 [[nodiscard]] int64_t axis_dim(int axis) const;
150
177 [[nodiscard]] const std::vector<size_t> &stride() const;
178
184 [[nodiscard]] std::vector<int64_t> axes_dims() const noexcept;
185
192 [[nodiscard]] bool is_fully_defined() const noexcept;
193
213 void push_axis_back(size_t dim);
214
237 void insert_axis(int axis, size_t dim);
238
260 void remove_axis(int axis);
261
267
290 void set_dim(int axis, size_t dim);
291
297 [[nodiscard]] size_t calculate_capacity() const noexcept;
298
304 [[nodiscard]] TensorShape clone() const;
305
306 private:
307 struct Impl;
308 std::unique_ptr<Impl> _impl{nullptr};
309
310 template <typename T>
311 friend class Tensor;
312
313 template <typename T>
314 friend class Predictor;
315
316 template <typename T>
317 friend class TensorAgg;
318
320
321 template <typename P>
322 void create_from_vector(P &&shape);
323
324 explicit TensorShape();
325};
326
331class TensorShapeError : public std::runtime_error {
332 public:
333 using std::runtime_error::runtime_error;
334};
335
336} // namespace txeo
337
338#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
Implements the mathematical concept of tensor, which is a magnitude of multiple order....
Definition Tensor.h:48
Exceptions concerning txeo::TensorShape.
The shape of a tensor is an ordered collection of dimensions of mathematical vector spaces.
Definition TensorShape.h:30
TensorShape(int number_of_axes, size_t dim)
Constructs a tensor shape with axes having the same dimension.
TensorShape clone() const
Returns a clone of this tensor.
bool operator!=(const TensorShape &shape) const
void remove_axis(int axis)
Removes a specified axis.
TensorShape(TensorShape &&shape) noexcept
int number_of_axes() const noexcept
Returns the size of the tensor shape.
TensorShape(const TensorShape &shape)
friend class txeo::detail::TensorHelper
void insert_axis(int axis, size_t dim)
Inserts a dimension at the specified axis.
TensorShape & operator=(const TensorShape &shape)
TensorShape & operator=(TensorShape &&shape) noexcept
int64_t axis_dim(int axis) const
Returns the dimension of the specified axis.
int size() const noexcept
Synonym for txeo::TensorShape::number_of_axes()
std::vector< int64_t > axes_dims() const noexcept
Returns the collection of tensor shape dimensions.
friend std::ostream & operator<<(std::ostream &os, const TensorShape &shape)
void push_axis_back(size_t dim)
Inserts a dimension after the last axis.
size_t calculate_capacity() const noexcept
Calculates the number of available tensor elements specified by the tensor shape.
void remove_all_axes()
Removes all axes from this shape, resulting an empty shape.
bool operator==(const TensorShape &shape) const
void set_dim(int axis, size_t dim)
Sets a dimension in a specified axis.
TensorShape(std::vector< size_t > &&shape)
Constructs a tensor shape from a std::vector.
TensorShape(const std::initializer_list< size_t > &shape)
Constructs a tensor shape from an initializer list.
TensorShape(const std::vector< size_t > &shape)
Constructs a tensor shape from a std::vector.
const std::vector< size_t > & stride() const
Returns the stride of each dimension in the tensor.
bool is_fully_defined() const noexcept
Indicates whether the tensor shape has any negative(undefined) dimensions or not.
Definition Matrix.h:11