8000 Merge pull request #764 from jfsantos/import_array. Closes #764 · CJavaScala/tensorflow@60114c4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 60114c4

Browse files
author
Vijay Vasudevan
committed
Merge pull request tensorflow#764 from jfsantos/import_array. Closes tensorflow#764
2 parents da44976 + 32ed124 commit 60114c4

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

tensorflow/python/client/tf_session.i

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,11 @@ tensorflow::ImportNumpy();
204204
// The wrapped function TF_GetOpList returns a TF_Buffer pointer. This typemap
205205
// creates a Python string from the TF_Buffer and returns it.
206206
%typemap(out) TF_Buffer TF_GetOpList {
207+
%#if PY_MAJOR_VERSION < 3
207208
$result = PyString_FromStringAndSize(
209+
%#else
210+
$result = PyUnicode_FromStringAndSize(
211+
%#endif
208212
reinterpret_cast<const char*>($1.data), $1.length);
209213
}
210214

tensorflow/python/lib/core/py_func.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ limitations under the License.
2424
#include "tensorflow/core/platform/mutex.h"
2525
#include "tensorflow/core/platform/port.h"
2626

27+
// Return type of import_array() changed between Python 2 and 3
28+
// NUMPY_IMPORT_ARRAY_RETVAL is NULL for Python 3
29+
#if PY_MAJOR_VERSION >= 3
30+
#define NUMPY_IMPORT_ARRAY_RETURN_TYPE int
31+
#else
32+
#define NUMPY_IMPORT_ARRAY_RETURN_TYPE void
33+
#endif
34+
2735
namespace tensorflow {
2836
namespace {
2937

@@ -39,7 +47,7 @@ PyObject* GetPyTrampoline() {
3947
}
4048

4149
// Module initialization (mainly import numpy) if needed.
42-
void InitIfNeeded() {
50+
NUMPY_IMPORT_ARRAY_RETURN_TYPE InitIfNeeded() {
4351
mutex_lock l(mu);
4452
if (!initialized) {
4553
PyGILState_STATE py_threadstate;

0 commit comments

Comments
 (0)
0