pub trait TensorBase:
Clone
+ Send
+ Sync
+ Debug {
// Required methods
fn shape(&self) -> &[usize];
fn dtype(&self) -> DType;
fn device(&self) -> Device;
fn to_dense(&self) -> DenseTensor;
fn to_sparse(&self) -> Option<SparseTensor>;
// Provided methods
fn ndim(&self) -> usize { ... }
fn numel(&self) -> usize { ... }
fn is_scalar(&self) -> bool { ... }
fn is_vector(&self) -> bool { ... }
fn is_matrix(&self) -> bool { ... }
}Expand description
Tensor 基础 trait:所有张量必须实现的核心操作
提供形状、数据类型、设备等基本信息查询
Required Methods§
Sourcefn to_dense(&self) -> DenseTensor
fn to_dense(&self) -> DenseTensor
转换为密集张量
Sourcefn to_sparse(&self) -> Option<SparseTensor>
fn to_sparse(&self) -> Option<SparseTensor>
转换为稀疏张量(如果适用)
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementors§
impl TensorBase for SparseTensor
Available on crate feature
tensor only.impl TensorBase for DenseTensor
Available on crate feature
tensor only.