pub struct RawTensorImpl<'a>(/* private fields */);Expand description
A raw tensor implementation.
This struct is a low-level match to the C++ TensorImpl class.
A TensorImpl or any of its
variants (TensorImplAny, TensorImplMut, etc) is preferred for most uses, but this struct
is exposed for low level users who need to avoid code size overhead (avoiding the regular
tensor generics).
The struct does not enforce any mutability rules, and the caller must ensure that the tensor
is used correctly according to its mutability.
Implementations§
Source§impl<'a> RawTensorImpl<'a>
impl<'a> RawTensorImpl<'a>
Sourcepub unsafe fn from_ptr<S: Scalar>(
sizes: &'a [SizesType],
data: *mut S,
dim_order: &'a [DimOrderType],
strides: &'a [StridesType],
) -> Result<Self, Error>
pub unsafe fn from_ptr<S: Scalar>( sizes: &'a [SizesType], data: *mut S, dim_order: &'a [DimOrderType], strides: &'a [StridesType], ) -> Result<Self, Error>
Create a new TensorImpl from a pointer to the data.
§Arguments
sizes- The shape of the tensor.data- A pointer to the data buffer.dim_order- The order of the dimensions of the tensor, must have the same length assizes.strides- The strides of the tensor, in units of elements (not bytes), must have the same length assizes.
§Errors
Returns an error if dim order is invalid, or if it doesn’t match the strides, or if the strides are not dense, i.e. if the strides are not the standard layout strides of some permutation of the sizes.
§Panics
If the sizes, dim_order or strides slices are of different lengths.
§Safety
The caller must ensure elements in the data can be safely accessed according to the scalar type, sizes, dim order and strides of the tensor. The caller must ensure that the data is valid for the lifetime of the TensorImpl.