SHOGUN  v1.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
List of all members | Public Member Functions | Protected Member Functions | Protected Attributes
CParseBuffer< T > Class Template Reference

Detailed Description

template<class T>
class shogun::CParseBuffer< T >

Class CParseBuffer implements a ring of examples of a defined size. The ring stores objects of the Example type.

The feature vector and label are provided to this class from an external source. CParseBuffer is only responsible for managing how these examples are represented and stored in the memory. It is also responsible for returning stored examples to be used by an external caller, and freeing up the space when the example is used to make room for another example to take its place.

Writing of examples is done into whichever position in the ring is free to be overwritten, or empty.

Definition at line 65 of file ParseBuffer.h.

Inheritance diagram for CParseBuffer< T >:
Inheritance graph
[legend]

Public Member Functions

 CParseBuffer (int32_t size=1024)
 ~CParseBuffer ()
Example< T > * get_free_example ()
int32_t write_example (Example< T > *ex)
Example< T > * return_example_to_read ()
Example< T > * get_unused_example ()
int32_t copy_example (Example< T > *ex)
void finalize_example (bool free_after_release)
void set_free_vectors_on_destruct (bool destroy)
bool get_free_vectors_on_destruct ()
virtual const char * get_name () const
- Public Member Functions inherited from CSGObject
 CSGObject ()
 CSGObject (const CSGObject &orig)
virtual ~CSGObject ()
virtual bool is_generic (EPrimitiveType *generic) const
template<class T >
void set_generic ()
void unset_generic ()
virtual void print_serializable (const char *prefix="")
virtual bool save_serializable (CSerializableFile *file, const char *prefix="")
virtual bool load_serializable (CSerializableFile *file, const char *prefix="")
void set_global_io (SGIO *io)
SGIOget_global_io ()
void set_global_parallel (Parallel *parallel)
Parallelget_global_parallel ()
void set_global_version (Version *version)
Versionget_global_version ()
SGVector< char * > get_modelsel_names ()
char * get_modsel_param_descr (const char *param_name)
index_t get_modsel_param_index (const char *param_name)

Protected Member Functions

virtual void inc_read_index ()
virtual void inc_write_index ()
- Protected Member Functions inherited from CSGObject
virtual void load_serializable_pre () throw (ShogunException)
virtual void load_serializable_post () throw (ShogunException)
virtual void save_serializable_pre () throw (ShogunException)
virtual void save_serializable_post () throw (ShogunException)

Protected Attributes

int32_t ring_size
 Size of ring as number of examples.
Example< T > * ex_ring
 Ring of examples.
E_IS_EXAMPLE_USEDex_used
 Enum used for representing used/unused/empty state of example.
pthread_mutex_t * ex_in_use_mutex
 Lock on state of example - used or unused.
pthread_cond_t * ex_in_use_cond
 Condition variable triggered when example is being/not being used.
pthread_mutex_t * read_lock
 Lock for reading examples from the ring.
pthread_mutex_t * write_lock
 Lock for writing new examples.
int32_t ex_write_index
 Write position for next example.
int32_t ex_read_index
 Position of next example to be read.
bool free_vectors_on_destruct
 Whether examples on the ring will be freed on destruction.

Additional Inherited Members

- Public Attributes inherited from CSGObject
SGIOio
Parallelparallel
Versionversion
Parameterm_parameters
Parameterm_model_selection_parameters

Constructor & Destructor Documentation

CParseBuffer ( int32_t  size = 1024)

Constructor, taking buffer size as argument.

Parameters
sizeRing size as number of examples

Definition at line 213 of file ParseBuffer.h.

Destructor, frees up buffer.

Definition at line 244 of file ParseBuffer.h.

Member Function Documentation

int32_t copy_example ( Example< T > *  ex)

Copies an example into the buffer, waiting for the destination example to be used if necessary.

Parameters
exExample to copy into buffer
Returns
1 on success, 0 on memory errors

Definition at line 306 of file ParseBuffer.h.

void finalize_example ( bool  free_after_release)

Mark the example in 'read' position as 'used'.

It will then be free to be overwritten.

Parameters
free_after_releasewhether to SG_FREE() the vector or not

Definition at line 327 of file ParseBuffer.h.

Example<T>* get_free_example ( )

Return the next position to write the example into the ring.

Returns
pointer to example

Definition at line 87 of file ParseBuffer.h.

bool get_free_vectors_on_destruct ( )

Return whether all example objects will be freed on destruction.

Definition at line 158 of file ParseBuffer.h.

virtual const char* get_name ( ) const
virtual

Return the name of the object

Returns
ParseBuffer

Implements CSGObject.

Definition at line 165 of file ParseBuffer.h.

Example< T > * get_unused_example ( )

Returns the next example from the buffer if unused, or NULL.

Returns
unused example object at next 'read' position or NULL.

Definition at line 284 of file ParseBuffer.h.

virtual void inc_read_index ( )
protectedvirtual

Increments the 'read' position in the buffer.

Definition at line 172 of file ParseBuffer.h.

virtual void inc_write_index ( )
protectedvirtual

Increments the 'write' position in the buffer.

Definition at line 181 of file ParseBuffer.h.

Example< T > * return_example_to_read ( )

Returns the example that should be read next from the buffer.

Returns
example object at next 'read' position

Definition at line 275 of file ParseBuffer.h.

void set_free_vectors_on_destruct ( bool  destroy)

Set whether all vectors are to be freed on destruction. This is true by default.

The features object should set this to false if the vectors are freed manually later.

Parameters
destroyfree examples on destruction or not

Definition at line 152 of file ParseBuffer.h.

int32_t write_example ( Example< T > *  ex)

Writes the given example into the appropriate buffer space. Feature vector is copied into a separate block.

Parameters
exExample to copy into buffer
Returns
1 if successful, 0 on failure (if no space available)

Definition at line 263 of file ParseBuffer.h.

Member Data Documentation

pthread_cond_t* ex_in_use_cond
protected

Condition variable triggered when example is being/not being used.

Definition at line 198 of file ParseBuffer.h.

pthread_mutex_t* ex_in_use_mutex
protected

Lock on state of example - used or unused.

Definition at line 196 of file ParseBuffer.h.

int32_t ex_read_index
protected

Position of next example to be read.

Definition at line 207 of file ParseBuffer.h.

Example<T>* ex_ring
protected

Ring of examples.

Definition at line 191 of file ParseBuffer.h.

E_IS_EXAMPLE_USED* ex_used
protected

Enum used for representing used/unused/empty state of example.

Definition at line 194 of file ParseBuffer.h.

int32_t ex_write_index
protected

Write position for next example.

Definition at line 205 of file ParseBuffer.h.

bool free_vectors_on_destruct
protected

Whether examples on the ring will be freed on destruction.

Definition at line 210 of file ParseBuffer.h.

pthread_mutex_t* read_lock
protected

Lock for reading examples from the ring.

Definition at line 200 of file ParseBuffer.h.

int32_t ring_size
protected

Size of ring as number of examples.

Definition at line 189 of file ParseBuffer.h.

pthread_mutex_t* write_lock
protected

Lock for writing new examples.

Definition at line 202 of file ParseBuffer.h.


The documentation for this class was generated from the following file:

SHOGUN Machine Learning Toolbox - Documentation