mptensor v0.6.0
Parallel Library for Tensor Network Methods
Loading...
Searching...
No Matches
Index, Axes and Shape

Lists of integers that specify element indices, axes, and shapes. More...

Classes

class  mptensor::BasicIndex< T >
 

Typedefs

using mptensor::Index = BasicIndex< std::ptrdiff_t >
 
using mptensor::Axes = Index
 
using mptensor::Shape = Index
 

Functions

template<typename T >
std::ostream & mptensor::operator<< (std::ostream &os, const BasicIndex< T > &idx)
 
template<typename T >
BasicIndex< T > mptensor::operator+ (const BasicIndex< T > &lhs, const BasicIndex< T > &rhs)
 
size_t mptensor::normalize_axis (std::ptrdiff_t a, size_t rank)
 
internal::UAxes mptensor::normalize_axes (const Axes &axes, size_t rank)
 
size_t mptensor::normalize_index (std::ptrdiff_t i, size_t n)
 
internal::UIndex mptensor::normalize_index (const Index &idx, const internal::UShape &shape)
 
size_t mptensor::normalize_slice_end (std::ptrdiff_t e, size_t n)
 
internal::UShape mptensor::to_internal_shape (const Shape &s)
 
Index mptensor::to_public (const internal::UIndex &u)
 
Index mptensor::range (const std::ptrdiff_t start, const std::ptrdiff_t stop, const std::ptrdiff_t step)
 Arithmetic sequence start, start+step, ... up to (not including) stop.
 
Index mptensor::range (const std::ptrdiff_t start, const std::ptrdiff_t stop)
 
Index mptensor::range (const std::ptrdiff_t stop)
 

Detailed Description

Lists of integers that specify element indices, axes, and shapes.

Index, Axes, and Shape are aliases of the same class, BasicIndex<std::ptrdiff_t>. Create one like a python list: Index(0, 1, 2), Axes{2, 0, 1}, or Axes a = 2;.

Negative values count from the end, as in numpy:

Out-of-range values throw std::out_of_range, and negative sizes in a Shape throw std::invalid_argument, before any communication starts.

range(start, stop, step) creates a sequence as in python, e.g. range(-1, -5, -1) reverses the axes of a rank-4 tensor.

Typedef Documentation

◆ Axes

◆ Index

Public element index.

◆ Shape

Function Documentation

◆ normalize_axes()

internal::UAxes mptensor::normalize_axes ( const Axes &  axes,
size_t  rank 
)
inline

Normalize each axis: [-rank, rank) -> [0, rank).

◆ normalize_axis()

size_t mptensor::normalize_axis ( std::ptrdiff_t  a,
size_t  rank 
)
inline

Normalize an axis: [-rank, rank) -> [0, rank).

◆ normalize_index() [1/2]

internal::UIndex mptensor::normalize_index ( const Index &  idx,
const internal::UShape &  shape 
)
inline

Normalize a global element index against shape.

◆ normalize_index() [2/2]

size_t mptensor::normalize_index ( std::ptrdiff_t  i,
size_t  n 
)
inline

Normalize an element index: [-n, n) -> [0, n).

◆ normalize_slice_end()

size_t mptensor::normalize_slice_end ( std::ptrdiff_t  e,
size_t  n 
)
inline

Normalize an exclusive slice end: [-n, n] -> [0, n].

◆ operator+()

template<typename T >
BasicIndex< T > mptensor::operator+ ( const BasicIndex< T > &  lhs,
const BasicIndex< T > &  rhs 
)

Joint two indices: Index(0,1) + Index(2,3) = Index(0,1,2,3)

◆ operator<<()

template<typename T >
std::ostream & mptensor::operator<< ( std::ostream &  os,
const BasicIndex< T > &  idx 
)

The format is the same as a list of python, for example "[0, 1, 2]".

◆ range() [1/3]

Index mptensor::range ( const std::ptrdiff_t  start,
const std::ptrdiff_t  stop 
)
inline

Same as range(start, stop, 1).

◆ range() [2/3]

Index mptensor::range ( const std::ptrdiff_t  start,
const std::ptrdiff_t  stop,
const std::ptrdiff_t  step 
)
inline

Arithmetic sequence start, start+step, ... up to (not including) stop.

Same as range() in python: the result is empty if stop is not reached in the direction of step, e.g. range(3, 2) or range(0, 5, -1). Negative values are allowed, e.g. range(-1, -5, -1) is [-1, -2, -3, -4], which reverses the axes of a rank-4 tensor.

!

Exceptions
std::invalid_argumentif step == 0.

◆ range() [3/3]

Index mptensor::range ( const std::ptrdiff_t  stop)
inline

Same as range(0, stop, 1).

◆ to_internal_shape()

internal::UShape mptensor::to_internal_shape ( const Shape &  s)
inline

Convert a public shape to the internal type. Negative sizes are invalid.

◆ to_public()

Index mptensor::to_public ( const internal::UIndex &  u)
inline

Convert an internal index to the public type.