Skip to main content

Tensor

Struct Tensor 

Source
pub struct Tensor { /* private fields */ }
Expand description

Dynamic tensor over the supported scalar types.

The erased tensor keeps dtype and rank dynamic: each preset scalar retains its typed owner without constructing a group, while caller-owned scalars remain External payloads recovered by their own type. Use TypedTensor<T, R> directly when the scalar type or rank should be represented in Rust’s type system.

§Examples

use tenferro_tensor::{DType, Tensor};

let tensor = Tensor::from_vec_col_major(vec![2], vec![1.0_f64, 2.0])?;
assert_eq!(tensor.dtype(), DType::F64);

Implementations§

Source§

impl Tensor

Source

pub fn linear_offset(&self, indices: &[usize]) -> Result<usize, Error>

Compute the linear physical-buffer offset for a logical index.

§Examples
use tenferro_tensor::Tensor;

let t = Tensor::from_vec_col_major(vec![2, 3], vec![0.0_f64; 6]).unwrap();
assert_eq!(t.linear_offset(&[1, 2])?, 5);
§Errors

Returns crate::Error::Validation containing tenferro_tensor_core::ValidationError::RankMismatch when indices has a rank different from the tensor, tenferro_tensor_core::ValidationError::InvalidArgument when an index is outside its axis extent, or tenferro_tensor_core::ValidationError::IntegerOverflow when checked offset arithmetic overflows.

Source

pub fn linear_offset2(&self, i: usize, j: usize) -> Result<usize, Error>

Compute the linear physical-buffer offset for a rank-2 logical index.

§Examples
use tenferro_tensor::Tensor;

let t = Tensor::from_vec_col_major(vec![2, 3], vec![0.0_f64; 6]).unwrap();
assert_eq!(t.linear_offset2(1, 2)?, 5);
§Errors

Returns crate::Error::Validation containing tenferro_tensor_core::ValidationError::RankMismatch when the tensor rank is not two, tenferro_tensor_core::ValidationError::InvalidArgument when i or j is outside its axis extent, or tenferro_tensor_core::ValidationError::IntegerOverflow when checked offset arithmetic overflows.

Source

pub fn linear_offset3( &self, i: usize, j: usize, k: usize, ) -> Result<usize, Error>

Compute the linear physical-buffer offset for a rank-3 logical index.

§Examples
use tenferro_tensor::Tensor;

let t = Tensor::from_vec_col_major(vec![2, 3, 2], vec![0.0_f64; 12]).unwrap();
assert_eq!(t.linear_offset3(1, 2, 1)?, 11);
§Errors

Returns crate::Error::Validation containing tenferro_tensor_core::ValidationError::RankMismatch when the tensor rank is not three, tenferro_tensor_core::ValidationError::InvalidArgument when i, j, or k is outside its axis extent, or tenferro_tensor_core::ValidationError::IntegerOverflow when checked offset arithmetic overflows.

Source

pub fn get<T>(&self, indices: &[usize]) -> Result<&T, Error>
where T: TensorScalar,

Borrow a single typed element by multi-index.

§Examples
use tenferro_tensor::Tensor;

let t = Tensor::from_vec_col_major(vec![2], vec![1.0_f64, 2.0]).unwrap();
assert_eq!(t.get::<f64>(&[1])?, &2.0);
assert!(t.get::<f32>(&[1]).is_err());
§Errors

Returns crate::Error::Validation containing tenferro_tensor_core::ValidationError::RankMismatch or tenferro_tensor_core::ValidationError::InvalidArgument for an invalid index, tenferro_tensor_core::ValidationError::DTypeMismatch when T does not match the tensor dtype, or crate::Error::RuntimeState for a device-backed tensor.

Source

pub fn get_mut<T>(&mut self, indices: &[usize]) -> Result<&mut T, Error>
where T: TensorScalar,

Mutably borrow a single typed element by multi-index.

§Examples
use tenferro_tensor::Tensor;

let mut t = Tensor::from_vec_col_major(vec![1], vec![1.0_f64]).unwrap();
*t.get_mut::<f64>(&[0])? = 2.0;
assert_eq!(t.as_slice::<f64>()?, &[2.0]);
§Errors

Returns crate::Error::Validation containing tenferro_tensor_core::ValidationError::RankMismatch or tenferro_tensor_core::ValidationError::InvalidArgument for an invalid index, tenferro_tensor_core::ValidationError::DTypeMismatch when T does not match the tensor dtype, or crate::Error::RuntimeState for a device-backed tensor.

Source

pub unsafe fn get_unchecked<T>(&self, indices: &[usize]) -> Result<&T, Error>
where T: TensorScalar,

Try to borrow a single typed element by multi-index without release-mode bounds checks.

Debug builds still validate the rank and bounds. Dtype and backend host-access failures are still reported as errors.

§Safety

indices must have the same rank as this tensor and every index must be in bounds.

§Examples
use tenferro_tensor::Tensor;

let t = Tensor::from_vec_col_major(vec![2], vec![1.0_f64, 2.0]).unwrap();
assert_eq!(unsafe { *t.get_unchecked::<f64>(&[1])? }, 2.0);
§Errors

Returns crate::Error::RuntimeState for a device-backed tensor and tenferro_tensor_core::ValidationError::DTypeMismatch when T does not match the tensor dtype.

§Panics

May panic if the unsafe rank/bounds precondition is violated and the checked linear-offset calculation overflows.

Source

pub unsafe fn get_unchecked_mut<T>( &mut self, indices: &[usize], ) -> Result<&mut T, Error>
where T: TensorScalar,

Try to mutably borrow a single typed element by multi-index without release-mode bounds checks.

Debug builds still validate the rank and bounds. Dtype and backend host-access failures are still reported as errors.

§Safety

indices must have the same rank as this tensor and every index must be in bounds.

§Examples
use tenferro_tensor::Tensor;

let mut t = Tensor::from_vec_col_major(vec![1], vec![1.0_f64]).unwrap();
unsafe {
    *t.get_unchecked_mut::<f64>(&[0])? = 2.0;
}
assert_eq!(t.as_slice::<f64>()?, &[2.0]);
§Errors

Returns crate::Error::RuntimeState for a device-backed tensor and tenferro_tensor_core::ValidationError::DTypeMismatch when T does not match the tensor dtype.

