pub struct Tensor { /* private fields */ }Expand description
Core tensor abstraction - the single source of truth for all tensor operations
Implementations§
Source§impl Tensor
impl Tensor
Sourcepub fn new(
shape: Vec<usize>,
dtype: DataType,
device: Device,
data: Arc<dyn TensorStorage>,
) -> Self
pub fn new( shape: Vec<usize>, dtype: DataType, device: Device, data: Arc<dyn TensorStorage>, ) -> Self
Create new tensor with data
Sourcepub fn narrow(&self, dim: usize, start: usize, length: usize) -> Result<Self>
pub fn narrow(&self, dim: usize, start: usize, length: usize) -> Result<Self>
Narrow (slice) a tensor along a dimension
Returns a view into the tensor containing elements from start to start + length
along the specified dimension.
Sourcepub fn from_candle(candle_tensor: CandleTensor) -> Self
pub fn from_candle(candle_tensor: CandleTensor) -> Self
Create tensor from Candle tensor
Sourcepub fn as_candle(&self) -> Option<&CandleTensor>
pub fn as_candle(&self) -> Option<&CandleTensor>
Try to get the underlying Candle tensor
Sourcepub fn to_candle(&self) -> Result<CandleTensor>
pub fn to_candle(&self) -> Result<CandleTensor>
Convert to Candle tensor (may involve copying)
Sourcepub fn zeros_candle(
shape: &[usize],
dtype: DataType,
device: &Device,
) -> Result<Self>
pub fn zeros_candle( shape: &[usize], dtype: DataType, device: &Device, ) -> Result<Self>
Create tensor with zeros using Candle backend
Sourcepub fn from_f32_slice(
data: &[f32],
shape: &[usize],
device: &Device,
) -> Result<Self>
pub fn from_f32_slice( data: &[f32], shape: &[usize], device: &Device, ) -> Result<Self>
Create tensor from f32 slice using Candle backend
Sourcepub fn from_i64_slice(
data: &[i64],
shape: &[usize],
device: &Device,
) -> Result<Self>
pub fn from_i64_slice( data: &[i64], shape: &[usize], device: &Device, ) -> Result<Self>
Create tensor from i64 slice using Candle backend
Sourcepub fn to_vec_f32(&self) -> Result<Vec<f32>>
pub fn to_vec_f32(&self) -> Result<Vec<f32>>
Get the raw data as f32 slice (if applicable)
Sourcepub fn transpose(&self) -> Result<Self>
pub fn transpose(&self) -> Result<Self>
Transpose tensor (swap last two dimensions) For 2D tensors [M, N] -> [N, M] For higher dims [.., M, N] -> [.., N, M]
Sourcepub fn transpose_dims(&self, dim0: usize, dim1: usize) -> Result<Self>
pub fn transpose_dims(&self, dim0: usize, dim1: usize) -> Result<Self>
Transpose tensor with specific dimensions
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Tensor
impl !UnwindSafe for Tensor
impl Freeze for Tensor
impl Send for Tensor
impl Sync for Tensor
impl Unpin for Tensor
impl UnsafeUnpin for Tensor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more