SHOGUN  v3.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
List of all members | Public Member Functions | Static Public Member Functions | Public Attributes
TParameter Struct Reference

Detailed Description

parameter struct

Definition at line 26 of file Parameter.h.

Public Member Functions

 TParameter (const TSGDataType *datatype, void *parameter, const char *name, const char *description)
 ~TParameter ()
void print (const char *prefix)
bool save (CSerializableFile *file, const char *prefix="")
bool load (CSerializableFile *file, const char *prefix="")
void allocate_data_from_scratch (SGVector< index_t > dims, bool new_cont_call=true)
void copy_data (const TParameter *source)
bool equals (TParameter *other, float64_t accuracy=0.0)
bool copy (TParameter *target)
bool operator== (const TParameter &other) const
bool operator< (const TParameter &other) const
bool operator> (const TParameter &other) const
void get_incremental_hash (uint32_t &hash, uint32_t &carry, uint32_t &total_length)
bool is_valid ()

Static Public Member Functions

static bool compare_ptype (EPrimitiveType ptype, void *data1, void *data2, floatmax_t accuracy=0.0)
static bool compare_stype (EStructType stype, EPrimitiveType ptype, void *data1, void *data2, floatmax_t accuracy=0.0)
static bool copy_ptype (EPrimitiveType ptype, void *source, void *target)
static bool copy_stype (EStructType stype, EPrimitiveType ptype, void *source, void *target)

Public Attributes

TSGDataType m_datatype
void * m_parameter
char * m_name
char * m_description
bool m_delete_data
bool m_was_allocated_from_scratch

Constructor & Destructor Documentation

TParameter ( const TSGDataType datatype,
void *  parameter,
const char *  name,
const char *  description 
)
explicit

explicit constructor

Parameters
datatypedatatype
parameterpointer to parameter
namename of parameter
descriptiondescription of parameter

Definition at line 1772 of file Parameter.cpp.

~TParameter ( )

destructor

Definition at line 1783 of file Parameter.cpp.

Member Function Documentation

void allocate_data_from_scratch ( SGVector< index_t dims,
bool  new_cont_call = true 
)

Allocates data for this instance from scratch. This is one of the core methods in parameter migration. It is used if parameters have to be loaded from file without having a class instance to put the data into. Namely, the data length variables are allocated, for numeric scalars, the memory is allocated, for SG_OBJECT scalars, a pointer to an CSGObject is allocated, for non-scalars, the pointer to the data is allocated for non-scalars, the actual data is also allocated via cont_new()

Parameters
dimsdesired length of the data
new_cont_callwhether new_cont should be called, if false, only scalar non-sgobject data will be allocated (needed for migration)

Definition at line 2983 of file Parameter.cpp.

bool compare_ptype ( EPrimitiveType  ptype,
void *  data1,
void *  data2,
floatmax_t  accuracy = 0.0 
)
static

Given two pointers to a scalar element of a given primitive-type, this method compares the values up to a given accuracy.

If the type of the data is SGObject, recursively calls equals on the object.

Parameters
ptypeprimitive type of both data
data1pointer 1
data2pointer 2
accuracyaccuracy to compare
Returns
whether the data was equal

ensure that no NULL data are de-referenced

Definition at line 3275 of file Parameter.cpp.

bool compare_stype ( EStructType  stype,
EPrimitiveType  ptype,
void *  data1,
void *  data2,
floatmax_t  accuracy = 0.0 
)
static

Given two pointers to a string element of a given primitive-type, this method compares the values up to a given accuracy.

If the type of the data is SGObject, recursively calls equals on the object.

Parameters
stypestring type of both data
ptypeprimitive type of both data
size_ptypesize of primitive type in bytes
data1pointer 1
data2pointer 2
accuracyaccuracy to compare
Returns
whether the data was equal

Definition at line 3669 of file Parameter.cpp.

bool copy ( TParameter target)

Definition at line 3943 of file Parameter.cpp.

void copy_data ( const TParameter source)

Given another TParameter instance (with same type, except for lengths) all its data is copied to the current one. This means in case of numeric scalars that the value is copied and in SG_OBJECT scalars and any arrays that the pointer to the data is copied. The old data is overwritten. Old SG_OBJECTS are SG_UNREF'ed and the new ones are SG_REF'ed.

Parameters
sourcesource TParameter instance to copy from

Definition at line 3072 of file Parameter.cpp.

bool copy_ptype ( EPrimitiveType  ptype,
void *  source,
void *  target 
)
static

Definition at line 3525 of file Parameter.cpp.

bool copy_stype ( EStructType  stype,
EPrimitiveType  ptype,
void *  source,
void *  target 
)
static

Definition at line 3797 of file Parameter.cpp.

bool equals ( TParameter other,
float64_t  accuracy = 0.0 
)

Numerically this instance with another instance. Compares recursively in case of non-numerical parameters

Parameters
otherother instance to compare with
accuracyaccuracy for numerical comparison
Returns
true if given parameter instance is equal, false otherwise

Definition at line 3132 of file Parameter.cpp.

void get_incremental_hash ( uint32_t &  hash,
uint32_t &  carry,
uint32_t &  total_length 
)

Incrementally get a hash from parameter value

Parameters
hashcurrent hash value
carryvalue for incremental murmur hashing
total_lengthbyte length of parameters. Function will add byte length to received value

Definition at line 2450 of file Parameter.cpp.

bool is_valid ( )

test if parameter can be validly accessed, e.g., in case of a list/vector/matrix of objects the list/vector/matrix has non-zero length

Definition at line 2534 of file Parameter.cpp.

bool load ( CSerializableFile file,
const char *  prefix = "" 
)

load from serializable file

Parameters
filesource file
prefixprefix

Definition at line 2639 of file Parameter.cpp.

bool operator< ( const TParameter other) const

operator for comparison (by string m_name)

Definition at line 2973 of file Parameter.cpp.

bool operator== ( const TParameter other) const

operator for comparison, (by string m_name)

Definition at line 2966 of file Parameter.cpp.

bool operator> ( const TParameter other) const

operator for comparison (by string m_name)

Definition at line 2978 of file Parameter.cpp.

void print ( const char *  prefix)

print with prefix

Parameters
prefixprefix to print

Definition at line 1835 of file Parameter.cpp.

bool save ( CSerializableFile file,
const char *  prefix = "" 
)

save to serializable file

Parameters
filedestination file
prefixprefix

Definition at line 2540 of file Parameter.cpp.

Member Data Documentation

TSGDataType m_datatype

type of parameter

Definition at line 138 of file Parameter.h.

bool m_delete_data

if this is set true, the data, m_parameter points to, m_parameter itself, and possible lengths of the type will be deleted in destructor. This is needed because in data migration, TParameter instances are created from scratch without having a class instance and allocated data has to ne deleted in this case. The only way to set this is via an alternate constructor, false by default

Definition at line 153 of file Parameter.h.

char* m_description

description of parameter

Definition at line 144 of file Parameter.h.

char* m_name

name of parameter

Definition at line 142 of file Parameter.h.

void* m_parameter

pointer to parameter

Definition at line 140 of file Parameter.h.

bool m_was_allocated_from_scratch
Returns
true if data was not allocated by a class which registered its parameter, but from scratch using allocate_data_from_scratch

Definition at line 157 of file Parameter.h.


The documentation for this struct was generated from the following files:

SHOGUN Machine Learning Toolbox - Documentation