§Panics

May panic if the unsafe rank/bounds precondition is violated and the checked linear-offset calculation overflows.

Source

pub fn as_slice_mut<T>(&mut self) -> Result<&mut [T], Error>
where T: TensorScalar,

Mutably borrow the host data as a typed slice.

§Examples
use tenferro_tensor::Tensor;

let mut t = Tensor::from_vec_col_major(vec![2], vec![1.0_f64, 2.0]).unwrap();
t.as_slice_mut::<f64>()?[0] = 3.0;
assert_eq!(t.as_slice::<f64>()?, &[3.0, 2.0]);
assert!(t.as_slice_mut::<f32>().is_err());
§Errors

Returns tenferro_tensor_core::ValidationError::DTypeMismatch when T does not match the tensor dtype, or crate::Error::RuntimeState when the tensor is backed by a device buffer.

Source

pub fn iter<T>(&self) -> Result<Iter<'_, T>, Error>
where T: TensorScalar,

Iterate over the contiguous host buffer in physical memory order.

§Examples
use tenferro_tensor::Tensor;

let t = Tensor::from_vec_col_major(vec![2], vec![1.0_f64, 2.0]).unwrap();
let sum: f64 = t.iter::<f64>()?.copied().sum();
assert_eq!(sum, 3.0);
assert!(t.iter::<f32>().is_err());
§Errors

Returns tenferro_tensor_core::ValidationError::DTypeMismatch when T does not match the tensor dtype, or crate::Error::RuntimeState when the tensor is backed by a device buffer.

Source

pub fn iter_mut<T>(&mut self) -> Result<IterMut<'_, T>, Error>
where T: TensorScalar,

Mutably iterate over the contiguous host buffer in physical memory order.

§Examples
use tenferro_tensor::Tensor;

let mut t = Tensor::from_vec_col_major(vec![2], vec![1.0_f64, 2.0]).unwrap();
for value in t.iter_mut::<f64>()? {
    *value += 1.0;
}
assert_eq!(t.as_slice::<f64>()?, &[2.0, 3.0]);
assert!(t.iter_mut::<f32>().is_err());
§Errors

Returns tenferro_tensor_core::ValidationError::DTypeMismatch when T does not match the tensor dtype, or crate::Error::RuntimeState when the tensor is backed by a device buffer.

Source§

impl Tensor

Source

pub fn index_select( &self, axis: isize, positions: &[usize], session: &mut dyn Engine, ) -> Result<Tensor, Error>

Select entries from one axis using host-known positions.

§Examples
use tenferro_tensor::{Engine, Tensor};

fn select_last_axis(
    session: &mut dyn Engine,
    x: &Tensor,
) -> tenferro_tensor::Result<Tensor> {
    x.index_select(-1, &[2, 0], session)
}
§Errors

Returns crate::Error::Validation with a typed shape, axis, or argument source when the inputs cannot be packed without violating their metadata.

Source

pub fn stack( tensors: &[&Tensor], dim: isize, session: &mut dyn Engine, ) -> Result<Tensor, Error>

Stack tensors along a newly inserted axis.

§Examples
use tenferro_tensor::{Engine, Tensor};

fn stack_scalars(
    session: &mut dyn Engine,
    a: &Tensor,
    b: &Tensor,
) -> tenferro_tensor::Result<Tensor> {
    Tensor::stack(&[a, b], -1, session)
}
§Errors

Returns crate::Error::Validation with a typed shape, axis, or argument source when the inputs cannot be packed without violating their metadata.

Source§

impl Tensor

Source

pub fn external(payload: ErasedHostTensor) -> Tensor

Carry an externally defined scalar as a caller-owned payload.

The payload keeps its own element type and is recovered by that type, so no bytes are reinterpreted. Placement defaults to unpinned host memory, which is where a caller-owned payload lives.

§Examples
use tenferro_tensor::{DType, Tensor};
use tenferro_tensor::{DynRank, ErasedHostTensor, Host, TypedTensor};

let payload = ErasedHostTensor::new(
    TypedTensor::<f64, DynRank, Host>::from_host_vec_col_major(vec![1], vec![1.0_f64])?,
);
let element = payload.element_type_id();
let tensor = Tensor::external(payload);
assert_eq!(tensor.dtype(), DType::External(element));
assert_eq!(tensor.shape(), &[1]);
Source

pub fn from_typed<T>(typed: TypedTensor<T>) -> Tensor
where T: TensorScalar,

Build a tensor from a typed one, without naming its variant.

A call site that constructs a tensor from a typed tensor should use this rather than a variant, so that changing how the erased representation is stored changes this function and not its 1290 call sites. The variants remain until the removal’s last step, so both forms currently produce the same value.

§Examples
use tenferro_tensor::Tensor;

let tensor = Tensor::from_vec_col_major(vec![2], vec![1.0_f64, 2.0])?;
let typed = tensor.into_typed::<f64>().unwrap();
let rebuilt = Tensor::from_typed(typed);
assert_eq!(rebuilt.as_typed::<f64>().unwrap().shape(), &[2]);
Source

pub fn external_payload(&self) -> Option<&ErasedHostTensor>

Borrow the erased payload of an externally defined tensor.

This is the counterpart of Tensor::external for dispatch: a table that matches on Tensor::dtype reaches the externally defined tag and needs the payload that tag stands for, just as the typed tags reach theirs through Tensor::as_typed. Every other tag returns None.

§Examples
use tenferro_tensor::Tensor;
use tenferro_tensor::{DynRank, ErasedHostTensor, Host, TypedTensor};

let payload = ErasedHostTensor::new(
    TypedTensor::<f64, DynRank, Host>::from_host_vec_col_major(vec![1], vec![1.0_f64])?,
);
let tensor = Tensor::external(payload);
assert!(tensor.external_payload().is_some());
Source

pub fn external_with_placement( payload: ErasedHostTensor, placement: Placement, ) -> Tensor

Carry an externally defined payload with an explicit placement.

Tensor::external defaults the placement to unpinned host memory, which is where a caller-owned payload normally lives; this entry point is for a caller that knows the placement it wants.

§Examples
use tenferro_tensor::{Placement, Tensor};
use tenferro_tensor::{DynRank, ErasedHostTensor, Host, TypedTensor};

