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 implementTensorLike
Implementations§
Source§impl<T: TensorLike> BlockTensor<T>
impl<T: TensorLike> BlockTensor<T>
Sourcepub fn num_blocks(&self) -> usize
pub fn num_blocks(&self) -> usize
Get the total number of blocks.
Sourcepub fn get_mut(&mut self, row: usize, col: usize) -> &mut T
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.
Sourcepub fn blocks_mut(&mut self) -> &mut [T]
pub fn blocks_mut(&mut self) -> &mut [T]
Get all blocks as a mutable slice.
Sourcepub fn into_blocks(self) -> Vec<T>
pub fn into_blocks(self) -> Vec<T>
Consume self and return the blocks.
Sourcepub fn validate_indices(&self) -> Result<()>
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>
impl<T: Clone + TensorLike> Clone for BlockTensor<T>
Source§fn clone(&self) -> BlockTensor<T>
fn clone(&self) -> BlockTensor<T>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<T: Debug + TensorLike> Debug for BlockTensor<T>
impl<T: Debug + TensorLike> Debug for BlockTensor<T>
Source§impl<T: TensorLike> TensorIndex for BlockTensor<T>
impl<T: TensorLike> TensorIndex for BlockTensor<T>
Source§type Index = <T as TensorIndex>::Index
type Index = <T as TensorIndex>::Index
The index type used by this object.
Source§fn external_indices(&self) -> Vec<Self::Index>
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>
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>
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
fn num_external_indices(&self) -> usize
Number of external indices. Read more
Source§impl<T: TensorLike> TensorLike for BlockTensor<T>
impl<T: TensorLike> TensorLike for BlockTensor<T>
Source§fn norm_squared(&self) -> f64
fn norm_squared(&self) -> f64
Compute the squared Frobenius norm of the tensor. Read more
Source§fn axpby(&self, a: AnyScalar, other: &Self, b: AnyScalar) -> Result<Self>
fn axpby(&self, a: AnyScalar, other: &Self, b: AnyScalar) -> Result<Self>
Compute a linear combination:
a * self + b * other. Read moreSource§fn inner_product(&self, other: &Self) -> Result<AnyScalar>
fn inner_product(&self, other: &Self) -> Result<AnyScalar>
Inner product (dot product) of two tensors. Read more
Source§fn factorize(
&self,
_left_inds: &[<Self as TensorIndex>::Index],
_options: &FactorizeOptions,
) -> Result<FactorizeResult<Self>, FactorizeError>
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>>
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>
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>
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>
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>
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>
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>
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>
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>
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 isapprox(&self, other: &Self, atol: f64, rtol: f64) -> bool
fn isapprox(&self, other: &Self, atol: f64, rtol: f64) -> bool
Approximate equality check (Julia
isapprox semantics). Read moreSource§fn delta(
input_indices: &[<Self as TensorIndex>::Index],
output_indices: &[<Self as TensorIndex>::Index],
) -> Result<Self>
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§
§impl<U> As for U
impl<U> As for U
§fn as_<T>(self) -> Twhere
T: CastFrom<U>,
fn as_<T>(self) -> Twhere
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 moreSource§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> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> Twhere
Self: Distribution<T>,
§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> Twhere
Self: Distribution<T>,
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