BlockTensor

Struct BlockTensor 

Source
pub struct BlockTensor<T: TensorLike> { /* private fields */ }
Expand description

A collection of tensors organized in a block structure.

Each block is a tensor of type T implementing TensorLike. The flattened block list is ordered row-by-row: (0, 0), (0, 1), ..., (1, 0), (1, 1), ....

§Type Parameters

  • T - The tensor type for each block, must implement TensorLike

Implementations§

Source§

impl<T: TensorLike> BlockTensor<T>

Source

pub fn try_new(blocks: Vec<T>, shape: (usize, usize)) -> Result<Self>

Create a new block tensor with validation.

§Arguments
  • blocks - Vector of blocks flattened row-by-row
  • shape - Block structure as (rows, cols)
§Errors

Returns an error if rows * cols != blocks.len().

Source

pub fn new(blocks: Vec<T>, shape: (usize, usize)) -> Self

Create a new block tensor.

§Arguments
  • blocks - Vector of blocks flattened row-by-row
  • shape - Block structure as (rows, cols)
§Panics

Panics if rows * cols != blocks.len().

Source

pub fn shape(&self) -> (usize, usize)

Get the block structure (rows, cols).

Source

pub fn num_blocks(&self) -> usize

Get the total number of blocks.

Source

pub fn get(&self, row: usize, col: usize) -> &T

Get a reference to the block at (row, col).

§Panics

Panics if the indices are out of bounds.

Source

pub fn get_mut(&mut self, row: usize, col: usize) -> &mut T

Get a mutable reference to the block at (row, col).

§Panics

Panics if the indices are out of bounds.

Source

pub fn blocks(&self) -> &[T]

Get all blocks as a slice.

Source

pub fn blocks_mut(&mut self) -> &mut [T]

Get all blocks as a mutable slice.

Source

pub fn into_blocks(self) -> Vec<T>

Consume self and return the blocks.

Source

pub fn validate_indices(&self) -> Result<()>

Validate that blocks share external indices consistently.

For column vectors (cols=1), no index sharing is required between blocks. Different rows can have independent physical indices (the operator determines their relationship).

For matrices (rows x cols), checks that:

  • All blocks have the same number of external indices.
  • Blocks in the same row share some common index IDs (output indices).
  • Blocks in the same column share some common index IDs (input indices).

Trait Implementations§

Source§

impl<T: Clone + TensorLike> Clone for BlockTensor<T>

Source§

fn clone(&self) -> BlockTensor<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + TensorLike> Debug for BlockTensor<T>

Source§

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

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

impl<T: TensorLike> TensorIndex for BlockTensor<T>

Source§

type Index = <T as TensorIndex>::Index

The index type used by this object.
Source§

fn external_indices(&self) -> Vec<Self::Index>

Return flattened external indices for this object. Read more
Source§

fn replaceind( &self, old_index: &Self::Index, new_index: &Self::Index, ) -> Result<Self>

Replace an index in this object. Read more
Source§

fn replaceinds( &self, old_indices: &[Self::Index], new_indices: &[Self::Index], ) -> Result<Self>

Replace multiple indices in this object. Read more
Source§

fn num_external_indices(&self) -> usize

Number of external indices. Read more
Source§

fn replaceinds_pairs( &self, pairs: &[(Self::Index, Self::Index)], ) -> Result<Self>

Replace indices using pairs of (old, new). Read more
Source§

impl<T: TensorLike> TensorLike for BlockTensor<T>

Source§

fn norm_squared(&self) -> f64

Compute the squared Frobenius norm of the tensor. Read more
Source§

fn maxabs(&self) -> f64

Maximum absolute value of all elements (L-infinity norm).
Source§

fn scale(&self, scalar: AnyScalar) -> Result<Self>

Scalar multiplication.
Source§

fn axpby(&self, a: AnyScalar, other: &Self, b: AnyScalar) -> Result<Self>

