Main Page   Modules   Data Structures   File List   Data Fields   Globals   Related Pages  

gnn_node_vector : Vector of nodes.
[gnn_node : Basic Building Block for Gradient Machines.]


Detailed Description

A node vector is a vector which can contain pointers to nodes.

Node vectors are defined by a gnn_node_vector structure which describes a slice of an array of gnn_node pointers. Different vectors can be created which point to the same block. A vector slice is a set of equally-spaced elements of an area of memory.

The gnn_node_vector structure contains five components, the size, the stride, a pointer to the memory where the elements are stored, data, a pointer to the block owned by the vector, block, if any, and an ownership flag, owner. The structure is very simple and looks like this,

 typedef struct
 {
     size_t size;
     size_t stride;
     size_t blocksize;
     double * data;
     int owner;
 } gnn_node_vector;

The size corresponds to the number of vector elements. The valid indices are 0, 1, 2, ..., size-1. The stride is the step size from one element to another in physical memory, measured in sizeof(gnn_node*). The pointer data points to the first vector element. If the vector own this pointer array, i.e. if it was created and will be destroyed with it, then owner is equal to 1. If it doesn't own the array, then owner is 0, and at deallocation of the gnn_node_vector, the array isn't deallocated. The blocksize field measures the number of memory units that the vector spans.

Functions

gnn_node_vectorgnn_node_vector_new (size_t size)
 Creates a new gnn_node vector.

void gnn_node_vector_free (gnn_node_vector *v)
 Frees gnn_node vector.

void gnn_node_vector_destroy_all (gnn_node_vector *v)
 Frees gnn_node vector and the pointed nodes.

gnn_nodegnn_node_vector_get (gnn_node_vector *v, size_t i)
 Gets an element.

int gnn_node_vector_set (gnn_node_vector *v, size_t i, gnn_node *n)
 Sets an element.

int gnn_node_vector_isnull (gnn_node_vector *v)
 Checks if vector is null.

size_t gnn_node_vector_count_nodes (gnn_node_vector *v)
 Returns the number of elements pointing to a node.

int gnn_node_vector_swap (gnn_node_vector *v, gnn_node_vector *w)
 Swap two vectors.

int gnn_node_vector_swap_elements (gnn_node_vector *v, size_t i, size_t j)
 Swap two vector elements.

int gnn_node_vector_reverse (gnn_node_vector *v)
 Reverse a vector's elements.

gnn_node_vectorgnn_node_vector_dup (gnn_node_vector *v)
 Duplicate a vector.

int gnn_node_vector_copy (gnn_node_vector *v, const gnn_node_vector *w)
 Copy a vector.

gnn_node_vector_view gnn_node_vector_subvector (gnn_node_vector *v, size_t i, size_t n)
 Creates a subvector view of a vector.

gnn_node_vector_view gnn_node_vector_subvector_with_stride (gnn_node_vector *v, size_t i, size_t stride, size_t n)
 Creates a subvector view of a vector.


Function Documentation

int gnn_node_vector_copy gnn_node_vector   v,
const gnn_node_vector   w
 

This function copies the elements of the vector w into v.

Parameters:
v  A pointer to a destiny gnn_node_vector.
v  A pointer to a source gnn_node_vector. @Return Returns 0 if succeeded.

Definition at line 381 of file gnn_node_vector.c.

size_t gnn_node_vector_count_nodes gnn_node_vector   v
 

This function counts the number of elements pointing to a non-NULL location.

Parameters:
v  A pointer to a gnn_node_vector. @Return Returns the count.

Definition at line 248 of file gnn_node_vector.c.

void gnn_node_vector_destroy_all gnn_node_vector   v
 

This function frees the memory of a gnn_node_vector and destroys all its pointed nodes by calling gnn_node_destroy on each one of them.

Parameters:
v  A pointer to a gnn_node_vector.

Definition at line 148 of file gnn_node_vector.c.

gnn_node_vector* gnn_node_vector_dup gnn_node_vector   v
 

This function duplicates a given vector, by creating a new fresh one pointing to the same nodes.

Parameters:
v  A pointer to a gnn_node_vector. @Return A pointer to a new gnn_node_vector or NULL if failed.

Definition at line 352 of file gnn_node_vector.c.

void gnn_node_vector_free gnn_node_vector   v
 

