40 template<>
void CSGObject::set_generic<bool>()
45 template<>
void CSGObject::set_generic<char>()
50 template<>
void CSGObject::set_generic<int8_t>()
55 template<>
void CSGObject::set_generic<uint8_t>()
60 template<>
void CSGObject::set_generic<int16_t>()
65 template<>
void CSGObject::set_generic<uint16_t>()
67 m_generic = PT_UINT16;
70 template<>
void CSGObject::set_generic<int32_t>()
75 template<>
void CSGObject::set_generic<uint32_t>()
77 m_generic = PT_UINT32;
80 template<>
void CSGObject::set_generic<int64_t>()
85 template<>
void CSGObject::set_generic<uint64_t>()
87 m_generic = PT_UINT64;
90 template<>
void CSGObject::set_generic<float32_t>()
92 m_generic = PT_FLOAT32;
95 template<>
void CSGObject::set_generic<float64_t>()
97 m_generic = PT_FLOAT64;
100 template<>
void CSGObject::set_generic<floatmax_t>()
102 m_generic = PT_FLOATMAX;
107 using namespace shogun;
112 set_global_objects();
118 :io(orig.io), parallel(orig.parallel), version(orig.version)
121 set_global_objects();
129 PTHREAD_LOCK_DESTROY(&m_ref_lock);
131 unset_global_objects();
137 #ifdef USE_REFERENCE_COUNTING
139 int32_t CSGObject::ref()
142 PTHREAD_LOCK(&m_ref_lock);
143 #endif //HAVE_PTHREAD
145 int32_t count=m_refcount;
147 PTHREAD_UNLOCK(&m_ref_lock);
148 #endif //HAVE_PTHREAD
149 SG_GCDEBUG(
"ref() refcount %ld obj %s (%p) increased\n", count, this->
get_name(),
this)
156 PTHREAD_LOCK(&m_ref_lock);
157 #endif //HAVE_PTHREAD
158 int32_t count=m_refcount;
160 PTHREAD_UNLOCK(&m_ref_lock);
161 #endif //HAVE_PTHREAD
169 PTHREAD_LOCK(&m_ref_lock);
170 #endif //HAVE_PTHREAD
171 if (m_refcount==0 || --m_refcount==0)
173 SG_GCDEBUG(
"unref() refcount %ld, obj %s (%p) destroying\n", m_refcount, this->
get_name(),
this)
175 PTHREAD_UNLOCK(&m_ref_lock);
176 #endif //HAVE_PTHREAD
182 SG_GCDEBUG(
"unref() refcount %ld obj %s (%p) decreased\n", m_refcount, this->
get_name(),
this)
184 PTHREAD_UNLOCK(&m_ref_lock);
185 #endif //HAVE_PTHREAD
189 #endif //USE_REFERENCE_COUNTING
192 void CSGObject::set_global_objects()
196 fprintf(stderr,
"call init_shogun() before using the library, dying.\n");
209 void CSGObject::unset_global_objects()
238 uint32_t new_hash = 0;
279 *
generic = m_generic;
291 SG_PRINT(
"\n%s\n================================================================================\n",
get_name())
296 const char* prefix, int32_t param_version)
305 SG_SWARNING(
"%s%s::save_serializable_pre(): ShogunException: "
311 if (!m_save_pre_called)
313 SG_SWARNING(
"%s%s::save_serializable_pre(): Implementation "
314 "error: BASE_CLASS::LOAD_SERIALIZABLE_PRE() not "
320 if (!save_parameter_version(file, prefix, param_version))
332 SG_SWARNING(
"%s%s::save_serializable_post(): ShogunException: "
338 if (!m_save_post_called)
340 SG_SWARNING(
"%s%s::save_serializable_post(): Implementation "
341 "error: BASE_CLASS::LOAD_SERIALIZABLE_POST() not "
346 if (prefix == NULL || *prefix ==
'\0')
355 const char* prefix, int32_t param_version)
364 SG_SWARNING(
"%s%s::load_serializable_pre(): ShogunException: "
369 if (!m_load_pre_called)
371 SG_SWARNING(
"%s%s::load_serializable_pre(): Implementation "
372 "error: BASE_CLASS::LOAD_SERIALIZABLE_PRE() not "
378 int32_t file_version=load_parameter_version(file, prefix);
379 SG_DEBUG(
"file_version=%d, current_version=%d\n", file_version, param_version)
383 SG_WARNING(
"%s%s::load_serializable(): File contains no parameter "
384 "version. Seems like your file is from the days before this "
385 "was introduced. Ignore warning or serialize with this version "
386 "of shogun to get rid of above and this warnings.\n",
390 if (file_version>param_version)
394 SG_WARNING(
"%s%s::load_serializable(): parameter version of file "
395 "larger than the one of shogun. Try with a more recent"
396 "version of shogun.\n", prefix,
get_name());
400 SG_WARNING(
"%s%s::load_serializable(): parameter version of file "
401 "larger than the current. This is probably an implementation"
407 if (file_version==param_version)
418 if (is_param_new(
SGParamInfo(current, param_version)))
421 if (!current->
load(file, prefix))
429 param_version, file, prefix);
439 if (is_param_new(
SGParamInfo(current, param_version)))
460 SG_DEBUG(
"replacing parameter data by loaded/mapped values\n")
464 char* s=SG_MALLOC(
char, 200);
470 if (is_param_new(
SGParamInfo(current, param_version)))
484 SG_DEBUG(
"copying migrated data into parameter\n")
489 SG_DEBUG(
"deleting old parameter base\n")
505 SG_SWARNING(
"%s%s::load_serializable_post(): ShogunException: "
511 if (!m_load_post_called)
513 SG_SWARNING(
"%s%s::load_serializable_post(): Implementation "
514 "error: BASE_CLASS::LOAD_SERIALIZABLE_POST() not "
524 const SGParamInfo* param_info, int32_t file_version,
531 SG_SERROR(
"parameter version of \"%s\" in file (%d) is more recent than"
532 " provided %d!\n", param_info->
m_name, file_version,
540 SG_SDEBUG(
"try to get mapping for: %s\n", s)
544 bool free_mapped=
false;
555 if (file_version<param_info->m_param_version)
593 SG_SDEBUG(
"recursion stop, loading from file\n")
621 if (!loaded->
load(file, prefix))
624 SG_ERROR(
"Could not load %s. The reason for this might be wrong "
625 "parameter mappings\n", s);
629 SG_DEBUG(
"loaded lengths: y=%d, x=%d\n",
647 SG_SDEBUG(
"starting recursion over %s\n", s)
657 SG_SDEBUG(
"appending all results to current result\n")
662 delete recursion_array;
695 if (is_param_new(*info))
728 SG_DEBUG(
"no target parameter infos\n")
742 SG_DEBUG(
"trying to get parameter mapping for %s\n", s)
763 SG_DEBUG(
"no mapping found, using %s\n", s)
782 if (mapped_version>base_version)
794 ASSERT(base_version==mapped_version)
801 SG_DEBUG(
"migrating one step to target: %s\n", s)
808 SG_DEBUG(
"deleting parameters base version %d\n", base_version)
812 SG_DEBUG(
"replacing old parameter base\n")
813 *param_base=*new_base;
814 base_version=mapped_version+1;
826 SG_DEBUG(
"(%d:) \"%s\": sgobject \"%s\" at %p\n", i,
839 SG_DEBUG(
"(%d:) \"%s\": sgobject \"%s\" at %p\n", i,
847 char* s=SG_MALLOC(
char, 200);
871 SG_DEBUG(
"CSGObject::entering CSGObject::one_to_one_migration_prepare() for "
872 "\"%s\"\n", target->
m_name);
879 char* name=target->
m_name;
916 SG_DEBUG(
"copied and SG_REF sgobject pointer for \"%s\" at %p\n",
923 SG_DEBUG(
"CSGObject::leaving CSGObject::one_to_one_migration_prepare() for "
924 "\"%s\"\n", target->
m_name);
955 SG_ERROR(
"Name change for parameter that has to be mapped to \"%s\","
956 " and to no migration method available\n", target->
m_name);
964 char* s=SG_MALLOC(
char, 200);
966 SG_DEBUG(
"nothing changed, using old data: %s\n", s)
996 SG_DEBUG(
"copying content of poitner for non-scalar data\n")
1003 SG_ERROR(
"No migration method available for %s!\n", s)
1013 const char* prefix, int32_t param_version)
1016 TParameter p(&t, ¶m_version,
"version_parameter",
1017 "Version of parameters of this object");
1018 return p.save(file, prefix);
1026 TParameter tp(&t, &v,
"version_parameter",
"");
1027 if (tp.load(file, prefix))
1035 m_load_pre_called =
true;
1040 m_load_post_called =
true;
1045 m_save_pre_called =
true;
1050 m_save_post_called =
true;
1053 #ifdef TRACE_MEMORY_ALLOCS
1058 void CSGObject::init()
1061 PTHREAD_LOCK_INIT(&m_ref_lock);
1064 #ifdef TRACE_MEMORY_ALLOCS
1067 int32_t idx=sg_mallocs->
index_of(
this);
1084 m_load_pre_called =
false;
1085 m_load_post_called =
false;
1098 for (
index_t i=0; i<num_param; i++)
1102 char* type=SG_MALLOC(
char, l);
1121 for (
index_t i=0; i<num_param; i++)
1128 if (len>max_string_length)
1129 max_string_length=len;
1143 SG_ERROR(
"There is no model selection parameter called \"%s\" for %s",
1161 if (!strcmp(param_name, current->
m_name))
1171 bool CSGObject::is_param_new(
const SGParamInfo param_info)
const
1180 void CSGObject::get_parameter_incremental_hash(
Parameter* param,
1181 uint32_t& hash, uint32_t& carry, uint32_t& total_length)
1202 get_parameter_incremental_hash(
1204 carry, total_length);