H2Lib  3.0
Data Structures | Typedefs | Functions
realavector

Representation of a vector as an array for real coefficients. More...

Data Structures

struct  _realavector
 

Typedefs

typedef struct _realavector realavector
 
typedef realavectorprealavector
 
typedef const realavectorpcrealavector
 

Functions

prealavector init_realavector (prealavector v, uint dim)
 Initialize an realavector object. More...
 
prealavector init_sub_realavector (prealavector v, prealavector src, uint dim, uint off)
 Initialize an realavector object to represent a subvector. More...
 
prealavector init_pointer_realavector (prealavector v, preal src, uint dim)
 Initialize an realavector object using a given array for the coefficients. More...
 
void uninit_realavector (prealavector v)
 Uninitialize an realavector object. More...
 
prealavector new_realavector (uint dim)
 Create a new realavector object. More...
 
prealavector new_sub_realavector (prealavector src, uint dim, uint off)
 Create a new realavector object representing a subvector. More...
 
prealavector new_pointer_realavector (preal src, uint dim)
 Create a new realavector object using a given array for the coefficients. More...
 
void del_realavector (prealavector v)
 Delete an realavector object. More...
 
void resize_realavector (prealavector v, uint dim)
 Change the dimension of an realavector object without preserving its coefficients. More...
 
void shrink_realavector (prealavector v, uint dim)
 Reduce the dimension of an realavector object without reallocating storage, preserving its coefficients. More...
 
real getentry_realavector (pcrealavector v, uint i)
 Read a vector entry $v_i$. More...
 
void setentry_realavector (prealavector v, uint i, real x)
 Set a vector entry, $v_i \gets x$. More...
 
real addentry_realavector (prealavector v, uint i, real x)
 Add to a vector entry, $v_i \gets v_i + x$. More...
 
uint getactives_realavector ()
 Get number of currently initialized realavector objects. More...
 
size_t getsize_realavector (pcrealavector v)
 Get size of a given realavector object. More...
 
size_t getsize_heap_realavector (pcrealavector v)
 Get heap size of a given realavector object. More...
 
void clear_realavector (prealavector v)
 Set a vector to zero. More...
 
void fill_realavector (prealavector v, real x)
 Set all coefficients in a vector to the same value. More...
 
void random_realavector (prealavector v)
 Fill a vector with random values. More...
 
void copy_realavector (pcrealavector v, prealavector w)
 Copy a vector into another vector, $w \gets v$. More...
 
void copy_sub_realavector (pcrealavector v, prealavector w)
 Copy a vector into another vector, $w \gets v$. More...
 
void print_realavector (pcrealavector v)
 Print a vector. More...
 
void scale_realavector (real alpha, prealavector v)
 Scale a vector $v$ by a factor $\alpha$, $v \gets \alpha v$. More...
 
real norm2_realavector (pcrealavector v)
 Compute the Euclidean norm $\|v\|_2$ of a vector $v$. More...
 
real dotprod_realavector (pcrealavector x, pcrealavector y)
 Compute the Euclidean innner product $\langle x, y\rangle_2$ of two vectors $x$ and $y$. More...
 
void add_realavector (real alpha, pcrealavector x, prealavector y)
 Add two vectors, $y \gets y + \alpha x$. More...
 

Detailed Description

Representation of a vector as an array for real coefficients.

The realavector class is used to handle standard linear algebra operations like adding, scaling and multiplying vectors for real valued vectors.

Attention
If one needs to have a vector field entries from a general field, then the class avector should be used instead.

Typedef Documentation

typedef const realavector* pcrealavector

Pointer to a constant avector object.

Pointer to a avector object.

typedef struct _realavector realavector

Representation of a vector as an array.

Function Documentation

void add_realavector ( real  alpha,
pcrealavector  x,
prealavector  y 
)

Add two vectors, $y \gets y + \alpha x$.

Parameters
alphaScaling factor $\alpha$.
xSource vector $x$.
yTarget vector $y$.
real addentry_realavector ( prealavector  v,
uint  i,
real  x 
)

Add to a vector entry, $v_i \gets v_i + x$.

Parameters
vVector $v$.
iIndex $i$.
xSummand.
Returns
New value of $v_i$.
void clear_realavector ( prealavector  v)

Set a vector to zero.

Parameters
vTarget vector.
void copy_realavector ( pcrealavector  v,
prealavector  w 
)

Copy a vector into another vector, $w \gets v$.

Both vectors have to be of the same dimension.

Remarks
If you want to copy between vectors of different dimension, consider using copy_sub_realavector.
Parameters
vSource vector.
wTarget vector.
void copy_sub_realavector ( pcrealavector  v,
prealavector  w 
)

Copy a vector into another vector, $w \gets v$.

If $w$ is smaller than $v$, only the first coefficients of $v$ are copied. If $v$ is smaller than $w$, only the first coefficients of $w$ are filled.

Parameters
vSource vector.
wTarget vector.
void del_realavector ( prealavector  v)

Delete an realavector object.

Releases the storage corresponding to the object.

Attention
Make sure that there are no submatrix objects referring to this object, since they might otherwise keep using pointers to invalid storage.
Parameters
vObject to be deleted.
real dotprod_realavector ( pcrealavector  x,
pcrealavector  y 
)

Compute the Euclidean innner product $\langle x, y\rangle_2$ of two vectors $x$ and $y$.

The Euclidean inner product is given by $\langle x, y \rangle_2 = \sum_i x_i y_i$.