This function frees the memory of a gnn_node_vector. The pointed nodes won't be destroyed.

Parameters:
v  A pointer to a gnn_node_vector.

Definition at line 128 of file gnn_node_vector.c.

gnn_node* gnn_node_vector_get gnn_node_vector   v,
size_t    i
 

This function returns the pointer located at the i-th position.

Parameters:
v  A pointer to a gnn_node_vector.
i  The index of the element to be retrieved. @Return Returns the i-th elements, which can point to a node or NULL.

Definition at line 177 of file gnn_node_vector.c.

int gnn_node_vector_isnull gnn_node_vector   v
 

This function returns 1 if all elements are equal to NULL.

Parameters:
v  A pointer to a gnn_node_vector. @Return Returns 1 (null) or 0 (not null).

Definition at line 223 of file gnn_node_vector.c.

gnn_node_vector* gnn_node_vector_new size_t    size
 

This function creates a new vector with NULL pointers of size size. The underlying memory block will be owned by the vector.

Parameters:
size  The number of elements.
Returns:
A pointer to a new gnn_node_vector.

Definition at line 86 of file gnn_node_vector.c.

int gnn_node_vector_reverse gnn_node_vector   v
 

Parameters:
v  A pointer to a gnn_node_vector. @Return Returns 0 if succeeded.

Definition at line 327 of file gnn_node_vector.c.

int gnn_node_vector_set gnn_node_vector   v,
size_t    i,
gnn_node   n
 

This function sets a new value for the element located at the i-th position. It should be a pointer to a valid gnn_node or NULL. You should be carefull and not delete a needed pointer in order to not lose memory.

Parameters:
v  A pointer to a gnn_node_vector.
i  The index of the element to be retrieved.
n  A pointer to a gnn_node or NULL. @Return Returns 0 if succeeded.

Definition at line 201 of file gnn_node_vector.c.

gnn_node_vector_view gnn_node_vector_subvector gnn_node_vector   v,
size_t    i,
size_t    n
 

This function creates a subvector view of the given vector, starting at i and ending at n. The returned gnn_node_view contains a vector field, where the subvector will be stored. To obtain a pointer of this vector, use the "&" operator:

 gnn_node_vector_view view;
 gnn_node_vector *w;

 // v is a pointer to a gnn_node_vector
 view = gnn_node_vector_subvector (v, 2, 5);

 // get a pointer
 w = &(view.vector);
Parameters:
v  A pointer to a gnn_node_vector.
i  The starting index.
n  The size of the subvector. @Return Returns a vector view.

Definition at line 431 of file gnn_node_vector.c.

gnn_node_vector_view gnn_node_vector_subvector_with_stride gnn_node_vector   v,
size_t    i,
size_t    stride,
size_t    n
 

This function creates a subvector view of the given vector, starting at i and ending at n, with stride stride. The returned gnn_node_view contains a vector field, where the subvector will be stored. To obtain a pointer of this vector, use the "&" operator:

 gnn_node_vector_view view;
 gnn_node_vector *w;

 // obtain a view of the first 5 odd elements of the vector v
 view = gnn_node_vector_subvector_with_stride (v, 1, 2, 5);

 // get a pointer
 w = &(view.vector);
Parameters:
v  A pointer to a gnn_node_vector.
i  The starting index.
stried  The stride.
n  The size of the subvector. @Return Returns a vector view.

Definition at line 464 of file gnn_node_vector.c.

int gnn_node_vector_swap gnn_node_vector   v,
gnn_node_vector   w
 

This function swaps the elements of the node vectors. This is accomplished by interchanging its underlying arrays.

Parameters:
v  A pointer to a gnn_node_vector.
w  A pointer to a gnn_node_vector. @Return Returns 0 if succeeded.

Definition at line 276 of file gnn_node_vector.c.

int gnn_node_vector_swap_elements gnn_node_vector   v,
size_t    i,
size_t    j
 

This function swaps the element located at i with the element located at position j.

Parameters:
v  A pointer to a gnn_node_vector.
i  An index.
j  An index. @Return Returns 0 if succeeded.

Definition at line 303 of file gnn_node_vector.c.


Generated on Sun Jun 13 20:51:43 2004 for libgnn Gradient Retropropagation Machine Library by doxygen1.2.18