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;
123 set_global_objects();
130 :io(orig.io), parallel(orig.parallel), version(orig.version)
133 set_global_objects();
143 unset_global_objects();
150 #ifdef USE_REFERENCE_COUNTING
151 int32_t CSGObject::ref()
153 int32_t count = m_refcount->
ref();
155 return m_refcount->ref_count();
162 return m_refcount->ref_count();
167 int32_t count = m_refcount->
unref();
170 SG_SGCDEBUG(
"unref() refcount %ld, obj %s (%p) destroying\n", count, this->
get_name(),
this)
177 return m_refcount->ref_count();
180 #endif //USE_REFERENCE_COUNTING
182 #ifdef TRACE_MEMORY_ALLOCS
186 void CSGObject::list_memory_allocs()
188 shogun::list_memory_allocs();
204 void CSGObject::set_global_objects()
208 fprintf(stderr,
"call init_shogun() before using the library, dying.\n");
221 void CSGObject::unset_global_objects()
256 get_parameter_incremental_hash(
m_hash, carry, length);
270 get_parameter_incremental_hash(hash, carry, length);
298 *
generic = m_generic;
310 SG_PRINT(
"\n%s\n================================================================================\n",
get_name())
324 SG_SWARNING(
"%s%s::save_serializable_pre(): ShogunException: "
330 if (!m_save_pre_called)
332 SG_SWARNING(
"%s%s::save_serializable_pre(): Implementation "
333 "error: BASE_CLASS::SAVE_SERIALIZABLE_PRE() not "
347 SG_SWARNING(
"%s%s::save_serializable_post(): ShogunException: "
353 if (!m_save_post_called)
355 SG_SWARNING(
"%s%s::save_serializable_post(): Implementation "
356 "error: BASE_CLASS::SAVE_SERIALIZABLE_POST() not "
361 if (prefix == NULL || *prefix ==
'\0')
372 REQUIRE(file != NULL,
"Serializable file object should be != NULL\n");
381 SG_SWARNING(
"%s%s::load_serializable_pre(): ShogunException: "
386 if (!m_load_pre_called)
388 SG_SWARNING(
"%s%s::load_serializable_pre(): Implementation "
389 "error: BASE_CLASS::LOAD_SERIALIZABLE_PRE() not "
403 SG_SWARNING(
"%s%s::load_serializable_post(): ShogunException: "
409 if (!m_load_post_called)
411 SG_SWARNING(
"%s%s::load_serializable_post(): Implementation "
412 "error: BASE_CLASS::LOAD_SERIALIZABLE_POST() not "
423 m_load_pre_called =
true;
428 m_load_post_called =
true;
433 m_save_pre_called =
true;
438 m_save_post_called =
true;
441 #ifdef TRACE_MEMORY_ALLOCS
446 void CSGObject::init()
448 #ifdef TRACE_MEMORY_ALLOCS
451 int32_t idx=sg_mallocs->
index_of(
this);
467 m_load_pre_called =
false;
468 m_load_post_called =
false;
469 m_save_pre_called =
false;
470 m_save_post_called =
false;
483 for (
index_t i=0; i<num_param; i++)
487 char* type=SG_MALLOC(
char, l);
506 for (
index_t i=0; i<num_param; i++)
513 if (len>max_string_length)
514 max_string_length=len;
528 SG_ERROR(
"There is no model selection parameter called \"%s\" for %s",
546 if (!strcmp(param_name, current->
m_name))
556 void CSGObject::get_parameter_incremental_hash(uint32_t& hash, uint32_t& carry,
557 uint32_t& total_length)
573 child->get_parameter_incremental_hash(hash, carry,
586 child[j]->get_parameter_incremental_hash(hash, carry,
639 SG_INFO(
"leaving %s::equals(): name of other object differs\n",
get_name());
647 SG_INFO(
"leaving %s::equals(): number of parameters of other object "
654 SG_DEBUG(
"comparing parameter %d\n", i);
661 if (!this_param && !other_param)
664 if (!this_param && other_param)
666 SG_DEBUG(
"leaving %s::equals(): parameter %d is NULL where other's "
671 if (this_param && !other_param)
673 SG_DEBUG(
"leaving %s::equals(): parameter %d is \"%s\" where other's "
678 SG_DEBUG(
"comparing parameter \"%s\" to other's \"%s\"\n",
682 if (!strcmp(
"DynamicObjectArray",
get_name()) &&
683 !strcmp(this_param->
m_name,
"num_elements") &&
684 !strcmp(other_param->
m_name,
"num_elements"))
686 SG_DEBUG(
"Ignoring DynamicObjectArray::num_elements field\n");
691 if (!strcmp(
"DynamicArray",
get_name()) &&
692 !strcmp(this_param->
m_name,
"num_elements") &&
693 !strcmp(other_param->
m_name,
"num_elements"))
695 SG_DEBUG(
"Ignoring DynamicArray::num_elements field\n");
700 if (!this_param->
equals(other_param, accuracy, tolerant))
702 SG_INFO(
"leaving %s::equals(): parameters at position %d with name"
703 " \"%s\" differs from other object parameter with name "
723 REQUIRE(copy,
"Could not create empty instance of \"%s\". The reason for "
724 "this usually is that get_name() of the class returns something "
725 "wrong, or that a class has a wrongly set generic type.\n",
730 SG_DEBUG(
"cloning parameter \"%s\" at index %d\n",
735 SG_DEBUG(
"leaving %s::clone(): Clone failed. Returning NULL\n",
virtual const char * get_name() const =0
SGStringList< char > get_modelsel_names()
template class SGStringList
Parallel * get_global_parallel()
virtual void update_parameter_hash()
int32_t index_of(const K &key)
virtual int32_t get_num_parameters()
virtual CSGObject * clone()
Class ShogunException defines an exception which is thrown whenever an error inside of shogun occurs...
virtual CSGObject * shallow_copy() const
TParameter * get_parameter(int32_t idx)
Version * get_global_version()
virtual void save_serializable_pre()
virtual bool is_generic(EPrimitiveType *generic) const
#define SG_NOTIMPLEMENTED
virtual bool load_serializable(CSerializableFile *file, const char *prefix="")
virtual void print(const char *prefix="")
static uint32_t FinalizeIncrementalMurmurHash3(uint32_t h, uint32_t carry, uint32_t total_length)
virtual bool load(CSerializableFile *file, const char *prefix="")
T * get_element_ptr(int32_t index)
char * get_modsel_param_descr(const char *param_name)
bool equals(TParameter *other, float64_t accuracy=0.0, bool tolerant=false)
int32_t add(const K &key, const T &data)
Class SGObject is the base class of all shogun objects.
void build_gradient_parameter_dictionary(CMap< TParameter *, CSGObject * > *dict)
virtual bool save(CSerializableFile *file, const char *prefix="")
virtual void save_serializable_post()
void print_modsel_params()
CSGObject * new_sgserializable(const char *sgserializable_name, EPrimitiveType generic)
Class Version provides version information.
Parameter * m_model_selection_parameters
index_t max_string_length
void get_incremental_hash(uint32_t &hash, uint32_t &carry, uint32_t &total_length)
virtual bool equals(CSGObject *other, float64_t accuracy=0.0, bool tolerant=false)
virtual CSGObject * deep_copy() const
void set_global_parallel(Parallel *parallel)
void to_string(char *dest, size_t n) const
virtual void load_serializable_pre()
virtual void load_serializable_post()
Class Parallel provides helper functions for multithreading.
virtual bool save_serializable(CSerializableFile *file, const char *prefix="")
const char * get_exception_string()
all of classes and functions are contained in the shogun namespace
index_t get_modsel_param_index(const char *param_name)
void set_global_io(SGIO *io)
bool copy(TParameter *target)
Class SGIO, used to do input output operations throughout shogun.
Parameter * m_gradient_parameters
virtual void print_serializable(const char *prefix="")
virtual bool parameter_hash_changed()
void set_global_version(Version *version)
the class CMap, a map based on the hash-table. w: http://en.wikipedia.org/wiki/Hash_table ...