Chemical Data Processing Library Python API - Version 1.4.0
Public Member Functions | Properties | List of all members
CDPL.Math.Slice Class Reference

Index slice ( \( start, stride, size \)) used for strided slicing of vector and matrix expressions. More...

+ Inheritance diagram for CDPL.Math.Slice:

Public Member Functions

None __init__ ()
 Constructs an empty slice ( \( 0, 0, 0 \)).
 
None __init__ (Slice s)
 Initializes a copy of the Slice instance s. More...
 
None __init__ (int start, int stride, int size)
 Constructs the slice (start, stride, size). More...
 
int getStart ()
 Returns the starting global index. More...
 
int getStride ()
 Returns the signed step size between consecutive entries. More...
 
int getSize ()
 Returns the number of entries in the slice. More...
 
bool isEmpty ()
 Tells whether the slice is empty. More...
 
int getIndex (int i)
 
Slice assign (Slice s)
 Replaces the current state of self with a copy of the state of the Slice instance s. More...
 
None swap (Slice s)
 Swaps the contents of self and s. More...
 
int getObjectID ()
 Returns the numeric identifier (ID) of the wrapped C++ class instance. More...
 
bool __eq__ (Slice s)
 Equality comparison. More...
 
bool __ne__ (Slice s)
 Inequality comparison. More...
 
int __call__ (int i)
 Maps the local position i to the global index \( start + i \cdot stride \). More...
 
int __getitem__ (int i)
 

Properties

 objectID = property(getObjectID)
 
 start = property(getStart)
 
 stride = property(getStride)
 
 size = property(getSize)
 

Detailed Description

Index slice ( \( start, stride, size \)) used for strided slicing of vector and matrix expressions.

Local position i is mapped to the global index \( start + i \cdot stride \). Negative strides (reverse iteration) are supported as long as the resulting indices stay non-negative.

Constructor & Destructor Documentation

◆ __init__() [1/2]

None CDPL.Math.Slice.__init__ ( Slice  s)

Initializes a copy of the Slice instance s.

Parameters
sThe Slice instance to copy.

◆ __init__() [2/2]

None CDPL.Math.Slice.__init__ ( int  start,
int  stride,
int  size 
)

Constructs the slice (start, stride, size).

Parameters
startThe starting global index.
strideThe signed step size between consecutive entries.
sizeThe number of entries.
Exceptions
Base.RangeErrorif the slice would produce a negative global index.

Member Function Documentation

◆ getStart()

int CDPL.Math.Slice.getStart ( )

Returns the starting global index.

Returns
The starting index.

◆ getStride()

int CDPL.Math.Slice.getStride ( )

Returns the signed step size between consecutive entries.

Returns
The stride.

◆ getSize()

int CDPL.Math.Slice.getSize ( )

Returns the number of entries in the slice.

Returns
The slice size.

◆ isEmpty()

bool CDPL.Math.Slice.isEmpty ( )

Tells whether the slice is empty.

Returns
True if the slice contains no entries, and False otherwise.

◆ getIndex()

int CDPL.Math.Slice.getIndex ( int  i)
Parameters
i
Returns

◆ assign()

Slice CDPL.Math.Slice.assign ( Slice  s)

Replaces the current state of self with a copy of the state of the Slice instance s.

Parameters
sThe Slice instance to copy.
Returns
self

◆ swap()

None CDPL.Math.Slice.swap ( Slice  s)

Swaps the contents of self and s.

Parameters
sThe other slice.

◆ getObjectID()

int CDPL.Math.Slice.getObjectID ( )

Returns the numeric identifier (ID) of the wrapped C++ class instance.

Different Python Slice instances may reference the same underlying C++ class instance. The commonly used Python expression a is not b thus cannot tell reliably whether the two Slice instances a and b reference different C++ objects. The numeric identifier returned by this method allows to correctly implement such an identity test via the simple expression a.getObjectID() != b.getObjectID().

Returns
The numeric ID of the internally referenced C++ class instance.

◆ __eq__()

bool CDPL.Math.Slice.__eq__ ( Slice  s)

Equality comparison.

Parameters
sThe other slice.
Returns
True if both slices have the same start, stride and size, and False otherwise.

◆ __ne__()

bool CDPL.Math.Slice.__ne__ ( Slice  s)

Inequality comparison.

Parameters
sThe other slice.
Returns
True if the slices differ in start, stride or size, and False otherwise.

◆ __call__()

int CDPL.Math.Slice.__call__ ( int  i)

Maps the local position i to the global index \( start + i \cdot stride \).

Parameters
iThe zero-based local position.
Returns
The global index.
Exceptions
Base.IndexErrorif i is not in the range \( [0, size) \).

◆ __getitem__()

int CDPL.Math.Slice.__getitem__ ( int  i)
Parameters
i
Returns