Skip to content

Commit

Permalink
a "fix" for octave and its ignorance about float and int
Browse files Browse the repository at this point in the history
  • Loading branch information
karlnapf committed Feb 6, 2018
1 parent e0dc2b6 commit 6da65ac
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
4 changes: 2 additions & 2 deletions examples/meta/src/meta_api/kwargs.sg
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@
# Real example
# ------------

Kernel k = kernel("GaussianKernel")
KernelMachine svm = kernel_machine("LibSVM", kernel=k)
Kernel k = kernel("GaussianKernel", log_width=2.0)
KernelMachine svm = kernel_machine("LibSVM", C1=1.0, kernel=k)

24 changes: 22 additions & 2 deletions src/shogun/base/SGObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1022,10 +1022,30 @@ void CSGObject::put(const std::string& name, T const & value) throw(ShogunExcep
put(tag, value); \
}

SGOBJECT_PUT_DEFINE(int32_t)
SGOBJECT_PUT_DEFINE(float64_t)
SGOBJECT_PUT_DEFINE(SGVector<int32_t>)
SGOBJECT_PUT_DEFINE(SGVector<float64_t>)
SGOBJECT_PUT_DEFINE(CSGObject*)

#define PUT_DEFINE_CHECK_AND_CAST(T) \
else if (has(Tag<T>(name))) \
put(Tag<T>(name), (T)value);

#define SGOBJECT_PUT_DEFINE_NUMBER(numeric_t) \
void CSGObject::put(const std::string& name, numeric_t const & value) throw(ShogunException)\
{ \
/* use correct type of possible, otherwise cast-convert */ \
if (has(Tag<numeric_t>(name))) \
put(Tag<numeric_t>(name), value); \
PUT_DEFINE_CHECK_AND_CAST(int32_t) \
PUT_DEFINE_CHECK_AND_CAST(float32_t) \
PUT_DEFINE_CHECK_AND_CAST(float64_t) \
else \
/* if nothing works, moan about original type */ \
put(Tag<numeric_t>(name), value); \
}

SGOBJECT_PUT_DEFINE_NUMBER(int32_t)
SGOBJECT_PUT_DEFINE_NUMBER(float32_t)
SGOBJECT_PUT_DEFINE_NUMBER(float64_t)

};
1 change: 1 addition & 0 deletions src/shogun/base/SGObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ class CSGObject
void put(const std::string& name, T const & value) throw(ShogunException);

SGOBJECT_PUT_DECLARE(int32_t)
SGOBJECT_PUT_DECLARE(float32_t)
SGOBJECT_PUT_DECLARE(float64_t)
SGOBJECT_PUT_DECLARE(SGVector<int32_t>)
SGOBJECT_PUT_DECLARE(SGVector<float64_t>)
Expand Down

0 comments on commit 6da65ac

Please sign in to comment.