#include <CoinDenseVector.hpp>
Public Member Functions | |
Get methods. | |
int | getNumElements () const |
Get the size. | |
int | size () const |
const T * | getElements () const |
Get element values. | |
T * | getElements () |
Get element values. | |
Set methods | |
void | clear () |
Reset the vector (i.e. set all elemenets to zero). | |
CoinDenseVector & | operator= (const CoinDenseVector &) |
T & | operator[] (int index) const |
void | setVector (int size, const T *elems) |
void | setConstant (int size, T elems) |
void | setElement (int index, T element) |
void | resize (int newSize, T fill=T()) |
void | append (const CoinDenseVector &) |
norms, sum and scale | |
T | oneNorm () const |
1-norm of vector | |
double | twoNorm () const |
2-norm of vector | |
T | infNorm () const |
infinity-norm of vector | |
T | sum () const |
sum of vector elements | |
void | scale (T factor) |
scale vector elements | |
Arithmetic operators. | |
void | operator+= (T value) |
add value to every entry | |
void | operator-= (T value) |
subtract value from every entry | |
void | operator *= (T value) |
multiply every entry by value | |
void | operator/= (T value) |
divide every entry by value | |
Constructors and destructors | |
CoinDenseVector () | |
CoinDenseVector (int size, const T *elems) | |
CoinDenseVector (int size, T element=T()) | |
CoinDenseVector (const CoinDenseVector &) | |
~CoinDenseVector () | |
Private Member Functions | |
Private methods | |
void | gutsOfSetVector (int size, const T *elems) |
Copy internal data. | |
void | gutsOfSetConstant (int size, T value) |
Set all elements to a given value. | |
Private Attributes | |
Private member data | |
int | nElements_ |
Size of element vector. | |
T * | elements_ |
Vector elements. |
Stores a dense (or expanded) vector of floating point values. Type of vector elements is controlled by templating. (Some working quantities such as accumulated sums are explicitly declared of type double). This allows the components of the vector integer, single or double precision.
Here is a sample usage:
const int ne = 4; double el[ne] = { 10., 40., 1., 50. }; // Create vector and set its value CoinDenseVector<double> r(ne,el); // access each element assert( r.getElements()[0]==10. ); assert( r.getElements()[1]==40. ); assert( r.getElements()[2]== 1. ); assert( r.getElements()[3]==50. ); // Test for equality CoinDenseVector<double> r1; r1=r; // Add dense vectors. // Similarly for subtraction, multiplication, // and division. CoinDenseVector<double> add = r + r1; assert( add[0] == 10.+10. ); assert( add[1] == 40.+40. ); assert( add[2] == 1.+ 1. ); assert( add[3] == 50.+50. ); assert( r.sum() == 10.+40.+1.+50. );
Definition at line 63 of file CoinDenseVector.hpp.
|
Default constructor Definition at line 129 of file CoinDenseVector.cpp.
00129 : 00130 nElements_(0), 00131 elements_(NULL) 00132 {} |
|
Alternate Constructors - set elements to vector of Ts Definition at line 137 of file CoinDenseVector.cpp. References CoinDenseVector< T >::gutsOfSetVector().
00137 : 00138 nElements_(0), 00139 elements_(NULL) 00140 { 00141 gutsOfSetVector(size, elems); 00142 } |
|
Alternate Constructors - set elements to same scalar value Definition at line 146 of file CoinDenseVector.cpp. References CoinDenseVector< T >::gutsOfSetConstant().
00146 : 00147 nElements_(0), 00148 elements_(NULL) 00149 { 00150 gutsOfSetConstant(size, value); 00151 } |
|
Copy constructors Definition at line 156 of file CoinDenseVector.cpp. References CoinDenseVector< T >::setVector().
00156 : 00157 nElements_(0), 00158 elements_(NULL) 00159 { 00160 setVector(rhs.getNumElements(), rhs.getElements()); 00161 } |
|
Destructor Definition at line 165 of file CoinDenseVector.cpp. References CoinDenseVector< T >::elements_.
00166 { 00167 delete [] elements_; 00168 } |
|
Append a dense vector to this dense vector Definition at line 81 of file CoinDenseVector.cpp. References CoinDenseVector< T >::elements_, CoinDenseVector< T >::getElements(), CoinDenseVector< T >::getNumElements(), CoinDenseVector< T >::nElements_, and CoinDenseVector< T >::resize().
00082 { 00083 const int s = nElements_; 00084 const int cs = caboose.getNumElements(); 00085 int newsize = s + cs; 00086 resize(newsize); 00087 const T * celem = caboose.getElements(); 00088 CoinDisjointCopyN(celem, cs, elements_ + s); 00089 } |
|
Assignment operator Definition at line 24 of file CoinDenseVector.cpp. References CoinDenseVector< T >::getElements(), CoinDenseVector< T >::getNumElements(), and CoinDenseVector< T >::setVector().
00025 { 00026 if (this != &rhs) { 00027 setVector(rhs.getNumElements(), rhs.getElements()); 00028 } 00029 return *this; 00030 } |
|
Member of array operator Definition at line 197 of file CoinDenseVector.cpp. References CoinDenseVector< T >::elements_, and CoinDenseVector< T >::nElements_.
00198 { 00199 assert(index >= 0 && index < nElements_); 00200 T *where = elements_ + index; 00201 return *where; 00202 } |
|
Resize the dense vector to be the first newSize elements. If length is decreased, vector is truncated. If increased new entries, set to new default element Definition at line 54 of file CoinDenseVector.cpp. References CoinDenseVector< T >::elements_, and CoinDenseVector< T >::nElements_. Referenced by CoinDenseVector< T >::append(), CoinDenseVector< T >::gutsOfSetConstant(), CoinDenseVector< T >::gutsOfSetVector(), CoinDenseVector< T >::setConstant(), and CoinDenseVector< T >::setVector().
00055 { 00056 if (newsize != nElements_){ 00057 assert(newsize > 0); 00058 T *newarray = new T[newsize]; 00059 int cpysize = min(newsize, nElements_); 00060 memcpy(newarray, elements_, cpysize*sizeof(T)); 00061 delete[] elements_; 00062 elements_ = newarray; 00063 nElements_ = newsize; 00064 for(int i=cpysize; i<newsize; i++) 00065 elements_[i] = value; 00066 } 00067 } |
|
Elements set to have the same scalar value Definition at line 44 of file CoinDenseVector.cpp. References CoinDenseVector< T >::elements_, and CoinDenseVector< T >::resize().
|
|
Set an existing element in the dense vector The first argument is the "index" into the elements() array Definition at line 72 of file CoinDenseVector.cpp. References CoinDenseVector< T >::elements_, and CoinDenseVector< T >::nElements_.
00073 { 00074 assert(index >= 0 && index < nElements_); 00075 elements_[index] = element; 00076 } |
|
Set vector size, and elements. Size is the length of the elements vector. The element vector is copied into this class instance's member data. Definition at line 35 of file CoinDenseVector.cpp. References CoinDenseVector< T >::elements_, and CoinDenseVector< T >::resize(). Referenced by CoinDenseVector< T >::CoinDenseVector(), and CoinDenseVector< T >::operator=().
00036 { 00037 resize(size); 00038 memcpy(elements_, elems, size*sizeof(T)); 00039 } |