6 #ifndef CoinPackedVector_H 
    7 #define CoinPackedVector_H 
   16 #ifndef COIN_NOTEST_DUPLICATE 
   17 #define COIN_NOTEST_DUPLICATE 
   21 #ifndef COIN_NOTEST_DUPLICATE 
   22 #define COIN_DEFAULT_VALUE_FOR_DUPLICATE true 
   24 #define COIN_DEFAULT_VALUE_FOR_DUPLICATE false 
  183   void setVector(
int size, 
const int *inds, 
const double *elems,
 
  187   void setConstant(
int size, 
const int *inds, 
double elems,
 
  191   void setFull(
int size, 
const double *elems,
 
  205   void insert(
int index, 
double element);
 
  210   void swap(
int i, 
int j);
 
  238   template < 
class CoinCompare3 >
 
  239   void sort(
const CoinCompare3 &tc)
 
  325     const int *inds, 
const double *elems,
 
  330     const int *inds, 
double value,
 
  368 template < 
class BinaryFunction >
 
  379     for (
int i = 0; i < s; ++i) {
 
  380       retVal.
insert(inds[i], bf(value, elems[i]));
 
  385 template < 
class BinaryFunction >
 
  394 template < 
class BinaryFunction >
 
  408   if (s1 == 0 && s2 == 0)
 
  420   for (i = 0; i < s1; ++i) {
 
  421     const int index = inds1[i];
 
  423     const double val = bf(elems1[i], pos2 == -1 ? 0.0 : elems2[pos2]);
 
  425     retVal.
insert(index, val);
 
  428   for (i = 0; i < s2; ++i) {
 
  429     const int index = inds2[i];
 
  434     const double val = bf(0.0, elems2[i]);
 
  436     retVal.
insert(index, val);
 
  442 template < 
class BinaryFunction >
 
  453 template < 
class BinaryFunction >
 
  464 template < 
class BinaryFunction >
 
  482   binaryOp(retVal, op1, op2, std::plus< double >());
 
  492   binaryOp(retVal, op1, op2, std::minus< double >());
 
  502   binaryOp(retVal, op1, op2, std::multiplies< double >());
 
  512   binaryOp(retVal, op1, op2, std::divides< double >());
 
  530   for (i = 0; i < len; i++) {
 
  541   int i, j, len1, len2;
 
  555   while (i < len1 && j < len2) {
 
  556     if (v1ind[i] == v2ind[j]) {
 
  557       acc += v1val[i] * v2val[j];
 
  560     } 
else if (v2ind[j] < v1ind[i]) {
 
  630   for (
int i = 0; i < size; ++i) {
 
  631     elems[i] = value - elems[i];
 
  652   for (
int i = 0; i < size; ++i) {
 
  653     elems[i] = value / elems[i];
 
void clear()
Reset the vector (as if were just created an empty vector) 
 
CoinPackedVector & operator=(const CoinPackedVector &)
Assignment operator. 
 
void truncate(int newSize)
Resize the packed vector to be the first newSize elements. 
 
double * getElements()
Get element values. 
 
void setTestForDuplicateIndex(bool test) const 
Set to the argument value whether to test for duplicate indices in the vector whenever they can occur...
 
void gutsOfSetVector(int size, const int *inds, const double *elems, bool testForDuplicateIndex, const char *method)
Copy internal date. 
 
CoinPackedVector(bool testForDuplicateIndex=COIN_DEFAULT_VALUE_FOR_DUPLICATE)
Default constructor. 
 
int nElements_
Size of indices and elements vectors. 
 
void binaryOp(CoinPackedVector &retVal, const CoinPackedVectorBase &op1, double value, BinaryFunction bf)
 
void setElement(int index, double element)
Set an existing element in the packed vector The first argument is the "index" into the elements() ar...
 
bool isExistingIndex(int i) const 
Return true if the i'th element of the full storage vector exists in the packed storage vector...
 
virtual int getNumElements() const 
Get the size. 
 
void gutsOfSetConstant(int size, const int *inds, double value, bool testForDuplicateIndex, const char *method)
 
void CoinPackedVectorUnitTest()
A function that tests the methods in the CoinPackedVector class. 
 
const int * getVectorIndices() const 
Get indices of elements. 
 
virtual const double * getElements() const 
Get element values. 
 
void operator+=(double value)
add value to every entry 
 
const int * getOriginalPosition() const 
Get pointer to int * vector of original postions. 
 
void operator-=(double value)
subtract value from every entry 
 
CoinDenseVector< T > operator+(const CoinDenseVector< T > &op1, const CoinDenseVector< T > &op2)
Return the sum of two dense vectors. 
 
void operator/=(double value)
divide every entry by value 
 
Abstract base class for various sparse vectors. 
 
virtual const double * getElements() const =0
Get element values. 
 
void operator*=(double value)
multiply every entry by value 
 
int * indices_
Vector indices. 
 
CoinDenseVector< T > operator-(const CoinDenseVector< T > &op1, const CoinDenseVector< T > &op2)
Return the difference of two dense vectors. 
 
bool testForDuplicateIndex() const 
Returns true if the vector should be tested for duplicate indices when they can occur. 
 
virtual ~CoinPackedVector()
Destructor. 
 
int getVectorNumElements() const 
Get the size. 
 
#define COIN_DEFAULT_VALUE_FOR_DUPLICATE
 
void assignVector(int size, int *&inds, double *&elems, bool testForDuplicateIndex=COIN_DEFAULT_VALUE_FOR_DUPLICATE)
Assign the ownership of the arguments to this vector. 
 
void setVector(int size, const int *inds, const double *elems, bool testForDuplicateIndex=COIN_DEFAULT_VALUE_FOR_DUPLICATE)
Set vector size, indices, and elements. 
 
void sort(const CoinCompare3 &tc)
Sort the packed storage vector. 
 
virtual int getNumElements() const =0
Get length of indices and elements vectors. 
 
CoinDenseVector< T > operator/(const CoinDenseVector< T > &op1, const CoinDenseVector< T > &op2)
Return the element-wise ratio of two dense vectors. 
 
void insert(int index, double element)
Insert an element into the vector. 
 
const double * getVectorElements() const 
Get element values. 
 
int capacity() const 
capacity returns the size which could be accomodated without having to reallocate storage...
 
friend void CoinPackedVectorUnitTest()
A function that tests the methods in the CoinPackedVector class. 
 
CoinDenseVector< T > operator*(const CoinDenseVector< T > &op1, const CoinDenseVector< T > &op2)
Return the element-wise product of two dense vectors. 
 
int * origIndices_
original unsorted indices 
 
void reserve(int n)
Reserve space. 
 
double sortedSparseDotProduct(const CoinPackedVectorBase &op1, const CoinPackedVectorBase &op2)
Returns the dot product of two sorted CoinPackedVector objects. 
 
void setFull(int size, const double *elems, bool testForDuplicateIndex=COIN_DEFAULT_VALUE_FOR_DUPLICATE)
Indices are not specified and are taken to be 0,1,...,size-1. 
 
void sortOriginalOrder()
Sort in original order. 
 
void CoinSort_3(S *sfirst, S *slast, T *tfirst, U *ufirst, const CoinCompare3 &tc)
Sort a triple of containers. 
 
int * getIndices()
Get indices of elements. 
 
double sparseDotProduct(const CoinPackedVectorBase &op1, const CoinPackedVectorBase &op2)
Returns the dot product of two CoinPackedVector objects whose elements are doubles. 
 
void setConstant(int size, const int *inds, double elems, bool testForDuplicateIndex=COIN_DEFAULT_VALUE_FOR_DUPLICATE)
Elements set to have the same scalar value. 
 
virtual const int * getIndices() const =0
Get indices of elements. 
 
int findIndex(int i) const 
Return the position of the i'th element of the full storage vector. 
 
virtual const int * getIndices() const 
Get indices of elements. 
 
void append(const CoinPackedVectorBase &caboose)
Append a CoinPackedVector to the end. 
 
int capacity_
Amount of memory allocated for indices_, origIndices_, and elements_. 
 
void setFullNonZero(int size, const double *elems, bool testForDuplicateIndex=COIN_DEFAULT_VALUE_FOR_DUPLICATE)
Indices are not specified and are taken to be 0,1,...,size-1, but only where non zero. 
 
double * elements_
Vector elements. 
 
void swap(int i, int j)
Swap values in positions i and j of indices and elements.