4#include "nforge/core/tensor.h"
5#include "nforge/core/tensor_layout.h"
6#include "nforge/core/tensor_shape.h"
18 View(
Tensor& parent,
const std::vector<size_t>& position);
41 inline std::vector<size_t>
getPosition()
const {
return m_position; }
167 struct BroadcastTag {};
174 std::vector<size_t> m_position;
Definition tensor_shape.h:15
Definition tensor_view.h:12
Tensor::View operator[](size_t idx) const
Indexes into the first dimension of this view.
Definition tensor_view.cpp:211
Tensor & getParent() const
Returns the referenced tensor.
Definition tensor_view.h:38
Tensor sum(size_t dim=0) const
Reduces dimensions [dim, rank) by summation. Result shape is shape[0:dim].
Definition tensor_view.cpp:154
std::vector< float > toVector() const
Copies the viewd elements into a flat vector.
Definition tensor_view.cpp:102
Tensor prod(size_t dim=0) const
Reduces dimensions [dim, rank) by taking the product. Result shape is shape[0:dim].
Definition tensor_view.cpp:169
Tensor operator<(const Tensor::View &rhs) const
Elementwise less than. Returns a tensor of 0.0 / 1.0.
Definition tensor_view.cpp:290
Tensor copy() const
Deep copies the viewed region into a new tensor.
Definition tensor_view.cpp:90
Tensor operator>=(const Tensor::View &rhs) const
Elementwise greater or equal. Returns a tensor of 0.0 / 1.0.
Definition tensor_view.cpp:305
bool operator!=(const Tensor &rhs) const
Definition tensor_view.cpp:285
Tensor mean(size_t dim=0) const
Reduces dimensions [dim, rank) by averaging. Result shape is shape[0:dim].
Definition tensor_view.cpp:149
Tensor isClose(const Tensor::View &rhs, float tolerance=1e-5f) const
Definition tensor_view.cpp:310
Backend getBackend() const
Returns the backend enum.
Definition tensor_view.h:59
Tensor matmul(const Tensor::View &rhs) const
Definition tensor_view.cpp:221
static Tensor::View subsample(const View &src, const std::vector< size_t > &factors)
Definition tensor_view.cpp:226
void print() const
Prints the view to stdout.
Definition tensor_view.cpp:65
void operator*=(const Tensor::View &rhs)
In-place elementwise multiplication with a tensor or view. Modifies the parent tensor.
Definition tensor_view.cpp:136
Tensor operator<=(const Tensor::View &rhs) const
Elementwise less or equal. Returns a tensor of 0.0 / 1.0.
Definition tensor_view.cpp:295
Tensor norm() const
L2 norm (scalar tensor equal to sqrt(sum(x^2))).
Definition tensor_view.cpp:174
const TensorLayout & getLayout() const
Returns the underlying physical layout.
Definition tensor_view.h:53
Tensor min(size_t dim=0) const
Reduces dimensions [dim, rank) by taking the minimum. Result shape is shape[0:dim].
Definition tensor_view.cpp:159
size_t getOffset() const
Returns the element offset from the parent's data start.
Definition tensor_view.h:44
void operator+=(const Tensor::View &rhs)
In-place elementwise addition with a tensor or view. Modifies the parent tensor.
Definition tensor_view.cpp:124
Tensor::Shape getShape() const
Returns the shape of the viewed region.
Definition tensor_view.h:47
void operator-=(const Tensor::View &rhs)
In-place elementwise subtraction with a tensor or view. Modifies the parent tensor.
Definition tensor_view.cpp:130
std::string getBackendString() const
Returns "CPU" or "CUDA".
Definition tensor_view.h:56
std::vector< size_t > getPosition() const
Returns the origin position within the parent tensor.
Definition tensor_view.h:41
static Tensor::View broadcast(Tensor &source, const Tensor::Shape &shape)
Definition tensor_view.cpp:30
bool operator==(const Tensor &rhs) const
Definition tensor_view.cpp:270
Tensor::View operator=(const Tensor &rhs)
Copies data from a tensor into the referenced position of this view.
Definition tensor_view.cpp:179
Tensor operator>(const Tensor::View &rhs) const
Elementwise greater than. Returns a tensor of 0.0 / 1.0.
Definition tensor_view.cpp:300
std::vector< size_t > getStride() const
Returns the logical stride per dimension, normalized by the parent's base stride.
Definition tensor_view.cpp:75
Tensor max(size_t dim=0) const
Reduces dimensions [dim, rank) by taking the maximum. Result shape is shape[0:dim].
Definition tensor_view.cpp:164
void operator/=(const Tensor::View &rhs)
In-place elementwise division by a tensor or view. Modifies the parent tensor.
Definition tensor_view.cpp:142
friend Tensor operator-(float scalar, const Tensor &rhs)
Elementwise subtraction of a tensor from a pure float.
Definition tensor.cpp:176
friend Tensor operator+(float scalar, const Tensor &rhs)
Elementwise addition of a pure float and a tensor.
Definition tensor.cpp:174
friend Tensor operator/(float scalar, const Tensor &rhs)
Elementwise division of a pure float by a tensor.
Definition tensor.cpp:180
Backend getBackend() const
Returns the backend enum.
Definition tensor.h:75
friend Tensor operator*(float scalar, const Tensor &rhs)
Elementwise multiplication of a pure float and a tensor.
Definition tensor.cpp:178
std::string getBackendString() const
Returns "CPU" or "CUDA".
Definition tensor.cpp:89
Definition tensor_layout.h:15
size_t offset
Storage offset before indexing begins.
Definition tensor_layout.h:23