Skip to content

Commit

Permalink
register kernel as CKernel* to make put work in cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
karlnapf committed Feb 8, 2018
1 parent 2f488e4 commit 20c432a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
15 changes: 14 additions & 1 deletion examples/meta/src/meta_api/kwargs.sg
Expand Up @@ -26,10 +26,23 @@
# KernelMachine svm2 = kernel_machine("LibSVM", kernel=kernel("GaussianKernel"))



# Real example
# ------------

RealMatrix matrix(1,2)
matrix[0,0] = 0.0
matrix[0,1] = 0.1

RealFeatures features()
features.put("feature_matrix", matrix)

RealVector vector(2)
vector[0] = 0.0
vector[1] = 0.1

RegressionLabels labels()
labels.put("labels", vector)

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

13 changes: 1 addition & 12 deletions src/shogun/base/SGObject.h
Expand Up @@ -364,24 +364,13 @@ class CSGObject
}
}

#ifndef SWIG
template <typename T, std::enable_if_t<std::is_convertible<T, CSGObject*>::value>* = nullptr>
[[deprecated ("SGObject parameters should be registered as a base class.")]]
void put(const std::string& name, const T value)
{
CSGObject* v = value;
Tag<CSGObject*> tag(name);
put(tag, v);
}
#endif

/** Setter for a class parameter, identified by a name.
* Throws an exception if the class does not have such a parameter.
*
* @param name name of the parameter
* @param value value of the parameter along with type information
*/
template<typename T, typename U = typename std::enable_if_t<!std::is_convertible<T, CSGObject*>::value>>
template <typename T, typename U = void>
void put(const std::string& name, const T value) throw(ShogunException)
{
Tag<T> tag(name);
Expand Down
6 changes: 5 additions & 1 deletion src/shogun/machine/KernelMachine.cpp
Expand Up @@ -634,7 +634,11 @@ void CKernelMachine::init()
use_linadd=true;
use_bias=true;

SG_ADD((CSGObject**) &kernel, "kernel", "", MS_AVAILABLE);
// SG_ADD((CSGObject**) &kernel, "kernel", "", MS_AVAILABLE);
m_parameters->add((CSGObject**)&kernel, "kernel", "");
watch_param(
"kernel", &kernel,
AnyParameterProperties("", MS_NOT_AVAILABLE, GRADIENT_NOT_AVAILABLE));
SG_ADD((CSGObject**) &m_custom_kernel, "custom_kernel", "Custom kernel for"
" data lock", MS_NOT_AVAILABLE);
SG_ADD((CSGObject**) &m_kernel_backup, "kernel_backup",
Expand Down

0 comments on commit 20c432a

Please sign in to comment.