13 #ifndef __SGOBJECT_H__ 14 #define __SGOBJECT_H__ 16 #include <shogun/lib/config.h> 35 class CSerializableFile;
37 template <
class T,
class K>
class CMap;
47 #ifdef USE_REFERENCE_COUNTING 48 #define SG_REF(x) { if (x) (x)->ref(); } 49 #define SG_UNREF(x) { if (x) { if ((x)->unref()==0) (x)=NULL; } } 50 #define SG_UNREF_NO_NULL(x) { if (x) { (x)->unref(); } } 54 #define SG_UNREF_NO_NULL(x) 63 #define VA_NARGS(...) INTERNAL_EXPAND_ARGS_PRIVATE(INTERNAL_ARGS_AUGMENTER(__VA_ARGS__)) 64 #define INTERNAL_ARGS_AUGMENTER(...) unused, __VA_ARGS__ 65 #define INTERNAL_EXPAND(x) x 66 #define INTERNAL_EXPAND_ARGS_PRIVATE(...) INTERNAL_EXPAND(INTERNAL_GET_ARG_COUNT_PRIVATE(__VA_ARGS__, 5, 4, 3, 2, 1, 0)) 67 #define INTERNAL_GET_ARG_COUNT_PRIVATE(_0_, _1_, _2_, _3_, _4_, _5_, count, ...) count 71 #define VA_NARGS_IMPL(_1, _2, _3, _4, _5, N, ...) N 72 #define VA_NARGS(...) VA_NARGS_IMPL(__VA_ARGS__, 5, 4, 3, 2, 1) 76 #define VARARG_IMPL2(base, count, ...) base##count(__VA_ARGS__) 77 #define VARARG_IMPL(base, count, ...) VARARG_IMPL2(base, count, __VA_ARGS__) 78 #define VARARG(base, ...) VARARG_IMPL(base, VA_NARGS(__VA_ARGS__), __VA_ARGS__) 80 #define SG_ADD4(param, name, description, ms_available) {\ 81 m_parameters->add(param, name, description);\ 83 m_model_selection_parameters->add(param, name, description);\ 86 #define SG_ADD5(param, name, description, ms_available, gradient_available) {\ 87 m_parameters->add(param, name, description);\ 89 m_model_selection_parameters->add(param, name, description);\ 90 if (gradient_available)\ 91 m_gradient_parameters->add(param, name, description);\ 94 #define SG_ADD(...) VARARG(SG_ADD, __VA_ARGS__) 137 #ifdef USE_REFERENCE_COUNTING 156 #endif //USE_REFERENCE_COUNTING 158 #ifdef TRACE_MEMORY_ALLOCS 159 static void list_memory_allocs();
177 virtual const char*
get_name()
const = 0;
187 virtual bool is_generic(EPrimitiveType*
generic)
const;
213 const char* prefix=
"");
225 const char* prefix=
"");
299 bool has(
const std::string& name)
const 301 return type_erased_has(
BaseTag(name));
309 template <
typename T>
312 return has<T>(tag.
name());
320 template <
typename T,
typename U=
void>
321 bool has(
const std::string& name)
const 324 if(!type_erased_has(tag))
326 const Any value = type_erased_get(tag);
336 template <
typename T>
337 void set(
const Tag<T>& _tag,
const T& value)
339 if(type_erased_has(_tag))
341 if(has<T>(_tag.name()))
345 SG_ERROR(
"Type for parameter with name \"%s\" is not correct.\n",
346 _tag.name().c_str());
351 SG_ERROR(
"\"%s\" does not have a parameter with name \"%s\".\n",
362 template <
typename T,
typename U=
void>
363 void set(
const std::string& name,
const T& value)
375 template <
typename T>
378 const Any value = type_erased_get(_tag);
381 return recall_type<T>(value);
383 catch (
const std::logic_error&)
385 SG_ERROR(
"Type for parameter with name \"%s\" is not correct in \"%s\".\n",
389 return recall_type<T>(value);
398 template <
typename T,
typename U=
void>
399 T
get(
const std::string& name)
const 449 template <
typename T>
462 template <
typename T>
513 void set_global_objects();
514 void unset_global_objects();
524 bool type_erased_has(
const BaseTag& _tag)
const;
532 void type_erased_set(
const BaseTag& _tag,
const Any& any);
540 Any type_erased_get(
const BaseTag& _tag)
const;
550 void get_parameter_incremental_hash(uint32_t& hash, uint32_t& carry,
551 uint32_t& total_length);
580 EPrimitiveType m_generic;
581 bool m_load_pre_called;
582 bool m_load_post_called;
583 bool m_save_pre_called;
584 bool m_save_post_called;
589 #endif // __SGOBJECT_H__
virtual const char * get_name() const =0
SGStringList< char > get_modelsel_names()
Parallel * get_global_parallel()
virtual void update_parameter_hash()
bool has(const Tag< T > &tag) const
virtual CSGObject * clone()
Base class for all tags. This class stores name and not the type information for a shogun object...
bool clone_parameters(CSGObject *other)
Class ShogunException defines an exception which is thrown whenever an error inside of shogun occurs...
bool has(const std::string &name) const
void register_param(const std::string &name, const T &value)
void register_param(Tag< T > &_tag, const T &value)
Version * get_global_version()
virtual void save_serializable_pre()
EModelSelectionAvailability
Allows to store objects of arbitrary types by using a BaseAnyPolicy and provides a type agnostic API...
virtual bool load_serializable(CSerializableFile *file, const char *prefix="")
char * get_modsel_param_descr(const char *param_name)
virtual CSGObject * deep_copy() const
Class SGObject is the base class of all shogun objects.
Template Dynamic array class that creates an array that can be used like a list or an array...
the class CMap, a map based on the hash-table. w: http://en.wikipedia.org/wiki/Hash_table ...
virtual void save_serializable_post()
void print_modsel_params()
Acts as an identifier for a shogun object. It contains type information and name of the object...
Class Version provides version information.
Parameter * m_model_selection_parameters
virtual bool equals(CSGObject *other, float64_t accuracy=0.0, bool tolerant=false)
void set_global_parallel(Parallel *parallel)
virtual void load_serializable_pre()
virtual void load_serializable_post()
void build_gradient_parameter_dictionary(CMap< TParameter *, CSGObject *> *dict)
Class Parallel provides helper functions for multithreading.
virtual bool save_serializable(CSerializableFile *file, const char *prefix="")
all of classes and functions are contained in the shogun namespace
bool has(const std::string &name) const
index_t get_modsel_param_index(const char *param_name)
void set_global_io(SGIO *io)
virtual bool is_generic(EPrimitiveType *generic) const
virtual CSGObject * shallow_copy() const
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)
Any erase_type(const T &v)
template class SGStringList