let payload = ErasedHostTensor::new(
    TypedTensor::<f64, DynRank, Host>::from_host_vec_col_major(vec![1], vec![1.0_f64])?,
);
let tensor = Tensor::external_with_placement(payload, Placement::default());
assert!(tensor.external_payload().is_some());
Source

pub fn external_payload_mut(&mut self) -> Option<&mut ErasedHostTensor>

Mutably borrow the erased payload of an externally defined tensor.

The counterpart of Tensor::external_payload for callers that update the payload in place, such as a mutation test that checks the copy boundary.

§Examples
use tenferro_tensor::Tensor;
use tenferro_tensor::{DynRank, ErasedHostTensor, Host, TypedTensor};

let mut tensor = Tensor::external(ErasedHostTensor::new(
    TypedTensor::<f64, DynRank, Host>::from_host_vec_col_major(vec![1], vec![1.0_f64])?,
));
assert!(tensor.external_payload_mut().is_some());
Source§

impl Tensor

Source

pub fn as_real_view(&self) -> Result<TensorView<'_>, Error>

Borrow a complex tensor as its sealed interleaved real representation.

§Errors

Returns crate::Error::Unsupported for a non-complex dtype and ValidationError::ViewOutOfBounds or ValidationError::InvalidArgument for invalid layout metadata.

Source

pub fn as_real_view_mut(&mut self) -> Result<TensorViewMut<'_>, Error>

Borrow a complex tensor mutably as its sealed interleaved real representation.

§Errors

Returns crate::Error::Unsupported for a non-complex dtype and ValidationError::ViewOutOfBounds or ValidationError::InvalidArgument for invalid layout metadata.

Source

pub fn into_real(self) -> Result<Tensor, ReinterpretError<Tensor>>

Consume a complex tensor and reinterpret its owner as real without copying.

§Errors

Returns ReinterpretError::error containing ValidationError::InvalidArgument or ValidationError::ViewOutOfBounds while retaining the unchanged owner.

Source

pub fn as_complex_view(&self) -> Result<TensorView<'_>, Error>

Borrow an interleaved real tensor as its sealed complex representation.

§Errors

Returns crate::Error::Unsupported for a non-real dtype and ValidationError::ViewOutOfBounds or ValidationError::InvalidArgument for invalid layout metadata.

Source

pub fn as_complex_view_mut(&mut self) -> Result<TensorViewMut<'_>, Error>

Borrow an interleaved real tensor mutably as its sealed complex representation.

§Errors

Returns crate::Error::Unsupported for a non-real dtype and ValidationError::ViewOutOfBounds or ValidationError::InvalidArgument for invalid layout metadata.

Source

pub fn into_complex(self) -> Result<Tensor, ReinterpretError<Tensor>>

Consume a real tensor and reinterpret its owner as complex without copying.

§Errors

Returns ReinterpretError::error containing ValidationError::InvalidArgument or ValidationError::ViewOutOfBounds while retaining the unchanged owner.

Source

pub fn duplicate(&self) -> Result<Tensor, Error>

Make an explicit owning copy of this dtype-erased tensor.

Tensor deliberately does not implement Clone: copying can fail (device-only storage is rejected) and allocates a new, independent owner, so it is an explicit fallible call rather than an infallible clone(). The copy shares nothing with self; mutating one never affects the other. To share one tensor between several users without copying, wrap it in std::sync::Arc or borrow views of it.

§Examples
use std::sync::Arc;
use tenferro_tensor::Tensor;

let weights = Tensor::from_vec_col_major(vec![2], vec![1.0_f64, 2.0])?;
// Two independent owners of the same values.
let copy = weights.duplicate()?;
assert_eq!(copy.as_slice::<f64>()?, weights.as_slice::<f64>()?);

// A shared, read-only handle instead of a copy.
let shared = Arc::new(weights);
let other = Arc::clone(&shared);
assert_eq!(other.shape(), &[2]);
§Errors

Returns crate::Error::RuntimeState or crate::Error::Unsupported when the selected backend/storage owner cannot be duplicated.

Source

pub fn from_vec_col_major<T>( shape: impl IntoShapeVec, data: Vec<T>, ) -> Result<Tensor, Error>
where T: TensorScalar,

Create a tensor from a shape and column-major flat data.

This is the Tensor-level equivalent of TypedTensor::<T>::from_vec_col_major.

§Examples
use tenferro_tensor::Tensor;

let t = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 3.0, 2.0, 4.0]).unwrap();
assert_eq!(t.shape(), &[2, 2]);
assert_eq!(t.as_slice::<f64>().unwrap(), &[1.0, 3.0, 2.0, 4.0]);
§Errors

Returns crate::Error::Validation with tenferro_tensor_core::ValidationError::ShapeDataLengthMismatch when the shape product differs from data.len(), or tenferro_tensor_core::ValidationError::IntegerOverflow when shape arithmetic overflows.

Source

pub fn from_vec_row_major<T>( shape: impl IntoShapeVec, data: Vec<T>, ) -> Result<Tensor, Error>
where T: TensorScalar,

Create a tensor from a shape and row-major (C-order) flat data.

The values are reordered once into tenferro’s column-major storage; no row-major owner is created. Use this for buffers authored in PyTorch/NumPy/C order instead of passing them to Self::from_vec_col_major, which would reinterpret them silently. This is the Tensor-level equivalent of TypedTensor::<T>::from_vec_row_major.

§Examples
use tenferro_tensor::Tensor;

// Row-major [[1, 2, 3], [4, 5, 6]].
let t = Tensor::from_vec_row_major(vec![2, 3], vec![1.0_f64, 2.0, 3.0, 4.0, 5.0, 6.0])?;
assert_eq!(t.shape(), &[2, 3]);
assert_eq!(t.as_slice::<f64>()?, &[1.0, 4.0, 2.0, 5.0, 3.0, 6.0]);
§Errors

Returns crate::Error::Validation with tenferro_tensor_core::ValidationError::ShapeDataLengthMismatch when the shape product differs from data.len(), or tenferro_tensor_core::ValidationError::IntegerOverflow when shape arithmetic overflows.

Source

pub fn shape(&self) -> &[usize]

Tensor shape.