Parameters
xVector $x$.
yVector $x$.
Returns
Euclidean inner product $\langle x, y\rangle_2$.
void fill_realavector ( prealavector  v,
real  x 
)

Set all coefficients in a vector to the same value.

Parameters
vTarget vector.
xFill value.
uint getactives_realavector ( )

Get number of currently initialized realavector objects.

Calls to initialization functions like init_realavector and constructors like new_realavector increase an internal counter, while uninit_realavector and del_realavector decrease it.

Remarks
Use this function to check whether a program correctly cleans up temporary variables.
Returns
Number of currently initialized realavector objects.
real getentry_realavector ( pcrealavector  v,
uint  i 
)

Read a vector entry $v_i$.

Parameters
vVector $v$.
iIndex $i$.
Returns
Vector entry $v_i$.
size_t getsize_heap_realavector ( pcrealavector  v)

Get heap size of a given realavector object.

Computes the size of storage allocated for the coefficients on the heap, but not for the realavector object itself. If the object uses the coefficients of another object (e.g., if it was created using new_sub_realavector), no storage is required.

Parameters
vVector object.
Returns
Size of allocated heap storage in bytes.
size_t getsize_realavector ( pcrealavector  v)

Get size of a given realavector object.

Computes the size of the realavector object and the storage allocated for the coefficients. If the object uses the coefficients of another object (e.g., if it was created using new_sub_realavector), no coefficient storage is added.

Parameters
vVector object.
Returns
Size of allocated storage in bytes.
prealavector init_pointer_realavector ( prealavector  v,
preal  src,
uint  dim 
)

Initialize an realavector object using a given array for the coefficients.

Sets up the components of the object and uses the given array to represent the coefficients.

Remarks
Should always be matched by a call to uninit_realavector that will not release the coefficient storage.
Parameters
vObject to be initialized.
srcSource array, should contain at least dim elements.
dimDimension of the new vector.
Returns
Initialized realavector object.
prealavector init_realavector ( prealavector  v,
uint  dim 
)

Initialize an realavector object.

Sets up the components of the object and allocates storage for the coefficient array.

Remarks
Should always be matched by a call to uninit_realavector.
Parameters
vObject to be initialized.
dimDimension of the new vector.
Returns
Initialized realavector object.
prealavector init_sub_realavector ( prealavector  v,
prealavector  src,
uint  dim,
uint  off 
)

Initialize an realavector object to represent a subvector.

Sets up the components of the object and uses part of the storage of another realavector for the coefficient array, leading to a new vector representing a subvector of the source. Changes to the coefficients of the new vector also change coefficients of the source vector.

Remarks
Should always be matched by a call to uninit_realavector that will not release the coefficient storage.
Parameters
vObject to be initialized.
srcSource vector.
dimDimension of the new vector.
offOffset in the source vector, should satisfy dim+off<=src->dim.
Returns
Initialized realavector object.
prealavector new_pointer_realavector ( preal  src,
uint  dim 
)

Create a new realavector object using a given array for the coefficients.

Parameters
srcSource array, should contain at least dim elements.
dimDimension of the new vector.
Returns
New realavector object.
prealavector new_realavector ( uint  dim)

Create a new realavector object.

Allocates storage for the object an sets up its components.

Remarks
Should always be matched by a call to del_realavector.
Parameters
dimDimension of the new vector.
Returns
New realavector object.
prealavector new_sub_realavector ( prealavector  src,
uint  dim,
uint  off 
)

Create a new realavector object representing a subvector.

Allocates storage for the object, but uses part of the storage of another realavector for the coefficient array, leading to a new vector representing a subvector of the source. Changes to the coefficients of the new vector also change coefficients of the source vector.

Remarks
Should always be matched by a call to del_realavector that will not release the coefficient storage.
Parameters
srcSource vector.
dimDimension of the new vector.
offOffset in the source vector, should satisfy dim+off<=src->dim.
Returns
New realavector object.
real norm2_realavector ( pcrealavector  v)

Compute the Euclidean norm $\|v\|_2$ of a vector $v$.

Parameters
vVector $v$.
Returns
Returns $\|v\|_2$.
void print_realavector ( pcrealavector  v)

Print a vector.

Parameters
vVector $v$.
void random_realavector ( prealavector  v)

Fill a vector with random values.

Parameters
vTarget vector.
void resize_realavector ( prealavector  v,
uint  dim 
)

Change the dimension of an realavector object without preserving its coefficients.

Allocates new storage for the coefficients and releases the old storage.

Attention
Make sure that there are no submatrix objects referring to this object, since they will otherwise keep using pointers to invalid storage.
Parameters
vVector to be resized.
dimNew vector dimension.
void scale_realavector ( real  alpha,
prealavector  v 
)

Scale a vector $v$ by a factor $\alpha$, $v \gets \alpha v$.

Parameters
alphaScaling factor $\alpha$.
vTarget vector $v$.
void setentry_realavector ( prealavector  v,
uint  i,
real  x 
)

Set a vector entry, $v_i \gets x$.

Parameters
vVector $v$.
iIndex $i$.
xNew value of $v_i$.
void shrink_realavector ( prealavector  v,
uint  dim 
)

Reduce the dimension of an realavector object without reallocating storage, preserving its coefficients.

Parameters
vVector to be resized.
dimNew vector dimension, not greater than v->dim.
void uninit_realavector ( prealavector  v)

Uninitialize an realavector object.

Invalidates pointers, freeing corresponding storage if appropriate, and prepares the object for deletion.

Parameters
vObject to be uninitialized.