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

Unbounded sparse vector holding floating-point values of type double. More...

+ Inheritance diagram for CDPL.Math.SparseDVector:

Public Member Functions

None __init__ ()
 Constructs an empty sparse vector (size zero, no stored entries).
 
None __init__ (SparseDVector v)
 Constructs a copy of the sparse vector v. More...
 
None __init__ (int n)
 Constructs a sparse vector of size n with no stored entries (every position reads as the default value). More...
 
None __init__ (ConstFVectorExpression e)
 Constructs a sparse vector from the vector expression e. More...
 
None __init__ (ConstDVectorExpression e)
 Constructs a sparse vector from the vector expression e. More...
 
None __init__ (ConstLVectorExpression e)
 Constructs a sparse vector from the vector expression e. More...
 
None __init__ (ConstULVectorExpression e)
 Constructs a sparse vector from the vector expression e. More...
 
None __init__ (object a)
 Constructs the vector from the numpy.ndarray object a. More...
 
None resize (int n)
 Resizes the logical element count to n, dropping any stored entries at indices beyond n. More...
 
None clear ()
 Removes all explicitly stored entries (the logical size remains unchanged).
 
int getNumElements ()
 Returns the number of explicitly stored (non-default) entries. More...
 
int getObjectID ()
 Returns the numeric identifier (ID) of the wrapped C++ class instance. More...
 
SparseDVector assign (ConstFVectorExpression e)
 Assigns the vector expression e to this sparse vector (via a temporary to handle aliasing). More...
 
SparseDVector assign (ConstDVectorExpression e)
 Assigns the vector expression e to this sparse vector (via a temporary to handle aliasing). More...
 
SparseDVector assign (ConstLVectorExpression e)
 Assigns the vector expression e to this sparse vector (via a temporary to handle aliasing). More...
 
SparseDVector assign (ConstULVectorExpression e)
 Assigns the vector expression e to this sparse vector (via a temporary to handle aliasing). More...
 
SparseDVector assign (SparseDVector v)
 Copy-assigns the contents of v to this sparse vector. More...
 
None assign (object a)
 Assigns the contents of the numpy.ndarray object a to this vector. More...
 
bool isEmpty ()
 Tells whether the vector's logical size is zero. More...
 
int getSize ()
 Returns the logical element count. More...
 
float getElement (int i)
 Returns the element at index i. More...
 
object toArray ()
 Converts the SparseDVector instance into a corresponding numpy.ndarray object. More...
 
None swap (SparseDVector v)
 Swaps the contents of this sparse vector with those of v. More...
 
None setElement (int i, float v)
 Sets the value of the element at index i to v. More...
 
bool __eq__ (SparseDVector v)
 Returns the result of the comparison operation self == v. More...
 
bool __eq__ (ConstDVectorExpression e)
 Returns the result of the comparison operation self == e. More...
 
bool __ne__ (SparseDVector v)
 Returns the result of the comparison operation self != v. More...
 
bool __ne__ (ConstDVectorExpression e)
 Returns the result of the comparison operation self != e. More...
 
float __call__ (int i)
 Returns the element at index i. More...
 
float __getitem__ (int i)
 Returns the element at index i. More...
 
int __len__ ()
 Returns the logical element count. More...
 
str __str__ ()
 Returns a string representation of the SparseDVector instance. More...
 
SparseDVector __pos__ ()
 Returns self. More...
 
ConstDVectorExpression __neg__ ()
 Returns the result of the operation self * -1. More...
 
ConstDVectorExpression __add__ (ConstDVectorExpression e)
 Returns the result of the addition operation self + e. More...
 
ConstDVectorExpression __sub__ (ConstDVectorExpression e)
 Returns the result of the subtraction operation self - e. More...
 
ConstDVectorExpression __mul__ (float t)
 Returns the result of the multiplication operation self * t. More...
 
ConstDVectorExpression __mul__ (ConstDMatrixExpression e)
 Returns the result of the multiplication operation self * e. More...
 
ConstDVectorExpression __div__ (float t)
 Returns the result of the division operation self // t. More...
 
ConstDVectorExpression __truediv__ (float t)
 Returns the result of the true division operation self / t. More...
 
ConstDVectorExpression __rmul__ (float t)
 Returns the result of the multiplication operation t * self. More...
 
None __setitem__ (int i, float v)
 Sets the value of the element at index i to v. More...
 
SparseDVector __iadd__ (SparseDVector v)
 Adds the contents of the vector v element-wise to this vector (no alias check needed). More...
 
SparseDVector __iadd__ (ConstDVectorExpression e)
 Adds the vector expression e element-wise to this sparse vector (via a temporary to handle aliasing). More...
 
SparseDVector __isub__ (SparseDVector v)
 Subtracts the contents of the vector v element-wise from this vector (no alias check needed). More...
 
SparseDVector __isub__ (ConstDVectorExpression e)
 Subtracts the vector expression e element-wise from this sparse vector (via a temporary to handle aliasing). More...
 
SparseDVector __imul__ (float t)
 Multiplies every stored entry by the scalar t. More...
 
SparseDVector __idiv__ (float t)
 Divides every stored entry by the scalar t. More...
 
SparseDVector __itruediv__ (float t)
 Divides every stored entry by the scalar t. More...
 

Properties

 objectID = property(getObjectID)
 
 size = property(getSize)
 
 numElements = property(getNumElements)
 

Detailed Description

Unbounded sparse vector holding floating-point values of type double.

Constructor & Destructor Documentation

◆ __init__() [1/7]

None CDPL.Math.SparseDVector.__init__ ( SparseDVector  v)

Constructs a copy of the sparse vector v.

Parameters
vThe sparse vector to copy.

◆ __init__() [2/7]

None CDPL.Math.SparseDVector.__init__ ( int  n)

Constructs a sparse vector of size n with no stored entries (every position reads as the default value).

Parameters
nThe logical element count.

◆ __init__() [3/7]

None CDPL.Math.SparseDVector.__init__ ( ConstFVectorExpression  e)

Constructs a sparse vector from the vector expression e.

Parameters
eThe source vector expression.

◆ __init__() [4/7]

None CDPL.Math.SparseDVector.__init__ ( ConstDVectorExpression  e)

Constructs a sparse vector from the vector expression e.

Parameters
eThe source vector expression.

◆ __init__() [5/7]

None CDPL.Math.SparseDVector.__init__ ( ConstLVectorExpression  e)

Constructs a sparse vector from the vector expression e.

Parameters
eThe source vector expression.

◆ __init__() [6/7]

None CDPL.Math.SparseDVector.__init__ ( ConstULVectorExpression  e)

Constructs a sparse vector from the vector expression e.

Parameters
eThe source vector expression.

◆ __init__() [7/7]

None CDPL.Math.SparseDVector.__init__ ( object  a)

Constructs the vector from the numpy.ndarray object a.

Parameters
aThe numpy.ndarray object.
See also
[NUMPY]

Member Function Documentation

◆ resize()

None CDPL.Math.SparseDVector.resize ( int  n)

Resizes the logical element count to n, dropping any stored entries at indices beyond n.

Parameters
nThe new logical element count.

◆ getNumElements()

int CDPL.Math.SparseDVector.getNumElements ( )

Returns the number of explicitly stored (non-default) entries.

Returns
The number of stored entries.

◆ getObjectID()

int CDPL.Math.SparseDVector.getObjectID ( )

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

Different Python SparseDVector 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 SparseDVector 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.

◆ assign() [1/6]

SparseDVector CDPL.Math.SparseDVector.assign ( ConstFVectorExpression  e)

Assigns the vector expression e to this sparse vector (via a temporary to handle aliasing).

Parameters
eThe source vector expression.
Returns
self.

◆ assign() [2/6]

SparseDVector CDPL.Math.SparseDVector.assign ( ConstDVectorExpression  e)

Assigns the vector expression e to this sparse vector (via a temporary to handle aliasing).

Parameters
eThe source vector expression.
Returns
self.

◆ assign() [3/6]

SparseDVector CDPL.Math.SparseDVector.assign ( ConstLVectorExpression  e)

Assigns the vector expression e to this sparse vector (via a temporary to handle aliasing).