§Examples
use tenferro_tensor::{Tensor, TypedTensor};

let t = Tensor::from_typed(TypedTensor::from_vec_col_major(vec![2], vec![1.0, 2.0]).unwrap());
assert_eq!(t.shape(), &[2]);
Source

pub fn dtype(&self) -> DType

Tensor dtype tag.

§Examples
use tenferro_tensor::{DType, Tensor, TypedTensor};

let t = Tensor::from_typed(TypedTensor::from_vec_col_major(vec![], vec![1.0]).unwrap());
assert_eq!(t.dtype(), DType::F64);
Source

pub fn placement(&self) -> &Placement

Return placement metadata for this dtype-erased tensor.

§Examples
use tenferro_tensor::{MemoryKind, Tensor};

let t = Tensor::from_vec_col_major(vec![1], vec![1.0_f64]).unwrap();
assert_eq!(t.placement().memory_kind, MemoryKind::UnpinnedHost);
Source

pub fn is_backend_buffer(&self) -> bool

Return whether this tensor is backed by backend-native storage.

§Examples
use tenferro_tensor::Tensor;

let t = Tensor::from_vec_col_major(vec![1], vec![1.0_f64]).unwrap();
assert!(!t.is_backend_buffer());
Source

pub fn is_host_memory(&self) -> bool

Return whether this tensor’s payload is host-addressed memory.

The one host/device answer, decided by the payload and never by Placement::memory_kind: the same answer TypedTensor::is_host_memory gives for a typed owner and TensorRead::is_host_memory for a read target. A caller-owned payload holds host bytes, so it is host memory; erasing its dtype, not its placement, is what makes a preset-scalar view unavailable.

§Examples
use tenferro_tensor::{Tensor, TensorRead};

let t = Tensor::from_vec_col_major(vec![1], vec![1.0_f64])?;
assert!(t.is_host_memory());
assert!(TensorRead::from_tensor(&t).is_host_memory());
Source

pub fn layout_linear_offset(&self, indices: &[usize]) -> Result<usize, Error>

Compute the physical element offset for a logical index.

§Examples
use tenferro_tensor::Tensor;

let t = Tensor::from_vec_col_major(vec![2], vec![1.0_f64, 2.0])?;
assert_eq!(t.layout_linear_offset(&[1])?, 1);
§Errors

Returns crate::Error::Validation with tenferro_tensor_core::ValidationError::RankMismatch when indices has the wrong rank, tenferro_tensor_core::ValidationError::InvalidArgument when an index is outside its axis extent, or tenferro_tensor_core::ValidationError::IntegerOverflow when offset arithmetic overflows.

Source

pub fn is_col_major_contiguous(&self) -> Result<bool, Error>

Return whether this tensor is compact column-major.

§Examples
use tenferro_tensor::Tensor;

let t = Tensor::from_vec_col_major(vec![2], vec![1.0_f64, 2.0])?;
assert!(t.is_col_major_contiguous()?);
§Errors

Returns crate::Error::Validation with tenferro_tensor_core::ValidationError::IntegerOverflow when compactness arithmetic overflows.

Source

pub fn layout_summary(&self) -> String

Return a compact string summary of this tensor’s layout metadata.

§Examples
use tenferro_tensor::Tensor;

let t = Tensor::from_vec_col_major(vec![2], vec![1.0_f64, 2.0])?;
assert!(t.layout_summary().contains("shape=[2]"));
Source

pub fn assert_col_major_contiguous(&self) -> Result<(), Error>

Assert this tensor is compact column-major.

§Examples
use tenferro_tensor::Tensor;

let t = Tensor::from_vec_col_major(vec![2], vec![1.0_f64, 2.0])?;
t.assert_col_major_contiguous()?;
§Errors

Returns crate::Error::Validation with tenferro_tensor_core::ValidationError::IntegerOverflow when compactness arithmetic overflows, or tenferro_tensor_core::ValidationError::InvalidArgument when the tensor is not compact column-major.

Source

pub fn as_slice<T>(&self) -> Result<&[T], Error>
where T: TensorScalar,

Try to borrow the host data as a typed slice.

Returns an error if the tensor dtype does not match T.

§Examples
use tenferro_tensor::{Tensor, TypedTensor};

let t = Tensor::from_typed(TypedTensor::from_vec_col_major(vec![3], vec![1.0, 2.0, 3.0]).unwrap());
assert_eq!(t.as_slice::<f64>().unwrap(), [1.0, 2.0, 3.0].as_slice());
assert!(t.as_slice::<f32>().is_err());
§Errors

Returns crate::Error::Validation with tenferro_tensor_core::ValidationError::DTypeMismatch when T does not match the tensor dtype, or crate::Error::RuntimeState when the matching tensor uses backend storage that has not been downloaded.

Source

pub fn as_typed<T>(&self) -> Option<&TypedTensor<T>>
where T: TensorScalar,

Borrow the typed tensor when the requested scalar matches this tensor’s dtype.

This is the accessor tag-based dispatch needs: it recovers the typed tensor — and with it the device buffer — from a value whose element type is only known at run time, so a caller can dispatch on Tensor::dtype instead of matching every variant. An externally defined scalar is not a typed tensor, so it returns None rather than guessing a representation.

§Examples
use tenferro_tensor::Tensor;

let tensor = Tensor::from_vec_col_major(vec![2], vec![1.0_f64, 2.0])?;
assert!(tensor.as_typed::<f64>().is_some());
assert!(tensor.as_typed::<f32>().is_none());
assert_eq!(tensor.as_typed::<f64>().unwrap().shape(), &[2]);
Source

pub fn as_typed_mut<T>(&mut self) -> Option<&mut TypedTensor<T>>
where T: TensorScalar,

Mutably borrow the typed tensor when the requested scalar matches this tensor’s dtype.

This is the mutable half of Tensor::as_typed, for the tables whose arm calls a method that needs &mut, such as marking a freshly allocated output with its placement. An externally defined scalar is not a typed tensor, so it returns None for the same reason.

§Examples
use tenferro_tensor::Tensor;

let mut tensor = Tensor::from_vec_col_major(vec![2], vec![1.0_f64, 2.0])?;
assert!(tensor.as_typed_mut::<f64>().is_some());
assert!(tensor.as_typed_mut::<f32>().is_none());
Source

