MADNESS 0.10.1
madness::Slice Class Reference

A slice defines a sub-range or patch of a dimension. More...

#include <slice.h>

Public Member Functions

 Slice ()
 Slice (const Slice &)=default
 Slice (long s, long e, long stp=1)
Slice & operator= (const Slice &)=default
template<typename Archive>
void serialize (Archive &ar)

Public Attributes

long end
long start
long step

Detailed Description

A slice defines a sub-range or patch of a dimension.

Introduction

The slice Slice(start,end,step) defines the subvector

long end
Definition slice.h:107
long step
Definition slice.h:108
long start
Definition slice.h:106

with indices as if generated from these loops

if (step > 0)
for (i=start; i<=end; i+=step) i;
else if (step < 0)
for (i=start; i>=end; i+=step) i;
else if (step == 0 && start == end)
defines a scalar
else
runtime error detected when slice is used
void error(const char *msg)
Definition world.cc:147
static const double a
Definition nonlinschro.cc:118

Note that start and end are inclusive, unlike the Python convention of specifying end+1 (note that we cannot do this easily in C/C++ unless we also define a special value to indicate the end of a dimension of unknown size).

Special meanings and conventions

Negative values for start or end (similar to Python) are relative to the end of the (possibly unknown) dimension. E.g.,

  • end=-1 is equivalent to end=dim-1
  • start=-4 is equivalent to start=dim-4
  • step=0 and start==end implies dimension will be eliminated when the slice is used to index a tensor
  • The default constructor specifies the entire dimension
  • If the input length is not an exact multiple of step, end is rounded towards start to recover the behaviour of the <= or >= bounds in the loops specified above.

Special slices have been defined as constants

  • _ (1 underscore) = Slice(0,-1,1) = full slice in current order
  • ___ (3 underscores) = Array of Slices with value _ so that t(___) will generate an assignable view of the entire tensor t .
  • _reverse = Slice(-1,0,-1) = full dimension reversed
Examples
  • Slice() — full slice in current order
  • Slice(0,-1,1) — full slice in current order
  • Slice(3,3,0) — eliminate this dimension setting index=3 (step=0)
  • Slice(3,3,1) — reduce a dimension to length 1 using index=3 (step=1)
  • Slice(-1,0,-1) — reverse a dimension
  • Slice(0,-1,2) — use all even numbered elements
  • Slice(1,-1,2) — use all odd numbered elements

Constructor & Destructor Documentation

◆ Slice() [1/3]

madness::Slice::Slice ( )
inline

References end, start, and step.

Referenced by Slice(), and operator=().

◆ Slice() [2/3]

madness::Slice::Slice ( long s,
long e,
long stp = 1 )
inline

References e(), end, start, and step.

◆ Slice() [3/3]

madness::Slice::Slice ( const Slice & )
default

References Slice().

Member Function Documentation

◆ operator=()

Slice & madness::Slice::operator= ( const Slice & )
default

References Slice().

◆ serialize()

template<typename Archive>
void madness::Slice::serialize ( Archive & ar)
inline

References end, start, and step.

Member Data Documentation

◆ end

long madness::Slice::end

Referenced by Slice(), Slice(), and serialize().

◆ start

long madness::Slice::start

Referenced by Slice(), Slice(), and serialize().

◆ step

long madness::Slice::step

Referenced by Slice(), Slice(), and serialize().


The documentation for this class was generated from the following file: