CoinPackedVectorBase
Abstract base class providing read-only access to sparse vectors.
Abstract base class providing read-only access to sparse vectors.
Derived classes: CoinPackedVector, CoinShallowPackedVector
Description
Since this class is abstract, no object of this type can be created. The sole purpose is to provide const access to sparse vector data. Sparse vectors store only non-zero elements as parallel arrays of indices and values.
Public Methods
getNumElements
Get the number of stored (non-zero) elements.
int getNumElements()
Returns: Count of index/value pairs
getIndices
Get pointer to array of element indices.
const int * getIndices()
Returns: Pointer to indices array (may be null if empty)
getElements
Get pointer to array of element values.
const double * getElements()
Returns: Pointer to values array (may be null if empty)
setTestForDuplicateIndex
Set to the argument value whether to test for duplicate indices in the vector whenever they can occur.
void setTestForDuplicateIndex(bool test)
Parameters:
test(bool)
setTestForDuplicateIndexWhenTrue
Set to the argument value whether to test for duplicate indices in the vector whenever they can occur BUT we know that right now the vector has no duplicate indices.
void setTestForDuplicateIndexWhenTrue(bool test)
Parameters:
test(bool)
testForDuplicateIndex
Check if duplicate index testing is enabled.
bool testForDuplicateIndex()
Returns: true if vector will be tested for duplicates when they can occur
setTestsOff
Disable all duplicate checking without exception handling.
void setTestsOff()
denseVector
Convert sparse vector to dense format.
double * denseVector(int denseSize)
Parameters:
denseSize(int) - Length of the dense vector to create
Returns: Newly allocated dense array (caller must delete[])
operator[]
Access element by dense index.
double operator[](int i)
Parameters:
i(int) - Index in the conceptual dense vector
Returns: Value at index i, or zero if not stored
getMaxIndex
Get the largest index in the sparse vector.
int getMaxIndex()
Returns: Maximum index value, or -infinity if empty
getMinIndex
Get the smallest index in the sparse vector.
int getMinIndex()
Returns: Minimum index value, or +infinity if empty
duplicateIndex
Throw CoinError if duplicate indices exist.
void duplicateIndex(const char * methodName = NULL, const char * className = NULL)
Parameters:
methodName(const char *) - Name of calling method (for error message)className(const char *) - Name of calling class (for error message)
isExistingIndex
Check if an index exists in the sparse vector.
bool isExistingIndex(int i)
Parameters:
i(int) - Index to search for
Returns: true if index i is stored
findIndex
Find position of an index in the sparse storage.
int findIndex(int i)
Parameters:
i(int) - Index to search for
Returns: Position in indices/elements arrays, or -1 if not found
operator==
Equal.
bool operator==(const CoinPackedVectorBase & rhs)
Parameters:
rhs(const CoinPackedVectorBase &)
operator!=
Not equal.
bool operator!=(const CoinPackedVectorBase & rhs)
Parameters:
rhs(const CoinPackedVectorBase &)
compare
This method establishes an ordering on packed vectors.
int compare(const CoinPackedVectorBase & rhs)
Parameters:
rhs(const CoinPackedVectorBase &)
isEquivalent
equivalent - If shallow packed vector A & B are equivalent, then they are still equivalent no matter how they are sorted.
bool isEquivalent(const CoinPackedVectorBase & rhs, const FloatEqual & eq)
Parameters:
rhs(const CoinPackedVectorBase &)eq(const FloatEqual &)
isEquivalent
bool isEquivalent(const CoinPackedVectorBase & rhs)
Parameters:
rhs(const CoinPackedVectorBase &)
dotProduct
Compute dot product with a dense vector.
double dotProduct(const double * dense)
Parameters:
dense(const double *) - Pointer to dense vector (must have length >= max index + 1)
Returns: Sum of element[i] * dense[index[i]] for all stored elements
oneNorm
Compute the 1-norm (sum of absolute values)
double oneNorm()
Returns: Sum of |element[i]| for all stored elements
normSquare
Compute the squared 2-norm.
double normSquare()
Returns: Sum of element[i]^2 for all stored elements
twoNorm
Compute the 2-norm (Euclidean length)
double twoNorm()
Returns: Square root of normSquare()
infNorm
Compute the infinity-norm (maximum absolute value)
double infNorm()
Returns: Maximum |element[i]| across all stored elements
sum
Compute the sum of all elements.
double sum()
Returns: Sum of element[i] for all stored elements
~CoinPackedVectorBase
Destructor.
~CoinPackedVectorBase()
Source
Header: layer-0/CoinUtils/src/CoinPackedVectorBase.hpp