Class TensorView#
Defined in File tensor.h
Class Documentation#
-
class TensorView#
A non-owning view of a Tensor.
This class stores a light-weight non-owning view of a Tensor. This is useful for accessing tensor data without retaining a strong reference to the Tensor. Since the caller may not always be able to pass in a strong referenced tensor.
It is the user’s responsibility to ensure that the underlying tensor data outlives the
TensorView
. This responsibility extends to all data pointed to by the underlying DLTensor. This includes not only the tensor elements in data but also the memory for shape and strides.When exposing a function that expects only expects a TensorView, we recommend using ffi::TensorView as the argument type instead of ffi::Tensor.
Public Functions
-
inline TensorView(const Tensor &tensor)#
Create a TensorView from a Tensor.
- Parameters:
tensor – The input Tensor.
-
inline TensorView(const DLTensor *tensor)#
Create a TensorView from a DLTensor.
- Parameters:
tensor – The input DLTensor.
-
TensorView(const TensorView &tensor) = default#
Copy constructor.
- Parameters:
tensor – The input TensorView.
-
TensorView(TensorView &&tensor) = default#
Move constructor.
- Parameters:
tensor – The input TensorView.
-
inline ShapeView strides() const#
Get the strides of the Tensor.
- Returns:
The strides of the Tensor.
-
inline void *data_ptr() const#
Get the data pointer of the Tensor.
- Returns:
The data pointer of the Tensor.
-
inline int32_t ndim() const#
Get the number of dimensions in the Tensor.
- Returns:
The number of dimensions in the Tensor.
-
inline int64_t numel() const#
Get the number of elements in the Tensor.
- Returns:
The number of elements in the Tensor.
-
inline TensorView(const Tensor &tensor)#