Parameters
eThe source vector expression.
Returns
self.

◆ assign() [4/6]

SparseDVector CDPL.Math.SparseDVector.assign ( ConstULVectorExpression  e)

Assigns the vector expression e to this sparse vector (via a temporary to handle aliasing).

Parameters
eThe source vector expression.
Returns
self.

◆ assign() [5/6]

SparseDVector CDPL.Math.SparseDVector.assign ( SparseDVector  v)

Copy-assigns the contents of v to this sparse vector.

Parameters
vThe source sparse vector.
Returns
self.

◆ assign() [6/6]

None CDPL.Math.SparseDVector.assign ( object  a)

Assigns the contents of the numpy.ndarray object a to this vector.

Parameters
aThe numpy.ndarray object.
See also
[NUMPY]

◆ isEmpty()

bool CDPL.Math.SparseDVector.isEmpty ( )

Tells whether the vector's logical size is zero.

Returns
True if the logical size is zero, and False otherwise.

◆ getSize()

int CDPL.Math.SparseDVector.getSize ( )

Returns the logical element count.

Returns
The number of elements.

◆ getElement()

float CDPL.Math.SparseDVector.getElement ( int  i)

Returns the element at index i.

Parameters
iThe zero-based element index.
Returns
The stored value, or the zero element if no entry exists.
Exceptions
Base.IndexErrorif i is out of range.

◆ toArray()

object CDPL.Math.SparseDVector.toArray ( )

Converts the SparseDVector instance into a corresponding numpy.ndarray object.

Returns
The generated numpy.ndarray object.
See also
[NUMPY]

◆ swap()

None CDPL.Math.SparseDVector.swap ( SparseDVector  v)

Swaps the contents of this sparse vector with those of v.

Parameters
vThe sparse vector to swap with.

◆ setElement()

None CDPL.Math.SparseDVector.setElement ( int  i,
float  v 
)

Sets the value of the element at index i to v.

Parameters
iThe zero-based element index.
vThe new value of the element.
Exceptions
Base.IndexErrorif i is not in the range [0, getSize()).

◆ __eq__() [1/2]

bool CDPL.Math.SparseDVector.__eq__ ( SparseDVector  v)

Returns the result of the comparison operation self == v.

Parameters
vThe SparseDVector instance to be compared with.
Returns
The result of the comparison operation.

◆ __eq__() [2/2]

bool CDPL.Math.SparseDVector.__eq__ ( ConstDVectorExpression  e)

Returns the result of the comparison operation self == e.

Parameters
eThe ConstDVectorExpression instance to be compared with.
Returns
The result of the comparison operation.

◆ __ne__() [1/2]

bool CDPL.Math.SparseDVector.__ne__ ( SparseDVector  v)

Returns the result of the comparison operation self != v.

Parameters
vThe SparseDVector instance to be compared with.
Returns
The result of the comparison operation.

◆ __ne__() [2/2]

bool CDPL.Math.SparseDVector.__ne__ ( ConstDVectorExpression  e)

Returns the result of the comparison operation self != e.

Parameters
eThe ConstDVectorExpression instance to be compared with.
Returns
The result of the comparison operation.

◆ __call__()

float CDPL.Math.SparseDVector.__call__ ( int  i)

Returns the element at index i.

Parameters
iThe zero-based element index.
Returns
The stored value, or the zero element if no entry exists.
Exceptions
Base.IndexErrorif i is out of range.

◆ __getitem__()

float CDPL.Math.SparseDVector.__getitem__ ( int  i)

Returns the element at index i.

Parameters
iThe zero-based element index.
Returns
The element.
Exceptions
Base.IndexErrorif i is out of range.

◆ __len__()

int CDPL.Math.SparseDVector.__len__ ( )

Returns the logical element count.

Returns
The number of elements.

◆ __str__()

str CDPL.Math.SparseDVector.__str__ ( )

Returns a string representation of the SparseDVector instance.

Returns
The generated string representation.

◆ __pos__()

SparseDVector CDPL.Math.SparseDVector.__pos__ ( )

Returns self.

Returns
self.

◆ __neg__()

ConstDVectorExpression CDPL.Math.SparseDVector.__neg__ ( )

