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;
118 using namespace shogun;
124 set_global_objects();
128 :
SGRefObject(orig), io(orig.io), parallel(orig.parallel), version(orig.version)
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()
194 get_parameter_incremental_hash(
m_hash, carry, length);
208 get_parameter_incremental_hash(hash, carry, length);
236 *
generic = m_generic;
248 SG_PRINT(
"\n%s\n================================================================================\n",
get_name())
253 const char* prefix, int32_t param_version)
262 SG_SWARNING(
"%s%s::save_serializable_pre(): ShogunException: "
268 if (!m_save_pre_called)
270 SG_SWARNING(
"%s%s::save_serializable_pre(): Implementation "
271 "error: BASE_CLASS::LOAD_SERIALIZABLE_PRE() not "
277 if (!save_parameter_version(file, prefix, param_version))
289 SG_SWARNING(
"%s%s::save_serializable_post(): ShogunException: "
295 if (!m_save_post_called)
297 SG_SWARNING(
"%s%s::save_serializable_post(): Implementation "
298 "error: BASE_CLASS::LOAD_SERIALIZABLE_POST() not "
303 if (prefix == NULL || *prefix ==
'\0')
312 const char* prefix, int32_t param_version)
321 SG_SWARNING(
"%s%s::load_serializable_pre(): ShogunException: "
326 if (!m_load_pre_called)
328 SG_SWARNING(
"%s%s::load_serializable_pre(): Implementation "
329 "error: BASE_CLASS::LOAD_SERIALIZABLE_PRE() not "
335 int32_t file_version=load_parameter_version(file, prefix);
336 SG_DEBUG(
"file_version=%d, current_version=%d\n", file_version, param_version)
340 SG_WARNING(
"%s%s::load_serializable(): File contains no parameter "
341 "version. Seems like your file is from the days before this "
342 "was introduced. Ignore warning or serialize with this version "
343 "of shogun to get rid of above and this warnings.\n",
347 if (file_version>param_version)
351 SG_WARNING(
"%s%s::load_serializable(): parameter version of file "
352 "larger than the one of shogun. Try with a more recent"
353 "version of shogun.\n", prefix,
get_name());
357 SG_WARNING(
"%s%s::load_serializable(): parameter version of file "
358 "larger than the current. This is probably an implementation"
364 if (file_version==param_version)
375 if (is_param_new(
SGParamInfo(current, param_version)))
378 if (!current->
load(file, prefix))
386 param_version, file, prefix);
396 if (is_param_new(
SGParamInfo(current, param_version)))
417 SG_DEBUG(
"replacing parameter data by loaded/mapped values\n")
421 char* s=SG_MALLOC(
char, 200);
427 if (is_param_new(
SGParamInfo(current, param_version)))
441 SG_DEBUG(
"copying migrated data into parameter\n")
446 SG_DEBUG(
"deleting old parameter base\n")
462 SG_SWARNING(
"%s%s::load_serializable_post(): ShogunException: "
468 if (!m_load_post_called)
470 SG_SWARNING(
"%s%s::load_serializable_post(): Implementation "
471 "error: BASE_CLASS::LOAD_SERIALIZABLE_POST() not "
481 const SGParamInfo* param_info, int32_t file_version,
488 SG_SERROR(
"parameter version of \"%s\" in file (%d) is more recent than"
489 " provided %d!\n", param_info->
m_name, file_version,
497 SG_SDEBUG(
"try to get mapping for: %s\n", s)
501 bool free_mapped=
false;
512 if (file_version<param_info->m_param_version)
550 SG_SDEBUG(
"recursion stop, loading from file\n")
578 if (!loaded->
load(file, prefix))
581 SG_ERROR(
"Could not load %s. The reason for this might be wrong "
582 "parameter mappings\n", s);
586 SG_DEBUG(
"loaded lengths: y=%d, x=%d\n",
604 SG_SDEBUG(
"starting recursion over %s\n", s)
614 SG_SDEBUG(
"appending all results to current result\n")
619 delete recursion_array;
652 if (is_param_new(*info))
685 SG_DEBUG(
"no target parameter infos\n")
699 SG_DEBUG(
"trying to get parameter mapping for %s\n", s)
720 SG_DEBUG(
"no mapping found, using %s\n", s)
739 if (mapped_version>base_version)
751 ASSERT(base_version==mapped_version)
758 SG_DEBUG(
"migrating one step to target: %s\n", s)
765 SG_DEBUG(
"deleting parameters base version %d\n", base_version)
769 SG_DEBUG(
"replacing old parameter base\n")
770 *param_base=*new_base;
771 base_version=mapped_version+1;
783 SG_DEBUG(
"(%d:) \"%s\": sgobject \"%s\" at %p\n", i,
796 SG_DEBUG(
"(%d:) \"%s\": sgobject \"%s\" at %p\n", i,
804 char* s=SG_MALLOC(
char, 200);
828 SG_DEBUG(
"CSGObject::entering CSGObject::one_to_one_migration_prepare() for "
829 "\"%s\"\n", target->
m_name);
836 char* name=target->
m_name;
873 SG_DEBUG(
"copied and SG_REF sgobject pointer for \"%s\" at %p\n",
880 SG_DEBUG(
"CSGObject::leaving CSGObject::one_to_one_migration_prepare() for "
881 "\"%s\"\n", target->
m_name);
912 SG_ERROR(
"Name change for parameter that has to be mapped to \"%s\","
913 " and to no migration method available\n", target->
m_name);
921 char* s=SG_MALLOC(
char, 200);
923 SG_DEBUG(
"nothing changed, using old data: %s\n", s)
953 SG_DEBUG(
"copying content of poitner for non-scalar data\n")
960 SG_ERROR(
"No migration method available for %s!\n", s)
970 const char* prefix, int32_t param_version)
973 TParameter p(&t, ¶m_version,
"version_parameter",
974 "Version of parameters of this object");
975 return p.save(file, prefix);
983 TParameter tp(&t, &v,
"version_parameter",
"");
984 if (tp.load(file, prefix))
992 m_load_pre_called =
true;
997 m_load_post_called =
true;
1002 m_save_pre_called =
true;
1007 m_save_post_called =
true;
1010 #ifdef TRACE_MEMORY_ALLOCS
1015 void CSGObject::init()
1017 #ifdef TRACE_MEMORY_ALLOCS
1020 int32_t idx=sg_mallocs->
index_of(
this);
1023 MemoryBlock* b=sg_mallocs->get_element_ptr(idx);
1037 m_load_pre_called =
false;
1038 m_load_post_called =
false;
1051 for (
index_t i=0; i<num_param; i++)
1055 char* type=SG_MALLOC(
char, l);
1074 for (
index_t i=0; i<num_param; i++)
1081 if (len>max_string_length)
1082 max_string_length=len;
1096 SG_ERROR(
"There is no model selection parameter called \"%s\" for %s",
1114 if (!strcmp(param_name, current->
m_name))
1124 bool CSGObject::is_param_new(
const SGParamInfo param_info)
const
1133 void CSGObject::get_parameter_incremental_hash(uint32_t& hash, uint32_t& carry,
1134 uint32_t& total_length)
1150 child->get_parameter_incremental_hash(hash, carry,
1163 child[j]->get_parameter_incremental_hash(hash, carry,
1216 SG_INFO(
"leaving %s::equals(): name of other object differs\n",
get_name());
1224 SG_INFO(
"leaving %s::equals(): number of parameters of other object "
1231 SG_DEBUG(
"comparing parameter %d\n", i);
1238 if (!this_param && !other_param)
1241 if (!this_param && other_param)
1243 SG_DEBUG(
"leaving %s::equals(): parameter %d is NULL where other's "
1248 if (this_param && !other_param)
1250 SG_DEBUG(
"leaving %s::equals(): parameter %d is \"%s\" where other's "
1255 SG_DEBUG(
"comparing parameter \"%s\" to other's \"%s\"\n",
1259 if (!strcmp(
"DynamicObjectArray",
get_name()) &&
1260 !strcmp(this_param->
m_name,
"num_elements") &&
1261 !strcmp(other_param->
m_name,
"num_elements"))
1263 SG_DEBUG(
"Ignoring DynamicObjectArray::num_elements field\n");
1268 if (!strcmp(
"DynamicArray",
get_name()) &&
1269 !strcmp(this_param->
m_name,
"num_elements") &&
1270 !strcmp(other_param->
m_name,
"num_elements"))
1272 SG_DEBUG(
"Ignoring DynamicArray::num_elements field\n");
1277 if (!this_param->
equals(other_param, accuracy, tolerant))
1279 SG_INFO(
"leaving %s::equals(): parameters at position %d with name"
1280 " \"%s\" differs from other object parameter with name "
1300 REQUIRE(copy,
"Could not create empty instance of \"%s\". The reason for "
1301 "this usually is that get_name() of the class returns something "
1302 "wrong, or that a class has a wrongly set generic type.\n",
1307 SG_DEBUG(
"cloning parameter \"%s\" at index %d\n",
1312 SG_DEBUG(
"leaving %s::clone(): Clone failed. Returning NULL\n",