41 template<>
void CSGObject::set_generic<bool>()
46 template<>
void CSGObject::set_generic<char>()
51 template<>
void CSGObject::set_generic<int8_t>()
56 template<>
void CSGObject::set_generic<uint8_t>()
61 template<>
void CSGObject::set_generic<int16_t>()
66 template<>
void CSGObject::set_generic<uint16_t>()
68 m_generic = PT_UINT16;
71 template<>
void CSGObject::set_generic<int32_t>()
76 template<>
void CSGObject::set_generic<uint32_t>()
78 m_generic = PT_UINT32;
81 template<>
void CSGObject::set_generic<int64_t>()
86 template<>
void CSGObject::set_generic<uint64_t>()
88 m_generic = PT_UINT64;
91 template<>
void CSGObject::set_generic<float32_t>()
93 m_generic = PT_FLOAT32;
96 template<>
void CSGObject::set_generic<float64_t>()
98 m_generic = PT_FLOAT64;
101 template<>
void CSGObject::set_generic<floatmax_t>()
103 m_generic = PT_FLOATMAX;
106 template<>
void CSGObject::set_generic<CSGObject*>()
108 m_generic = PT_SGOBJECT;
111 template<>
void CSGObject::set_generic<complex128_t>()
113 m_generic = PT_COMPLEX128;
124 set_global_objects();
131 set_global_objects();
136 unset_global_objects();
143 void CSGObject::set_global_objects()
147 fprintf(stderr,
"call init_shogun() before using the library, dying.\n");
160 void CSGObject::unset_global_objects()
189 uint32_t new_hash = 0;
230 *
generic = m_generic;
242 SG_PRINT(
"\n%s\n================================================================================\n",
get_name())
247 const char* prefix, int32_t param_version)
256 SG_SWARNING(
"%s%s::save_serializable_pre(): ShogunException: " 262 if (!m_save_pre_called)
264 SG_SWARNING(
"%s%s::save_serializable_pre(): Implementation " 265 "error: BASE_CLASS::LOAD_SERIALIZABLE_PRE() not " 271 if (!save_parameter_version(file, prefix, param_version))
283 SG_SWARNING(
"%s%s::save_serializable_post(): ShogunException: " 289 if (!m_save_post_called)
291 SG_SWARNING(
"%s%s::save_serializable_post(): Implementation " 292 "error: BASE_CLASS::LOAD_SERIALIZABLE_POST() not " 297 if (prefix == NULL || *prefix ==
'\0')
306 const char* prefix, int32_t param_version)
315 SG_SWARNING(
"%s%s::load_serializable_pre(): ShogunException: " 320 if (!m_load_pre_called)
322 SG_SWARNING(
"%s%s::load_serializable_pre(): Implementation " 323 "error: BASE_CLASS::LOAD_SERIALIZABLE_PRE() not " 329 int32_t file_version=load_parameter_version(file, prefix);
330 SG_DEBUG(
"file_version=%d, current_version=%d\n", file_version, param_version)
334 SG_WARNING(
"%s%s::load_serializable(): File contains no parameter " 335 "version. Seems like your file is from the days before this " 336 "was introduced. Ignore warning or serialize with this version " 337 "of shogun to get rid of above and this warnings.\n",
341 if (file_version>param_version)
345 SG_WARNING(
"%s%s::load_serializable(): parameter version of file " 346 "larger than the one of shogun. Try with a more recent" 347 "version of shogun.\n", prefix,
get_name());
351 SG_WARNING(
"%s%s::load_serializable(): parameter version of file " 352 "larger than the current. This is probably an implementation" 358 if (file_version==param_version)
369 if (is_param_new(
SGParamInfo(current, param_version)))
372 if (!current->
load(file, prefix))
380 param_version, file, prefix);
390 if (is_param_new(
SGParamInfo(current, param_version)))
411 SG_DEBUG(
"replacing parameter data by loaded/mapped values\n")
415 char* s=SG_MALLOC(
char, 200);
421 if (is_param_new(
SGParamInfo(current, param_version)))
435 SG_DEBUG(
"copying migrated data into parameter\n")
440 SG_DEBUG(
"deleting old parameter base\n")
456 SG_SWARNING(
"%s%s::load_serializable_post(): ShogunException: " 462 if (!m_load_post_called)
464 SG_SWARNING(
"%s%s::load_serializable_post(): Implementation " 465 "error: BASE_CLASS::LOAD_SERIALIZABLE_POST() not " 475 const SGParamInfo* param_info, int32_t file_version,
482 SG_SERROR(
"parameter version of \"%s\" in file (%d) is more recent than" 483 " provided %d!\n", param_info->
m_name, file_version,
491 SG_SDEBUG(
"try to get mapping for: %s\n", s)
495 bool free_mapped=
false;
506 if (file_version<param_info->m_param_version)
544 SG_SDEBUG(
"recursion stop, loading from file\n")
572 if (!loaded->
load(file, prefix))
575 SG_ERROR(
"Could not load %s. The reason for this might be wrong " 576 "parameter mappings\n", s);
580 SG_DEBUG(
"loaded lengths: y=%d, x=%d\n",
598 SG_SDEBUG(
"starting recursion over %s\n", s)
608 SG_SDEBUG(
"appending all results to current result\n")
613 delete recursion_array;
646 if (is_param_new(*info))
679 SG_DEBUG(
"no target parameter infos\n")
693 SG_DEBUG(
"trying to get parameter mapping for %s\n", s)
714 SG_DEBUG(
"no mapping found, using %s\n", s)
733 if (mapped_version>base_version)
745 ASSERT(base_version==mapped_version)
752 SG_DEBUG(
"migrating one step to target: %s\n", s)
759 SG_DEBUG(
"deleting parameters base version %d\n", base_version)
763 SG_DEBUG(
"replacing old parameter base\n")
764 *param_base=*new_base;
765 base_version=mapped_version+1;
777 SG_DEBUG(
"(%d:) \"%s\": sgobject \"%s\" at %p\n", i,
790 SG_DEBUG(
"(%d:) \"%s\": sgobject \"%s\" at %p\n", i,
798 char* s=SG_MALLOC(
char, 200);
822 SG_DEBUG(
"CSGObject::entering CSGObject::one_to_one_migration_prepare() for " 823 "\"%s\"\n", target->
m_name);
830 char* name=target->
m_name;
867 SG_DEBUG(
"copied and SG_REF sgobject pointer for \"%s\" at %p\n",
874 SG_DEBUG(
"CSGObject::leaving CSGObject::one_to_one_migration_prepare() for " 875 "\"%s\"\n", target->
m_name);
906 SG_ERROR(
"Name change for parameter that has to be mapped to \"%s\"," 907 " and to no migration method available\n", target->
m_name);
915 char* s=SG_MALLOC(
char, 200);
917 SG_DEBUG(
"nothing changed, using old data: %s\n", s)
947 SG_DEBUG(
"copying content of poitner for non-scalar data\n")
954 SG_ERROR(
"No migration method available for %s!\n", s)
964 const char* prefix, int32_t param_version)
967 TParameter p(&t, ¶m_version,
"version_parameter",
968 "Version of parameters of this object");
969 return p.
save(file, prefix);
977 TParameter tp(&t, &v,
"version_parameter",
"");
978 if (tp.
load(file, prefix))
986 m_load_pre_called =
true;
991 m_load_post_called =
true;
996 m_save_pre_called =
true;
1001 m_save_post_called =
true;
1004 #ifdef TRACE_MEMORY_ALLOCS 1009 void CSGObject::init()
1011 #ifdef TRACE_MEMORY_ALLOCS 1014 int32_t idx=sg_mallocs->
index_of(
this);
1031 m_load_pre_called =
false;
1032 m_load_post_called =
false;
1045 for (
index_t i=0; i<num_param; i++)
1049 char* type=SG_MALLOC(
char, l);
1068 for (
index_t i=0; i<num_param; i++)
1075 if (len>max_string_length)
1076 max_string_length=len;
1090 SG_ERROR(
"There is no model selection parameter called \"%s\" for %s",
1108 if (!strcmp(param_name, current->
m_name))
1118 bool CSGObject::is_param_new(
const SGParamInfo param_info)
const 1127 void CSGObject::get_parameter_incremental_hash(
Parameter* param,
1128 uint32_t& hash, uint32_t& carry, uint32_t& total_length)
1150 get_parameter_incremental_hash(
1152 carry, total_length);
1198 SG_INFO(
"leaving %s::equals(): name of other object differs\n",
get_name());
1206 SG_INFO(
"leaving %s::equals(): number of parameters of other object " 1213 SG_DEBUG(
"comparing parameter %d\n", i);
1220 if (!this_param && !other_param)
1223 if (!this_param && other_param)
1225 SG_DEBUG(
"leaving %s::equals(): parameter %d is NULL where other's " 1230 if (this_param && !other_param)
1232 SG_DEBUG(
"leaving %s::equals(): parameter %d is \"%s\" where other's " 1237 SG_DEBUG(
"comparing parameter \"%s\" to other's \"%s\"\n",
1241 if (!strcmp(
"DynamicObjectArray",
get_name()) &&
1242 !strcmp(this_param->
m_name,
"num_elements") &&
1243 !strcmp(other_param->
m_name,
"num_elements"))
1245 SG_DEBUG(
"Ignoring DynamicObjectArray::num_elements field\n");
1250 if (!strcmp(
"DynamicArray",
get_name()) &&
1251 !strcmp(this_param->
m_name,
"num_elements") &&
1252 !strcmp(other_param->
m_name,
"num_elements"))
1254 SG_DEBUG(
"Ignoring DynamicArray::num_elements field\n");
1259 if (!this_param->
equals(other_param, accuracy))
1261 SG_INFO(
"leaving %s::equals(): parameters at position %d with name" 1262 " \"%s\" differs from other object parameter with name " 1282 REQUIRE(copy,
"Could not create empty instance of \"%s\". The reason for " 1283 "this usually is that get_name() of the class returns something " 1284 "wrong, or that a class has a wrongly set generic type.\n",
1289 SG_DEBUG(
"cloning parameter \"%s\" at index %d\n",
1294 SG_DEBUG(
"leaving %s::clone(): Clone failed. Returning NULL\n",
virtual const char * get_name() const =0
SGStringList< char > get_modelsel_names()
T get_element(int32_t index) const
Parallel * get_global_parallel()
virtual bool save_serializable(CSerializableFile *file, const char *prefix="", int32_t param_version=Version::get_version_parameter())
Class that holds informations about a certain parameter of an CSGObject. Contains name...
Class SGRefObject is a reference count based memory management class.
ParameterMap * m_parameter_map
virtual TParameter * migrate(DynArray< TParameter * > *param_base, const SGParamInfo *target)
bool append_element(T element)
virtual int32_t get_num_parameters()
virtual CSGObject * clone()
Class ShogunException defines an exception which is thrown whenever an error inside of shogun occurs...
static int32_t binary_search(T *output, int32_t size, T elem)
TParameter * get_parameter(int32_t idx)
DynArray< const SGParamInfo * > * get(const SGParamInfo) const
Version * get_global_version()
virtual void save_serializable_pre()
virtual bool is_generic(EPrimitiveType *generic) const
virtual void print(const char *prefix="")
static uint32_t FinalizeIncrementalMurmurHash3(uint32_t h, uint32_t carry, uint32_t total_length)
int32_t get_num_elements() const
static int32_t get_version_parameter()
SGParamInfo * duplicate() const
Implements a map of ParameterMapElement instances Maps one key to a set of values.
Datatypes that shogun supports.
virtual bool update_parameter_hash()
static void qsort(T *output, int32_t size)
char * get_modsel_param_descr(const char *param_name)
bool save(CSerializableFile *file, const char *prefix="")
DynArray< TParameter * > * load_file_parameters(const SGParamInfo *param_info, int32_t file_version, CSerializableFile *file, const char *prefix="")
Class SGObject is the base class of all shogun objects.
void build_gradient_parameter_dictionary(CMap< TParameter *, CSGObject * > *dict)
virtual bool equals(CSGObject *other, float64_t accuracy=0.0)
Template Dynamic array class that creates an array that can be used like a list or an array...
virtual bool load_serializable(CSerializableFile *file, const char *prefix="", int32_t param_version=Version::get_version_parameter())
DynArray< TParameter * > * load_all_file_parameters(int32_t file_version, int32_t current_version, CSerializableFile *file, const char *prefix="")
virtual bool save(CSerializableFile *file, const char *prefix="")
index_t max_string_length
the class CMap, a map based on the hash-table. w: http://en.wikipedia.org/wiki/Hash_table ...
T * get_element_ptr(int32_t index)
virtual void save_serializable_post()
void print_modsel_params()
CSGObject * new_sgserializable(const char *sgserializable_name, EPrimitiveType generic)
Class Version provides version information.
Parameter * m_model_selection_parameters
void get_incremental_hash(uint32_t &hash, uint32_t &carry, uint32_t &total_length)
void set_global_parallel(Parallel *parallel)
void to_string(char *dest, size_t n) const
virtual void load_serializable_pre()
virtual void load_serializable_post()
Class Parallel provides helper functions for multithreading.
int32_t index_of(const K &key)
virtual void one_to_one_migration_prepare(DynArray< TParameter * > *param_base, const SGParamInfo *target, TParameter *&replacement, TParameter *&to_migrate, char *old_name=NULL)
const char * get_exception_string()
all of classes and functions are contained in the shogun namespace
bool load(CSerializableFile *file, const char *prefix="")
int32_t add(const K &key, const T &data)
bool equals(TParameter *other, float64_t accuracy=0.0)
void map_parameters(DynArray< TParameter * > *param_base, int32_t &base_version, DynArray< const SGParamInfo * > *target_param_infos)
index_t get_modsel_param_index(const char *param_name)
void set_global_io(SGIO *io)
bool copy(TParameter *target)
void copy_data(const TParameter *source)
Class which collects generic mathematical functions.
Class SGIO, used to do input output operations throughout shogun.
Parameter * m_gradient_parameters
virtual void print_serializable(const char *prefix="")
void set_global_version(Version *version)
void allocate_data_from_scratch(SGVector< index_t > dims, bool new_cont_call=true)
template class SGStringList