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;
105 template<>
void CSGObject::set_generic<CSGObject*>()
107 m_generic = PT_SGOBJECT;
110 template<>
void CSGObject::set_generic<complex128_t>()
112 m_generic = PT_COMPLEX128;
117 using namespace shogun;
122 set_global_objects();
129 :io(orig.io), parallel(orig.parallel), version(orig.version)
132 set_global_objects();
133 m_refcount = orig.m_refcount;
141 unset_global_objects();
149 #ifdef USE_REFERENCE_COUNTING
150 int32_t CSGObject::ref()
152 int32_t count = m_refcount->
ref();
153 SG_GCDEBUG(
"ref() refcount %ld obj %s (%p) increased\n", count, this->
get_name(),
this)
154 return m_refcount->ref_count();
161 return m_refcount->ref_count();
166 int32_t count = m_refcount->
unref();
169 SG_GCDEBUG(
"unref() refcount %ld, obj %s (%p) destroying\n", count, this->
get_name(),
this)
175 SG_GCDEBUG(
"unref() refcount %ld obj %s (%p) decreased\n", count, this->
get_name(),
this)
176 return m_refcount->ref_count();
179 #endif //USE_REFERENCE_COUNTING
182 void CSGObject::set_global_objects()
186 fprintf(stderr,
"call init_shogun() before using the library, dying.\n");
199 void CSGObject::unset_global_objects()
228 uint32_t new_hash = 0;
269 *
generic = m_generic;
281 SG_PRINT(
"\n%s\n================================================================================\n",
get_name())
286 const char* prefix, int32_t param_version)
295 SG_SWARNING(
"%s%s::save_serializable_pre(): ShogunException: "
301 if (!m_save_pre_called)
303 SG_SWARNING(
"%s%s::save_serializable_pre(): Implementation "
304 "error: BASE_CLASS::LOAD_SERIALIZABLE_PRE() not "
310 if (!save_parameter_version(file, prefix, param_version))
322 SG_SWARNING(
"%s%s::save_serializable_post(): ShogunException: "
328 if (!m_save_post_called)
330 SG_SWARNING(
"%s%s::save_serializable_post(): Implementation "
331 "error: BASE_CLASS::LOAD_SERIALIZABLE_POST() not "
336 if (prefix == NULL || *prefix ==
'\0')
345 const char* prefix, int32_t param_version)
354 SG_SWARNING(
"%s%s::load_serializable_pre(): ShogunException: "
359 if (!m_load_pre_called)
361 SG_SWARNING(
"%s%s::load_serializable_pre(): Implementation "
362 "error: BASE_CLASS::LOAD_SERIALIZABLE_PRE() not "
368 int32_t file_version=load_parameter_version(file, prefix);
369 SG_DEBUG(
"file_version=%d, current_version=%d\n", file_version, param_version)
373 SG_WARNING(
"%s%s::load_serializable(): File contains no parameter "
374 "version. Seems like your file is from the days before this "
375 "was introduced. Ignore warning or serialize with this version "
376 "of shogun to get rid of above and this warnings.\n",
380 if (file_version>param_version)
384 SG_WARNING(
"%s%s::load_serializable(): parameter version of file "
385 "larger than the one of shogun. Try with a more recent"
386 "version of shogun.\n", prefix,
get_name());
390 SG_WARNING(
"%s%s::load_serializable(): parameter version of file "
391 "larger than the current. This is probably an implementation"
397 if (file_version==param_version)
408 if (is_param_new(
SGParamInfo(current, param_version)))
411 if (!current->
load(file, prefix))
419 param_version, file, prefix);
429 if (is_param_new(
SGParamInfo(current, param_version)))
450 SG_DEBUG(
"replacing parameter data by loaded/mapped values\n")
454 char* s=SG_MALLOC(
char, 200);
460 if (is_param_new(
SGParamInfo(current, param_version)))
474 SG_DEBUG(
"copying migrated data into parameter\n")
479 SG_DEBUG(
"deleting old parameter base\n")
495 SG_SWARNING(
"%s%s::load_serializable_post(): ShogunException: "
501 if (!m_load_post_called)
503 SG_SWARNING(
"%s%s::load_serializable_post(): Implementation "
504 "error: BASE_CLASS::LOAD_SERIALIZABLE_POST() not "
514 const SGParamInfo* param_info, int32_t file_version,
521 SG_SERROR(
"parameter version of \"%s\" in file (%d) is more recent than"
522 " provided %d!\n", param_info->
m_name, file_version,
530 SG_SDEBUG(
"try to get mapping for: %s\n", s)
534 bool free_mapped=
false;
545 if (file_version<param_info->m_param_version)
583 SG_SDEBUG(
"recursion stop, loading from file\n")
611 if (!loaded->
load(file, prefix))
614 SG_ERROR(
"Could not load %s. The reason for this might be wrong "
615 "parameter mappings\n", s);
619 SG_DEBUG(
"loaded lengths: y=%d, x=%d\n",
637 SG_SDEBUG(
"starting recursion over %s\n", s)
647 SG_SDEBUG(
"appending all results to current result\n")
652 delete recursion_array;
685 if (is_param_new(*info))
718 SG_DEBUG(
"no target parameter infos\n")
732 SG_DEBUG(
"trying to get parameter mapping for %s\n", s)
753 SG_DEBUG(
"no mapping found, using %s\n", s)
772 if (mapped_version>base_version)
784 ASSERT(base_version==mapped_version)
791 SG_DEBUG(
"migrating one step to target: %s\n", s)
798 SG_DEBUG(
"deleting parameters base version %d\n", base_version)
802 SG_DEBUG(
"replacing old parameter base\n")
803 *param_base=*new_base;
804 base_version=mapped_version+1;
816 SG_DEBUG(
"(%d:) \"%s\": sgobject \"%s\" at %p\n", i,
829 SG_DEBUG(
"(%d:) \"%s\": sgobject \"%s\" at %p\n", i,
837 char* s=SG_MALLOC(
char, 200);
861 SG_DEBUG(
"CSGObject::entering CSGObject::one_to_one_migration_prepare() for "
862 "\"%s\"\n", target->
m_name);
869 char* name=target->
m_name;
906 SG_DEBUG(
"copied and SG_REF sgobject pointer for \"%s\" at %p\n",
913 SG_DEBUG(
"CSGObject::leaving CSGObject::one_to_one_migration_prepare() for "
914 "\"%s\"\n", target->
m_name);
945 SG_ERROR(
"Name change for parameter that has to be mapped to \"%s\","
946 " and to no migration method available\n", target->
m_name);
954 char* s=SG_MALLOC(
char, 200);
956 SG_DEBUG(
"nothing changed, using old data: %s\n", s)
986 SG_DEBUG(
"copying content of poitner for non-scalar data\n")
993 SG_ERROR(
"No migration method available for %s!\n", s)
1003 const char* prefix, int32_t param_version)
1006 TParameter p(&t, ¶m_version,
"version_parameter",
1007 "Version of parameters of this object");
1008 return p.save(file, prefix);
1016 TParameter tp(&t, &v,
"version_parameter",
"");
1017 if (tp.load(file, prefix))
1025 m_load_pre_called =
true;
1030 m_load_post_called =
true;
1035 m_save_pre_called =
true;
1040 m_save_post_called =
true;
1043 #ifdef TRACE_MEMORY_ALLOCS
1048 void CSGObject::init()
1050 #ifdef TRACE_MEMORY_ALLOCS
1053 int32_t idx=sg_mallocs->
index_of(
this);
1070 m_load_pre_called =
false;
1071 m_load_post_called =
false;
1084 for (
index_t i=0; i<num_param; i++)
1088 char* type=SG_MALLOC(
char, l);
1107 for (
index_t i=0; i<num_param; i++)
1114 if (len>max_string_length)
1115 max_string_length=len;
1129 SG_ERROR(
"There is no model selection parameter called \"%s\" for %s",
1147 if (!strcmp(param_name, current->
m_name))
1157 bool CSGObject::is_param_new(
const SGParamInfo param_info)
const
1166 void CSGObject::get_parameter_incremental_hash(
Parameter* param,
1167 uint32_t& hash, uint32_t& carry, uint32_t& total_length)
1189 get_parameter_incremental_hash(
1191 carry, total_length);
1237 SG_DEBUG(
"leaving %s::equals(): name of other object differs\n",
get_name());
1245 SG_DEBUG(
"leaving %s::equals(): number of parameters of other object "
1252 SG_DEBUG(
"comparing parameter %d\n", i);
1259 if (!this_param && !other_param)
1262 if (!this_param && other_param)
1264 SG_DEBUG(
"leaving %s::equals(): parameter %d is NULL where other's "
1269 if (this_param && !other_param)
1271 SG_DEBUG(
"leaving %s::equals(): parameter %d is \"%s\" where other's "
1276 SG_DEBUG(
"comparing parameter \"%s\" to other's \"%s\"\n",
1280 if (!strcmp(
"DynamicObjectArray",
get_name()) &&
1281 !strcmp(this_param->
m_name,
"num_elements") &&
1282 !strcmp(other_param->
m_name,
"num_elements"))
1284 SG_DEBUG(
"Ignoring DynamicObjectArray::num_elements field\n");
1289 if (!strcmp(
"DynamicArray",
get_name()) &&
1290 !strcmp(this_param->
m_name,
"num_elements") &&
1291 !strcmp(other_param->
m_name,
"num_elements"))
1293 SG_DEBUG(
"Ignoring DynamicArray::num_elements field\n");
1298 if (!this_param->
equals(other_param, accuracy))
1300 SG_DEBUG(
"leaving %s::equals(): parameters at position %d with name"
1301 " \"%s\" differs from other object parameter with name "
1321 REQUIRE(copy,
"Could not create empty instance of \"%s\". The reason for "
1322 "this usually is that get_name() of the class returns something "
1323 "wrong, or that a class has a wrongly set generic type.\n",
1328 SG_DEBUG(
"cloning parameter \"%s\" at index %d\n",
1333 SG_DEBUG(
"leaving %s::clone(): Clone failed. Returning NULL\n",
virtual const char * get_name() const =0
SGStringList< char > get_modelsel_names()
T get_element(int32_t index) const
Parallel * get_global_parallel()
virtual bool save_serializable(CSerializableFile *file, const char *prefix="", int32_t param_version=Version::get_version_parameter())
Class that holds informations about a certain parameter of an CSGObject. Contains name...
ParameterMap * m_parameter_map
virtual TParameter * migrate(DynArray< TParameter * > *param_base, const SGParamInfo *target)
bool append_element(T element)
virtual int32_t get_num_parameters()
virtual CSGObject * clone()
Class ShogunException defines an exception which is thrown whenever an error inside of shogun occurs...
static int32_t binary_search(T *output, int32_t size, T elem)
TParameter * get_parameter(int32_t idx)
DynArray< const SGParamInfo * > * get(const SGParamInfo) const
Version * get_global_version()
virtual void save_serializable_pre()
virtual bool is_generic(EPrimitiveType *generic) const
virtual void print(const char *prefix="")
static uint32_t FinalizeIncrementalMurmurHash3(uint32_t h, uint32_t carry, uint32_t total_length)
int32_t get_num_elements() const
static int32_t get_version_parameter()
SGParamInfo * duplicate() const
Implements a map of ParameterMapElement instances Maps one key to a set of values.
Datatypes that shogun supports.
virtual bool update_parameter_hash()
static void qsort(T *output, int32_t size)
char * get_modsel_param_descr(const char *param_name)
DynArray< TParameter * > * load_file_parameters(const SGParamInfo *param_info, int32_t file_version, CSerializableFile *file, const char *prefix="")
Class SGObject is the base class of all shogun objects.
void build_gradient_parameter_dictionary(CMap< TParameter *, CSGObject * > *dict)
virtual bool equals(CSGObject *other, float64_t accuracy=0.0)
Template Dynamic array class that creates an array that can be used like a list or an array...
virtual bool load_serializable(CSerializableFile *file, const char *prefix="", int32_t param_version=Version::get_version_parameter())
DynArray< TParameter * > * load_all_file_parameters(int32_t file_version, int32_t current_version, CSerializableFile *file, const char *prefix="")
virtual bool save(CSerializableFile *file, const char *prefix="")
index_t max_string_length
the class CMap, a map based on the hash-table. w: http://en.wikipedia.org/wiki/Hash_table ...
T * get_element_ptr(int32_t index)
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
void get_incremental_hash(uint32_t &hash, uint32_t &carry, uint32_t &total_length)
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.
int32_t index_of(const K &key)
virtual void one_to_one_migration_prepare(DynArray< TParameter * > *param_base, const SGParamInfo *target, TParameter *&replacement, TParameter *&to_migrate, char *old_name=NULL)
const char * get_exception_string()
bool load(CSerializableFile *file, const char *prefix="")
int32_t add(const K &key, const T &data)
bool equals(TParameter *other, float64_t accuracy=0.0)
void map_parameters(DynArray< TParameter * > *param_base, int32_t &base_version, DynArray< const SGParamInfo * > *target_param_infos)
index_t get_modsel_param_index(const char *param_name)
void set_global_io(SGIO *io)
bool copy(TParameter *target)
void copy_data(const TParameter *source)
Class which collects generic mathematical functions.
Class SGIO, used to do input output operations throughout shogun.
Parameter * m_gradient_parameters
virtual void print_serializable(const char *prefix="")
void set_global_version(Version *version)
void allocate_data_from_scratch(SGVector< index_t > dims, bool new_cont_call=true)
template class SGStringList