SHOGUN  4.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
SGObject.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 2008-2009 Soeren Sonnenburg
8  * Written (W) 2011-2013 Heiko Strathmann
9  * Written (W) 2013-2014 Thoralf Klein
10  * Copyright (C) 2008-2009 Fraunhofer Institute FIRST and Max Planck Society
11  */
12 
13 #include <shogun/lib/config.h>
14 #include <shogun/lib/memory.h>
15 #include <shogun/lib/RefCount.h>
16 
17 #include <shogun/base/SGObject.h>
18 #include <shogun/io/SGIO.h>
19 #include <shogun/base/Version.h>
20 #include <shogun/base/Parameter.h>
22 #include <shogun/base/DynArray.h>
23 #include <shogun/lib/Map.h>
24 #include <shogun/lib/SGVector.h>
27 
28 #include <shogun/base/class_list.h>
29 
30 #include <stdlib.h>
31 #include <stdio.h>
32 #include <string.h>
33 
34 namespace shogun
35 {
36  class Parallel;
37 
38  extern Parallel* sg_parallel;
39  extern SGIO* sg_io;
40  extern Version* sg_version;
41 
42  template<> void CSGObject::set_generic<bool>()
43  {
44  m_generic = PT_BOOL;
45  }
46 
47  template<> void CSGObject::set_generic<char>()
48  {
49  m_generic = PT_CHAR;
50  }
51 
52  template<> void CSGObject::set_generic<int8_t>()
53  {
54  m_generic = PT_INT8;
55  }
56 
57  template<> void CSGObject::set_generic<uint8_t>()
58  {
59  m_generic = PT_UINT8;
60  }
61 
62  template<> void CSGObject::set_generic<int16_t>()
63  {
64  m_generic = PT_INT16;
65  }
66 
67  template<> void CSGObject::set_generic<uint16_t>()
68  {
69  m_generic = PT_UINT16;
70  }
71 
72  template<> void CSGObject::set_generic<int32_t>()
73  {
74  m_generic = PT_INT32;
75  }
76 
77  template<> void CSGObject::set_generic<uint32_t>()
78  {
79  m_generic = PT_UINT32;
80  }
81 
82  template<> void CSGObject::set_generic<int64_t>()
83  {
84  m_generic = PT_INT64;
85  }
86 
87  template<> void CSGObject::set_generic<uint64_t>()
88  {
89  m_generic = PT_UINT64;
90  }
91 
92  template<> void CSGObject::set_generic<float32_t>()
93  {
94  m_generic = PT_FLOAT32;
95  }
96 
97  template<> void CSGObject::set_generic<float64_t>()
98  {
99  m_generic = PT_FLOAT64;
100  }
101 
102  template<> void CSGObject::set_generic<floatmax_t>()
103  {
104  m_generic = PT_FLOATMAX;
105  }
106 
107  template<> void CSGObject::set_generic<CSGObject*>()
108  {
109  m_generic = PT_SGOBJECT;
110  }
111 
112  template<> void CSGObject::set_generic<complex128_t>()
113  {
114  m_generic = PT_COMPLEX128;
115  }
116 
117 } /* namespace shogun */
118 
119 using namespace shogun;
120 
122 {
123  init();
124  set_global_objects();
125  m_refcount = new RefCount(0);
126 
127  SG_SGCDEBUG("SGObject created (%p)\n", this)
128 }
129 
131 :io(orig.io), parallel(orig.parallel), version(orig.version)
132 {
133  init();
134  set_global_objects();
135  m_refcount = new RefCount(0);
136 
137  SG_SGCDEBUG("SGObject copied (%p)\n", this)
138 }
139 
141 {
142  SG_SGCDEBUG("SGObject destroyed (%p)\n", this)
143 
144  unset_global_objects();
145  delete m_parameters;
147  delete m_gradient_parameters;
148  delete m_parameter_map;
149  delete m_refcount;
150 }
151 
152 #ifdef USE_REFERENCE_COUNTING
153 int32_t CSGObject::ref()
154 {
155  int32_t count = m_refcount->ref();
156  SG_SGCDEBUG("ref() refcount %ld obj %s (%p) increased\n", count, this->get_name(), this)
157  return m_refcount->ref_count();
158 }
159 
160 int32_t CSGObject::ref_count()
161 {
162  int32_t count = m_refcount->ref_count();
163  SG_SGCDEBUG("ref_count(): refcount %d, obj %s (%p)\n", count, this->get_name(), this)
164  return m_refcount->ref_count();
165 }
166 
167 int32_t CSGObject::unref()
168 {
169  int32_t count = m_refcount->unref();
170  if (count<=0)
171  {
172  SG_SGCDEBUG("unref() refcount %ld, obj %s (%p) destroying\n", count, this->get_name(), this)
173  delete this;
174  return 0;
175  }
176  else
177  {
178  SG_SGCDEBUG("unref() refcount %ld obj %s (%p) decreased\n", count, this->get_name(), this)
179  return m_refcount->ref_count();
180  }
181 }
182 #endif //USE_REFERENCE_COUNTING
183 
184 #ifdef TRACE_MEMORY_ALLOCS
185 #include <shogun/lib/Map.h>
186 extern CMap<void*, shogun::MemoryBlock>* sg_mallocs;
187 
188 void CSGObject::list_memory_allocs()
189 {
190  shogun::list_memory_allocs();
191 }
192 #endif
193 
195 {
197  return NULL;
198 }
199 
201 {
203  return NULL;
204 }
205 
206 void CSGObject::set_global_objects()
207 {
208  if (!sg_io || !sg_parallel || !sg_version)
209  {
210  fprintf(stderr, "call init_shogun() before using the library, dying.\n");
211  exit(1);
212  }
213 
214  SG_REF(sg_io);
217 
218  io=sg_io;
221 }
222 
223 void CSGObject::unset_global_objects()
224 {
225  SG_UNREF(version);
227  SG_UNREF(io);
228 }
229 
231 {
232  SG_REF(new_io);
233  SG_UNREF(sg_io);
234  sg_io=new_io;
235 }
236 
238 {
239  SG_REF(sg_io);
240  return sg_io;
241 }
242 
244 {
245  SG_REF(new_parallel);
247  sg_parallel=new_parallel;
248 }
249 
251 {
252  SG_DEBUG("entering\n")
253 
254  uint32_t carry=0;
255  uint32_t length=0;
256 
257  m_hash=0;
258  get_parameter_incremental_hash(m_hash, carry, length);
260 
261  SG_DEBUG("leaving\n")
262 }
263 
265 {
266  SG_DEBUG("entering\n")
267 
268  uint32_t hash=0;
269  uint32_t carry=0;
270  uint32_t length=0;
271 
272  get_parameter_incremental_hash(hash, carry, length);
273  hash=CHash::FinalizeIncrementalMurmurHash3(hash, carry, length);
274 
275  SG_DEBUG("leaving\n")
276  return (m_hash!=hash);
277 }
278 
280 {
282  return sg_parallel;
283 }
284 
286 {
287  SG_REF(new_version);
289  sg_version=new_version;
290 }
291 
293 {
295  return sg_version;
296 }
297 
298 bool CSGObject::is_generic(EPrimitiveType* generic) const
299 {
300  *generic = m_generic;
301 
302  return m_generic != PT_NOT_GENERIC;
303 }
304 
306 {
307  m_generic = PT_NOT_GENERIC;
308 }
309 
310 void CSGObject::print_serializable(const char* prefix)
311 {
312  SG_PRINT("\n%s\n================================================================================\n", get_name())
313  m_parameters->print(prefix);
314 }
315 
317  const char* prefix, int32_t param_version)
318 {
319  SG_DEBUG("START SAVING CSGObject '%s'\n", get_name())
320  try
321  {
323  }
324  catch (ShogunException& e)
325  {
326  SG_SWARNING("%s%s::save_serializable_pre(): ShogunException: "
327  "%s\n", prefix, get_name(),
329  return false;
330  }
331 
332  if (!m_save_pre_called)
333  {
334  SG_SWARNING("%s%s::save_serializable_pre(): Implementation "
335  "error: BASE_CLASS::SAVE_SERIALIZABLE_PRE() not "
336  "called!\n", prefix, get_name());
337  return false;
338  }
339 
340  /* save parameter version */
341  if (!save_parameter_version(file, prefix, param_version))
342  return false;
343 
344  if (!m_parameters->save(file, prefix))
345  return false;
346 
347  try
348  {
350  }
351  catch (ShogunException& e)
352  {
353  SG_SWARNING("%s%s::save_serializable_post(): ShogunException: "
354  "%s\n", prefix, get_name(),
356  return false;
357  }
358 
359  if (!m_save_post_called)
360  {
361  SG_SWARNING("%s%s::save_serializable_post(): Implementation "
362  "error: BASE_CLASS::SAVE_SERIALIZABLE_POST() not "
363  "called!\n", prefix, get_name());
364  return false;
365  }
366 
367  if (prefix == NULL || *prefix == '\0')
368  file->close();
369 
370  SG_DEBUG("DONE SAVING CSGObject '%s' (%p)\n", get_name(), this)
371 
372  return true;
373 }
374 
376  const char* prefix, int32_t param_version)
377 {
378  REQUIRE(file != NULL, "Serializable file object should be != NULL\n");
379 
380  SG_DEBUG("START LOADING CSGObject '%s'\n", get_name())
381  try
382  {
384  }
385  catch (ShogunException& e)
386  {
387  SG_SWARNING("%s%s::load_serializable_pre(): ShogunException: "
388  "%s\n", prefix, get_name(),
390  return false;
391  }
392  if (!m_load_pre_called)
393  {
394  SG_SWARNING("%s%s::load_serializable_pre(): Implementation "
395  "error: BASE_CLASS::LOAD_SERIALIZABLE_PRE() not "
396  "called!\n", prefix, get_name());
397  return false;
398  }
399 
400  /* try to load version of parameters */
401  int32_t file_version=load_parameter_version(file, prefix);
402  SG_DEBUG("file_version=%d, current_version=%d\n", file_version, param_version)
403 
404  if (file_version<0)
405  {
406  SG_WARNING("%s%s::load_serializable(): File contains no parameter "
407  "version. Seems like your file is from the days before this "
408  "was introduced. Ignore warning or serialize with this version "
409  "of shogun to get rid of above and this warnings.\n",
410  prefix, get_name());
411  }
412 
413  if (file_version>param_version)
414  {
415  if (param_version==Version::get_version_parameter())
416  {
417  SG_WARNING("%s%s::load_serializable(): parameter version of file "
418  "larger than the one of shogun. Try with a more recent"
419  "version of shogun.\n", prefix, get_name());
420  }
421  else
422  {
423  SG_WARNING("%s%s::load_serializable(): parameter version of file "
424  "larger than the current. This is probably an implementation"
425  " error.\n", prefix, get_name());
426  }
427  return false;
428  }
429 
430  if (file_version==param_version)
431  {
432  /* load normally if file has current version */
433  SG_DEBUG("loading normally\n")
434 
435  /* load all parameters, except new ones */
436  for (int32_t i=0; i<m_parameters->get_num_parameters(); i++)
437  {
439 
440  /* skip new parameters */
441  if (is_param_new(SGParamInfo(current, param_version)))
442  continue;
443 
444  if (!current->load(file, prefix))
445  return false;
446  }
447  }
448  else
449  {
450  /* load all parameters from file, mappings to current version */
451  DynArray<TParameter*>* param_base=load_all_file_parameters(file_version,
452  param_version, file, prefix);
453 
454  /* create an array of param infos from current parameters */
455  DynArray<const SGParamInfo*>* param_infos=
457  for (index_t i=0; i<m_parameters->get_num_parameters(); ++i)
458  {
460 
461  /* skip new parameters */
462  if (is_param_new(SGParamInfo(current, param_version)))
463  continue;
464 
465  param_infos->append_element(
466  new SGParamInfo(current, param_version));
467  }
468 
469  /* map all parameters, result may be empty if input is */
470  map_parameters(param_base, file_version, param_infos);
471  SG_DEBUG("mapping is done!\n")
472 
473  /* this is assumed now, mapping worked or no parameters in base */
474  ASSERT(file_version==param_version || !param_base->get_num_elements())
475 
476  /* delete above created param infos */
477  for (index_t i=0; i<param_infos->get_num_elements(); ++i)
478  delete param_infos->get_element(i);
479 
480  delete param_infos;
481 
482  /* replace parameters by loaded and mapped */
483  SG_DEBUG("replacing parameter data by loaded/mapped values\n")
484  for (index_t i=0; i<m_parameters->get_num_parameters(); ++i)
485  {
487  char* s=SG_MALLOC(char, 200);
488  current->m_datatype.to_string(s, 200);
489  SG_DEBUG("processing \"%s\": %s\n", current->m_name, s)
490  SG_FREE(s);
491 
492  /* skip new parameters */
493  if (is_param_new(SGParamInfo(current, param_version)))
494  {
495  SG_DEBUG("%s is new, skipping\n", current->m_name)
496  continue;
497  }
498 
499  /* search for current parameter in mapped ones */
500  index_t index=CMath::binary_search(param_base->get_array(),
501  param_base->get_num_elements(), current);
502 
503  TParameter* migrated=param_base->get_element(index);
504 
505  /* now copy data from migrated TParameter instance
506  * (this automatically deletes the old data allocations) */
507  SG_DEBUG("copying migrated data into parameter\n")
508  current->copy_data(migrated);
509  }
510 
511  /* delete the migrated parameter data base */
512  SG_DEBUG("deleting old parameter base\n")
513  for (index_t i=0; i<param_base->get_num_elements(); ++i)
514  {
515  TParameter* current=param_base->get_element(i);
516  SG_DEBUG("deleting old \"%s\"\n", current->m_name)
517  delete current;
518  }
519  delete param_base;
520  }
521 
522  try
523  {
525  }
526  catch (ShogunException& e)
527  {
528  SG_SWARNING("%s%s::load_serializable_post(): ShogunException: "
529  "%s\n", prefix, get_name(),
531  return false;
532  }
533 
534  if (!m_load_post_called)
535  {
536  SG_SWARNING("%s%s::load_serializable_post(): Implementation "
537  "error: BASE_CLASS::LOAD_SERIALIZABLE_POST() not "
538  "called!\n", prefix, get_name());
539  return false;
540  }
541  SG_DEBUG("DONE LOADING CSGObject '%s' (%p)\n", get_name(), this)
542 
543  return true;
544 }
545 
547  const SGParamInfo* param_info, int32_t file_version,
548  CSerializableFile* file, const char* prefix)
549 {
550  /* ensure that recursion works */
551  SG_SDEBUG("entering %s::load_file_parameters\n", get_name())
552  if (file_version>param_info->m_param_version)
553  {
554  SG_SERROR("parameter version of \"%s\" in file (%d) is more recent than"
555  " provided %d!\n", param_info->m_name, file_version,
556  param_info->m_param_version);
557  }
558 
559  DynArray<TParameter*>* result_array=new DynArray<TParameter*>();
560 
561  /* do mapping */
562  char* s=param_info->to_string();
563  SG_SDEBUG("try to get mapping for: %s\n", s)
564  SG_FREE(s);
565 
566  /* mapping has only be deleted if was created here (no mapping was found) */
567  bool free_mapped=false;
568  DynArray<const SGParamInfo*>* mapped=m_parameter_map->get(param_info);
569  if (!mapped)
570  {
571  /* since a new mapped array will be created, set deletion flag */
572  free_mapped=true;
573  mapped=new DynArray<const SGParamInfo*>();
574 
575  /* if no mapping was found, nothing has changed. Simply create new param
576  * info with decreased version */
577  SG_SDEBUG("no mapping found\n")
578  if (file_version<param_info->m_param_version)
579  {
580  /* create new array and put param info with decreased version in */
581  mapped->append_element(new SGParamInfo(param_info->m_name,
582  param_info->m_ctype, param_info->m_stype,
583  param_info->m_ptype, param_info->m_param_version-1));
584 
585  SG_SDEBUG("using:\n")
586  for (index_t i=0; i<mapped->get_num_elements(); ++i)
587  {
588  s=mapped->get_element(i)->to_string();
589  SG_SDEBUG("\t%s\n", s)
590  SG_FREE(s);
591  }
592  }
593  else
594  {
595  /* create new array and put original param info in */
596  SG_SDEBUG("reached file version\n")
597  mapped->append_element(param_info->duplicate());
598  }
599  }
600  else
601  {
602  SG_SDEBUG("found:\n")
603  for (index_t i=0; i<mapped->get_num_elements(); ++i)
604  {
605  s=mapped->get_element(i)->to_string();
606  SG_SDEBUG("\t%s\n", s)
607  SG_FREE(s);
608  }
609  }
610 
611 
612  /* case file version same as provided version.
613  * means that parameters have to be loaded from file, recursion stops */
614  if (file_version==param_info->m_param_version)
615  {
616  SG_SDEBUG("recursion stop, loading from file\n")
617  /* load all parameters in mapping from file */
618  for (index_t i=0; i<mapped->get_num_elements(); ++i)
619  {
620  const SGParamInfo* current=mapped->get_element(i);
621  s=current->to_string();
622  SG_SDEBUG("loading %s\n", s)
623  SG_FREE(s);
624 
625  TParameter* loaded;
626  /* allocate memory for length and matrix/vector
627  * This has to be done because this stuff normally is in the class
628  * variables which do not exist in this case. Deletion is handled
629  * via the allocated_from_scratch flag of TParameter */
630 
631  /* create type and copy lengths, empty data for now */
632  TSGDataType type(current->m_ctype, current->m_stype,
633  current->m_ptype);
634  loaded=new TParameter(&type, NULL, current->m_name, "");
635 
636  /* allocate data/length variables for the TParameter, lengths are not
637  * important now, so set to one */
638  SGVector<index_t> dims(2);
639  dims[0]=1;
640  dims[1]=1;
641  loaded->allocate_data_from_scratch(dims);
642 
643  /* tell instance to load data from file */
644  if (!loaded->load(file, prefix))
645  {
646  s=param_info->to_string();
647  SG_ERROR("Could not load %s. The reason for this might be wrong "
648  "parameter mappings\n", s);
649  SG_FREE(s);
650  }
651 
652  SG_DEBUG("loaded lengths: y=%d, x=%d\n",
653  loaded->m_datatype.m_length_y ? *loaded->m_datatype.m_length_y : -1,
654  loaded->m_datatype.m_length_x ? *loaded->m_datatype.m_length_x : -1);
655 
656  /* append new TParameter to result array */
657  result_array->append_element(loaded);
658  }
659  SG_SDEBUG("done loading from file\n")
660  }
661  /* recursion with mapped type, a mapping exists in this case (ensured by
662  * above assert) */
663  else
664  {
665  /* for all elements in mapping, do recursion */
666  for (index_t i=0; i<mapped->get_num_elements(); ++i)
667  {
668  const SGParamInfo* current=mapped->get_element(i);
669  s=current->to_string();
670  SG_SDEBUG("starting recursion over %s\n", s)
671 
672  /* recursively get all file parameters for this parameter */
673  DynArray<TParameter*>* recursion_array=
674  load_file_parameters(current, file_version, file, prefix);
675 
676  SG_SDEBUG("recursion over %s done\n", s)
677  SG_FREE(s);
678 
679  /* append all recursion data to current array */
680  SG_SDEBUG("appending all results to current result\n")
681  for (index_t j=0; j<recursion_array->get_num_elements(); ++j)
682  result_array->append_element(recursion_array->get_element(j));
683 
684  /* clean up */
685  delete recursion_array;
686  }
687  }
688 
689  SG_SDEBUG("cleaning up old mapping \n")
690 
691 
692  /* clean up mapping */
693  if (free_mapped)
694  {
695  for (index_t i=0; i<mapped->get_num_elements(); ++i)
696  delete mapped->get_element(i);
697 
698  delete mapped;
699  }
700 
701  SG_SDEBUG("leaving %s::load_file_parameters\n", get_name())
702  return result_array;
703 }
704 
706  int32_t current_version, CSerializableFile* file, const char* prefix)
707 {
709 
710  for (index_t i=0; i<m_parameters->get_num_parameters(); ++i)
711  {
713 
714  /* extract current parameter info */
715  const SGParamInfo* info=new SGParamInfo(current, current_version);
716 
717  /* skip new parameters */
718  if (is_param_new(*info))
719  {
720  delete info;
721  continue;
722  }
723 
724  /* in the other case, load parameters data from file */
725  DynArray<TParameter*>* temp=load_file_parameters(info, file_version,
726  file, prefix);
727 
728  /* and append them all to array */
729  for (index_t j=0; j<temp->get_num_elements(); ++j)
730  result->append_element(temp->get_element(j));
731 
732  /* clean up */
733  delete temp;
734  delete info;
735  }
736 
737  /* sort array before returning */
738  CMath::qsort(result->get_array(), result->get_num_elements());
739 
740  return result;
741 }
742 
744  int32_t& base_version, DynArray<const SGParamInfo*>* target_param_infos)
745 {
746  SG_DEBUG("entering %s::map_parameters\n", get_name())
747  /* NOTE: currently the migration is done step by step over every version */
748 
749  if (!target_param_infos->get_num_elements())
750  {
751  SG_DEBUG("no target parameter infos\n")
752  SG_DEBUG("leaving %s::map_parameters\n", get_name())
753  return;
754  }
755 
756  /* map all target parameter infos once */
757  DynArray<const SGParamInfo*>* mapped_infos=
760  for (index_t i=0; i<target_param_infos->get_num_elements(); ++i)
761  {
762  const SGParamInfo* current=target_param_infos->get_element(i);
763 
764  char* s=current->to_string();
765  SG_DEBUG("trying to get parameter mapping for %s\n", s)
766  SG_FREE(s);
767 
769 
770  if (mapped)
771  {
772  mapped_infos->append_element(mapped->get_element(0));
773  for (index_t j=0; j<mapped->get_num_elements(); ++j)
774  {
775  s=mapped->get_element(j)->to_string();
776  SG_DEBUG("found mapping: %s\n", s)
777  SG_FREE(s);
778  }
779  }
780  else
781  {
782  /* these have to be deleted above */
783  SGParamInfo* no_change=new SGParamInfo(*current);
784  no_change->m_param_version--;
785  s=no_change->to_string();
786  SG_DEBUG("no mapping found, using %s\n", s)
787  SG_FREE(s);
788  mapped_infos->append_element(no_change);
789  to_delete->append_element(no_change);
790  }
791  }
792 
793  /* assert that at least one mapping exists */
794  ASSERT(mapped_infos->get_num_elements())
795  int32_t mapped_version=mapped_infos->get_element(0)->m_param_version;
796 
797  /* assert that all param versions are equal for now (if not empty param) */
798  for (index_t i=1; i<mapped_infos->get_num_elements(); ++i)
799  {
800  ASSERT(mapped_infos->get_element(i)->m_param_version==mapped_version ||
801  *mapped_infos->get_element(i)==SGParamInfo());
802  }
803 
804  /* recursion, after this call, base is at version of mapped infos */
805  if (mapped_version>base_version)
806  map_parameters(param_base, base_version, mapped_infos);
807 
808  /* delete mapped parameter infos array */
809  delete mapped_infos;
810 
811  /* delete newly created parameter infos which have to name or type change */
812  for (index_t i=0; i<to_delete->get_num_elements(); ++i)
813  delete to_delete->get_element(i);
814 
815  delete to_delete;
816 
817  ASSERT(base_version==mapped_version)
818 
819  /* do migration of one version step, create new base */
821  for (index_t i=0; i<target_param_infos->get_num_elements(); ++i)
822  {
823  char* s=target_param_infos->get_element(i)->to_string();
824  SG_DEBUG("migrating one step to target: %s\n", s)
825  SG_FREE(s);
826  TParameter* p=migrate(param_base, target_param_infos->get_element(i));
827  new_base->append_element(p);
828  }
829 
830  /* replace base by new base, delete old base, if it was created in migrate */
831  SG_DEBUG("deleting parameters base version %d\n", base_version)
832  for (index_t i=0; i<param_base->get_num_elements(); ++i)
833  delete param_base->get_element(i);
834 
835  SG_DEBUG("replacing old parameter base\n")
836  *param_base=*new_base;
837  base_version=mapped_version+1;
838 
839  SG_DEBUG("new parameter base of size %d:\n", param_base->get_num_elements())
840  for (index_t i=0; i<param_base->get_num_elements(); ++i)
841  {
842  TParameter* current=param_base->get_element(i);
843  TSGDataType type=current->m_datatype;
844  if (type.m_ptype==PT_SGOBJECT)
845  {
846  if (type.m_ctype==CT_SCALAR)
847  {
848  CSGObject* object=*(CSGObject**)current->m_parameter;
849  SG_DEBUG("(%d:) \"%s\": sgobject \"%s\" at %p\n", i,
850  current->m_name, object ? object->get_name() : "",
851  object);
852  }
853  else
854  {
855  index_t len=1;
856  len*=type.m_length_x ? *type.m_length_x : 1;
857  len*=type.m_length_y ? *type.m_length_y : 1;
858  CSGObject** array=*(CSGObject***)current->m_parameter;
859  for (index_t j=0; j<len; ++j)
860  {
861  CSGObject* object=array[j];
862  SG_DEBUG("(%d:) \"%s\": sgobject \"%s\" at %p\n", i,
863  current->m_name, object ? object->get_name() : "",
864  object);
865  }
866  }
867  }
868  else
869  {
870  char* s=SG_MALLOC(char, 200);
871  current->m_datatype.to_string(s, 200);
872  SG_DEBUG("(%d:) \"%s\": type: %s at %p\n", i, current->m_name, s,
873  current->m_parameter);
874  SG_FREE(s);
875  }
876  }
877 
878  /* because content was copied, new base may be deleted */
879  delete new_base;
880 
881  /* sort the just created new base */
882  SG_DEBUG("sorting base\n")
883  CMath::qsort(param_base->get_array(), param_base->get_num_elements());
884 
885  /* at this point the param_base is at the same version as the version of
886  * the provided parameter infos */
887  SG_DEBUG("leaving %s::map_parameters\n", get_name())
888 }
889 
891  const SGParamInfo* target, TParameter*& replacement,
892  TParameter*& to_migrate, char* old_name)
893 {
894  SG_DEBUG("CSGObject::entering CSGObject::one_to_one_migration_prepare() for "
895  "\"%s\"\n", target->m_name);
896 
897  /* generate type of target structure */
898  TSGDataType type(target->m_ctype, target->m_stype, target->m_ptype);
899 
900  /* first find index of needed data.
901  * in this case, element in base with same name or old name */
902  char* name=target->m_name;
903  if (old_name)
904  name=old_name;
905 
906  /* dummy for searching, search and save result in to_migrate parameter */
907  TParameter* t=new TParameter(&type, NULL, name, "");
908  index_t i=CMath::binary_search(param_base->get_array(),
909  param_base->get_num_elements(), t);
910  delete t;
911 
912  /* assert that something is found */
913  ASSERT(i>=0)
914  to_migrate=param_base->get_element(i);
915 
916  /* result structure, data NULL for now */
917  replacement=new TParameter(&type, NULL, target->m_name,
918  to_migrate->m_description);
919 
920  SGVector<index_t> dims(2);
921  dims[0]=1;
922  dims[1]=1;
923  /* allocate content to write into, lengths are needed for this */
924  if (to_migrate->m_datatype.m_length_x)
925  dims[0]=*to_migrate->m_datatype.m_length_x;
926 
927  if (to_migrate->m_datatype.m_length_y)
928  dims[1]=*to_migrate->m_datatype.m_length_y;
929 
930  replacement->allocate_data_from_scratch(dims);
931 
932  /* in case of sgobject, copy pointer data and SG_REF */
933  if (to_migrate->m_datatype.m_ptype==PT_SGOBJECT)
934  {
935  /* note that the memory is already allocated before the migrate call */
936  CSGObject* object=*((CSGObject**)to_migrate->m_parameter);
937  *((CSGObject**)replacement->m_parameter)=object;
938  SG_REF(object);
939  SG_DEBUG("copied and SG_REF sgobject pointer for \"%s\" at %p\n",
940  object->get_name(), object);
941  }
942 
943  /* tell the old TParameter to delete its data on deletion */
944  to_migrate->m_delete_data=true;
945 
946  SG_DEBUG("CSGObject::leaving CSGObject::one_to_one_migration_prepare() for "
947  "\"%s\"\n", target->m_name);
948 }
949 
951  const SGParamInfo* target)
952 {
953  SG_DEBUG("entering %s::migrate\n", get_name())
954  /* this is only executed, iff there was no migration method which handled
955  * migration to the provided target. In this case, it is assumed that the
956  * parameter simply has not changed. Verify this here and return copy of
957  * data in case its true.
958  * If not, throw an exception -- parameter migration HAS to be implemented
959  * by hand everytime, a parameter changes type or name. */
960 
961  TParameter* result=NULL;
962 
963  /* first find index of needed data.
964  * in this case, element in base with same name */
965  /* type is also needed */
966  TSGDataType type(target->m_ctype, target->m_stype,
967  target->m_ptype);
968 
969  /* dummy for searching, search and save result */
970  TParameter* t=new TParameter(&type, NULL, target->m_name, "");
971  index_t i=CMath::binary_search(param_base->get_array(),
972  param_base->get_num_elements(), t);
973  delete t;
974 
975  /* check if name change occurred while no migration method was specified */
976  if (i<0)
977  {
978  SG_ERROR("Name change for parameter that has to be mapped to \"%s\","
979  " and to no migration method available\n", target->m_name);
980  }
981 
982  TParameter* to_migrate=param_base->get_element(i);
983 
984  /* check if element in base is equal to target one */
985  if (*target==SGParamInfo(to_migrate, target->m_param_version))
986  {
987  char* s=SG_MALLOC(char, 200);
988  to_migrate->m_datatype.to_string(s, 200);
989  SG_DEBUG("nothing changed, using old data: %s\n", s)
990  SG_FREE(s);
991  result=new TParameter(&to_migrate->m_datatype, NULL, to_migrate->m_name,
992  to_migrate->m_description);
993 
994  SGVector<index_t> dims(2);
995  dims[0]=1;
996  dims[1]=1;
997  if (to_migrate->m_datatype.m_length_x)
998  dims[0]=*to_migrate->m_datatype.m_length_x;
999 
1000  if (to_migrate->m_datatype.m_length_y)
1001  dims[1]=*to_migrate->m_datatype.m_length_y;
1002 
1003  /* allocate lengths and evtl scalar data but not non-scalar data (no
1004  * new_cont call */
1005  result->allocate_data_from_scratch(dims, false);
1006 
1007  /* now use old data */
1008  if (to_migrate->m_datatype.m_ctype==CT_SCALAR &&
1009  to_migrate->m_datatype.m_ptype!=PT_SGOBJECT)
1010  {
1011  /* copy data */
1012  SG_DEBUG("copying scalar data\n")
1013  memcpy(result->m_parameter,to_migrate->m_parameter,
1014  to_migrate->m_datatype.get_size());
1015  }
1016  else
1017  {
1018  /* copy content of pointer */
1019  SG_DEBUG("copying content of poitner for non-scalar data\n")
1020  *(void**)result->m_parameter=*(void**)(to_migrate->m_parameter);
1021  }
1022  }
1023  else
1024  {
1025  char* s=target->to_string();
1026  SG_ERROR("No migration method available for %s!\n", s)
1027  SG_FREE(s);
1028  }
1029 
1030  SG_DEBUG("leaving %s::migrate\n", get_name())
1031 
1032  return result;
1033 }
1034 
1035 bool CSGObject::save_parameter_version(CSerializableFile* file,
1036  const char* prefix, int32_t param_version)
1037 {
1038  TSGDataType t(CT_SCALAR, ST_NONE, PT_INT32);
1039  TParameter p(&t, &param_version, "version_parameter",
1040  "Version of parameters of this object");
1041  return p.save(file, prefix);
1042 }
1043 
1044 int32_t CSGObject::load_parameter_version(CSerializableFile* file,
1045  const char* prefix)
1046 {
1047  REQUIRE(file != NULL, "Serializable file object should be != NULL");
1048 
1049  TSGDataType t(CT_SCALAR, ST_NONE, PT_INT32);
1050  int32_t v;
1051  TParameter tp(&t, &v, "version_parameter", "");
1052  if (tp.load(file, prefix))
1053  return v;
1054  else
1055  return -1;
1056 }
1057 
1059 {
1060  m_load_pre_called = true;
1061 }
1062 
1064 {
1065  m_load_post_called = true;
1066 }
1067 
1069 {
1070  m_save_pre_called = true;
1071 }
1072 
1074 {
1075  m_save_post_called = true;
1076 }
1077 
1078 #ifdef TRACE_MEMORY_ALLOCS
1079 #include <shogun/lib/Map.h>
1080 extern CMap<void*, shogun::MemoryBlock>* sg_mallocs;
1081 #endif
1082 
1083 void CSGObject::init()
1084 {
1085 #ifdef TRACE_MEMORY_ALLOCS
1086  if (sg_mallocs)
1087  {
1088  int32_t idx=sg_mallocs->index_of(this);
1089  if (idx>-1)
1090  {
1091  MemoryBlock* b=sg_mallocs->get_element_ptr(idx);
1092  b->set_sgobject();
1093  }
1094  }
1095 #endif
1096 
1097  io = NULL;
1098  parallel = NULL;
1099  version = NULL;
1100  m_parameters = new Parameter();
1104  m_generic = PT_NOT_GENERIC;
1105  m_load_pre_called = false;
1106  m_load_post_called = false;
1107  m_save_pre_called = false;
1108  m_save_post_called = false;
1109  m_hash = 0;
1110 }
1111 
1113 {
1114  SG_PRINT("parameters available for model selection for %s:\n", get_name())
1115 
1117 
1118  if (!num_param)
1119  SG_PRINT("\tnone\n")
1120 
1121  for (index_t i=0; i<num_param; i++)
1122  {
1124  index_t l=200;
1125  char* type=SG_MALLOC(char, l);
1126  if (type)
1127  {
1128  current->m_datatype.to_string(type, l);
1129  SG_PRINT("\t%s (%s): %s\n", current->m_name, current->m_description,
1130  type);
1131  SG_FREE(type);
1132  }
1133  }
1134 }
1135 
1137 {
1139 
1140  SGStringList<char> result(num_param, -1);
1141 
1142  index_t max_string_length=-1;
1143 
1144  for (index_t i=0; i<num_param; i++)
1145  {
1147  index_t len=strlen(name);
1148  // +1 to have a zero terminated string
1149  result.strings[i]=SGString<char>(name, len+1);
1150 
1151  if (len>max_string_length)
1152  max_string_length=len;
1153  }
1154 
1155  result.max_string_length=max_string_length;
1156 
1157  return result;
1158 }
1159 
1160 char* CSGObject::get_modsel_param_descr(const char* param_name)
1161 {
1162  index_t index=get_modsel_param_index(param_name);
1163 
1164  if (index<0)
1165  {
1166  SG_ERROR("There is no model selection parameter called \"%s\" for %s",
1167  param_name, get_name());
1168  }
1169 
1171 }
1172 
1174 {
1175  /* use fact that names extracted from below method are in same order than
1176  * in m_model_selection_parameters variable */
1178 
1179  /* search for parameter with provided name */
1180  index_t index=-1;
1181  for (index_t i=0; i<names.num_strings; i++)
1182  {
1184  if (!strcmp(param_name, current->m_name))
1185  {
1186  index=i;
1187  break;
1188  }
1189  }
1190 
1191  return index;
1192 }
1193 
1194 bool CSGObject::is_param_new(const SGParamInfo param_info) const
1195 {
1196  /* check if parameter is new in this version (has empty mapping) */
1197  DynArray<const SGParamInfo*>* value=m_parameter_map->get(&param_info);
1198  bool result=value && *value->get_element(0) == SGParamInfo();
1199 
1200  return result;
1201 }
1202 
1203 void CSGObject::get_parameter_incremental_hash(uint32_t& hash, uint32_t& carry,
1204  uint32_t& total_length)
1205 {
1206  for (index_t i=0; i<m_parameters->get_num_parameters(); i++)
1207  {
1209 
1210  SG_DEBUG("Updating hash for parameter %s.%s\n", get_name(), p->m_name);
1211 
1212  if (p->m_datatype.m_ptype == PT_SGOBJECT)
1213  {
1214  if (p->m_datatype.m_ctype == CT_SCALAR)
1215  {
1216  CSGObject* child = *((CSGObject**)(p->m_parameter));
1217 
1218  if (child)
1219  {
1220  child->get_parameter_incremental_hash(hash, carry,
1221  total_length);
1222  }
1223  }
1224  else if (p->m_datatype.m_ctype==CT_VECTOR ||
1225  p->m_datatype.m_ctype==CT_SGVECTOR)
1226  {
1227  CSGObject** child=(*(CSGObject***)(p->m_parameter));
1228 
1229  for (index_t j=0; j<*(p->m_datatype.m_length_y); j++)
1230  {
1231  if (child[j])
1232  {
1233  child[j]->get_parameter_incremental_hash(hash, carry,
1234  total_length);
1235  }
1236  }
1237  }
1238  }
1239  else
1240  p->get_incremental_hash(hash, carry, total_length);
1241  }
1242 }
1243 
1245 {
1246  for (index_t i=0; i<m_gradient_parameters->get_num_parameters(); i++)
1247  {
1249  dict->add(p, this);
1250  }
1251 
1253  {
1255  CSGObject* child=*(CSGObject**)(p->m_parameter);
1256 
1257  if ((p->m_datatype.m_ptype == PT_SGOBJECT) &&
1258  (p->m_datatype.m_ctype == CT_SCALAR) && child)
1259  {
1261  }
1262  }
1263 }
1264 
1265 bool CSGObject::equals(CSGObject* other, float64_t accuracy, bool tolerant)
1266 {
1267  SG_DEBUG("entering %s::equals()\n", get_name());
1268 
1269  if (other==this)
1270  {
1271  SG_DEBUG("leaving %s::equals(): other object is me\n", get_name());
1272  return true;
1273  }
1274 
1275  if (!other)
1276  {
1277  SG_DEBUG("leaving %s::equals(): other object is NULL\n", get_name());
1278  return false;
1279  }
1280 
1281  SG_DEBUG("comparing \"%s\" to \"%s\"\n", get_name(), other->get_name());
1282 
1283  /* a crude type check based on the get_name */
1284  if (strcmp(other->get_name(), get_name()))
1285  {
1286  SG_INFO("leaving %s::equals(): name of other object differs\n", get_name());
1287  return false;
1288  }
1289 
1290  /* should not be necessary but just ot be sure that type has not changed.
1291  * Will assume that parameters are in same order with same name from here */
1293  {
1294  SG_INFO("leaving %s::equals(): number of parameters of other object "
1295  "differs\n", get_name());
1296  return false;
1297  }
1298 
1299  for (index_t i=0; i<m_parameters->get_num_parameters(); ++i)
1300  {
1301  SG_DEBUG("comparing parameter %d\n", i);
1302 
1303  TParameter* this_param=m_parameters->get_parameter(i);
1304  TParameter* other_param=other->m_parameters->get_parameter(i);
1305 
1306  /* some checks to make sure parameters have same order and names and
1307  * are not NULL. Should never be the case but check anyway. */
1308  if (!this_param && !other_param)
1309  continue;
1310 
1311  if (!this_param && other_param)
1312  {
1313  SG_DEBUG("leaving %s::equals(): parameter %d is NULL where other's "
1314  "parameter \"%s\" is not\n", get_name(), other_param->m_name);
1315  return false;
1316  }
1317 
1318  if (this_param && !other_param)
1319  {
1320  SG_DEBUG("leaving %s::equals(): parameter %d is \"%s\" where other's "
1321  "parameter is NULL\n", get_name(), this_param->m_name);
1322  return false;
1323  }
1324 
1325  SG_DEBUG("comparing parameter \"%s\" to other's \"%s\"\n",
1326  this_param->m_name, other_param->m_name);
1327 
1328  /* hard-wired exception for DynamicObjectArray parameter num_elements */
1329  if (!strcmp("DynamicObjectArray", get_name()) &&
1330  !strcmp(this_param->m_name, "num_elements") &&
1331  !strcmp(other_param->m_name, "num_elements"))
1332  {
1333  SG_DEBUG("Ignoring DynamicObjectArray::num_elements field\n");
1334  continue;
1335  }
1336 
1337  /* hard-wired exception for DynamicArray parameter num_elements */
1338  if (!strcmp("DynamicArray", get_name()) &&
1339  !strcmp(this_param->m_name, "num_elements") &&
1340  !strcmp(other_param->m_name, "num_elements"))
1341  {
1342  SG_DEBUG("Ignoring DynamicArray::num_elements field\n");
1343  continue;
1344  }
1345 
1346  /* use equals method of TParameter from here */
1347  if (!this_param->equals(other_param, accuracy, tolerant))
1348  {
1349  SG_INFO("leaving %s::equals(): parameters at position %d with name"
1350  " \"%s\" differs from other object parameter with name "
1351  "\"%s\"\n",
1352  get_name(), i, this_param->m_name, other_param->m_name);
1353  return false;
1354  }
1355  }
1356 
1357  SG_DEBUG("leaving %s::equals(): object are equal\n", get_name());
1358  return true;
1359 }
1360 
1362 {
1363  SG_DEBUG("entering %s::clone()\n", get_name());
1364 
1365  SG_DEBUG("constructing an empty instance of %s\n", get_name());
1366  CSGObject* copy=new_sgserializable(get_name(), this->m_generic);
1367 
1368  SG_REF(copy);
1369 
1370  REQUIRE(copy, "Could not create empty instance of \"%s\". The reason for "
1371  "this usually is that get_name() of the class returns something "
1372  "wrong, or that a class has a wrongly set generic type.\n",
1373  get_name());
1374 
1375  for (index_t i=0; i<m_parameters->get_num_parameters(); ++i)
1376  {
1377  SG_DEBUG("cloning parameter \"%s\" at index %d\n",
1379 
1381  {
1382  SG_DEBUG("leaving %s::clone(): Clone failed. Returning NULL\n",
1383  get_name());
1384  return NULL;
1385  }
1386  }
1387 
1388  SG_DEBUG("leaving %s::clone(): Clone successful\n", get_name());
1389  return copy;
1390 }
virtual const char * get_name() const =0
EStructType m_stype
Definition: ParameterMap.h:97
SGStringList< char > get_modelsel_names()
Definition: SGObject.cpp:1136
#define SG_INFO(...)
Definition: SGIO.h:118
T get_element(int32_t index) const
Definition: DynArray.h:142
template class SGStringList
Definition: SGObject.h:40
Parallel * get_global_parallel()
Definition: SGObject.cpp:279
virtual bool save_serializable(CSerializableFile *file, const char *prefix="", int32_t param_version=Version::get_version_parameter())
Definition: SGObject.cpp:316
virtual void update_parameter_hash()
Definition: SGObject.cpp:250
Class that holds informations about a certain parameter of an CSGObject. Contains name...
Definition: ParameterMap.h:32
ParameterMap * m_parameter_map
Definition: SGObject.h:514
virtual TParameter * migrate(DynArray< TParameter * > *param_base, const SGParamInfo *target)
Definition: SGObject.cpp:950
int32_t index_of(const K &key)
Definition: Map.h:154
bool append_element(T element)
Definition: DynArray.h:244
int32_t index_t
Definition: common.h:62
virtual int32_t get_num_parameters()
virtual CSGObject * clone()
Definition: SGObject.cpp:1361
Class ShogunException defines an exception which is thrown whenever an error inside of shogun occurs...
int32_t ref_count()
Definition: RefCount.cpp:31
virtual CSGObject * shallow_copy() const
Definition: SGObject.cpp:194
#define SG_SWARNING(...)
Definition: SGIO.h:178
void unset_generic()
Definition: SGObject.cpp:305
static int32_t binary_search(T *output, int32_t size, T elem)
Definition: Math.h:1809
TParameter * get_parameter(int32_t idx)
DynArray< const SGParamInfo * > * get(const SGParamInfo) const
Version * get_global_version()
Definition: SGObject.cpp:292
index_t * m_length_x
Definition: DataType.h:80
parameter struct
virtual void save_serializable_pre()
Definition: SGObject.cpp:1068
#define SG_ERROR(...)
Definition: SGIO.h:129
#define REQUIRE(x,...)
Definition: SGIO.h:206
virtual bool is_generic(EPrimitiveType *generic) const
Definition: SGObject.cpp:298
#define SG_NOTIMPLEMENTED
Definition: SGIO.h:139
Parameter * m_parameters
Definition: SGObject.h:505
virtual void print(const char *prefix="")
Definition: Parameter.cpp:2799
static uint32_t FinalizeIncrementalMurmurHash3(uint32_t h, uint32_t carry, uint32_t total_length)
Definition: Hash.cpp:376
int32_t get_num_elements() const
Definition: DynArray.h:130
static int32_t get_version_parameter()
Definition: Version.cpp:106
Parallel * parallel
Definition: SGObject.h:499
SGParamInfo * duplicate() const
#define SG_REF(x)
Definition: SGObject.h:51
Implements a map of ParameterMapElement instances Maps one key to a set of values.
Definition: ParameterMap.h:165
Datatypes that shogun supports.
Definition: DataType.h:68
Version * sg_version
Definition: init.cpp:37
T * get_element_ptr(int32_t index)
Definition: Map.h:232
static void qsort(T *output, int32_t size)
Definition: Math.h:1313
char * get_modsel_param_descr(const char *param_name)
Definition: SGObject.cpp:1160
bool equals(TParameter *other, float64_t accuracy=0.0, bool tolerant=false)
Definition: Parameter.cpp:3148
int32_t add(const K &key, const T &data)
Definition: Map.h:101
TSGDataType m_datatype
EContainerType m_ctype
Definition: ParameterMap.h:94
#define SG_PRINT(...)
Definition: SGIO.h:137
DynArray< TParameter * > * load_file_parameters(const SGParamInfo *param_info, int32_t file_version, CSerializableFile *file, const char *prefix="")
Definition: SGObject.cpp:546
Parallel * sg_parallel
Definition: init.cpp:35
Parameter class.
#define ASSERT(x)
Definition: SGIO.h:201
Class SGObject is the base class of all shogun objects.
Definition: SGObject.h:112
virtual ~CSGObject()
Definition: SGObject.cpp:140
SGIO * sg_io
Definition: init.cpp:36
void build_gradient_parameter_dictionary(CMap< TParameter *, CSGObject * > *dict)
Definition: SGObject.cpp:1244
int32_t unref()
Definition: RefCount.cpp:18
Template Dynamic array class that creates an array that can be used like a list or an array...
Definition: DynArray.h:32
double float64_t
Definition: common.h:50
virtual bool load_serializable(CSerializableFile *file, const char *prefix="", int32_t param_version=Version::get_version_parameter())
Definition: SGObject.cpp:375
DynArray< TParameter * > * load_all_file_parameters(int32_t file_version, int32_t current_version, CSerializableFile *file, const char *prefix="")
Definition: SGObject.cpp:705
Version * version
Definition: SGObject.h:502
virtual bool save(CSerializableFile *file, const char *prefix="")
Definition: Parameter.cpp:2806
virtual void save_serializable_post()
Definition: SGObject.cpp:1073
void print_modsel_params()
Definition: SGObject.cpp:1112
int32_t ref()
Definition: RefCount.cpp:5
CSGObject * new_sgserializable(const char *sgserializable_name, EPrimitiveType generic)
EPrimitiveType m_ptype
Definition: ParameterMap.h:100
Class Version provides version information.
Definition: Version.h:28
Parameter * m_model_selection_parameters
Definition: SGObject.h:508
void get_incremental_hash(uint32_t &hash, uint32_t &carry, uint32_t &total_length)
Definition: Parameter.cpp:2460
virtual bool equals(CSGObject *other, float64_t accuracy=0.0, bool tolerant=false)
Definition: SGObject.cpp:1265
index_t * m_length_y
Definition: DataType.h:78
virtual CSGObject * deep_copy() const
Definition: SGObject.cpp:200
void set_global_parallel(Parallel *parallel)
Definition: SGObject.cpp:243
void to_string(char *dest, size_t n) const
Definition: DataType.cpp:145
virtual void load_serializable_pre()
Definition: SGObject.cpp:1058
virtual void load_serializable_post()
Definition: SGObject.cpp:1063
EContainerType m_ctype
Definition: DataType.h:71
#define SG_UNREF(x)
Definition: SGObject.h:52
Class Parallel provides helper functions for multithreading.
Definition: Parallel.h:27
#define SG_DEBUG(...)
Definition: SGIO.h:107
virtual void one_to_one_migration_prepare(DynArray< TParameter * > *param_base, const SGParamInfo *target, TParameter *&replacement, TParameter *&to_migrate, char *old_name=NULL)
Definition: SGObject.cpp:890
const char * get_exception_string()
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
bool load(CSerializableFile *file, const char *prefix="")
Definition: Parameter.cpp:2649
#define SG_SDEBUG(...)
Definition: SGIO.h:168
#define SG_SGCDEBUG(...)
Definition: SGIO.h:163
SGIO * get_global_io()
Definition: SGObject.cpp:237
#define PT_NOT_GENERIC
Definition: DataType.h:21
SGString< T > * strings
Definition: SGStringList.h:88
#define SG_SERROR(...)
Definition: SGIO.h:179
void map_parameters(DynArray< TParameter * > *param_base, int32_t &base_version, DynArray< const SGParamInfo * > *target_param_infos)
Definition: SGObject.cpp:743
index_t get_modsel_param_index(const char *param_name)
Definition: SGObject.cpp:1173
T * get_array() const
Definition: DynArray.h:372
void set_global_io(SGIO *io)
Definition: SGObject.cpp:230
uint32_t m_hash
Definition: SGObject.h:517
bool copy(TParameter *target)
Definition: Parameter.cpp:3956
void copy_data(const TParameter *source)
Definition: Parameter.cpp:3088
char * to_string() const
EPrimitiveType m_ptype
Definition: DataType.h:75
#define SG_WARNING(...)
Definition: SGIO.h:128
Class SGIO, used to do input output operations throughout shogun.
Definition: SGIO.h:243
Parameter * m_gradient_parameters
Definition: SGObject.h:511
virtual void print_serializable(const char *prefix="")
Definition: SGObject.cpp:310
virtual bool parameter_hash_changed()
Definition: SGObject.cpp:264
void set_global_version(Version *version)
Definition: SGObject.cpp:285
void allocate_data_from_scratch(SGVector< index_t > dims, bool new_cont_call=true)
Definition: Parameter.cpp:2999
the class CMap, a map based on the hash-table. w: http://en.wikipedia.org/wiki/Hash_table ...
Definition: SGObject.h:36

SHOGUN Machine Learning Toolbox - Documentation