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 <initializer_list>
8#include <memory>
9#include <ostream>
10#include <stdexcept>
11#include <vector>
12
13namespace txeo {
14
15namespace detail {
16class TensorHelper;
17}
18
32 public:
33 explicit TensorShape();
34 TensorShape(const TensorShape &shape);
35 TensorShape(TensorShape &&shape) noexcept;
37
39 TensorShape &operator=(TensorShape &&shape) noexcept;
40 bool operator==(const TensorShape &shape) const;
41 bool operator!=(const TensorShape &shape) const;
42
43 friend std::ostream &operator<<(std::ostream &os, const TensorShape &shape);
44
66 explicit TensorShape(int number_of_axes, size_t dim);
67
85 explicit TensorShape(std::vector<size_t> &&shape);
86
106 explicit TensorShape(const std::vector<size_t> &shape)
107 : TensorShape(std::vector<size_t>(shape)) {};
108
127 explicit TensorShape(const std::initializer_list<size_t> &shape)
128 : TensorShape(std::vector<size_t>(shape)) {}
129
136
142 [[nodiscard]] int size() const noexcept { return this->number_of_axes(); };
143
154
181 [[nodiscard]] const std::vector<size_t> &stride() const;
182
188 [[nodiscard]] std::vector<int64_t> axes_dims() const noexcept;
189
197
217 void push_axis_back(size_t dim);
218
241 void insert_axis(int axis, size_t dim);
242
264 void remove_axis(int axis);
265
271
294 void set_dim(int axis, size_t dim);
295
302
309
310 private:
311 struct Impl;
312
313 std::unique_ptr<Impl> _impl{nullptr};
314
315 template <typename T>
316 friend class Tensor;
317
318 template <typename T>
319 friend class Predictor;
320
321 template <typename T>
322 friend class TensorAgg;
323
325
326 template <typename P>
327 void create_from_vector(P &&shape);
328};
329
334class TensorShapeError : public std::runtime_error {
335 public:
336 using std::runtime_error::runtime_error;
337};
338
339} // namespace txeo
340
341#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
Implements the mathematical concept of tensor, which is a magnitude of multiple order....
Definition Tensor.h:50
Exceptions concerning txeo::TensorShape.
The shape of a tensor is an ordered collection of dimensions of mathematical vector spaces.
Definition TensorShape.h:31
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.