H2Lib  3.0
Data Structures | Typedefs | Functions
avector

Representation of a vector as an array. More...

Data Structures

struct  _avector
 

Typedefs

typedef struct _avector avector
 
typedef avectorpavector
 
typedef const avectorpcavector
 

Functions

pavector init_avector (pavector v, uint dim)
 Initialize an avector object. More...
 
pavector init_sub_avector (pavector v, pavector src, uint dim, uint off)
 Initialize an avector object to represent a subvector. More...
 
pavector init_zero_avector (pavector v, uint dim)
 Initialize an avector object and set it to zero. More...
 
pavector init_column_avector (pavector v, pamatrix src, uint col)
 Initialize an avector object to represent a column vector of a given matrix. More...
 
pavector init_pointer_avector (pavector v, pfield src, uint dim)
 Initialize an avector object using a given array for the coefficients. More...
 
void uninit_avector (pavector v)
 Uninitialize an avector object. More...
 
pavector new_avector (uint dim)
 Create a new avector object. More...
 
pavector new_sub_avector (pavector src, uint dim, uint off)
 Create a new avector object representing a subvector. More...
 
pavector new_zero_avector (uint dim)
 Create a new avector object representing a zero vector. More...
 
pavector new_pointer_avector (pfield src, uint dim)
 Create a new avector object using a given array for the coefficients. More...
 
void del_avector (pavector v)
 Delete an avector object. More...
 
void resize_avector (pavector v, uint dim)
 Change the dimension of an avector object without preserving its coefficients. More...
 
void shrink_avector (pavector v, uint dim)
 Reduce the dimension of an avector object without reallocating storage, preserving its coefficients. More...
 
field getentry_avector (pcavector v, uint i)
 Read a vector entry $v_i$. More...
 
void setentry_avector (pavector v, uint i, field x)
 Set a vector entry, $v_i \gets x$. More...
 
field addentry_avector (pavector v, uint i, field x)
 Add to a vector entry, $v_i \gets v_i + x$. More...
 
uint getactives_avector ()
 Get number of currently initialized avector objects. More...
 
size_t getsize_avector (pcavector v)
 Get size of a given avector object. More...
 
size_t getsize_heap_avector (pcavector v)
 Get heap size of a given avector object. More...
 
void clear_avector (pavector v)
 Set a vector to zero. More...
 
void fill_avector (pavector v, field x)
 Set all coefficients in a vector to the same value. More...
 
void random_avector (pavector v)
 Fill a vector with random values. More...
 
void random_real_avector (pavector v)
 Fill a vector with real valued random values. More...
 
void copy_avector (pcavector v, pavector w)
 Copy a vector into another vector, $w \gets v$. More...
 
void copy_sub_avector (pcavector v, pavector w)
 Copy a vector into another vector, $w \gets v$. More...
 
void print_avector (pcavector v)
 Print a vector. More...
 
void scale_avector (field alpha, pavector v)
 Scale a vector $v$ by a factor $\alpha$, $v \gets \alpha v$. More...
 
real norm2_avector (pcavector v)
 Compute the Euclidean norm $\|v\|_2$ of a vector $v$. More...
 
field dotprod_avector (pcavector x, pcavector y)
 Compute the Euclidean innner product $\langle x, y\rangle_2$ of two vectors $x$ and $y$. More...
 
void add_avector (field alpha, pcavector x, pavector y)
 Add two vectors, $y \gets y + \alpha x$. More...
 

Detailed Description

Representation of a vector as an array.

The avector class is used to handle standard linear algebra operations like adding, scaling and multiplying vectors.

Typedef Documentation

typedef struct _avector avector

Representation of a vector as an array.

typedef avector* pavector

Pointer to a avector object.

typedef const avector* pcavector

Pointer to a constant avector object.

Function Documentation

void add_avector ( field  alpha,
pcavector  x,
pavector  y 
)

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

