35 template<>
void CSGObject::set_generic<bool>()
40 template<>
void CSGObject::set_generic<char>()
45 template<>
void CSGObject::set_generic<int8_t>()
50 template<>
void CSGObject::set_generic<uint8_t>()
55 template<>
void CSGObject::set_generic<int16_t>()
60 template<>
void CSGObject::set_generic<uint16_t>()
62 m_generic = PT_UINT16;
65 template<>
void CSGObject::set_generic<int32_t>()
70 template<>
void CSGObject::set_generic<uint32_t>()
72 m_generic = PT_UINT32;
75 template<>
void CSGObject::set_generic<int64_t>()
80 template<>
void CSGObject::set_generic<uint64_t>()
82 m_generic = PT_UINT64;
85 template<>
void CSGObject::set_generic<float32_t>()
87 m_generic = PT_FLOAT32;
90 template<>
void CSGObject::set_generic<float64_t>()
92 m_generic = PT_FLOAT64;
95 template<>
void CSGObject::set_generic<floatmax_t>()
97 m_generic = PT_FLOATMAX;
102 using namespace shogun;
107 set_global_objects();
113 :io(orig.io), parallel(orig.parallel), version(orig.version)
116 set_global_objects();
121 SG_GCDEBUG(
"SGObject destroyed (%p)\n",
this);
124 PTHREAD_LOCK_DESTROY(&m_ref_lock);
126 unset_global_objects();
131 #ifdef USE_REFERENCE_COUNTING
133 int32_t CSGObject::ref()
136 PTHREAD_LOCK(&m_ref_lock);
137 #endif //HAVE_PTHREAD
139 int32_t count=m_refcount;
141 PTHREAD_UNLOCK(&m_ref_lock);
142 #endif //HAVE_PTHREAD
143 SG_GCDEBUG(
"ref() refcount %ld obj %s (%p) increased\n", count, this->
get_name(),
this);
147 int32_t CSGObject::ref_count()
150 PTHREAD_LOCK(&m_ref_lock);
151 #endif //HAVE_PTHREAD
152 int32_t count=m_refcount;
154 PTHREAD_UNLOCK(&m_ref_lock);
155 #endif //HAVE_PTHREAD
160 int32_t CSGObject::unref()
163 PTHREAD_LOCK(&m_ref_lock);
164 #endif //HAVE_PTHREAD
165 if (m_refcount==0 || --m_refcount==0)
167 SG_GCDEBUG(
"unref() refcount %ld, obj %s (%p) destroying\n", m_refcount, this->
get_name(),
this);
169 PTHREAD_UNLOCK(&m_ref_lock);
170 #endif //HAVE_PTHREAD
176 SG_GCDEBUG(
"unref() refcount %ld obj %s (%p) decreased\n", m_refcount, this->
get_name(),
this);
178 PTHREAD_UNLOCK(&m_ref_lock);
179 #endif //HAVE_PTHREAD
183 #endif //USE_REFERENCE_COUNTING
186 void CSGObject::set_global_objects()
190 fprintf(stderr,
"call init_shogun() before using the library, dying.\n");
203 void CSGObject::unset_global_objects()
251 *
generic = m_generic;
263 SG_PRINT(
"\n%s\n================================================================================\n",
get_name());
277 SG_SWARNING(
"%s%s::save_serializable_pre(): ShogunException: "
282 if (!m_save_pre_called)
284 SG_SWARNING(
"%s%s::save_serializable_pre(): Implementation "
285 "error: BASE_CLASS::LOAD_SERIALIZABLE_PRE() not "
291 if (!save_parameter_version(file, prefix))
303 SG_SWARNING(
"%s%s::save_serializable_post(): ShogunException: "
309 if (!m_save_post_called)
311 SG_SWARNING(
"%s%s::save_serializable_post(): Implementation "
312 "error: BASE_CLASS::LOAD_SERIALIZABLE_POST() not "
317 if (prefix == NULL || *prefix ==
'\0')
335 SG_SWARNING(
"%s%s::load_serializable_pre(): ShogunException: "
340 if (!m_load_pre_called)
342 SG_SWARNING(
"%s%s::load_serializable_pre(): Implementation "
343 "error: BASE_CLASS::LOAD_SERIALIZABLE_PRE() not "
349 int32_t file_version=load_parameter_version(file, prefix);
353 SG_WARNING(
"%s%s::load_serializable(): File contains no parameter "
354 "version. Seems like your file is from the days before this "
355 "was introduced. Ignore warning or serialize with this version "
356 "of shogun to get rid of above and this warnings.\n",
362 SG_WARNING(
"%s%s::load_serializable(): parameter version of file "
363 "larger than the one of shogun. Try with a more recent version "
364 "of shogun.\n", prefix,
get_name());
377 SG_SWARNING(
"%s%s::load_serializable_post(): ShogunException: "
383 if (!m_load_post_called)
385 SG_SWARNING(
"%s%s::load_serializable_post(): Implementation "
386 "error: BASE_CLASS::LOAD_SERIALIZABLE_POST() not "
401 "Version of parameters of this object");
402 return p.save(file, prefix);
410 TParameter tp(&t, &v,
"version_parameter",
"");
411 if (tp.load(file, prefix))
419 m_load_pre_called =
true;
424 m_load_post_called =
true;
429 m_save_pre_called =
true;
434 m_save_post_called =
true;
437 #ifdef TRACE_MEMORY_ALLOCS
442 void CSGObject::init()
445 PTHREAD_LOCK_INIT(&m_ref_lock);
448 #ifdef TRACE_MEMORY_ALLOCS
451 int32_t idx=sg_mallocs->index_of(MemoryBlock(
this));
454 MemoryBlock* b=sg_mallocs->get_element_ptr(idx);
467 m_load_pre_called =
false;
468 m_load_post_called =
false;
488 SG_ERROR(
"There is no model selection parameter called \"%s\" for %s",
506 if (!strcmp(param_name, current->
m_name))