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;
123 set_global_objects();
130 :io(orig.io), parallel(orig.parallel), version(orig.version)
133 set_global_objects();
134 m_refcount = orig.m_refcount;
142 unset_global_objects();
150 #ifdef USE_REFERENCE_COUNTING
151 int32_t CSGObject::ref()
153 int32_t count = m_refcount->
ref();
154 SG_GCDEBUG(
"ref() refcount %ld obj %s (%p) increased\n", count, this->
get_name(),
this)
155 return m_refcount->ref_count();
162 return m_refcount->ref_count();
167 int32_t count = m_refcount->
unref();
170 SG_GCDEBUG(
"unref() refcount %ld, obj %s (%p) destroying\n", count, this->
get_name(),
this)
176 SG_GCDEBUG(
"unref() refcount %ld obj %s (%p) decreased\n", count, this->
get_name(),
this)
177 return m_refcount->ref_count();
180 #endif //USE_REFERENCE_COUNTING
183 void CSGObject::set_global_objects()
187 fprintf(stderr,
"call init_shogun() before using the library, dying.\n");
200 void CSGObject::unset_global_objects()
229 uint32_t new_hash = 0;
270 *
generic = m_generic;
282 SG_PRINT(
"\n%s\n================================================================================\n",
get_name())
287 const char* prefix, int32_t param_version)
296 SG_SWARNING(
"%s%s::save_serializable_pre(): ShogunException: "
302 if (!m_save_pre_called)
304 SG_SWARNING(
"%s%s::save_serializable_pre(): Implementation "
305 "error: BASE_CLASS::LOAD_SERIALIZABLE_PRE() not "
311 if (!save_parameter_version(file, prefix, param_version))
323 SG_SWARNING(
"%s%s::save_serializable_post(): ShogunException: "
329 if (!m_save_post_called)
331 SG_SWARNING(
"%s%s::save_serializable_post(): Implementation "
332 "error: BASE_CLASS::LOAD_SERIALIZABLE_POST() not "
337 if (prefix == NULL || *prefix ==
'\0')
346 const char* prefix, int32_t param_version)
355 SG_SWARNING(
"%s%s::load_serializable_pre(): ShogunException: "
360 if (!m_load_pre_called)
362 SG_SWARNING(
"%s%s::load_serializable_pre(): Implementation "
363 "error: BASE_CLASS::LOAD_SERIALIZABLE_PRE() not "
369 int32_t file_version=load_parameter_version(file, prefix);
370 SG_DEBUG(
"file_version=%d, current_version=%d\n", file_version, param_version)
374 SG_WARNING(
"%s%s::load_serializable(): File contains no parameter "
375 "version. Seems like your file is from the days before this "
376 "was introduced. Ignore warning or serialize with this version "
377 "of shogun to get rid of above and this warnings.\n",
381 if (file_version>param_version)
385 SG_WARNING(
"%s%s::load_serializable(): parameter version of file "
386 "larger than the one of shogun. Try with a more recent"
387 "version of shogun.\n", prefix,
get_name());
391 SG_WARNING(
"%s%s::load_serializable(): parameter version of file "
392 "larger than the current. This is probably an implementation"
398 if (file_version==param_version)
409 if (is_param_new(
SGParamInfo(current, param_version)))
412 if (!current->
load(file, prefix))
420 param_version, file, prefix);
430 if (is_param_new(
SGParamInfo(current, param_version)))
451 SG_DEBUG(
"replacing parameter data by loaded/mapped values\n")
455 char* s=SG_MALLOC(
char, 200);
461 if (is_param_new(
SGParamInfo(current, param_version)))
475 SG_DEBUG(
"copying migrated data into parameter\n")
480 SG_DEBUG(
"deleting old parameter base\n")
496 SG_SWARNING(
"%s%s::load_serializable_post(): ShogunException: "
502 if (!m_load_post_called)
504 SG_SWARNING(
"%s%s::load_serializable_post(): Implementation "
505 "error: BASE_CLASS::LOAD_SERIALIZABLE_POST() not "
515 const SGParamInfo* param_info, int32_t file_version,
522 SG_SERROR(
"parameter version of \"%s\" in file (%d) is more recent than"
523 " provided %d!\n", param_info->
m_name, file_version,
531 SG_SDEBUG(
"try to get mapping for: %s\n", s)
535 bool free_mapped=
false;
546 if (file_version<param_info->m_param_version)
584 SG_SDEBUG(
"recursion stop, loading from file\n")
612 if (!loaded->
load(file, prefix))
615 SG_ERROR(
"Could not load %s. The reason for this might be wrong "
616 "parameter mappings\n", s);
620 SG_DEBUG(
"loaded lengths: y=%d, x=%d\n",
638 SG_SDEBUG(
"starting recursion over %s\n", s)
648 SG_SDEBUG(
"appending all results to current result\n")
653 delete recursion_array;
686 if (is_param_new(*info))
719 SG_DEBUG(
"no target parameter infos\n")
733 SG_DEBUG(
"trying to get parameter mapping for %s\n", s)
754 SG_DEBUG(
"no mapping found, using %s\n", s)
773 if (mapped_version>base_version)
785 ASSERT(base_version==mapped_version)
792 SG_DEBUG(
"migrating one step to target: %s\n", s)
799 SG_DEBUG(
"deleting parameters base version %d\n", base_version)
803 SG_DEBUG(
"replacing old parameter base\n")
804 *param_base=*new_base;
805 base_version=mapped_version+1;
817 SG_DEBUG(
"(%d:) \"%s\": sgobject \"%s\" at %p\n", i,
830 SG_DEBUG(
"(%d:) \"%s\": sgobject \"%s\" at %p\n", i,
838 char* s=SG_MALLOC(
char, 200);
862 SG_DEBUG(
"CSGObject::entering CSGObject::one_to_one_migration_prepare() for "
863 "\"%s\"\n", target->
m_name);
870 char* name=target->
m_name;
907 SG_DEBUG(
"copied and SG_REF sgobject pointer for \"%s\" at %p\n",
914 SG_DEBUG(
"CSGObject::leaving CSGObject::one_to_one_migration_prepare() for "
915 "\"%s\"\n", target->
m_name);
946 SG_ERROR(
"Name change for parameter that has to be mapped to \"%s\","
947 " and to no migration method available\n", target->
m_name);
955 char* s=SG_MALLOC(
char, 200);
957 SG_DEBUG(
"nothing changed, using old data: %s\n", s)
987 SG_DEBUG(
"copying content of poitner for non-scalar data\n")
994 SG_ERROR(
"No migration method available for %s!\n", s)
1004 const char* prefix, int32_t param_version)
1007 TParameter p(&t, ¶m_version,
"version_parameter",
1008 "Version of parameters of this object");
1009 return p.save(file, prefix);
1017 TParameter tp(&t, &v,
"version_parameter",
"");
1018 if (tp.load(file, prefix))
1026 m_load_pre_called =
true;
1031 m_load_post_called =
true;
1036 m_save_pre_called =
true;
1041 m_save_post_called =
true;
1044 #ifdef TRACE_MEMORY_ALLOCS
1049 void CSGObject::init()
1051 #ifdef TRACE_MEMORY_ALLOCS
1054 int32_t idx=sg_mallocs->
index_of(
this);
1071 m_load_pre_called =
false;
1072 m_load_post_called =
false;
1085 for (
index_t i=0; i<num_param; i++)
1089 char* type=SG_MALLOC(
char, l);
1108 for (
index_t i=0; i<num_param; i++)
1115 if (len>max_string_length)
1116 max_string_length=len;
1130 SG_ERROR(
"There is no model selection parameter called \"%s\" for %s",
1148 if (!strcmp(param_name, current->
m_name))
1158 bool CSGObject::is_param_new(
const SGParamInfo param_info)
const
1167 void CSGObject::get_parameter_incremental_hash(
Parameter* param,
1168 uint32_t& hash, uint32_t& carry, uint32_t& total_length)
1190 get_parameter_incremental_hash(
1192 carry, total_length);
1238 SG_DEBUG(
"leaving %s::equals(): name of other object differs\n",
get_name());
1246 SG_DEBUG(
"leaving %s::equals(): number of parameters of other object "
1253 SG_DEBUG(
"comparing parameter %d\n", i);
1260 if (!this_param && !other_param)
1263 if (!this_param && other_param)
1265 SG_DEBUG(
"leaving %s::equals(): parameter %d is NULL where other's "
1270 if (this_param && !other_param)
1272 SG_DEBUG(
"leaving %s::equals(): parameter %d is \"%s\" where other's "
1277 SG_DEBUG(
"comparing parameter \"%s\" to other's \"%s\"\n",
1281 if (!strcmp(
"DynamicObjectArray",
get_name()) &&
1282 !strcmp(this_param->
m_name,
"num_elements") &&
1283 !strcmp(other_param->
m_name,
"num_elements"))
1285 SG_DEBUG(
"Ignoring DynamicObjectArray::num_elements field\n");
1290 if (!strcmp(
"DynamicArray",
get_name()) &&
1291 !strcmp(this_param->
m_name,
"num_elements") &&
1292 !strcmp(other_param->
m_name,
"num_elements"))
1294 SG_DEBUG(
"Ignoring DynamicArray::num_elements field\n");
1299 if (!this_param->
equals(other_param, accuracy))
1301 SG_DEBUG(
"leaving %s::equals(): parameters at position %d with name"
1302 " \"%s\" differs from other object parameter with name "
1322 REQUIRE(copy,
"Could not create empty instance of \"%s\". The reason for "
1323 "this usually is that get_name() of the class returns something "
1324 "wrong, or that a class has a wrongly set generic type.\n",
1329 SG_DEBUG(
"cloning parameter \"%s\" at index %d\n",
1334 SG_DEBUG(
"leaving %s::clone(): Clone failed. Returning NULL\n",