pub fn into_typed<T>(self) -> Result<TypedTensor<T>, ReinterpretError<Tensor>>
where T: TensorScalar,

Consume this tensor and return the owned typed tensor when the dtype matches.

This is the consuming counterpart of Tensor::as_typed, for the tables whose arm hands the typed tensor to a function that takes it by value — reusing its buffer rather than copying it.

§Examples
use tenferro_tensor::Tensor;

let tensor = Tensor::from_vec_col_major(vec![2], vec![1.0_f64, 2.0])?;
assert!(tensor.into_typed::<f64>().is_ok());

let tensor = Tensor::from_vec_col_major(vec![2], vec![1.0_f32, 2.0])?;
assert!(tensor.into_typed::<f64>().is_err());
§Errors

Returns ReinterpretError carrying the unchanged tensor when T is not this tensor’s dtype, with crate::Error::Validation and tenferro_tensor_core::ValidationError::DTypeMismatch as the cause. A matching tensor is handed over as it is, including one whose storage lives in a backend buffer.

Source

pub fn into_vec_col_major<T>( self, ) -> Result<(Vec<usize>, Vec<T>), ReinterpretError<Tensor>>
where T: TensorScalar,

Consume this tensor and return its owned column-major buffer when the dtype matches.

§Examples
use tenferro_tensor::Tensor;

let t = Tensor::from_vec_col_major(vec![1], vec![2.0_f64]).unwrap();
assert_eq!(t.into_vec_col_major::<f64>().unwrap().1, vec![2.0]);
§Errors

Returns ReinterpretError carrying the unchanged tensor when T does not match the tensor dtype or when the matching tensor uses backend storage that has not been downloaded.

Trait Implementations§

Source§

impl AsView for Tensor

Source§

type Repr = Erased

The representation results take for this input.
Source§

fn as_read(&self) -> TensorRead<'_>

Borrow this input as a TensorRead. Metadata only; never copies element data. Read more
Source§

impl Debug for Tensor

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl From<TypedTensor<Complex<f32>>> for Tensor

Wrap a Complex32 TypedTensor into the corresponding Tensor variant.

§Examples

use num_complex::Complex32;
use tenferro_tensor::{Tensor, TypedTensor};

let typed = TypedTensor::from_vec_col_major(
    vec![1],
    vec![Complex32::new(1.0, 2.0)],
).unwrap();
let tensor: Tensor = typed.into();
assert_eq!(tensor.shape(), &[1]);
Source§

fn from(t: TypedTensor<Complex<f32>>) -> Tensor

Converts to this type from the input type.
Source§

impl From<TypedTensor<Complex<f64>>> for Tensor

Wrap a Complex64 TypedTensor into the corresponding Tensor variant.

§Examples

use num_complex::Complex64;
use tenferro_tensor::{Tensor, TypedTensor};

let typed = TypedTensor::from_vec_col_major(
    vec![1],
    vec![Complex64::new(1.0, 2.0)],
).unwrap();
let tensor: Tensor = typed.into();
assert_eq!(tensor.shape(), &[1]);
Source§

fn from(t: TypedTensor<Complex<f64>>) -> Tensor

Converts to this type from the input type.
Source§

impl From<TypedTensor<bool>> for Tensor

Wrap a bool TypedTensor into the corresponding Tensor variant.

§Examples

use tenferro_tensor::{DType, Tensor, TypedTensor};

let typed = TypedTensor::from_vec_col_major(vec![2], vec![true, false]).unwrap();
let tensor: Tensor = typed.into();
assert_eq!(tensor.dtype(), DType::Bool);
assert_eq!(tensor.shape(), &[2]);
Source§

fn from(t: TypedTensor<bool>) -> Tensor

Converts to this type from the input type.
Source§

impl From<TypedTensor<f32>> for Tensor

Wrap an f32 TypedTensor into the corresponding Tensor variant.

§Examples

use tenferro_tensor::{Tensor, TypedTensor};

let typed = TypedTensor::from_vec_col_major(vec![2], vec![1.0_f32, 2.0]).unwrap();
let tensor: Tensor = typed.into();
assert_eq!(tensor.shape(), &[2]);
Source§

fn from(t: TypedTensor<f32>) -> Tensor

Converts to this type from the input type.
Source§

impl From<TypedTensor<f64>> for Tensor

Wrap an f64 TypedTensor into the corresponding Tensor variant.

§Examples

use tenferro_tensor::{Tensor, TypedTensor};

let typed = TypedTensor::from_vec_col_major(vec![2], vec![1.0_f64, 2.0]).unwrap();
let tensor: Tensor = typed.into();
assert_eq!(tensor.shape(), &[2]);
Source§

fn from(t: TypedTensor<f64>) -> Tensor

Converts to this type from the input type.
Source§

impl From<TypedTensor<i32>> for Tensor

Wrap an i32 TypedTensor into the corresponding Tensor variant.

§Examples

use tenferro_tensor::{DType, Tensor, TypedTensor};

let typed = TypedTensor::from_vec_col_major(vec![2], vec![1_i32, 2]).unwrap();
let tensor: Tensor = typed.into();
assert_eq!(tensor.dtype(), DType::I32);
assert_eq!(tensor.shape(), &[2]);
Source§

fn from(t: TypedTensor<i32>) -> Tensor

Converts to this type from the input type.
Source§

impl From<TypedTensor<i64>> for Tensor

Wrap an i64 TypedTensor into the corresponding Tensor variant.

§Examples

use tenferro_tensor::{DType, Tensor, TypedTensor};

let typed = TypedTensor::from_vec_col_major(vec![2], vec![1_i64, 2]).unwrap();
let tensor: Tensor = typed.into();
assert_eq!(tensor.dtype(), DType::I64);
assert_eq!(tensor.shape(), &[2]);
Source§

fn from(t: TypedTensor<i64>) -> Tensor

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> ByRef<T> for T

§

fn by_ref(&self) -> &T

Source§

impl<X> CoreOps for X
where X: AsView + ?Sized,

Source§

