Skip to main content

DefaultScalarsView

Enum DefaultScalarsView 

Source
pub enum DefaultScalarsView<'a> {
    F32(TypedTensorView<'a, f32, DynRank, Host>),
    F64(TypedTensorView<'a, f64, DynRank, Host>),
    I32(TypedTensorView<'a, i32, DynRank, Host>),
    I64(TypedTensorView<'a, i64, DynRank, Host>),
    Bool(TypedTensorView<'a, bool, DynRank, Host>),
    C32(TypedTensorView<'a, Complex32, DynRank, Host>),
    C64(TypedTensorView<'a, Complex64, DynRank, Host>),
}
Expand description

Dynamic borrowed host tensor view.

§Examples

use tenferro_tensor::{DefaultScalars, DType};

let tensor = DefaultScalars::from_vec_col_major(vec![1], vec![true])?;
let view = tensor.as_view();
assert_eq!(view.dtype(), DType::Bool);
ⓘ
let a = tensor.as_view();
let b = tensor.as_view();
let _ = a == b;

Variants§

Implementations§

Source§

impl<'a> DefaultScalarsView<'a>

Source

pub fn dtype(&self) -> DType

Return this view’s dtype.

§Examples
use tenferro_tensor::{DefaultScalars, DType};

let tensor = DefaultScalars::from_vec_col_major(vec![1], vec![1.0_f32])?;
assert_eq!(tensor.as_view().dtype(), DType::F32);
Source

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

Borrow this view’s shape.

§Examples
use tenferro_tensor::DefaultScalars;

let tensor = DefaultScalars::from_vec_col_major(vec![1], vec![1.0_f64])?;
assert_eq!(tensor.as_view().shape(), &[1]);
Source

pub fn rank(&self) -> usize

Return the view rank.

§Examples
use tenferro_tensor::DefaultScalars;

let tensor = DefaultScalars::from_vec_col_major(vec![1, 1], vec![1_i64])?;
assert_eq!(tensor.as_view().rank(), 2);
Source

pub fn is_empty(&self) -> bool

Return whether this view has zero logical elements.

§Examples
use tenferro_tensor::DefaultScalars;

let tensor = DefaultScalars::from_vec_col_major(vec![0], Vec::<f64>::new())?;
assert!(tensor.as_view().is_empty());
Source

pub fn reshape_view(&self, shape: impl AsRef<[usize]>) -> Result<Self>

Return a metadata-only reshape of this dynamic view.

§Examples
use tenferro_tensor::DefaultScalars;

let tensor = DefaultScalars::from_vec_col_major(vec![4], vec![1_i32, 2, 3, 4])?;
assert_eq!(tensor.as_view().reshape_view(vec![2, 2])?.shape(), &[2, 2]);
§Errors

Returns a validation error carrying tenferro_tensor_core::ValidationError::ShapeMismatch when the element counts differ, tenferro_tensor_core::ValidationError::NonContiguousViewAsSlice when the view’s strides cannot express the new shape, or tenferro_tensor_core::ValidationError::IntegerOverflow when shape arithmetic overflows.

Source

pub fn transpose_view(&self, axes: &[usize]) -> Result<Self>

Return a metadata-only transposed dynamic view with axes in the requested order.

§Examples
use tenferro_tensor::DefaultScalars;

let tensor = DefaultScalars::from_vec_col_major(vec![1, 2], vec![1_i64, 2])?;
assert_eq!(tensor.as_view().transpose_view(&[1, 0])?.shape(), &[2, 1]);
§Errors

Returns a validation error carrying tenferro_tensor_core::ValidationError::InvalidPermutationLength, tenferro_tensor_core::ValidationError::AxisOutOfBounds or tenferro_tensor_core::ValidationError::DuplicateAxis when axes is not a permutation of the view rank.

Source

pub fn slice_view(&self, spec: &[StridedSliceSpec]) -> Result<Self>

Return a metadata-only positive-step slice of this dynamic view.

§Examples
use tenferro_tensor::{DefaultScalars, StridedSliceSpec};

let tensor = DefaultScalars::from_vec_col_major(vec![3], vec![1_i64, 2, 3])?;
assert_eq!(
    tensor.as_view().slice_view(&[StridedSliceSpec::new(1, Some(3), 1)])?.shape(),
    &[2],
);
§Errors

Returns crate::Error::Validation for a rank mismatch or invalid slice bounds or step.

Trait Implementations§

Source§

impl<'a> Clone for DefaultScalarsView<'a>

Source§

fn clone(&self) -> DefaultScalarsView<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for DefaultScalarsView<'a>

Source§

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

Formats the value using the given formatter. Read more

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

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.