DyLP
1.10.4
|
Dense Vector. More...
#include <CoinDenseVector.hpp>
Public Member Functions | |
Get methods. | |
int | getNumElements () const |
Get the size. More... | |
int | size () const |
const T * | getElements () const |
Get element values. More... | |
T * | getElements () |
Get element values. More... | |
Set methods | |
void | clear () |
Reset the vector (i.e. set all elemenets to zero) More... | |
CoinDenseVector & | operator= (const CoinDenseVector &) |
Assignment operator. More... | |
T & | operator[] (int index) const |
Member of array operator. More... | |
void | setVector (int size, const T *elems) |
Set vector size, and elements. More... | |
void | setConstant (int size, T elems) |
Elements set to have the same scalar value. More... | |
void | setElement (int index, T element) |
Set an existing element in the dense vector The first argument is the "index" into the elements() array. More... | |
void | resize (int newSize, T fill=T()) |
Resize the dense vector to be the first newSize elements. More... | |
void | append (const CoinDenseVector &) |
Append a dense vector to this dense vector. More... | |
norms, sum and scale | |
T | oneNorm () const |
1-norm of vector More... | |
double | twoNorm () const |
2-norm of vector More... | |
T | infNorm () const |
infinity-norm of vector More... | |
T | sum () const |
sum of vector elements More... | |
void | scale (T factor) |
scale vector elements More... | |
Arithmetic operators. | |
void | operator+= (T value) |
add value to every entry More... | |
void | operator-= (T value) |
subtract value from every entry More... | |
void | operator*= (T value) |
multiply every entry by value More... | |
void | operator/= (T value) |
divide every entry by value More... | |
Constructors and destructors | |
CoinDenseVector () | |
Default constructor. More... | |
CoinDenseVector (int size, const T *elems) | |
Alternate Constructors - set elements to vector of Ts. More... | |
CoinDenseVector (int size, T element=T()) | |
Alternate Constructors - set elements to same scalar value. More... | |
CoinDenseVector (const CoinDenseVector &) | |
Copy constructors. More... | |
~CoinDenseVector () | |
Destructor. More... | |
Private Member Functions | |
Private methods | |
void | gutsOfSetVector (int size, const T *elems) |
Copy internal data. More... | |
void | gutsOfSetConstant (int size, T value) |
Set all elements to a given value. More... | |
Private Attributes | |
Private member data | |
int | nElements_ |
Size of element vector. More... | |
T * | elements_ |
Vector elements. More... | |
Dense Vector.
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 68 of file CoinDenseVector.hpp.
CoinDenseVector< T >::CoinDenseVector | ( | ) |
Default constructor.
CoinDenseVector< T >::CoinDenseVector | ( | int | size, |
const T * | elems | ||
) |
Alternate Constructors - set elements to vector of Ts.
CoinDenseVector< T >::CoinDenseVector | ( | int | size, |
T | element = T() |
||
) |
Alternate Constructors - set elements to same scalar value.
CoinDenseVector< T >::CoinDenseVector | ( | const CoinDenseVector< T > & | ) |
Copy constructors.
CoinDenseVector< T >::~CoinDenseVector | ( | ) |
Destructor.
|
inline |
Get the size.
Definition at line 82 of file CoinDenseVector.hpp.
|
inline |
Definition at line 83 of file CoinDenseVector.hpp.
|
inline |
Get element values.
Definition at line 85 of file CoinDenseVector.hpp.
|
inline |
Get element values.
Definition at line 87 of file CoinDenseVector.hpp.
void CoinDenseVector< T >::clear | ( | ) |
Reset the vector (i.e. set all elemenets to zero)
CoinDenseVector& CoinDenseVector< T >::operator= | ( | const CoinDenseVector< T > & | ) |
Assignment operator.
T& CoinDenseVector< T >::operator[] | ( | int | index | ) | const |
Member of array operator.
void CoinDenseVector< T >::setVector | ( | int | size, |
const T * | elems | ||
) |
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.
void CoinDenseVector< T >::setConstant | ( | int | size, |
T | elems | ||
) |
Elements set to have the same scalar value.
void CoinDenseVector< T >::setElement | ( | int | index, |
T | element | ||
) |
Set an existing element in the dense vector The first argument is the "index" into the elements() array.
void CoinDenseVector< T >::resize | ( | int | newSize, |
T | fill = T() |
||
) |
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
void CoinDenseVector< T >::append | ( | const CoinDenseVector< T > & | ) |
Append a dense vector to this dense vector.
|
inline |
1-norm of vector
Definition at line 127 of file CoinDenseVector.hpp.
|
inline |
2-norm of vector
Definition at line 135 of file CoinDenseVector.hpp.
|
inline |
infinity-norm of vector
Definition at line 145 of file CoinDenseVector.hpp.
|
inline |
sum of vector elements
Definition at line 153 of file CoinDenseVector.hpp.
|
inline |
scale vector elements
Definition at line 161 of file CoinDenseVector.hpp.
void CoinDenseVector< T >::operator+= | ( | T | value | ) |
add value
to every entry
void CoinDenseVector< T >::operator-= | ( | T | value | ) |
subtract value
from every entry
void CoinDenseVector< T >::operator*= | ( | T | value | ) |
multiply every entry by value
void CoinDenseVector< T >::operator/= | ( | T | value | ) |
divide every entry by value
|
private |
Copy internal data.
|
private |
Set all elements to a given value.
|
private |
Size of element vector.
Definition at line 73 of file CoinDenseVector.hpp.
|
private |
Vector elements.
Definition at line 75 of file CoinDenseVector.hpp.