Repository: incubator-singa Updated Branches: refs/heads/master 3a373987a -> f73ae5a5f
SINGA-350 Error from python3 test Update the minimum version of swig to 3.0.10, which is required to fix the bugs (related to string) from py3. Add comments in model_layer.i for handling strings. Project: http://git-wip-us.apache.org/repos/asf/incubator-singa/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-singa/commit/72b1a69d Tree: http://git-wip-us.apache.org/repos/asf/incubator-singa/tree/72b1a69d Diff: http://git-wip-us.apache.org/repos/asf/incubator-singa/diff/72b1a69d Branch: refs/heads/master Commit: 72b1a69df14a7e14a2456f32eb6e3e0730d325d9 Parents: fb7b0d3 Author: Wang Wei <[email protected]> Authored: Tue May 1 23:42:40 2018 +0800 Committer: Wang Wei <[email protected]> Committed: Tue May 1 23:42:40 2018 +0800 ---------------------------------------------------------------------- cmake/Dependencies.cmake | 2 +- python/singa/layer.py | 2 +- src/api/model_layer.i | 21 +++++++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/72b1a69d/cmake/Dependencies.cmake ---------------------------------------------------------------------- diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake index 187d467..e221aa8 100644 --- a/cmake/Dependencies.cmake +++ b/cmake/Dependencies.cmake @@ -128,7 +128,7 @@ IF(USE_PYTHON) set(Python_ADDITIONAL_VERSIONS 3.6 3.5 3.4) FIND_PACKAGE(PythonInterp 3 REQUIRED) FIND_PACKAGE(PythonLibs 3 REQUIRED) - FIND_PACKAGE(SWIG 3.0.8 REQUIRED) + FIND_PACKAGE(SWIG 3.0.10 REQUIRED) ELSE() FIND_PACKAGE(PythonInterp 2.7 REQUIRED) FIND_PACKAGE(PythonLibs 2.7 REQUIRED) http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/72b1a69d/python/singa/layer.py ---------------------------------------------------------------------- diff --git a/python/singa/layer.py b/python/singa/layer.py index c6ff30a..1f3cb56 100644 --- a/python/singa/layer.py +++ b/python/singa/layer.py @@ -1354,4 +1354,4 @@ def get_layer_list(): """ Return a list of strings which include the identifiers (tags) of all supported layers """ - return singa_wrap.GetRegisteredLayers() + return [str(l) for l in singa_wrap.GetRegisteredLayers()] http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/72b1a69d/src/api/model_layer.i ---------------------------------------------------------------------- diff --git a/src/api/model_layer.i b/src/api/model_layer.i index 4760da3..d449f24 100644 --- a/src/api/model_layer.i +++ b/src/api/model_layer.i @@ -29,7 +29,28 @@ %{ +// To make the code compatible between py2 and py3, the follow +// macro is required, which forces the +// interface (function) to accept byte string (from python) and +// return byte string (in python) in py3. Otherwise the strings +// should be unicode strings in py3. +// Note that by default the strings in python3 are of type unicode. +// You have to encode it with the correct encoding (default is utf-8) +// to convert it into bytes. Sometimes, the string is already byte string +// e.g. from protobuf SerializeToString, then there is no need to do +// conversion. The output byte strings should be decoded into unicode. +// For python2, the default type of string is byte string. +// +// Because protobuf::SerializeToString cannot be decoded into unicode +// string, we cannot use SWIG_PYTHON_2_UNICODE which forces the +// interface (function) to accept unicode strings as input args +// and return unicode strings. +// +// TODO(wangwei) make strings compatible between py2 and py3. + #define SWIG_PYTHON_STRICT_BYTE_CHAR + + #include "singa/model/layer.h" #include "../src/model/layer/rnn.h" #include "../src/model/layer/cudnn_rnn.h"
