|
NForge
Tensor library
|
#include <tensor_view.h>
Public Member Functions | |
| View (Tensor &parent) | |
| Full view at the origin. | |
| View (Tensor &parent, const std::vector< size_t > &position) | |
View of a sub tensor starting at position. | |
| View (Tensor &parent, const std::vector< size_t > &position, const TensorLayout &layout) | |
View with explicit position and TensorLayout. | |
| View (const Tensor &parent) | |
| Implicit conversion from Tensor. | |
| void | print () const |
| Prints the view to stdout. | |
| Tensor & | getParent () const |
| Returns the referenced tensor. | |
| std::vector< size_t > | getPosition () const |
| Returns the origin position within the parent tensor. | |
| size_t | getOffset () const |
| Returns the element offset from the parent's data start. | |
| Tensor::Shape | getShape () const |
| Returns the shape of the viewed region. | |
| std::vector< size_t > | getStride () const |
| Returns the logical stride per dimension, normalized by the parent's base stride. | |
| const TensorLayout & | getLayout () const |
| Returns the underlying physical layout. | |
| std::string | getBackendString () const |
| Returns "CPU" or "CUDA". | |
| Backend | getBackend () const |
| Returns the backend enum. | |
| Tensor | copy () const |
| Deep copies the viewed region into a new tensor. | |
| std::vector< float > | toVector () const |
| Copies the viewd elements into a flat vector. | |
| Tensor | operator+ (const Tensor::View &rhs) const |
| Elementwise addition with a tensor or view. Copies then computes. | |
| Tensor | operator- (const Tensor::View &rhs) const |
| Elementwise subtraction with a tensor or view. Copies then computes. | |
| Tensor | operator* (const Tensor::View &rhs) const |
| Elementwise multiplication with a tensor or view. Copies then computes. | |
| Tensor | operator/ (const Tensor::View &rhs) const |
| Elementwise division by a tensor or view. Copies then computes. | |
| void | operator+= (const Tensor::View &rhs) |
| In-place elementwise addition with a tensor or view. Modifies the parent tensor. | |
| void | operator-= (const Tensor::View &rhs) |
| In-place elementwise subtraction with a tensor or view. Modifies the parent tensor. | |
| void | operator*= (const Tensor::View &rhs) |
| In-place elementwise multiplication with a tensor or view. Modifies the parent tensor. | |
| void | operator/= (const Tensor::View &rhs) |
| In-place elementwise division by a tensor or view. Modifies the parent tensor. | |
| Tensor | mean (size_t dim=0) const |
| Reduces dimensions [dim, rank) by averaging. Result shape is shape[0:dim]. | |
| Tensor | sum (size_t dim=0) const |
| Reduces dimensions [dim, rank) by summation. Result shape is shape[0:dim]. | |
| Tensor | min (size_t dim=0) const |
| Reduces dimensions [dim, rank) by taking the minimum. Result shape is shape[0:dim]. | |
| Tensor | max (size_t dim=0) const |
| Reduces dimensions [dim, rank) by taking the maximum. Result shape is shape[0:dim]. | |
| Tensor | prod (size_t dim=0) const |
| Reduces dimensions [dim, rank) by taking the product. Result shape is shape[0:dim]. | |
| Tensor | norm () const |
L2 norm (scalar tensor equal to sqrt(sum(x^2))). | |
| Tensor::View | operator= (const Tensor &rhs) |
| Copies data from a tensor into the referenced position of this view. | |
| Tensor::View | operator= (const Tensor::View &rhs) |
| Copies data from a view into the referenced position of this view. | |
| Tensor::View | operator= (float scalar) |
| Tensor::View | operator[] (size_t idx) const |
| Indexes into the first dimension of this view. | |
| Tensor | matmul (const Tensor::View &rhs) const |
| Tensor::View | subsample (std::vector< size_t > strides) const |
Strided subsampling view. Views every strides[i]-th element along dim i. | |
| bool | operator== (const Tensor &rhs) const |
| bool | operator== (const Tensor::View &rhs) const |
| bool | operator!= (const Tensor &rhs) const |
| bool | operator!= (const Tensor::View &rhs) const |
| Tensor | operator< (const Tensor::View &rhs) const |
| Elementwise less than. Returns a tensor of 0.0 / 1.0. | |
| Tensor | operator<= (const Tensor::View &rhs) const |
| Elementwise less or equal. Returns a tensor of 0.0 / 1.0. | |
| Tensor | operator> (const Tensor::View &rhs) const |
| Elementwise greater than. Returns a tensor of 0.0 / 1.0. | |
| Tensor | operator>= (const Tensor::View &rhs) const |
| Elementwise greater or equal. Returns a tensor of 0.0 / 1.0. | |
| Tensor | isClose (const Tensor::View &rhs, float tolerance=1e-5f) const |
Static Public Member Functions | |
| static Tensor::View | broadcast (Tensor &source, const Tensor::Shape &shape) |
| static Tensor::View | subsample (const View &src, const std::vector< size_t > &factors) |
Non-owning reference to a sub region of a Tensor.
A View describes a sub region of a Tensor via an position, shape, and stride layout. Multiple views can reference the same underlying data at different offsets and shapes.
|
static |
Creates a broadcast view of source to shape. Size-1 dimensions are broadcast by setting their stride to 0.
| Tensor Tensor::View::isClose | ( | const Tensor::View & | rhs, |
| float | tolerance = 1e-5f |
||
| ) | const |
Elementwise closeness check within tolerance. Returns a tensor of 0.0 / 1.0.
| tolerance | Maximum absolute difference (default: 1e-5). |
| Tensor Tensor::View::matmul | ( | const Tensor::View & | rhs | ) | const |
Matrix multiplication. Inputs must be 2D or 3D tensors. 2D: (N, M) @ (M, K) => (N, K).
3D: (B, N, M) @ (B, M, K) => (B, N, K).
Batch dims must be broadcastable, match or be 1.
| bool Tensor::View::operator!= | ( | const Tensor & | rhs | ) | const |
Returns true if any element differs from rhs.
.isClose() | bool Tensor::View::operator!= | ( | const Tensor::View & | rhs | ) | const |
Returns true if any element differs from rhs.
.isClose() | Tensor::View Tensor::View::operator= | ( | float | scalar | ) |
Assigns a pure float to a View.
| bool Tensor::View::operator== | ( | const Tensor & | rhs | ) | const |
Returns true if shape and every element matches rhs.
.isClose() | bool Tensor::View::operator== | ( | const Tensor::View & | rhs | ) | const |
Returns true if shape and every element matches rhs.
.isClose()
|
static |
Creates a subsampled view of src. A factor of 0 freezes that dimension to a single element (stride 0).