fn exp( &self, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Elementwise exponential. Read more
Source§

fn neg( &self, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Elementwise negation. Read more
Source§

fn sign( &self, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Elementwise sign. Read more
Source§

fn conj( &self, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Elementwise complex conjugate (identity on real dtypes). Read more
Source§

fn log( &self, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Elementwise natural logarithm. Read more
Source§

fn expm1( &self, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Elementwise exp(x) - 1. Read more
Source§

fn log1p( &self, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Elementwise log(1 + x). Read more
Source§

fn erf( &self, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Elementwise error function. Read more
Source§

fn sin( &self, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Elementwise sine. Read more
Source§

fn cos( &self, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Elementwise cosine. Read more
Source§

fn tanh( &self, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Elementwise hyperbolic tangent. Read more
Source§

fn sqrt( &self, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Elementwise square root. Read more
Source§

fn rsqrt( &self, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Elementwise reciprocal square root. Read more
Source§

fn abs( &self, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as CoreRepr>::Real, Error>
where <X as AsView>::Repr: CoreRepr,

Elementwise absolute value; complex inputs return their modulus. Read more
Source§

fn sigmoid( &self, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Logistic sigmoid. Read more
Source§

fn silu( &self, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

SiLU (x * sigmoid(x)). Read more
Source§

fn softplus( &self, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Softplus log(1 + exp(x)). Read more
Source§

fn gelu( &self, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

GELU with the exact error function. Read more
Source§

fn gelu_tanh( &self, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

GELU with the tanh approximation. Read more
Source§

fn mul( &self, b: &impl AsView<Repr = <X as AsView>::Repr>, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Elementwise product with broadcasting. Read more
Source§

fn sub( &self, b: &impl AsView<Repr = <X as AsView>::Repr>, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Elementwise difference with broadcasting. Read more
Source§

fn div( &self, b: &impl AsView<Repr = <X as AsView>::Repr>, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Elementwise quotient with broadcasting. Read more
Source§

fn rem( &self, b: &impl AsView<Repr = <X as AsView>::Repr>, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Elementwise remainder with broadcasting. Read more
Source§

fn pow( &self, b: &impl AsView<Repr = <X as AsView>::Repr>, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Elementwise power with broadcasting. Read more
Source§

fn maximum( &self, b: &impl AsView<Repr = <X as AsView>::Repr>, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Elementwise maximum with broadcasting. Read more
Source§

fn minimum( &self, b: &impl AsView<Repr = <X as AsView>::Repr>, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Elementwise minimum with broadcasting. Read more
Source§

fn add( &self, b: &impl AsView<Repr = <X as AsView>::Repr>, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Elementwise sum with broadcasting. Read more
Source§

fn add_into( &self, b: &impl AsView<Repr = <X as AsView>::Repr>, exec: &mut dyn Engine, dest: Dest<<<X as AsView>::Repr as Repr>::Write<'_>>, ) -> Result<(), Error>
where <X as AsView>::Repr: CoreRepr,

Elementwise sum with broadcasting. Read more
Source§

fn matmul( &self, b: &impl AsView<Repr = <X as AsView>::Repr>, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Matrix product of the two leading axes, batched over trailing axes. Read more
Source§

fn compare( &self, b: &impl AsView<Repr = <X as AsView>::Repr>, dir: CompareDir, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as CoreRepr>::Bool, Error>
where <X as AsView>::Repr: CoreRepr,

Elementwise comparison with broadcasting; returns a bool tensor. Read more
Source§

fn clamp( &self, lower: &impl AsView<Repr = <X as AsView>::Repr>, upper: &impl AsView<Repr = <X as AsView>::Repr>, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Elementwise clamp to [lower, upper] with broadcasting. Read more
Source§

fn where_select<Y>( &self, on_true: &Y, on_false: &impl AsView<Repr = <Y as AsView>::Repr>, exec: &mut dyn Engine, ) -> Result<<<Y as AsView>::Repr as Repr>::Value, Error>
where Y: SelectOperand<<X as AsView>::Repr> + ?Sized, <X as AsView>::Repr: CoreRepr,

Elementwise selection: on_true where the receiver is true, on_false elsewhere, with broadcasting. The receiver is the bool condition; a typed receiver must be TypedTensor<bool>. Read more
Source§

fn dot_general( &self, b: &impl AsView<Repr = <X as AsView>::Repr>, config: DotGeneralConfig, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

General contraction with batch dimensions (DotGeneralConfig); DotGeneralOptions conjugates an operand. Read more
Source§

fn dot_general_with( &self, b: &impl AsView<Repr = <X as AsView>::Repr>, config: DotGeneralConfig, options: &DotGeneralOptions, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

General contraction with batch dimensions (DotGeneralConfig); DotGeneralOptions conjugates an operand. Read more
Source§

fn reduce_sum( &self, axes: Option<&[isize]>, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Sum over axes (None: every axis); axes are signed, -1 is the last axis. Read more
Source§

fn reduce_max( &self, axes: Option<&[isize]>, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Maximum over axes (None: every axis); axes are signed, -1 is the last axis. Read more
Source§

fn reduce_min( &self, axes: Option<&[isize]>, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Minimum over axes (None: every axis); axes are signed, -1 is the last axis. Read more
Source§

fn reduce_prod( &self, axes: Option<&[isize]>, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Product over axes (None: every axis); axes are signed, -1 is the last axis. Read more
Source§

fn reduce_sum_squares( &self, axes: Option<&[isize]>, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Sum of squared magnitudes over axes (None: every axis); axes are signed, -1 is the last axis. Read more
Source§

fn reduce_mean( &self, axes: Option<&[isize]>, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Mean over axes (None: every axis); axes are signed, -1 is the last axis. Read more
Source§

fn reshape( &self, shape: &[usize], exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Reshape to shape in column-major element order. Read more
Source§

fn broadcast_in_dim( &self, shape: &[usize], dims: &[usize], exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Broadcast to shape; dims[i] is the output axis of input axis i (an IR-level dimension map, unsigned like the *Config structs). Read more
Source§

fn transpose( &self, perm: &[isize], exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Permute axes; perm is signed (-1 is the last axis). Read more
Source§

fn reverse( &self, axes: &[isize], exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Reverse the order of elements along axes (signed). Read more
Source§

fn tril( &self, k: i64, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Lower triangle of the two leading axes relative to diagonal k. Read more
Source§

fn triu( &self, k: i64, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Upper triangle of the two leading axes relative to diagonal k. Read more
Source§

fn extract_diag( &self, axis_a: isize, axis_b: isize, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Extract the diagonal of axes axis_a and axis_b (signed). Read more
Source§

fn embed_diag( &self, axis_a: isize, axis_b: isize, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Embed axis axis_a of the receiver as the diagonal of a new axis pair; axis_b (signed, against the output rank) is the position of the inserted axis. Read more
Source§

fn slice( &self, config: SliceConfig, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Static strided slice (SliceConfig). Read more
Source§

fn pad( &self, config: PadConfig, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Pad with edge and interior padding (PadConfig). Read more
Source§

fn gather( &self, indices: &impl AsView, config: GatherConfig, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

XLA-style gather (GatherConfig); indices is an integer tensor of any representation. Read more
Source§

fn scatter( &self, indices: &impl AsView, updates: &impl AsView, config: ScatterConfig, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

XLA-style scatter (ScatterConfig); indices and updates may have any representation. Read more
Source§

fn dynamic_slice( &self, starts: &impl AsView, sizes: &[usize], exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Slice of sizes starting at the run-time starts (an integer vector). Read more
Source§

fn dynamic_update_slice( &self, update: &impl AsView<Repr = <X as AsView>::Repr>, starts: &impl AsView, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Copy of the receiver with update written at the run-time starts. Read more
Source§

fn concatenate( inputs: &[&X], axis: isize, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr, X: Sized,

Concatenate inputs along axis (signed). Called as CoreOps::concatenate(&[&a, &b], axis, exec). Read more
Source§

fn convert(&self, to: DType, exec: &mut dyn Engine) -> Result<Tensor, Error>
where <X as AsView>::Repr: CoreRepr,

Checked dtype conversion along tenferro’s promotion lattice. The result is a dtype-erased Tensor because its dtype is a run-time value. Read more
Source§

fn cast(&self, to: DType, exec: &mut dyn Engine) -> Result<Tensor, Error>
where <X as AsView>::Repr: CoreRepr,

Explicit, possibly lossy dtype projection. The result is a dtype-erased Tensor because its dtype is a run-time value. Read more
Source§

fn scale_real( &self, factor: f64, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Multiply by a real scalar. Read more
Source§

fn scale_complex( &self, factor: Complex<f64>, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Multiply by a complex scalar. Read more
Source§

fn softmax( &self, axis: isize, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Softmax along axis (signed). Read more
Source§

fn log_softmax( &self, axis: isize, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Log-softmax along axis (signed). Read more
Source§

fn masked_softmax( &self, mask: &impl AsView, axis: isize, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Softmax along axis over the entries where mask is true. Read more
Source§

fn masked_log_softmax( &self, mask: &impl AsView, axis: isize, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Log-softmax along axis over the entries where mask is true. Read more
Source§

fn take_along_axis( &self, indices: &impl AsView, axis: isize, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Gather along axis (signed) with per-position integer indices. Read more
Source§

fn layer_norm( &self, axis: isize, weight: Option<&X>, bias: Option<&X>, eps: f64, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Layer normalization over axis (signed) with optional affine weight and bias. Read more
Source§

fn rms_norm( &self, axis: isize, weight: Option<&X>, bias: Option<&X>, eps: f64, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

RMS normalization over axis (signed) with optional affine weight and bias. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Imply<T> for U
where T: ?Sized, U: ?Sized,

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

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
Source§

impl<X> LinalgOps for X
where X: AsView + ?Sized,

Source§

fn svd( &self, exec: &mut dyn Engine, ) -> Result<Svd<<<X as AsView>::Repr as Repr>::Value, <<X as AsView>::Repr as LinalgRepr>::Real>, Error>
where <X as AsView>::Repr: LinalgRepr,

Singular value decomposition a = u diag(s) vh; SvdShape::Full returns the full-matrices factors. Read more
Source§

fn svd_with( &self, options: &SvdOptions, exec: &mut dyn Engine, ) -> Result<Svd<<<X as AsView>::Repr as Repr>::Value, <<X as AsView>::Repr as LinalgRepr>::Real>, Error>
where <X as AsView>::Repr: LinalgRepr,

Singular value decomposition a = u diag(s) vh; SvdShape::Full returns the full-matrices factors. Read more
Source§

fn svdvals( &self, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as LinalgRepr>::Real, Error>
where <X as AsView>::Repr: LinalgRepr,

Singular values only, in descending order. Read more
Source§

fn svdvals_with( &self, options: &SvdvalsOptions, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as LinalgRepr>::Real, Error>
where <X as AsView>::Repr: LinalgRepr,

Singular values only, in descending order. Read more
Source§

fn qr( &self, exec: &mut dyn Engine, ) -> Result<Qr<<<X as AsView>::Repr as Repr>::Value>, Error>
where <X as AsView>::Repr: LinalgRepr,

Thin QR factorization a = q r. Read more
Source§

fn qr_with( &self, options: &QrOptions, exec: &mut dyn Engine, ) -> Result<Qr<<<X as AsView>::Repr as Repr>::Value>, Error>
where <X as AsView>::Repr: LinalgRepr,

Thin QR factorization a = q r. Read more
Source§

fn householder_qr( &self, exec: &mut dyn Engine, ) -> Result<HouseholderQr<<<X as AsView>::Repr as Repr>::Value>, Error>
where <X as AsView>::Repr: LinalgRepr,

Compact Householder QR: an opaque factorization state from which r and q_columns are extracted. Read more
Source§

fn rank_revealing_qr( &self, exec: &mut dyn Engine, ) -> Result<RankRevealingQrResult<<<X as AsView>::Repr as Repr>::Value, <<X as AsView>::Repr as LinalgRepr>::Index>, Error>
where <X as AsView>::Repr: LinalgRepr,

Column-pivoted QR with a numerical rank: q, r, column_permutation and rank. Read more
Source§

fn rank_revealing_qr_with( &self, options: &RankRevealingQrOptions, exec: &mut dyn Engine, ) -> Result<RankRevealingQrResult<<<X as AsView>::Repr as Repr>::Value, <<X as AsView>::Repr as LinalgRepr>::Index>, Error>
where <X as AsView>::Repr: LinalgRepr,

Column-pivoted QR with a numerical rank: q, r, column_permutation and rank. Read more
Source§

fn lu( &self, exec: &mut dyn Engine, ) -> Result<Lu<<<X as AsView>::Repr as Repr>::Value>, Error>
where <X as AsView>::Repr: LinalgRepr,

Partial-pivot LU a = p l u; p is a permutation matrix and parity is the real sign of the permutation. Read more
Source§

fn full_piv_lu( &self, exec: &mut dyn Engine, ) -> Result<FullPivLu<<<X as AsView>::Repr as Repr>::Value, <<X as AsView>::Repr as LinalgRepr>::Real>, Error>
where <X as AsView>::Repr: LinalgRepr,

Complete-pivot LU a = p l u q; p and q are permutation matrices and parity is the real sign of the permutations. Read more
Source§

fn full_piv_lu_solve( &self, b: &impl AsView<Repr = <X as AsView>::Repr>, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: LinalgRepr,

Solves a x = b through the complete-pivot LU of a; a rank-deficient system is rejected. Read more
Source§

fn solve( &self, b: &impl AsView<Repr = <X as AsView>::Repr>, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: LinalgRepr,

Solves a x = b with a partial-pivot LU of a; solve_into overwrites a destination. Read more
Source§

fn solve_into( &self, b: &impl AsView<Repr = <X as AsView>::Repr>, exec: &mut dyn Engine, dest: Dest<<<X as AsView>::Repr as Repr>::Write<'_>>, ) -> Result<(), Error>
where <X as AsView>::Repr: LinalgRepr,

Solves a x = b with a partial-pivot LU of a; solve_into overwrites a destination. Read more
Source§

fn lstsq( &self, b: &impl AsView<Repr = <X as AsView>::Repr>, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: LinalgRepr,

Least-squares solution of a x = b for a tall or square, full-column-rank a (thin QR, then a triangular solve). Read more
Source§

fn triangular_solve( &self, b: &impl AsView<Repr = <X as AsView>::Repr>, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: LinalgRepr,

Solves a triangular system with a (or its transpose) on the chosen side; only the selected triangle of a is read. Read more
Source§

fn triangular_solve_with( &self, b: &impl AsView<Repr = <X as AsView>::Repr>, options: &TriangularSolveOptions, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: LinalgRepr,

Solves a triangular system with a (or its transpose) on the chosen side; only the selected triangle of a is read. Read more
Source§

fn cholesky( &self, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: LinalgRepr,

Lower Cholesky factor l of a Hermitian positive-definite matrix, a = l l^H. Read more
Source§

fn cholesky_with( &self, options: &CholeskyOptions, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: LinalgRepr,

Lower Cholesky factor l of a Hermitian positive-definite matrix, a = l l^H. Read more
Source§

fn eig( &self, exec: &mut dyn Engine, ) -> Result<Eig<<<X as AsView>::Repr as LinalgRepr>::Complex>, Error>
where <X as AsView>::Repr: LinalgRepr,

General eigendecomposition a v = v diag(values); eigenvectors have unit 2-norm. Read more
Source§

fn eigvals( &self, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as LinalgRepr>::Complex, Error>
where <X as AsView>::Repr: LinalgRepr,

Eigenvalues of a general matrix, as complex numbers. Read more
Source§

fn eigh( &self, exec: &mut dyn Engine, ) -> Result<Eigh<<<X as AsView>::Repr as Repr>::Value, <<X as AsView>::Repr as LinalgRepr>::Real>, Error>
where <X as AsView>::Repr: LinalgRepr,

Eigendecomposition of a Hermitian matrix (the lower triangle is read); values are real and ascending. Read more
Source§

fn eigh_with( &self, options: &EighOptions, exec: &mut dyn Engine, ) -> Result<Eigh<<<X as AsView>::Repr as Repr>::Value, <<X as AsView>::Repr as LinalgRepr>::Real>, Error>
where <X as AsView>::Repr: LinalgRepr,

Eigendecomposition of a Hermitian matrix (the lower triangle is read); values are real and ascending. Read more
Source§

fn eigvalsh( &self, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as LinalgRepr>::Real, Error>
where <X as AsView>::Repr: LinalgRepr,

Eigenvalues of a Hermitian matrix (the lower triangle is read), real and ascending. Read more
Source§

fn eigvalsh_with( &self, options: &EigvalshOptions, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as LinalgRepr>::Real, Error>
where <X as AsView>::Repr: LinalgRepr,

Eigenvalues of a Hermitian matrix (the lower triangle is read), real and ascending. Read more
Source§

fn slogdet( &self, exec: &mut dyn Engine, ) -> Result<Slogdet<<<X as AsView>::Repr as Repr>::Value, <<X as AsView>::Repr as LinalgRepr>::Real>, Error>
where <X as AsView>::Repr: LinalgRepr,

Sign and natural log of the absolute determinant of a square matrix. Read more
Source§

fn det( &self, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: LinalgRepr,

Determinant of a square matrix, computed as sign * exp(log_abs_det). Read more
Source§

fn inv( &self, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: LinalgRepr,

Inverse of a square matrix (a solve against the identity). Read more
Source§

fn pinv( &self, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: LinalgRepr,

Moore-Penrose pseudoinverse through the SVD; singular values below rtol * max(s) are dropped. Read more
Source§

fn pinv_with( &self, options: &PinvOptions, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: LinalgRepr,

Moore-Penrose pseudoinverse through the SVD; singular values below rtol * max(s) are dropped. Read more
Source§

fn norm( &self, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as LinalgRepr>::Real, Error>
where <X as AsView>::Repr: LinalgRepr,

Vector or matrix norm over the chosen axes, selected by NormOrd; NormOrd::Zero counts entries != 0 (NaN counts as nonzero). Read more
Source§

fn norm_with( &self, options: &NormOptions, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as LinalgRepr>::Real, Error>
where <X as AsView>::Repr: LinalgRepr,

Vector or matrix norm over the chosen axes, selected by NormOrd; NormOrd::Zero counts entries != 0 (NaN counts as nonzero). Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<Y, C> SelectOperand<C> for Y
where Y: AsView + ?Sized, C: SelectCondition,

§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

§

fn simd_from(_simd: S, value: T) -> T

§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

§

fn simd_into(self, simd: S) -> T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.