42 template<>
void CSGObject::set_generic<bool>()
47 template<>
void CSGObject::set_generic<char>()
52 template<>
void CSGObject::set_generic<int8_t>()
57 template<>
void CSGObject::set_generic<uint8_t>()
62 template<>
void CSGObject::set_generic<int16_t>()
67 template<>
void CSGObject::set_generic<uint16_t>()
69 m_generic = PT_UINT16;
72 template<>
void CSGObject::set_generic<int32_t>()
77 template<>
void CSGObject::set_generic<uint32_t>()
79 m_generic = PT_UINT32;
82 template<>
void CSGObject::set_generic<int64_t>()
87 template<>
void CSGObject::set_generic<uint64_t>()
89 m_generic = PT_UINT64;
92 template<>
void CSGObject::set_generic<float32_t>()
94 m_generic = PT_FLOAT32;
97 template<>
void CSGObject::set_generic<float64_t>()
99 m_generic = PT_FLOAT64;
102 template<>
void CSGObject::set_generic<floatmax_t>()
104 m_generic = PT_FLOATMAX;
107 template<>
void CSGObject::set_generic<CSGObject*>()
109 m_generic = PT_SGOBJECT;
112 template<>
void CSGObject::set_generic<complex128_t>()
114 m_generic = PT_COMPLEX128;
124 set_global_objects();
131 :io(orig.io), parallel(orig.parallel), version(orig.version)
134 set_global_objects();
144 unset_global_objects();
152 #ifdef USE_REFERENCE_COUNTING
153 int32_t CSGObject::ref()
155 int32_t count = m_refcount->
ref();
157 return m_refcount->ref_count();
164 return m_refcount->ref_count();
169 int32_t count = m_refcount->
unref();
172 SG_SGCDEBUG(
"unref() refcount %ld, obj %s (%p) destroying\n", count, this->
get_name(),
this)
179 return m_refcount->ref_count();
182 #endif //USE_REFERENCE_COUNTING
184 #ifdef TRACE_MEMORY_ALLOCS
188 void CSGObject::list_memory_allocs()
190 shogun::list_memory_allocs();
206 void CSGObject::set_global_objects()
210 fprintf(stderr,
"call init_shogun() before using the library, dying.\n");
223 void CSGObject::unset_global_objects()
257 get_parameter_incremental_hash(
m_hash, carry, length);
271 get_parameter_incremental_hash(hash, carry, length);
299 *
generic = m_generic;
311 SG_PRINT(
"\n%s\n================================================================================\n",
get_name())
316 const char* prefix, int32_t param_version)
325 SG_SWARNING(
"%s%s::save_serializable_pre(): ShogunException: "
331 if (!m_save_pre_called)
333 SG_SWARNING(
"%s%s::save_serializable_pre(): Implementation "
334 "error: BASE_CLASS::SAVE_SERIALIZABLE_PRE() not "
340 if (!save_parameter_version(file, prefix, param_version))
352 SG_SWARNING(
"%s%s::save_serializable_post(): ShogunException: "
358 if (!m_save_post_called)
360 SG_SWARNING(
"%s%s::save_serializable_post(): Implementation "
361 "error: BASE_CLASS::SAVE_SERIALIZABLE_POST() not "
366 if (prefix == NULL || *prefix ==
'\0')
375 const char* prefix, int32_t param_version)
377 REQUIRE(file != NULL,
"Serializable file object should be != NULL\n");
386 SG_SWARNING(
"%s%s::load_serializable_pre(): ShogunException: "
391 if (!m_load_pre_called)
393 SG_SWARNING(
"%s%s::load_serializable_pre(): Implementation "
394 "error: BASE_CLASS::LOAD_SERIALIZABLE_PRE() not "
400 int32_t file_version=load_parameter_version(file, prefix);
401 SG_DEBUG(
"file_version=%d, current_version=%d\n", file_version, param_version)
405 SG_WARNING(
"%s%s::load_serializable(): File contains no parameter "
406 "version. Seems like your file is from the days before this "
407 "was introduced. Ignore warning or serialize with this version "
408 "of shogun to get rid of above and this warnings.\n",
412 if (file_version>param_version)
416 SG_WARNING(
"%s%s::load_serializable(): parameter version of file "
417 "larger than the one of shogun. Try with a more recent"
418 "version of shogun.\n", prefix,
get_name());
422 SG_WARNING(
"%s%s::load_serializable(): parameter version of file "
423 "larger than the current. This is probably an implementation"
429 if (file_version==param_version)
440 if (is_param_new(
SGParamInfo(current, param_version)))
443 if (!current->
load(file, prefix))
451 param_version, file, prefix);
461 if (is_param_new(
SGParamInfo(current, param_version)))
482 SG_DEBUG(
"replacing parameter data by loaded/mapped values\n")
486 char* s=SG_MALLOC(
char, 200);
492 if (is_param_new(
SGParamInfo(current, param_version)))
506 SG_DEBUG(
"copying migrated data into parameter\n")
511 SG_DEBUG(
"deleting old parameter base\n")
527 SG_SWARNING(
"%s%s::load_serializable_post(): ShogunException: "
533 if (!m_load_post_called)
535 SG_SWARNING(
"%s%s::load_serializable_post(): Implementation "
536 "error: BASE_CLASS::LOAD_SERIALIZABLE_POST() not "
546 const SGParamInfo* param_info, int32_t file_version,
553 SG_SERROR(
"parameter version of \"%s\" in file (%d) is more recent than"
554 " provided %d!\n", param_info->
m_name, file_version,
562 SG_SDEBUG(
"try to get mapping for: %s\n", s)
566 bool free_mapped=
false;
577 if (file_version<param_info->m_param_version)
615 SG_SDEBUG(
"recursion stop, loading from file\n")
643 if (!loaded->
load(file, prefix))
646 SG_ERROR(
"Could not load %s. The reason for this might be wrong "
647 "parameter mappings\n", s);
651 SG_DEBUG(
"loaded lengths: y=%d, x=%d\n",
669 SG_SDEBUG(
"starting recursion over %s\n", s)
679 SG_SDEBUG(
"appending all results to current result\n")
684 delete recursion_array;
717 if (is_param_new(*info))
750 SG_DEBUG(
"no target parameter infos\n")
764 SG_DEBUG(
"trying to get parameter mapping for %s\n", s)
785 SG_DEBUG(
"no mapping found, using %s\n", s)
804 if (mapped_version>base_version)
816 ASSERT(base_version==mapped_version)
823 SG_DEBUG(
"migrating one step to target: %s\n", s)
830 SG_DEBUG(
"deleting parameters base version %d\n", base_version)
834 SG_DEBUG(
"replacing old parameter base\n")
835 *param_base=*new_base;
836 base_version=mapped_version+1;
848 SG_DEBUG(
"(%d:) \"%s\": sgobject \"%s\" at %p\n", i,
861 SG_DEBUG(
"(%d:) \"%s\": sgobject \"%s\" at %p\n", i,
869 char* s=SG_MALLOC(
char, 200);
893 SG_DEBUG(
"CSGObject::entering CSGObject::one_to_one_migration_prepare() for "
894 "\"%s\"\n", target->
m_name);
901 char* name=target->
m_name;
938 SG_DEBUG(
"copied and SG_REF sgobject pointer for \"%s\" at %p\n",
945 SG_DEBUG(
"CSGObject::leaving CSGObject::one_to_one_migration_prepare() for "
946 "\"%s\"\n", target->
m_name);
977 SG_ERROR(
"Name change for parameter that has to be mapped to \"%s\","
978 " and to no migration method available\n", target->
m_name);
986 char* s=SG_MALLOC(
char, 200);
988 SG_DEBUG(
"nothing changed, using old data: %s\n", s)
1018 SG_DEBUG(
"copying content of poitner for non-scalar data\n")
1025 SG_ERROR(
"No migration method available for %s!\n", s)
1035 const char* prefix, int32_t param_version)
1038 TParameter p(&t, ¶m_version,
"version_parameter",
1039 "Version of parameters of this object");
1040 return p.save(file, prefix);
1046 REQUIRE(file != NULL,
"Serializable file object should be != NULL");
1050 TParameter tp(&t, &v,
"version_parameter",
"");
1051 if (tp.load(file, prefix))
1059 m_load_pre_called =
true;
1064 m_load_post_called =
true;
1069 m_save_pre_called =
true;
1074 m_save_post_called =
true;
1077 #ifdef TRACE_MEMORY_ALLOCS
1082 void CSGObject::init()
1084 #ifdef TRACE_MEMORY_ALLOCS
1087 int32_t idx=sg_mallocs->
index_of(
this);
1104 m_load_pre_called =
false;
1105 m_load_post_called =
false;
1106 m_save_pre_called =
false;
1107 m_save_post_called =
false;
1120 for (
index_t i=0; i<num_param; i++)
1124 char* type=SG_MALLOC(
char, l);
1143 for (
index_t i=0; i<num_param; i++)
1150 if (len>max_string_length)
1151 max_string_length=len;
1165 SG_ERROR(
"There is no model selection parameter called \"%s\" for %s",
1183 if (!strcmp(param_name, current->
m_name))
1193 bool CSGObject::is_param_new(
const SGParamInfo param_info)
const
1202 void CSGObject::get_parameter_incremental_hash(uint32_t& hash, uint32_t& carry,
1203 uint32_t& total_length)
1219 child->get_parameter_incremental_hash(hash, carry,
1232 child[j]->get_parameter_incremental_hash(hash, carry,
1285 SG_INFO(
"leaving %s::equals(): name of other object differs\n",
get_name());
1293 SG_INFO(
"leaving %s::equals(): number of parameters of other object "
1300 SG_DEBUG(
"comparing parameter %d\n", i);
1307 if (!this_param && !other_param)
1310 if (!this_param && other_param)
1312 SG_DEBUG(
"leaving %s::equals(): parameter %d is NULL where other's "
1317 if (this_param && !other_param)
1319 SG_DEBUG(
"leaving %s::equals(): parameter %d is \"%s\" where other's "
1324 SG_DEBUG(
"comparing parameter \"%s\" to other's \"%s\"\n",
1328 if (!strcmp(
"DynamicObjectArray",
get_name()) &&
1329 !strcmp(this_param->
m_name,
"num_elements") &&
1330 !strcmp(other_param->
m_name,
"num_elements"))
1332 SG_DEBUG(
"Ignoring DynamicObjectArray::num_elements field\n");
1337 if (!strcmp(
"DynamicArray",
get_name()) &&
1338 !strcmp(this_param->
m_name,
"num_elements") &&
1339 !strcmp(other_param->
m_name,
"num_elements"))
1341 SG_DEBUG(
"Ignoring DynamicArray::num_elements field\n");
1346 if (!this_param->
equals(other_param, accuracy, tolerant))
1348 SG_INFO(
"leaving %s::equals(): parameters at position %d with name"
1349 " \"%s\" differs from other object parameter with name "
1369 REQUIRE(copy,
"Could not create empty instance of \"%s\". The reason for "
1370 "this usually is that get_name() of the class returns something "
1371 "wrong, or that a class has a wrongly set generic type.\n",
1376 SG_DEBUG(
"cloning parameter \"%s\" at index %d\n",
1381 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())
virtual void update_parameter_hash()
Class that holds informations about a certain parameter of an CSGObject. Contains name...
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...
virtual CSGObject * shallow_copy() const
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
#define SG_NOTIMPLEMENTED
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.
static void qsort(T *output, int32_t size)
char * get_modsel_param_descr(const char *param_name)
bool equals(TParameter *other, float64_t accuracy=0.0, bool tolerant=false)
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)
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)
virtual bool equals(CSGObject *other, float64_t accuracy=0.0, bool tolerant=false)
virtual CSGObject * deep_copy() const
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)
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 SGIO, used to do input output operations throughout shogun.
Parameter * m_gradient_parameters
virtual void print_serializable(const char *prefix="")
virtual bool parameter_hash_changed()
void set_global_version(Version *version)
void allocate_data_from_scratch(SGVector< index_t > dims, bool new_cont_call=true)
template class SGStringList