Returns the result of the operation self * -1.

Returns
A ConstDVectorExpression instance holding the result of the element negation.

◆ __add__()

ConstDVectorExpression CDPL.Math.SparseDVector.__add__ ( ConstDVectorExpression  e)

Returns the result of the addition operation self + e.

Parameters
eSpecifies the second addend.
Returns
A ConstDVectorExpression instance holding the result of the addition.

◆ __sub__()

ConstDVectorExpression CDPL.Math.SparseDVector.__sub__ ( ConstDVectorExpression  e)

Returns the result of the subtraction operation self - e.

Parameters
eSpecifies the subtrahend.
Returns
A SparseDVector instance holding the result of the subtraction.

◆ __mul__() [1/2]

ConstDVectorExpression CDPL.Math.SparseDVector.__mul__ ( float  t)

Returns the result of the multiplication operation self * t.

Parameters
tSpecifies the multiplier.
Returns
A ConstDVectorExpression instance holding the result of the multiplication.

◆ __mul__() [2/2]

ConstDVectorExpression CDPL.Math.SparseDVector.__mul__ ( ConstDMatrixExpression  e)

Returns the result of the multiplication operation self * e.

Parameters
eSpecifies the multiplier.
Returns
A ConstDVectorExpression instance holding the result of the multiplication.

◆ __div__()

ConstDVectorExpression CDPL.Math.SparseDVector.__div__ ( float  t)

Returns the result of the division operation self // t.

Parameters
tSpecifies the divisor.
Returns
A ConstDVectorExpression instance holding the result of the division.

◆ __truediv__()

ConstDVectorExpression CDPL.Math.SparseDVector.__truediv__ ( float  t)

Returns the result of the true division operation self / t.

Parameters
tSpecifies the divisor.
Returns
A ConstDVectorExpression instance holding the result of the division.

◆ __rmul__()

ConstDVectorExpression CDPL.Math.SparseDVector.__rmul__ ( float  t)

Returns the result of the multiplication operation t * self.

Parameters
tSpecifies the multiplicand.
Returns
A ConstDVectorExpression instance holding the result of the multiplication.

◆ __setitem__()

None CDPL.Math.SparseDVector.__setitem__ ( int  i,
float  v 
)

Sets the value of the element at index i to v.

Parameters
iThe zero-based element index.
vThe new value of the element.
Exceptions
Base.IndexErrorif i is not in the range [0, getSize()).

◆ __iadd__() [1/2]

SparseDVector CDPL.Math.SparseDVector.__iadd__ ( SparseDVector  v)

Adds the contents of the vector v element-wise to this vector (no alias check needed).

Parameters
vThe source vector.
Returns
self.

◆ __iadd__() [2/2]

SparseDVector CDPL.Math.SparseDVector.__iadd__ ( ConstDVectorExpression  e)

Adds the vector expression e element-wise to this sparse vector (via a temporary to handle aliasing).

Parameters
eThe source vector expression.
Returns
self.

◆ __isub__() [1/2]

SparseDVector CDPL.Math.SparseDVector.__isub__ ( SparseDVector  v)

Subtracts the contents of the vector v element-wise from this vector (no alias check needed).

Parameters
vThe source vector.
Returns
self.

◆ __isub__() [2/2]

SparseDVector CDPL.Math.SparseDVector.__isub__ ( ConstDVectorExpression  e)

Subtracts the vector expression e element-wise from this sparse vector (via a temporary to handle aliasing).

Parameters
eThe source vector expression.
Returns
self.

◆ __imul__()

SparseDVector CDPL.Math.SparseDVector.__imul__ ( float  t)

Multiplies every stored entry by the scalar t.

Parameters
tThe scalar multiplier.
Returns
self.

◆ __idiv__()

SparseDVector CDPL.Math.SparseDVector.__idiv__ ( float  t)

Divides every stored entry by the scalar t.

Parameters
tThe scalar divisor.
Returns
self.

◆ __itruediv__()

SparseDVector CDPL.Math.SparseDVector.__itruediv__ ( float  t)

Divides every stored entry by the scalar t.

Parameters
tThe scalar divisor.
Returns
self.