Skip to content

Commit

Permalink
pythonic factories
Browse files Browse the repository at this point in the history
  • Loading branch information
gf712 committed Mar 6, 2019
1 parent 66e9864 commit 3ac32e0
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/interfaces/python/swig_typemaps.i
Expand Up @@ -1293,6 +1293,17 @@ TYPEMAP_SPARSEFEATURES_OUT(PyObject, NPY_OBJECT)
SWIG_fail;
}


%include "std_set.i"

%template(stringSet) std::set<std::string>;

%ignore create;
%ignore delete_object;
%ignore create_object;
%rename(_available_objects) available_objects;
%include <shogun/base/class_list.h>

%feature("nothread") _rename_python_function;
%feature("docstring", "Renames a Python function in the given module or class. \n"
"Similar functionality to SWIG's %rename.") _rename_python_function;
Expand Down Expand Up @@ -1437,6 +1448,34 @@ def _internal_get_param(self, name):
_swig_monkey_patch(SGObject, "get", _internal_get_param)
import functools
def _internal_factory_mapping(algorithm_name, docstring=None):
"""
Internal function to export factories to the module
scope.
"""
for factory in _FACTORIES:
try:
sys.modules[__name__].__dict__[factory](algorithm_name)
func = functools.partial(sys.modules[__name__].__dict__[factory], algorithm_name)
func.__doc__ = docstring
return func
except SystemError:
pass
except Exception:
raise
raise ImportError("Could not generate new class for {}".format(algorithm_name))
for algorithm in _shogun._available_objects():
try:
_swig_monkey_patch(sys.modules[__name__], algorithm, _internal_factory_mapping(algorithm))
except ValueError:
# nothing to do here, class is already in module
continue
except Exception as e:
print(algorithm, e)
__version__ = _shogun.Version_get_version_main()
%}
Expand Down

0 comments on commit 3ac32e0

Please sign in to comment.