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;
108 using namespace shogun;
113 set_global_objects();
119 :io(orig.io), parallel(orig.parallel), version(orig.version)
122 set_global_objects();
127 SG_GCDEBUG(
"SGObject destroyed (%p)\n",
this);
130 PTHREAD_LOCK_DESTROY(&m_ref_lock);
132 unset_global_objects();
138 #ifdef USE_REFERENCE_COUNTING
140 int32_t CSGObject::ref()
143 PTHREAD_LOCK(&m_ref_lock);
144 #endif //HAVE_PTHREAD
146 int32_t count=m_refcount;
148 PTHREAD_UNLOCK(&m_ref_lock);
149 #endif //HAVE_PTHREAD
150 SG_GCDEBUG(
"ref() refcount %ld obj %s (%p) increased\n", count, this->
get_name(),
this);
154 int32_t CSGObject::ref_count()
157 PTHREAD_LOCK(&m_ref_lock);
158 #endif //HAVE_PTHREAD
159 int32_t count=m_refcount;
161 PTHREAD_UNLOCK(&m_ref_lock);
162 #endif //HAVE_PTHREAD
167 int32_t CSGObject::unref()
170 PTHREAD_LOCK(&m_ref_lock);
171 #endif //HAVE_PTHREAD
172 if (m_refcount==0 || --m_refcount==0)
174 SG_GCDEBUG(
"unref() refcount %ld, obj %s (%p) destroying\n", m_refcount, this->
get_name(),
this);
176 PTHREAD_UNLOCK(&m_ref_lock);
177 #endif //HAVE_PTHREAD
183 SG_GCDEBUG(
"unref() refcount %ld obj %s (%p) decreased\n", m_refcount, this->
get_name(),
this);
185 PTHREAD_UNLOCK(&m_ref_lock);
186 #endif //HAVE_PTHREAD
190 #endif //USE_REFERENCE_COUNTING
193 void CSGObject::set_global_objects()
197 fprintf(stderr,
"call init_shogun() before using the library, dying.\n");
210 void CSGObject::unset_global_objects()
239 uint32_t new_hash = 0;
280 *
generic = m_generic;
292 SG_PRINT(
"\n%s\n================================================================================\n",
get_name());
297 const char* prefix, int32_t param_version)
306 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");
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");
618 if (!loaded->
load(file, prefix))
621 SG_ERROR(
"Could not load %s. The reason for this might be wrong "
622 "parameter mappings\n", s);
626 SG_DEBUG(
"loaded lengths: y=%d, x=%d\n",
644 SG_SDEBUG(
"starting recursion over %s\n", s);
650 SG_SDEBUG(
"recursion over %s done\n", s);
654 SG_SDEBUG(
"appending all results to current result\n");
659 delete recursion_array;
692 if (is_param_new(*info))
725 SG_DEBUG(
"no target parameter infos\n");
739 SG_DEBUG(
"trying to get parameter mapping for %s\n", s);
760 SG_DEBUG(
"no mapping found, using %s\n", s);
779 if (mapped_version>base_version)
791 ASSERT(base_version==mapped_version);
798 SG_DEBUG(
"migrating one step to target: %s\n", s);
805 SG_DEBUG(
"deleting parameters base version %d\n", base_version);
809 SG_DEBUG(
"replacing old parameter base\n");
810 *param_base=*new_base;
811 base_version=mapped_version+1;
823 SG_DEBUG(
"(%d:) \"%s\": sgobject \"%s\" at %p\n", i,
836 SG_DEBUG(
"(%d:) \"%s\": sgobject \"%s\" at %p\n", i,
868 SG_DEBUG(
"CSGObject::entering CSGObject::one_to_one_migration_prepare() for "
869 "\"%s\"\n", target->
m_name);
876 char* name=target->
m_name;
912 SG_DEBUG(
"copied and SG_REF sgobject pointer for \"%s\" at %p\n",
919 SG_DEBUG(
"CSGObject::leaving CSGObject::one_to_one_migration_prepare() for "
920 "\"%s\"\n", target->
m_name);
951 SG_ERROR(
"Name change for parameter that has to be mapped to \"%s\","
952 " and to no migration method available\n", target->
m_name);
962 SG_DEBUG(
"nothing changed, using old data: %s\n", s);
991 SG_DEBUG(
"copying content of poitner for non-scalar data\n");
998 SG_ERROR(
"No migration method available for %s!\n", s);
1008 const char* prefix, int32_t param_version)
1011 TParameter p(&t, ¶m_version,
"version_parameter",
1012 "Version of parameters of this object");
1013 return p.save(file, prefix);
1021 TParameter tp(&t, &v,
"version_parameter",
"");
1022 if (tp.load(file, prefix))
1030 m_load_pre_called =
true;
1035 m_load_post_called =
true;
1040 m_save_pre_called =
true;
1045 m_save_post_called =
true;
1048 #ifdef TRACE_MEMORY_ALLOCS
1053 void CSGObject::init()
1056 PTHREAD_LOCK_INIT(&m_ref_lock);
1059 #ifdef TRACE_MEMORY_ALLOCS
1062 int32_t idx=sg_mallocs->index_of(
this);
1065 MemoryBlock* b=sg_mallocs->get_element_ptr(idx);
1079 m_load_pre_called =
false;
1080 m_load_post_called =
false;
1086 SG_PRINT(
"parameters available for model selection for %s:\n",
get_name());
1093 for (
index_t i=0; i<num_param; i++)
1116 for (
index_t i=0; i<num_param; i++)
1123 if (len>max_string_length)
1124 max_string_length=len;
1138 SG_ERROR(
"There is no model selection parameter called \"%s\" for %s",
1156 if (!strcmp(param_name, current->
m_name))
1169 bool CSGObject::is_param_new(
const SGParamInfo param_info)
const
1178 void CSGObject::get_parameter_incremental_hash(
Parameter* param,
1179 uint32_t& hash, uint32_t& carry, uint32_t& total_length)
1193 get_parameter_incremental_hash(
1195 carry, total_length);