Skip to content

Commit

Permalink
switch SGObject::parameter_names() return value to vector
Browse files Browse the repository at this point in the history
as swig typemap for std::vector exists for all supported languages
  • Loading branch information
vigsterkr committed Jan 30, 2018
1 parent ad236ed commit 532a8d4
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 31 deletions.
4 changes: 0 additions & 4 deletions src/interfaces/swig/ParameterObserver.i
@@ -1,7 +1,3 @@
%include "std_vector.i"
%include "std_string.i"
%template(ParameterList) std::vector<std::string>;

%rename(ParameterObserverCV) CParameterObserverCV;

%{
Expand Down
10 changes: 1 addition & 9 deletions src/interfaces/swig/SGBase.i
Expand Up @@ -312,20 +312,12 @@ public void readExternal(java.io.ObjectInput in) throws java.io.IOException, jav

%include "swig_typemaps.i"

#if !defined(SWIGJAVA)
%include "std_vector.i"
namespace std {
%template(IntStdVector) vector<int32_t>;
%template(DoubleStdVector) vector<float64_t>;
%template(StringStdVector) vector<string>;
}
#endif

#if defined(SWIGPYTHON) || defined(SWIGRUBY)
%include "std_set.i"
namespace std {
%template(StringSet) set<string>;
}
#endif

#ifndef SWIGR
%include <shogun/base/init.h>
Expand Down
17 changes: 8 additions & 9 deletions src/shogun/base/SGObject.cpp
@@ -1,9 +1,9 @@
/*
* This software is distributed under BSD 3-clause license (see LICENSE file).
*
* Authors: Heiko Strathmann, Soeren Sonnenburg, Sergey Lisitsyn, Thoralf Klein,
* Giovanni De Toni, Jacob Walker, Fernando Iglesias, Roman Votyakov,
* Soumyajit De, Evgeniy Andreev, Evangelos Anagnostopoulos,
* Authors: Heiko Strathmann, Soeren Sonnenburg, Sergey Lisitsyn, Thoralf Klein,
* Giovanni De Toni, Jacob Walker, Fernando Iglesias, Roman Votyakov,
* Soumyajit De, Evgeniy Andreev, Evangelos Anagnostopoulos,
* Leon Kuchenbecker, Sanuj Sharma, Wu Lin
*/

Expand Down Expand Up @@ -31,6 +31,7 @@
#include <rxcpp/operators/rx-filter.hpp>
#include <rxcpp/rx-lite.hpp>

#include <algorithm>
#include <unordered_map>
#include <memory>

Expand Down Expand Up @@ -939,13 +940,11 @@ std::string CSGObject::to_string() const
return ss.str();
}

std::set<std::string> CSGObject::parameter_names() const
std::vector<std::string> CSGObject::parameter_names() const
{
std::set<std::string> result;
for (const auto& each : self->map)
{
result.insert(each.first.name());
}
std::vector<std::string> result;
std::transform(self->map.cbegin(), self->map.cend(), std::back_inserter(result),
[](const auto& each) -> std::string { return each.first.name(); });
return result;
}

Expand Down
10 changes: 5 additions & 5 deletions src/shogun/base/SGObject.h
@@ -1,9 +1,9 @@
/*
* This software is distributed under BSD 3-clause license (see LICENSE file).
*
* Authors: Heiko Strathmann, Soeren Sonnenburg, Sergey Lisitsyn,
* Giovanni De Toni, Jacob Walker, Thoralf Klein, Chiyuan Zhang,
* Fernando Iglesias, Sanuj Sharma, Roman Votyakov, Yuyu Zhang,
* Authors: Heiko Strathmann, Soeren Sonnenburg, Sergey Lisitsyn,
* Giovanni De Toni, Jacob Walker, Thoralf Klein, Chiyuan Zhang,
* Fernando Iglesias, Sanuj Sharma, Roman Votyakov, Yuyu Zhang,
* Viktor Gal, Björn Esser, Evangelos Anagnostopoulos, Pan Deng
*/

Expand All @@ -23,8 +23,8 @@
#include <shogun/lib/parameter_observers/ObservedValue.h>
#include <shogun/lib/tag.h>

#include <set>
#include <utility>
#include <vector>

/** \namespace shogun
* @brief all of classes and functions are contained in the shogun namespace
Expand Down Expand Up @@ -414,7 +414,7 @@ class CSGObject
/** Returns set of all parameter names of the object.
*
*/
std::set<std::string> parameter_names() const;
std::vector<std::string> parameter_names() const;

#ifndef SWIG
/**
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/base/SGObject_unittest.cc
Expand Up @@ -572,14 +572,14 @@ TEST(SGObjectAll, DISABLED_tag_coverage)
ASSERT_NE(obj, nullptr);

// old parameter framework names
std::set<std::string> old_names;
std::vector<std::string> old_names;
for (auto i : range(obj->m_parameters->get_num_parameters()))
old_names.insert(obj->m_parameters->get_parameter(i)->m_name);
old_names.push_back(obj->m_parameters->get_parameter(i)->m_name);
auto tag_names = obj->parameter_names();

// hack to increase readability of error messages
old_names.insert("Class: " + class_name);
tag_names.insert("Class: " + class_name);
old_names.push_back("Class: " + class_name);
tag_names.push_back("Class: " + class_name);

EXPECT_EQ(tag_names, old_names);

Expand Down

0 comments on commit 532a8d4

Please sign in to comment.