Skip to content

Commit

Permalink
move swig specific put type dispatchers to swig interface
Browse files Browse the repository at this point in the history
  • Loading branch information
karlnapf committed Feb 28, 2018
1 parent 04f3bee commit 0ab6ee5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 24 deletions.
20 changes: 19 additions & 1 deletion src/interfaces/swig/shogun.i
Expand Up @@ -144,18 +144,36 @@ namespace shogun
else
$self->put(tag_t, value);
}

#ifdef SWIGJAVA
template <typename T, typename T2 = typename std::enable_if<std::is_same<SGMatrix<float64_t>, T>::value, T>::type>
void put_vector_or_matrix_dispatcher(const std::string& name, T value)
{
Tag<SGVector<float64_t>> tag_vec(name);
Tag<SGMatrix<float64_t>> tag_mat(name);

if ($self->has(tag_mat))
$self->put(tag_mat, value);
else if ((value.num_rows==1 || value.num_cols==1) && $self->has(tag_vec))
$self->put(tag_vec, SGVector<float64_t>(value.data()));
else
$self->put(tag_mat, value);
}
#endif // SWIGJAVA
}

%template(put) CSGObject::put_scalar_dispatcher<int32_t, int32_t>;
#ifndef SWIGJAVA
%template(put) CSGObject::put_scalar_dispatcher<int64_t, int64_t>;
#endif // SWIGJAVA
%template(put) CSGObject::put_scalar_dispatcher<float64_t, float64_t>;


#ifndef SWIGJAVA
%template(put) CSGObject::put<SGVector<float64_t>, SGVector<float64_t>>;
%template(put) CSGObject::put<SGMatrix<float64_t>, SGMatrix<float64_t>>;
#else // SWIGJAVA
%template(put) CSGObject::put_vector_or_matrix<SGMatrix<float64_t>, SGMatrix<float64_t>>;
%template(put) CSGObject::put_vector_or_matrix_dispatcher<SGMatrix<float64_t>, SGMatrix<float64_t>>;
#endif // SWIGJAVA

} // namespace shogun
18 changes: 0 additions & 18 deletions src/shogun/base/SGObject.cpp
Expand Up @@ -1039,21 +1039,3 @@ void CSGObject::put(const std::string& name, CSGObject* value)
put(Tag<CSGObject*>(name), value);
}

namespace shogun
{
// TODO: Move this to SGBase.i and make it SGMatrix<T> (T=float64) rather than T=SGMatrix<float64>
template<>
void CSGObject::put_vector_or_matrix(const std::string& name, SGMatrix<float64_t> value)
{
Tag<SGVector<float64_t>> tag_vec(name);
Tag<SGMatrix<float64_t>> tag_mat(name);

if (has(tag_mat))
put(tag_mat, value);
else if ((value.num_rows==1 || value.num_cols==1) && has(tag_vec))
put(tag_vec, SGVector<float64_t>(value.data()));
else
put(tag_mat, value);
}
}

5 changes: 0 additions & 5 deletions src/shogun/base/SGObject.h
Expand Up @@ -421,11 +421,6 @@ class CSGObject
put(Tag<T>(name), value);
}

// FIXME: move to swig interface.i, can be moved once the typemaps match
// also should be void put_vector_or_matrix(const std::string& name, SGMatrix<T> value);
template <typename T, typename T2 = typename std::enable_if<!std::is_base_of<CSGObject, typename std::remove_pointer<T>::type>::value, T>::type>
void put_vector_or_matrix(const std::string& name, T value);

/** Getter for a class parameter, identified by a Tag.
* Throws an exception if the class does not have such a parameter.
*
Expand Down

0 comments on commit 0ab6ee5

Please sign in to comment.