pub struct Index<Id, Tags = TagSet> {
pub id: Id,
pub dim: usize,
pub plev: i64,
pub tags: Tags,
}Expand description
Index with generic identity type Id and tag type Tags.
Id = DynIdfor ITensors-like runtime identityId = ZST marker typefor compile-time-known identityTags = TagSetfor tags (default, Arc-wrapped for cheap cloning)
Note: This default implementation does not include symmetry (quantum numbers). For QSpace-compatible indices with non-Abelian symmetries, use a separate concrete type.
§Memory Layout
With default types (DynId, TagSet):
- Size: 32 bytes (8 + 8 + 8 + 8)
- Tags are shared via
Arc, so cloning is cheap (reference count increment only)
Equality: Two Index values are considered equal if and only if their id and tags
fields and plev match (matching ITensors.jl semantics where equality = id + plev + tags).
§Example
use tensor4all_core::index::{Index, DynId, TagSet};
// Create shared tags once
let site_tags = TagSet::from_str("Site").unwrap();
// Share the same tags across many indices (cheap clone)
let i1 = Index::<DynId>::new_dyn_with_tags(2, site_tags.clone());
let i2 = Index::<DynId>::new_dyn_with_tags(2, site_tags.clone());
// i1.tags and i2.tags point to the same ArcFields§
§id: IdThe unique identifier for this index.
dim: usizeThe dimension (size) of this index.
plev: i64The prime level of this index.
The tag set associated with this index.
Implementations§
Source§impl<Id, Tags> Index<Id, Tags>where
Tags: Default,
impl<Id, Tags> Index<Id, Tags>where
Tags: Default,
Sourcepub fn new_with_size(id: Id, size: usize) -> Self
pub fn new_with_size(id: Id, size: usize) -> Self
Create a new index from dimension (convenience constructor).
Create a new index from dimension and tags.
Source§impl Index<DynId, TagSet>
impl Index<DynId, TagSet>
Sourcepub fn new_dyn(size: usize) -> Self
pub fn new_dyn(size: usize) -> Self
Create a new index with a generated dynamic ID and no tags.
Create a new index with a generated dynamic ID and shared tags.
This is the most efficient way to create many indices with the same tags.
The Arc is cloned (reference count increment only), not the underlying data.
§Example
use tensor4all_core::index::{Index, DynId, TagSet};
let site_tags = TagSet::from_str("Site").unwrap();
let i1 = Index::<DynId>::new_dyn_with_tags(2, site_tags.clone());
let i2 = Index::<DynId>::new_dyn_with_tags(2, site_tags.clone());Sourcepub fn new_dyn_with_tag(size: usize, tag: &str) -> Result<Self, TagSetError>
pub fn new_dyn_with_tag(size: usize, tag: &str) -> Result<Self, TagSetError>
Create a new index with a generated dynamic ID and a single tag.
This creates a new TagSet with the given tag.
For sharing the same tag across many indices, create the TagSet
once and use new_dyn_with_tags instead.
Sourcepub fn new_link(size: usize) -> Result<Self, TagSetError>
pub fn new_link(size: usize) -> Result<Self, TagSetError>
Create a new bond index with “Link” tag (for SVD, QR, etc.).
This is a convenience method for creating bond indices commonly used in tensor decompositions like SVD and QR factorization.
Source§impl Index<DynId>
impl Index<DynId>
Sourcepub fn new_bond(dim: usize) -> Result<Self>
pub fn new_bond(dim: usize) -> Result<Self>
Create a new bond index with a fresh identity and the specified dimension.
This is used by factorization operations (SVD, QR) to create new internal bond indices connecting the factors.
§Arguments
dim- The dimension of the new index
§Returns
A new index with a unique identity and the specified dimension.
Trait Implementations§
impl<Id: Copy, Tags: Copy> Copy for Index<Id, Tags>
impl<Id: Eq, Tags: Eq> Eq for Index<Id, Tags>
Auto Trait Implementations§
impl<Id, Tags> Freeze for Index<Id, Tags>
impl<Id, Tags> RefUnwindSafe for Index<Id, Tags>where
Id: RefUnwindSafe,
Tags: RefUnwindSafe,
impl<Id, Tags> Send for Index<Id, Tags>
impl<Id, Tags> Sync for Index<Id, Tags>
impl<Id, Tags> Unpin for Index<Id, Tags>
impl<Id, Tags> UnwindSafe for Index<Id, Tags>where
Id: UnwindSafe,
Tags: 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>,
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
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>,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.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>
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>
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