Compute a linear combination: a * self + b * other. Read more
Source§

fn inner_product(&self, other: &Self) -> Result<AnyScalar>

Inner product (dot product) of two tensors. Read more
Source§

fn conj(&self) -> Self

Tensor conjugate operation. Read more
Source§

fn validate(&self) -> Result<()>

Validate structural consistency of this tensor. Read more
Source§

fn factorize( &self, _left_inds: &[<Self as TensorIndex>::Index], _options: &FactorizeOptions, ) -> Result<FactorizeResult<Self>, FactorizeError>

Factorize this tensor into left and right factors. Read more
Source§

fn direct_sum( &self, _other: &Self, _pairs: &[(<Self as TensorIndex>::Index, <Self as TensorIndex>::Index)], ) -> Result<DirectSumResult<Self>>

Direct sum of two tensors along specified index pairs. Read more
Source§

fn outer_product(&self, _other: &Self) -> Result<Self>

Outer product (tensor product) of two tensors. Read more
Source§

fn permuteinds( &self, _new_order: &[<Self as TensorIndex>::Index], ) -> Result<Self>

Permute tensor indices to match the specified order. Read more
Source§

fn contract(_tensors: &[&Self], _allowed: AllowedPairs<'_>) -> Result<Self>

Contract multiple tensors over their contractable indices. Read more
Source§

fn contract_connected( _tensors: &[&Self], _allowed: AllowedPairs<'_>, ) -> Result<Self>

Contract multiple tensors that must form a connected graph. Read more
Source§

fn diagonal( _input_index: &<Self as TensorIndex>::Index, _output_index: &<Self as TensorIndex>::Index, ) -> Result<Self>

Create a diagonal (Kronecker delta) tensor for a single index pair. Read more
Source§

fn scalar_one() -> Result<Self>

Create a scalar tensor with value 1.0. Read more
Source§

fn ones(_indices: &[<Self as TensorIndex>::Index]) -> Result<Self>

Create a tensor filled with 1.0 for the given indices. Read more
Source§

fn onehot(_index_vals: &[(<Self as TensorIndex>::Index, usize)]) -> Result<Self>

Create a one-hot tensor with value 1.0 at the specified index positions. Read more
Source§

fn norm(&self) -> f64

Compute the Frobenius norm of the tensor.
Source§

fn sub(&self, other: &Self) -> Result<Self>

Element-wise subtraction: self - other. Read more
Source§

fn neg(&self) -> Result<Self>

Negate all elements: -self.
Source§

fn isapprox(&self, other: &Self, atol: f64, rtol: f64) -> bool

Approximate equality check (Julia isapprox semantics). Read more
Source§

fn delta( input_indices: &[<Self as TensorIndex>::Index], output_indices: &[<Self as TensorIndex>::Index], ) -> Result<Self>

Create a delta (identity) tensor as outer product of diagonals. Read more

Auto Trait Implementations§

§

impl<T> Freeze for BlockTensor<T>

§

impl<T> RefUnwindSafe for BlockTensor<T>
where T: RefUnwindSafe,

§

impl<T> Send for BlockTensor<T>

§

impl<T> Sync for BlockTensor<T>

§

impl<T> Unpin for BlockTensor<T>
where T: Unpin,

§

impl<T> UnwindSafe for BlockTensor<T>
where T: UnwindSafe,

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
§

impl<U> As for U

§

fn as_<T>(self) -> T
where T: CastFrom<U>,

Casts self to type T. The semantics of numeric casting with the as operator are followed, so <T as As>::as_::<U> can be used in the same way as T as U for numeric conversions. 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

§

impl<T> ByRef<T> for T

§

fn by_ref(&self) -> &T

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
§

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

§

fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> T
where Self: Distribution<T>,

§

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

§

fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> T
where Self: Distribution<T>,

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

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

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

§

impl<T> MaybeSend for T

§

impl<T> MaybeSendSync for T

§

impl<T> MaybeSync for T