Parameters
alphaScaling factor $\alpha$.
xSource vector $x$.
yTarget vector $y$.
field addentry_avector ( pavector  v,
uint  i,
field  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_avector ( pavector  v)

Set a vector to zero.

Parameters
vTarget vector.
void copy_avector ( pcavector  v,
pavector  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_avector.
Parameters
vSource vector.
wTarget vector.
void copy_sub_avector ( pcavector  v,
pavector  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_avector ( pavector  v)

Delete an avector 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.
field dotprod_avector ( pcavector  x,
pcavector  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 \bar x_i y_i$.

Parameters
xVector $x$.
yVector $x$.
Returns
Euclidean inner product $\langle x, y\rangle_2$.
void fill_avector ( pavector  v,
field  x 
)

Set all coefficients in a vector to the same value.

Parameters
vTarget vector.
xFill value.
uint getactives_avector ( )

Get number of currently initialized avector objects.

Calls to initialization functions like init_avector and constructors like new_avector increase an internal counter, while uninit_avector and del_avector decrease it.

Remarks
Use this function to check whether a program correctly cleans up temporary variables.
Returns
Number of currently initialized avector objects.
field getentry_avector ( pcavector  v,
uint  i 
)

Read a vector entry $v_i$.

Parameters
vVector $v$.
iIndex $i$.
Returns
Vector entry $v_i$.
size_t getsize_avector ( pcavector  v)

Get size of a given avector object.

Computes the size of the avector 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_avector), no coefficient storage is added.

Parameters
vVector object.
Returns
Size of allocated storage in bytes.
size_t getsize_heap_avector ( pcavector  v)

Get heap size of a given avector object.

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

Parameters
vVector object.
Returns
Size of allocated heap storage in bytes.
pavector init_avector ( pavector  v,
uint  dim 
)

Initialize an avector 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_avector.
Parameters
vObject to be initialized.
dimDimension of the new vector.
Returns
Initialized avector object.
pavector init_column_avector ( pavector  v,
pamatrix  src,
uint  col 
)

Initialize an avector object to represent a column vector of a given matrix.

Sets up the components of the object and uses part of the storage of an amatrix corresponding to one of its columns. Changes to the coefficients of the new vector also change the column of the source matrix.

Remarks
Should always be matched by a call to uninit_avector that will not release the coefficient storage.
Parameters
vObject to be initialized.
srcSource matrix.
colColumn of the source matrix that will be used for the vector.
Returns
Initialized avector object.
pavector init_pointer_avector ( pavector  v,
pfield  src,
uint  dim 
)

Initialize an avector 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_avector 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 avector object.
pavector init_sub_avector ( pavector  v,
pavector  src,
uint  dim,
uint  off 
)

Initialize an avector object to represent a subvector.

Sets up the components of the object and uses part of the storage of another avector 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_avector 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 avector object.
pavector init_zero_avector ( pavector  v,
uint  dim 
)

Initialize an avector object and set it to zero.

Sets up the components of the object, allocates storage for the coefficient array, and dets it to zero.

Parameters
vObject to be initialized.
dimDimension of the vector.
Returns
Initialized avector object.
pavector new_avector ( uint  dim)

Create a new avector object.

Allocates storage for the object an sets up its components.

Remarks
Should always be matched by a call to del_avector.
Parameters
dimDimension of the new vector.
Returns
New avector object.
pavector new_pointer_avector ( pfield  src,
uint  dim 
)

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

Parameters
srcSource array, should contain at least dim elements.
dimDimension of the new vector.
Returns
New avector object.
pavector new_sub_avector ( pavector  src,
uint  dim,
uint  off 
)

Create a new avector object representing a subvector.

Allocates storage for the object, but uses part of the storage of another avector 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_avector 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 avector object.
pavector new_zero_avector ( uint  dim)

Create a new avector object representing a zero vector.

Allocates storage for the object and sets all coefficients to zero.

Remarks
Should always be matched by a call to del_avector.
Parameters
dimDimension of the new vector.
Returns
New amatrix object.
real norm2_avector ( pcavector  v)

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

Parameters
vVector $v$.
Returns
Returns $\|v\|_2$.
void print_avector ( pcavector  v)

Print a vector.

Parameters
vVector $v$.
void random_avector ( pavector  v)

Fill a vector with random values.

Parameters
vTarget vector.
void random_real_avector ( pavector  v)

Fill a vector with real valued random values.

Parameters
vTarget vector.
void resize_avector ( pavector  v,
uint  dim 
)

Change the dimension of an avector 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_avector ( field  alpha,
pavector  v 
)

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

Parameters
alphaScaling factor $\alpha$.
vTarget vector $v$.
void setentry_avector ( pavector  v,
uint  i,
field  x 
)

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

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

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

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

Uninitialize an avector object.

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

Parameters
vObject to be uninitialized.