6 #ifndef CoinPackedMatrix_H
7 #define CoinPackedMatrix_H
170 #ifndef COIN_FAST_CODE
172 throw CoinError(
"bad index",
"vectorFirst",
"CoinPackedMatrix");
180 #ifndef COIN_FAST_CODE
182 throw CoinError(
"bad index",
"vectorLast",
"CoinPackedMatrix");
189 #ifndef COIN_FAST_CODE
191 throw CoinError(
"bad index",
"vectorSize",
"CoinPackedMatrix");
195 #ifndef CLP_NO_VECTOR
199 #ifndef COIN_FAST_CODE
201 throw CoinError(
"bad index",
"vector",
"CoinPackedMatrix");
239 #ifndef CLP_NO_VECTOR
255 const int *vecind,
const double *vecelem);
256 #ifndef CLP_NO_VECTOR
273 const double *element,
int numberRows = -1);
274 #ifndef CLP_NO_VECTOR
290 const int *vecind,
const double *vecelem);
291 #ifndef CLP_NO_VECTOR
308 const double *element,
int numberColumns = -1);
322 void deleteCols(
const int numDel,
const int *indDel);
324 void deleteRows(
const int numDel,
const int *indDel);
330 const int numReplace,
const double *newElements);
336 bool keepZero =
false);
376 const int numMajor,
const int *indMajor);
381 const int numMajor,
const int *indMajor);
387 const int numMajor,
const int * indMajor,
388 const int numMinor,
const int * indMinor);
397 void copyOf(
const bool colordered,
398 const int minor,
const int major,
const CoinBigIndex numels,
399 const double *elem,
const int *ind,
401 const double extraMajor = 0.0,
const double extraGap = 0.0);
425 const int minor,
const int major,
427 double *&elem,
int *&ind,
429 const int maxmajor = -1,
const CoinBigIndex maxsize = -1);
465 void times(
const double *x,
double *y)
const;
466 #ifndef CLP_NO_VECTOR
475 #ifndef CLP_NO_VECTOR
521 void dumpMatrix(
const char *fname = NULL)
const;
537 #ifndef CLP_NO_VECTOR
543 const double *vecelem);
544 #ifndef CLP_NO_VECTOR
554 const double *vecelem);
555 #ifndef CLP_NO_VECTOR
574 const double *element);
629 void timesMajor(
const double *x,
double *y)
const;
630 #ifndef CLP_NO_VECTOR
640 void timesMinor(
const double *x,
double *y)
const;
641 #ifndef CLP_NO_VECTOR
653 #ifndef CLP_NO_VECTOR
661 template <
class FloatEqual >
764 const double extraMajor,
const double extraGap);
767 const int minor,
const int major,
const CoinBigIndex numels,
768 const double *elem,
const int *ind,
770 const double extraMajor,
const double extraGap);
773 const int minor,
const int major,
const CoinBigIndex numels,
774 const double *elem,
const int *ind,
788 const int *rowIndices,
789 const int *colIndices,
790 const double *elements,
811 int extraForMajor,
int extraElements,
817 int numberRows,
const int *whichRows,
818 int numberColumns,
const int *whichColumns);
854 const int minor,
const int major,
const CoinBigIndex numels,
855 const double *elem,
const int *ind,
857 const double extraMajor = 0.0,
const double extraGap = 0.0);
860 const int minor,
const int major,
861 const double *elem,
const int *ind,
864 const int minor,
const int major,
const CoinBigIndex numels,
865 const double *elem,
const int *ind,
881 const double *element,
int numberOther = -1);
893 const double *element,
int numberOther = -1);
void majorAppendSameOrdered(const CoinPackedMatrix &matrix)
Append the columns of the argument to the right end of this matrix.
void transpose()
Transpose the matrix.
void removeGaps(double removeValue=-1.0)
Remove the gaps from the matrix if there were any Can also remove small elements fabs() <= removeValu...
void reserve(const int newMaxMajorDim, const CoinBigIndex newMaxSize, bool create=false)
Reserve sufficient space for appending major-ordered vectors.
Error Class thrown by an exception.
int appendMajor(const int number, const CoinBigIndex *starts, const int *index, const double *element, int numberOther=-1)
Append a set of rows (columns) to the end of a row (colum) ordered matrix.
bool colOrdered_
A flag indicating whether the matrix is column or row major ordered.
void appendRow(const CoinPackedVectorBase &vec)
Append a row to the end of the matrix.
int getVectorSize(const int i) const
The length of i'th vector.
CoinBigIndex getNumElements() const
Number of entries in the packed matrix.
void submatrixOfWithDuplicates(const CoinPackedMatrix &matrix, const int numMajor, const int *indMajor)
Extract a submatrix from matrix.
CoinBigIndex size_
the number of nonzero entries
void deleteMajorVectors(const int numDel, const int *indDel)
Delete the major-dimension vectors whose indices are listed in indDel.
void timesMajor(const double *x, double *y) const
Return A * x (multiplied from the "right" direction) in y.
void deleteCols(const int numDel, const int *indDel)
Delete the columns whose indices are listed in indDel.
void appendCols(const int numcols, const CoinPackedVectorBase *const *cols)
Append a set of columns to the end of the matrix.
CoinBigIndex maxSize_
max space allocated for entries
int * length_
Lengths of major-dimension vectors.
const CoinShallowPackedVector getVector(int i) const
Return the i'th vector in matrix.
void dumpMatrix(const char *fname=NULL) const
Dump the matrix on stdout.
int * index_
List of nonzero element minor-dimension indices.
CoinBigIndex * getMutableVectorStarts() const
The positions where the major-dimension vectors start in element_ and index_.
int * getMajorIndices() const
Returns an array containing major indices.
bool isEquivalent(const CoinPackedMatrix &rhs, const FloatEqual &eq) const
Test for equivalence.
double extraMajor_
his much times more space should be allocated for major-dimension vectors when the matrix is resized...
unsigned int verbosity
Verbosity level of unit tests.
void modifyCoefficient(int row, int column, double newElement, bool keepZero=false)
Modify one element of packed matrix.
void nullStartArray()
NULLify start array.
void setDimensions(int numrows, int numcols)
Set the dimensions of the matrix.
void nullLengthArray()
NULLify length array.
int verifyMtx(int verbosity=1, bool zeroesAreError=false) const
Scan the matrix for anomalies.
void setNumElements(CoinBigIndex value)
Change the size of the bulk store after modifying - be careful.
void gutsOfCopyOfNoGaps(const bool colordered, const int minor, const int major, const double *elem, const int *ind, const CoinBigIndex *start)
When no gaps we can do faster.
int maxMajorDim_
max space allocated for major-dimension
bool hasGaps() const
Whether the packed matrix has gaps or not.
void setExtraGap(const double newGap)
Set the extra gap to be allocated to the specified value.
bool isEquivalent(const CoinPackedVectorBase &rhs, const FloatEqual &eq) const
equivalent - If shallow packed vector A & B are equivalent, then they are still equivalent no matter ...
CoinBigIndex * start_
Starting positions of major-dimension vectors.
int minorDim_
size of other dimension
bool isColOrdered() const
Whether the packed matrix is column major ordered or not.
double * element_
List of nonzero element values.
void appendCol(const CoinPackedVectorBase &vec)
Append a column to the end of the matrix.
void submatrixOf(const CoinPackedMatrix &matrix, const int numMajor, const int *indMajor)
Extract a submatrix from matrix.
Abstract base class for various sparse vectors.
void reverseOrderedCopyOf(const CoinPackedMatrix &rhs)
Make a reverse-ordered copy.
void clear()
Clear the data, but do not free any arrays.
void timesMinor(const double *x, double *y) const
Return A * x (multiplied from the "right" direction) in y.
int * getMutableVectorLengths() const
The lengths of the major-dimension vectors.
int majorDim_
number of vectors in matrix
CoinPackedMatrix & operator=(const CoinPackedMatrix &rhs)
Assignment operator.
int getNumCols() const
Number of columns.
void nullIndexArray()
NULLify index array.
int appendMinor(const int number, const CoinBigIndex *starts, const int *index, const double *element, int numberOther=-1)
Append a set of rows (columns) to the end of a column (row) ordered matrix.
int * countOrthoLength() const
Count the number of entries in every minor-dimension vector and return an array containing these leng...
void minorAppendSameOrdered(const CoinPackedMatrix &matrix)
Append the columns of the argument to the bottom end of this matrix.
Equality to a scaled tolerance.
void appendMinorVectors(const int numvecs, const CoinPackedVectorBase *const *vecs)
Append several minor-dimension vectors to the end of the matrix.
void times(const double *x, double *y) const
Return A * x in y.
const CoinBigIndex * getVectorStarts() const
The positions where the major-dimension vectors start in elements and indices.
void setMinorDim(int value)
Set minor dimension.
void deleteMinorVectors(const int numDel, const int *indDel)
Delete the minor-dimension vectors whose indices are listed in indDel.
void orderMatrix()
Sort all columns so indices are increasing.in each column.
void assignMatrix(const bool colordered, const int minor, const int major, const CoinBigIndex numels, double *&elem, int *&ind, CoinBigIndex *&start, int *&len, const int maxmajor=-1, const CoinBigIndex maxsize=-1)
Assign the arguments to the matrix.
void bottomAppendPackedMatrix(const CoinPackedMatrix &matrix)
Append the argument to the "bottom" of the current matrix.
void resizeForAddingMajorVectors(const int numVec, const int *lengthVec)
void minorAppendOrthoOrdered(const CoinPackedMatrix &matrix)
Append the rows of the argument to the bottom end of this matrix.
double * getMutableElements() const
A vector containing the elements in the packed matrix.
void setMajorDim(int value)
Set major dimension.
CoinBigIndex getLastStart() const
const double * getElements() const
A vector containing the elements in the packed matrix.
virtual ~CoinPackedMatrix()
Destructor.
void deleteRows(const int numDel, const int *indDel)
Delete the rows whose indices are listed in indDel.
void gutsOfCopyOf(const bool colordered, const int minor, const int major, const CoinBigIndex numels, const double *elem, const int *ind, const CoinBigIndex *start, const int *len, const double extraMajor=0.0, const double extraGap=0.0)
int getSizeVectorLengths() const
The size of the vectorLengths array.
void appendMinorVector(const CoinPackedVectorBase &vec)
Append a minor-dimension vector to the end of the matrix.
int getNumRows() const
Number of rows.
CoinBigIndex getVectorLast(const int i) const
The position of the last element (well, one entry past the last) in the i'th major-dimension vector...
void majorAppendOrthoOrdered(const CoinPackedMatrix &matrix)
Append the rows of the argument to the right end of this matrix.
int getMaxMajorDim() const
Current maximum for major dimension.
Sparse Matrix Base Class.
double getExtraGap() const
Return the current setting of the extra gap.
void reverseOrdering()
Reverse the ordering of the packed matrix.
void copyOf(const CoinPackedMatrix &rhs)
Copy method.
void replaceVector(const int index, const int numReplace, const double *newElements)
Replace the elements of a vector.
double extraGap_
This much times more space should be allocated for each major-dimension vector (with respect to the n...
CoinBigIndex compress(double threshold)
Eliminate all elements in matrix whose absolute value is less than threshold.
const int * getVectorLengths() const
The lengths of the major-dimension vectors.
CoinBigIndex cleanMatrix(double threshold=1.0e-20)
Really clean up matrix.
bool isEquivalent2(const CoinPackedMatrix &rhs) const
Test for equivalence and report differences.
void nullElementArray()
NULLify element array.
void appendMajorVector(const CoinPackedVectorBase &vec)
Append a major-dimension vector to the end of the matrix.
const int * getIndices() const
A vector containing the minor indices of the elements in the packed matrix.
void transposeTimes(const double *x, double *y) const
Return x * A in y.
void appendMajorVectors(const int numvecs, const CoinPackedVectorBase *const *vecs)
Append several major-dimensonvectors to the end of the matrix.
CoinBigIndex eliminateDuplicates(double threshold)
Eliminate all duplicate AND small elements in matrix The column starts are not affected.
void gutsOfOpEqual(const bool colordered, const int minor, const int major, const CoinBigIndex numels, const double *elem, const int *ind, const CoinBigIndex *start, const int *len)
int * getMutableIndices() const
A vector containing the minor indices of the elements in the packed matrix.
void CoinPackedMatrixUnitTest()
Test the methods in the CoinPackedMatrix class.
double getExtraMajor() const
Return the current setting of the extra major.
void printMatrixElement(const int row_val, const int col_val) const
Print a single matrix element.
int getSizeVectorStarts() const
The size of the vectorStarts array.
void setExtraMajor(const double newMajor)
Set the extra major to be allocated to the specified value.
CoinPackedMatrix()
Default Constructor creates an empty column ordered packed matrix.
int getMinorDim() const
Minor dimension.
CoinBigIndex getVectorFirst(const int i) const
The position of the first element in the i'th major-dimension vector.
void resizeForAddingMinorVectors(const int *addedEntries)
friend void CoinPackedMatrixUnitTest()
Test the methods in the CoinPackedMatrix class.
void swap(CoinPackedMatrix &matrix)
Swap the content of two packed matrices.
void appendRows(const int numrows, const CoinPackedVectorBase *const *rows)
Append a set of rows to the end of the matrix.
void rightAppendPackedMatrix(const CoinPackedMatrix &matrix)
Append the argument to the "right" of the current matrix.
void appendMinorFast(const int number, const CoinBigIndex *starts, const int *index, const double *element)
Append a set of rows (columns) to the end of a column (row) ordered matrix.
double getCoefficient(int row, int column) const
Return one element of packed matrix.
int getMajorDim() const
Major dimension.
void copyReuseArrays(const CoinPackedMatrix &rhs)
Copy method.