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.
This is the most common way to create indices. Each call generates
a unique random ID, so two calls to new_dyn with the same dimension
produce non-equal indices.
§Examples
use tensor4all_core::{DynIndex, IndexLike};
let i = DynIndex::new_dyn(4);
let j = DynIndex::new_dyn(4);
assert_eq!(i.dim(), 4);
assert_ne!(i, j); // different IDs
assert!(i.is_contractable(&i)); // same index is contractable with itself
assert!(!i.is_contractable(&j)); // different IDsCreate 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.
§Examples
use tensor4all_core::DynIndex;
use tensor4all_core::TagSetLike;
let site = DynIndex::new_dyn_with_tag(2, "Site").unwrap();
assert!(site.tags().has_tag("Site"));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.
§Examples
use tensor4all_core::DynIndex;
use tensor4all_core::TagSetLike;
let link = DynIndex::new_link(4).unwrap();
assert!(link.tags().has_tag("Link"));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.
§Examples
use tensor4all_core::{DynIndex, IndexLike};
let bond = DynIndex::new_bond(8).unwrap();
assert_eq!(bond.dim(), 8);Sourcepub fn prime(&self) -> Self
pub fn prime(&self) -> Self
Return a copy of this index with its prime level incremented by one.
Primed indices are commonly used to distinguish bra and ket indices
in MPO operations (e.g., i for input, i' for output).
§Examples
use tensor4all_core::{DynIndex, IndexLike};
let i = DynIndex::new_dyn(4);
assert_eq!(i.plev(), 0);
let i_prime = i.prime();
assert_eq!(i_prime.plev(), 1);
// Primed and unprimed indices have the same ID but are not equal
assert!(i.same_id(&i_prime));
assert_ne!(i, i_prime);
// Primed indices are not contractable with unprimed ones
assert!(!i.is_contractable(&i_prime));Sourcepub fn noprime(&self) -> Self
pub fn noprime(&self) -> Self
Return a copy of this index with its prime level reset to zero.
§Examples
use tensor4all_core::{DynIndex, IndexLike};
let i = DynIndex::new_dyn(4);
let i2 = i.prime().prime();
assert_eq!(i2.plev(), 2);
let i0 = i2.noprime();
assert_eq!(i0.plev(), 0);
assert_eq!(i0, i);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> UnsafeUnpin for Index<Id, Tags>where
Id: UnsafeUnpin,
Tags: UnsafeUnpin,
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