From 0ab6ee5612205a3780aeef4919f0a4035654684a Mon Sep 17 00:00:00 2001 From: Heiko Strathmann Date: Mon, 19 Feb 2018 16:52:47 +0000 Subject: [PATCH] move swig specific put type dispatchers to swig interface --- src/interfaces/swig/shogun.i | 20 +++++++++++++++++++- src/shogun/base/SGObject.cpp | 18 ------------------ src/shogun/base/SGObject.h | 5 ----- 3 files changed, 19 insertions(+), 24 deletions(-) diff --git a/src/interfaces/swig/shogun.i b/src/interfaces/swig/shogun.i index 88407aa7ba5..f1ce36cb7f8 100644 --- a/src/interfaces/swig/shogun.i +++ b/src/interfaces/swig/shogun.i @@ -144,10 +144,28 @@ namespace shogun else $self->put(tag_t, value); } + +#ifdef SWIGJAVA + template , T>::value, T>::type> + void put_vector_or_matrix_dispatcher(const std::string& name, T value) + { + Tag> tag_vec(name); + Tag> 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(value.data())); + else + $self->put(tag_mat, value); + } +#endif // SWIGJAVA } %template(put) CSGObject::put_scalar_dispatcher; +#ifndef SWIGJAVA %template(put) CSGObject::put_scalar_dispatcher; +#endif // SWIGJAVA %template(put) CSGObject::put_scalar_dispatcher; @@ -155,7 +173,7 @@ namespace shogun %template(put) CSGObject::put, SGVector>; %template(put) CSGObject::put, SGMatrix>; #else // SWIGJAVA -%template(put) CSGObject::put_vector_or_matrix, SGMatrix>; +%template(put) CSGObject::put_vector_or_matrix_dispatcher, SGMatrix>; #endif // SWIGJAVA } // namespace shogun diff --git a/src/shogun/base/SGObject.cpp b/src/shogun/base/SGObject.cpp index c931b2fc6dc..def57d14184 100644 --- a/src/shogun/base/SGObject.cpp +++ b/src/shogun/base/SGObject.cpp @@ -1039,21 +1039,3 @@ void CSGObject::put(const std::string& name, CSGObject* value) put(Tag(name), value); } -namespace shogun -{ -// TODO: Move this to SGBase.i and make it SGMatrix (T=float64) rather than T=SGMatrix -template<> -void CSGObject::put_vector_or_matrix(const std::string& name, SGMatrix value) -{ - Tag> tag_vec(name); - Tag> 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(value.data())); - else - put(tag_mat, value); -} -} - diff --git a/src/shogun/base/SGObject.h b/src/shogun/base/SGObject.h index 67d3d37381f..bb46e9be948 100644 --- a/src/shogun/base/SGObject.h +++ b/src/shogun/base/SGObject.h @@ -421,11 +421,6 @@ class CSGObject put(Tag(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 value); - template ::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. *