diff --git a/python4j/pom.xml b/python4j/pom.xml
index 1fe50344f..3f1d026a5 100644
--- a/python4j/pom.xml
+++ b/python4j/pom.xml
@@ -25,7 +25,7 @@
4.0.0
- org.eclipse
+ org.nd4j
python4j-parent
pom
diff --git a/python4j/python4j-core/pom.xml b/python4j/python4j-core/pom.xml
index e74d32392..26e77b8d1 100644
--- a/python4j/python4j-core/pom.xml
+++ b/python4j/python4j-core/pom.xml
@@ -21,7 +21,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
python4j-parent
- org.eclipse
+ org.nd4j
1.0.0-SNAPSHOT
jar
diff --git a/python4j/python4j-core/src/main/java/org/eclipse/python4j/Python.java b/python4j/python4j-core/src/main/java/org/nd4j/python4j/Python.java
similarity index 99%
rename from python4j/python4j-core/src/main/java/org/eclipse/python4j/Python.java
rename to python4j/python4j-core/src/main/java/org/nd4j/python4j/Python.java
index fd6fff112..03c2fdaab 100644
--- a/python4j/python4j-core/src/main/java/org/eclipse/python4j/Python.java
+++ b/python4j/python4j-core/src/main/java/org/nd4j/python4j/Python.java
@@ -15,7 +15,7 @@
******************************************************************************/
-package org.eclipse.python4j;
+package org.nd4j.python4j;
import org.bytedeco.cpython.PyObject;
diff --git a/python4j/python4j-core/src/main/java/org/eclipse/python4j/PythonContextManager.java b/python4j/python4j-core/src/main/java/org/nd4j/python4j/PythonContextManager.java
similarity index 95%
rename from python4j/python4j-core/src/main/java/org/eclipse/python4j/PythonContextManager.java
rename to python4j/python4j-core/src/main/java/org/nd4j/python4j/PythonContextManager.java
index 5675d0864..0090e38d4 100644
--- a/python4j/python4j-core/src/main/java/org/eclipse/python4j/PythonContextManager.java
+++ b/python4j/python4j-core/src/main/java/org/nd4j/python4j/PythonContextManager.java
@@ -14,7 +14,7 @@
* SPDX-License-Identifier: Apache-2.0
******************************************************************************/
-package org.eclipse.python4j;
+package org.nd4j.python4j;
import javax.lang.model.SourceVersion;
@@ -103,7 +103,18 @@ public class PythonContextManager {
}
private static boolean validateContextName(String s) {
- return SourceVersion.isIdentifier(s) && !s.startsWith(COLLAPSED_KEY);
+ for (int i=0; i= '0' && c <= '9'){
+ return false;
+ }
+ }
+ if (!(c=='_' || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9'))){
+ return false;
+ }
+ }
+ return true;
}
private static String getContextPrefix(String contextName) {
diff --git a/python4j/python4j-core/src/main/java/org/eclipse/python4j/PythonException.java b/python4j/python4j-core/src/main/java/org/nd4j/python4j/PythonException.java
similarity index 98%
rename from python4j/python4j-core/src/main/java/org/eclipse/python4j/PythonException.java
rename to python4j/python4j-core/src/main/java/org/nd4j/python4j/PythonException.java
index a9bbf596c..e8f64f2be 100644
--- a/python4j/python4j-core/src/main/java/org/eclipse/python4j/PythonException.java
+++ b/python4j/python4j-core/src/main/java/org/nd4j/python4j/PythonException.java
@@ -14,7 +14,7 @@
* SPDX-License-Identifier: Apache-2.0
******************************************************************************/
-package org.eclipse.python4j;
+package org.nd4j.python4j;
/**
diff --git a/python4j/python4j-core/src/main/java/org/eclipse/python4j/PythonExecutioner.java b/python4j/python4j-core/src/main/java/org/nd4j/python4j/PythonExecutioner.java
similarity index 99%
rename from python4j/python4j-core/src/main/java/org/eclipse/python4j/PythonExecutioner.java
rename to python4j/python4j-core/src/main/java/org/nd4j/python4j/PythonExecutioner.java
index 542778f76..bc48b0e98 100644
--- a/python4j/python4j-core/src/main/java/org/eclipse/python4j/PythonExecutioner.java
+++ b/python4j/python4j-core/src/main/java/org/nd4j/python4j/PythonExecutioner.java
@@ -15,7 +15,7 @@
******************************************************************************/
-package org.eclipse.python4j;
+package org.nd4j.python4j;
import org.bytedeco.cpython.PyObject;
@@ -25,7 +25,6 @@ import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
diff --git a/python4j/python4j-core/src/main/java/org/eclipse/python4j/PythonGC.java b/python4j/python4j-core/src/main/java/org/nd4j/python4j/PythonGC.java
similarity index 99%
rename from python4j/python4j-core/src/main/java/org/eclipse/python4j/PythonGC.java
rename to python4j/python4j-core/src/main/java/org/nd4j/python4j/PythonGC.java
index 5531b67d3..e18d2072d 100644
--- a/python4j/python4j-core/src/main/java/org/eclipse/python4j/PythonGC.java
+++ b/python4j/python4j-core/src/main/java/org/nd4j/python4j/PythonGC.java
@@ -15,7 +15,7 @@
******************************************************************************/
-package org.eclipse.python4j;
+package org.nd4j.python4j;
import org.bytedeco.cpython.PyObject;
import org.bytedeco.javacpp.Pointer;
diff --git a/python4j/python4j-core/src/main/java/org/eclipse/python4j/PythonGIL.java b/python4j/python4j-core/src/main/java/org/nd4j/python4j/PythonGIL.java
similarity index 97%
rename from python4j/python4j-core/src/main/java/org/eclipse/python4j/PythonGIL.java
rename to python4j/python4j-core/src/main/java/org/nd4j/python4j/PythonGIL.java
index 074be294a..3a88253e0 100644
--- a/python4j/python4j-core/src/main/java/org/eclipse/python4j/PythonGIL.java
+++ b/python4j/python4j-core/src/main/java/org/nd4j/python4j/PythonGIL.java
@@ -14,11 +14,10 @@
* SPDX-License-Identifier: Apache-2.0
******************************************************************************/
-package org.eclipse.python4j;
+package org.nd4j.python4j;
import org.bytedeco.cpython.PyThreadState;
-import org.omg.SendingContext.RunTime;
import java.util.concurrent.atomic.AtomicBoolean;
diff --git a/python4j/python4j-core/src/main/java/org/eclipse/python4j/PythonJob.java b/python4j/python4j-core/src/main/java/org/nd4j/python4j/PythonJob.java
similarity index 99%
rename from python4j/python4j-core/src/main/java/org/eclipse/python4j/PythonJob.java
rename to python4j/python4j-core/src/main/java/org/nd4j/python4j/PythonJob.java
index 0818de890..f357388f7 100644
--- a/python4j/python4j-core/src/main/java/org/eclipse/python4j/PythonJob.java
+++ b/python4j/python4j-core/src/main/java/org/nd4j/python4j/PythonJob.java
@@ -14,12 +14,11 @@
* SPDX-License-Identifier: Apache-2.0
******************************************************************************/
-package org.eclipse.python4j;
+package org.nd4j.python4j;
import lombok.Builder;
import lombok.Data;
-import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import javax.annotation.Nonnull;
diff --git a/python4j/python4j-core/src/main/java/org/eclipse/python4j/PythonObject.java b/python4j/python4j-core/src/main/java/org/nd4j/python4j/PythonObject.java
similarity index 99%
rename from python4j/python4j-core/src/main/java/org/eclipse/python4j/PythonObject.java
rename to python4j/python4j-core/src/main/java/org/nd4j/python4j/PythonObject.java
index 69252a5f7..94b60d320 100644
--- a/python4j/python4j-core/src/main/java/org/eclipse/python4j/PythonObject.java
+++ b/python4j/python4j-core/src/main/java/org/nd4j/python4j/PythonObject.java
@@ -14,7 +14,7 @@
* SPDX-License-Identifier: Apache-2.0
******************************************************************************/
-package org.eclipse.python4j;
+package org.nd4j.python4j;
import org.bytedeco.cpython.PyObject;
diff --git a/python4j/python4j-core/src/main/java/org/eclipse/python4j/PythonProcess.java b/python4j/python4j-core/src/main/java/org/nd4j/python4j/PythonProcess.java
similarity index 99%
rename from python4j/python4j-core/src/main/java/org/eclipse/python4j/PythonProcess.java
rename to python4j/python4j-core/src/main/java/org/nd4j/python4j/PythonProcess.java
index 0ca17fb49..bce8809f5 100644
--- a/python4j/python4j-core/src/main/java/org/eclipse/python4j/PythonProcess.java
+++ b/python4j/python4j-core/src/main/java/org/nd4j/python4j/PythonProcess.java
@@ -15,7 +15,7 @@
******************************************************************************/
-package org.eclipse.python4j;
+package org.nd4j.python4j;
import org.apache.commons.io.IOUtils;
import org.bytedeco.javacpp.Loader;
diff --git a/python4j/python4j-core/src/main/java/org/eclipse/python4j/PythonType.java b/python4j/python4j-core/src/main/java/org/nd4j/python4j/PythonType.java
similarity index 98%
rename from python4j/python4j-core/src/main/java/org/eclipse/python4j/PythonType.java
rename to python4j/python4j-core/src/main/java/org/nd4j/python4j/PythonType.java
index 47b725cd5..79b0ccaab 100644
--- a/python4j/python4j-core/src/main/java/org/eclipse/python4j/PythonType.java
+++ b/python4j/python4j-core/src/main/java/org/nd4j/python4j/PythonType.java
@@ -14,7 +14,7 @@
* SPDX-License-Identifier: Apache-2.0
******************************************************************************/
-package org.eclipse.python4j;
+package org.nd4j.python4j;
import java.io.File;
diff --git a/python4j/python4j-core/src/main/java/org/eclipse/python4j/PythonTypes.java b/python4j/python4j-core/src/main/java/org/nd4j/python4j/PythonTypes.java
similarity index 74%
rename from python4j/python4j-core/src/main/java/org/eclipse/python4j/PythonTypes.java
rename to python4j/python4j-core/src/main/java/org/nd4j/python4j/PythonTypes.java
index cd7ac7d7c..089c8aefe 100644
--- a/python4j/python4j-core/src/main/java/org/eclipse/python4j/PythonTypes.java
+++ b/python4j/python4j-core/src/main/java/org/nd4j/python4j/PythonTypes.java
@@ -14,14 +14,12 @@
* SPDX-License-Identifier: Apache-2.0
******************************************************************************/
-package org.eclipse.python4j;
+package org.nd4j.python4j;
import org.bytedeco.cpython.PyObject;
import org.bytedeco.javacpp.BytePointer;
-import org.bytedeco.javacpp.Loader;
import org.bytedeco.javacpp.Pointer;
-import sun.misc.Unsafe;
import sun.nio.ch.DirectBuffer;
import java.lang.reflect.Field;
@@ -37,7 +35,7 @@ public class PythonTypes {
private static List getPrimitiveTypes() {
- return Arrays.asList(STR, INT, FLOAT, BOOL, MEMORYVIEW);
+ return Arrays.asList(STR, INT, FLOAT, BOOL, BYTES);
}
private static List getCollectionTypes() {
@@ -258,6 +256,10 @@ public class PythonTypes {
int[] arr = (int[]) javaObject;
for (int x : arr) ret.add(x);
return ret;
+ }else if (javaObject instanceof byte[]){
+ byte[] arr = (byte[]) javaObject;
+ for (int x : arr) ret.add(x);
+ return ret;
} else if (javaObject instanceof long[]) {
long[] arr = (long[]) javaObject;
for (long x : arr) ret.add(x);
@@ -410,83 +412,125 @@ public class PythonTypes {
};
- public static final PythonType MEMORYVIEW = new PythonType("memoryview", BytePointer.class) {
+ public static final PythonType BYTES = new PythonType("bytes", byte[].class) {
@Override
- public BytePointer toJava(PythonObject pythonObject) {
+ public byte[] toJava(PythonObject pythonObject) {
try (PythonGC gc = PythonGC.watch()) {
- if (!(Python.isinstance(pythonObject, Python.memoryviewType()))) {
- throw new PythonException("Expected memoryview. Received: " + pythonObject);
+ if (!(Python.isinstance(pythonObject, Python.bytesType()))) {
+ throw new PythonException("Expected bytes. Received: " + pythonObject);
}
PythonObject pySize = Python.len(pythonObject);
- PythonObject ctypes = Python.importModule("ctypes");
- PythonObject charType = ctypes.attr("c_char");
- PythonObject charArrayType = new PythonObject(PyNumber_Multiply(charType.getNativePythonObject(),
- pySize.getNativePythonObject()));
- PythonObject fromBuffer = charArrayType.attr("from_buffer");
- if (pythonObject.attr("readonly").toBoolean()) {
- pythonObject = Python.bytearray(pythonObject);
+ byte[] ret = new byte[pySize.toInt()];
+ for (int i = 0; i < ret.length; i++) {
+ ret[i] = (byte)pythonObject.get(i).toInt();
}
- PythonObject arr = fromBuffer.call(pythonObject);
- PythonObject cast = ctypes.attr("cast");
- PythonObject voidPtrType = ctypes.attr("c_void_p");
- PythonObject voidPtr = cast.call(arr, voidPtrType);
- long address = voidPtr.attr("value").toLong();
- long size = pySize.toLong();
- try {
- Field addressField = Buffer.class.getDeclaredField("address");
- addressField.setAccessible(true);
- Field capacityField = Buffer.class.getDeclaredField("capacity");
- capacityField.setAccessible(true);
- ByteBuffer buff = ByteBuffer.allocateDirect(0).order(ByteOrder.nativeOrder());
- addressField.setLong(buff, address);
- capacityField.setInt(buff, (int) size);
- BytePointer ret = new BytePointer(buff);
- ret.limit(size);
- return ret;
-
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
-
+ return ret;
}
}
@Override
- public PythonObject toPython(BytePointer javaObject) {
- long address = javaObject.address();
- long size = javaObject.limit();
- try (PythonGC gc = PythonGC.watch()) {
- PythonObject ctypes = Python.importModule("ctypes");
- PythonObject charType = ctypes.attr("c_char");
- PythonObject pySize = new PythonObject(size);
- PythonObject charArrayType = new PythonObject(PyNumber_Multiply(charType.getNativePythonObject(),
- pySize.getNativePythonObject()));
- PythonObject fromAddress = charArrayType.attr("from_address");
- PythonObject arr = fromAddress.call(new PythonObject(address));
- PythonObject memoryView = Python.memoryview(arr).attr("cast").call("b");
- PythonGC.keep(memoryView);
- return memoryView;
+ public PythonObject toPython(byte[] javaObject) {
+ try(PythonGC gc = PythonGC.watch()){
+ PythonObject ret = Python.bytes(LIST.toPython(LIST.adapt(javaObject)));
+ PythonGC.keep(ret);
+ return ret;
}
-
}
-
@Override
public boolean accepts(Object javaObject) {
- return javaObject instanceof Pointer || javaObject instanceof DirectBuffer;
+ return javaObject instanceof byte[];
+ }
+ @Override
+ public byte[] adapt(Object javaObject) {
+ if (javaObject instanceof byte[]){
+ return (byte[])javaObject;
+ }
+ throw new PythonException("Cannot cast object of type " + javaObject.getClass().getName() + " to byte[]");
}
- @Override
- public BytePointer adapt(Object javaObject) {
- if (javaObject instanceof BytePointer) {
- return (BytePointer) javaObject;
- } else if (javaObject instanceof Pointer) {
- return new BytePointer((Pointer) javaObject);
- } else if (javaObject instanceof DirectBuffer) {
- return new BytePointer((ByteBuffer) javaObject);
- } else {
- throw new PythonException("Cannot cast object of type " + javaObject.getClass().getName() + " to BytePointer");
- }
- }
};
+ /**
+ * Crashes on Adopt OpenJDK
+ * Use implementation in python4j-numpy instead for zero-copy byte buffers.
+ */
+// public static final PythonType MEMORYVIEW = new PythonType("memoryview", BytePointer.class) {
+// @Override
+// public BytePointer toJava(PythonObject pythonObject) {
+// try (PythonGC gc = PythonGC.watch()) {
+// if (!(Python.isinstance(pythonObject, Python.memoryviewType()))) {
+// throw new PythonException("Expected memoryview. Received: " + pythonObject);
+// }
+// PythonObject pySize = Python.len(pythonObject);
+// PythonObject ctypes = Python.importModule("ctypes");
+// PythonObject charType = ctypes.attr("c_char");
+// PythonObject charArrayType = new PythonObject(PyNumber_Multiply(charType.getNativePythonObject(),
+// pySize.getNativePythonObject()));
+// PythonObject fromBuffer = charArrayType.attr("from_buffer");
+// if (pythonObject.attr("readonly").toBoolean()) {
+// pythonObject = Python.bytearray(pythonObject);
+// }
+// PythonObject arr = fromBuffer.call(pythonObject);
+// PythonObject cast = ctypes.attr("cast");
+// PythonObject voidPtrType = ctypes.attr("c_void_p");
+// PythonObject voidPtr = cast.call(arr, voidPtrType);
+// long address = voidPtr.attr("value").toLong();
+// long size = pySize.toLong();
+// try {
+// Field addressField = Buffer.class.getDeclaredField("address");
+// addressField.setAccessible(true);
+// Field capacityField = Buffer.class.getDeclaredField("capacity");
+// capacityField.setAccessible(true);
+// ByteBuffer buff = ByteBuffer.allocateDirect(0).order(ByteOrder.nativeOrder());
+// addressField.setLong(buff, address);
+// capacityField.setInt(buff, (int) size);
+// BytePointer ret = new BytePointer(buff);
+// ret.limit(size);
+// return ret;
+//
+// } catch (Exception e) {
+// throw new RuntimeException(e);
+// }
+//
+// }
+// }
+//
+// @Override
+// public PythonObject toPython(BytePointer javaObject) {
+// long address = javaObject.address();
+// long size = javaObject.limit();
+// try (PythonGC gc = PythonGC.watch()) {
+// PythonObject ctypes = Python.importModule("ctypes");
+// PythonObject charType = ctypes.attr("c_char");
+// PythonObject pySize = new PythonObject(size);
+// PythonObject charArrayType = new PythonObject(PyNumber_Multiply(charType.getNativePythonObject(),
+// pySize.getNativePythonObject()));
+// PythonObject fromAddress = charArrayType.attr("from_address");
+// PythonObject arr = fromAddress.call(new PythonObject(address));
+// PythonObject memoryView = Python.memoryview(arr).attr("cast").call("b");
+// PythonGC.keep(memoryView);
+// return memoryView;
+// }
+//
+// }
+//
+// @Override
+// public boolean accepts(Object javaObject) {
+// return javaObject instanceof Pointer || javaObject instanceof DirectBuffer;
+// }
+//
+// @Override
+// public BytePointer adapt(Object javaObject) {
+// if (javaObject instanceof BytePointer) {
+// return (BytePointer) javaObject;
+// } else if (javaObject instanceof Pointer) {
+// return new BytePointer((Pointer) javaObject);
+// } else if (javaObject instanceof DirectBuffer) {
+// return new BytePointer((ByteBuffer) javaObject);
+// } else {
+// throw new PythonException("Cannot cast object of type " + javaObject.getClass().getName() + " to BytePointer");
+// }
+// }
+// };
+
}
diff --git a/python4j/python4j-core/src/main/java/org/eclipse/python4j/PythonVariable.java b/python4j/python4j-core/src/main/java/org/nd4j/python4j/PythonVariable.java
similarity index 98%
rename from python4j/python4j-core/src/main/java/org/eclipse/python4j/PythonVariable.java
rename to python4j/python4j-core/src/main/java/org/nd4j/python4j/PythonVariable.java
index 3deb4d2e7..038904ec9 100644
--- a/python4j/python4j-core/src/main/java/org/eclipse/python4j/PythonVariable.java
+++ b/python4j/python4j-core/src/main/java/org/nd4j/python4j/PythonVariable.java
@@ -14,7 +14,7 @@
* SPDX-License-Identifier: Apache-2.0
******************************************************************************/
-package org.eclipse.python4j;
+package org.nd4j.python4j;
@lombok.Data
public class PythonVariable {
diff --git a/python4j/python4j-core/src/main/java/org/eclipse/python4j/PythonVariables.java b/python4j/python4j-core/src/main/java/org/nd4j/python4j/PythonVariables.java
similarity index 98%
rename from python4j/python4j-core/src/main/java/org/eclipse/python4j/PythonVariables.java
rename to python4j/python4j-core/src/main/java/org/nd4j/python4j/PythonVariables.java
index 32ae0b2f5..ed9ccff5d 100644
--- a/python4j/python4j-core/src/main/java/org/eclipse/python4j/PythonVariables.java
+++ b/python4j/python4j-core/src/main/java/org/nd4j/python4j/PythonVariables.java
@@ -14,7 +14,7 @@
* SPDX-License-Identifier: Apache-2.0
******************************************************************************/
-package org.eclipse.python4j;
+package org.nd4j.python4j;
import java.util.ArrayList;
import java.util.Arrays;
diff --git a/python4j/python4j-core/src/main/resources/org/nd4j/python4j/pythonexec/__init__.py b/python4j/python4j-core/src/main/resources/org/nd4j/python4j/pythonexec/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/python4j/python4j-core/src/main/resources/org/eclipse/python4j/pythonexec/pythonexec.py b/python4j/python4j-core/src/main/resources/org/nd4j/python4j/pythonexec/pythonexec.py
similarity index 100%
rename from python4j/python4j-core/src/main/resources/org/eclipse/python4j/pythonexec/pythonexec.py
rename to python4j/python4j-core/src/main/resources/org/nd4j/python4j/pythonexec/pythonexec.py
diff --git a/python4j/python4j-core/src/test/java/PythonBasicExecutionTest.java b/python4j/python4j-core/src/test/java/PythonBasicExecutionTest.java
index 9f5b43dba..c26b5c874 100644
--- a/python4j/python4j-core/src/test/java/PythonBasicExecutionTest.java
+++ b/python4j/python4j-core/src/test/java/PythonBasicExecutionTest.java
@@ -15,9 +15,12 @@
******************************************************************************/
-import org.eclipse.python4j.*;
import org.junit.Assert;
import org.junit.Test;
+import org.nd4j.python4j.PythonContextManager;
+import org.nd4j.python4j.PythonExecutioner;
+import org.nd4j.python4j.PythonTypes;
+import org.nd4j.python4j.PythonVariable;
import javax.annotation.concurrent.NotThreadSafe;
import java.util.*;
diff --git a/python4j/python4j-core/src/test/java/PythonBufferTest.java b/python4j/python4j-core/src/test/java/PythonBufferTest.java
deleted file mode 100644
index c59b86c15..000000000
--- a/python4j/python4j-core/src/test/java/PythonBufferTest.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2020 Konduit K.K.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Apache License, Version 2.0 which is available at
- * https://www.apache.org/licenses/LICENSE-2.0.
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations
- * under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- ******************************************************************************/
-
-
-import org.bytedeco.javacpp.BytePointer;
-import org.bytedeco.javacpp.Loader;
-import org.eclipse.python4j.*;
-import org.junit.Assert;
-import org.junit.Test;
-import sun.nio.ch.DirectBuffer;
-
-import javax.annotation.concurrent.NotThreadSafe;
-import java.nio.Buffer;
-import java.nio.ByteBuffer;
-import java.util.*;
-
-@NotThreadSafe
-public class PythonBufferTest {
-
- @Test
- public void testBuffer() {
- ByteBuffer buff = ByteBuffer.allocateDirect(3);
- buff.put((byte) 97);
- buff.put((byte) 98);
- buff.put((byte) 99);
- buff.rewind();
-
- BytePointer bp = new BytePointer(buff);
-
- List inputs = new ArrayList<>();
- inputs.add(new PythonVariable<>("buff", PythonTypes.MEMORYVIEW, buff));
-
- List outputs = new ArrayList<>();
- outputs.add(new PythonVariable<>("s1", PythonTypes.STR));
- outputs.add(new PythonVariable<>("s2", PythonTypes.STR));
-
- String code = "s1 = ''.join(chr(c) for c in buff)\nbuff[2] += 2\ns2 = ''.join(chr(c) for c in buff)";
-
- PythonExecutioner.exec(code, inputs, outputs);
- Assert.assertEquals("abc", outputs.get(0).getValue());
- Assert.assertEquals("abe", outputs.get(1).getValue());
- Assert.assertEquals(101, buff.get(2));
-
- }
- @Test
- public void testBuffer2() {
- ByteBuffer buff = ByteBuffer.allocateDirect(3);
- buff.put((byte) 97);
- buff.put((byte) 98);
- buff.put((byte) 99);
- buff.rewind();
-
- BytePointer bp = new BytePointer(buff);
-
- List inputs = new ArrayList<>();
- inputs.add(new PythonVariable<>("buff", PythonTypes.MEMORYVIEW, bp));
-
- List outputs = new ArrayList<>();
- outputs.add(new PythonVariable<>("s1", PythonTypes.STR));
- outputs.add(new PythonVariable<>("s2", PythonTypes.STR));
-
- String code = "s1 = ''.join(chr(c) for c in buff)\nbuff[2] += 2\ns2 = ''.join(chr(c) for c in buff)";
-
- PythonExecutioner.exec(code, inputs, outputs);
- Assert.assertEquals("abc", outputs.get(0).getValue());
- Assert.assertEquals("abe", outputs.get(1).getValue());
- Assert.assertEquals(101, buff.get(2));
-
- }
-
- @Test
- public void testBuffer3() {
- ByteBuffer buff = ByteBuffer.allocateDirect(3);
- buff.put((byte) 97);
- buff.put((byte) 98);
- buff.put((byte) 99);
- buff.rewind();
-
- BytePointer bp = new BytePointer(buff);
-
- List inputs = new ArrayList<>();
- inputs.add(new PythonVariable<>("buff", PythonTypes.MEMORYVIEW, bp));
-
- List outputs = new ArrayList<>();
- outputs.add(new PythonVariable<>("s1", PythonTypes.STR));
- outputs.add(new PythonVariable<>("s2", PythonTypes.STR));
- outputs.add(new PythonVariable<>("buff2", PythonTypes.MEMORYVIEW));
- String code = "s1 = ''.join(chr(c) for c in buff)\nbuff[2] += 2\ns2 = ''.join(chr(c) for c in buff)\nbuff2=buff[1:]";
- PythonExecutioner.exec(code, inputs, outputs);
-
- Assert.assertEquals("abc", outputs.get(0).getValue());
- Assert.assertEquals("abe", outputs.get(1).getValue());
- Assert.assertEquals(101, buff.get(2));
- BytePointer outBuffer = (BytePointer) outputs.get(2).getValue();
- Assert.assertEquals(2, outBuffer.capacity());
- Assert.assertEquals((byte)98, outBuffer.get(0));
- Assert.assertEquals((byte)101, outBuffer.get(1));
-
- }
-}
\ No newline at end of file
diff --git a/python4j/python4j-core/src/test/java/PythonCollectionsTest.java b/python4j/python4j-core/src/test/java/PythonCollectionsTest.java
index 7e63d9d28..ba4d8e14a 100644
--- a/python4j/python4j-core/src/test/java/PythonCollectionsTest.java
+++ b/python4j/python4j-core/src/test/java/PythonCollectionsTest.java
@@ -15,9 +15,9 @@
******************************************************************************/
-import org.eclipse.python4j.PythonException;
-import org.eclipse.python4j.PythonObject;
-import org.eclipse.python4j.PythonTypes;
+import org.nd4j.python4j.PythonException;
+import org.nd4j.python4j.PythonObject;
+import org.nd4j.python4j.PythonTypes;
import org.junit.Assert;
import org.junit.Test;
diff --git a/python4j/python4j-core/src/test/java/PythonContextManagerTest.java b/python4j/python4j-core/src/test/java/PythonContextManagerTest.java
index a4451764c..4961f94d8 100644
--- a/python4j/python4j-core/src/test/java/PythonContextManagerTest.java
+++ b/python4j/python4j-core/src/test/java/PythonContextManagerTest.java
@@ -16,9 +16,9 @@
******************************************************************************/
-import org.eclipse.python4j.Python;
-import org.eclipse.python4j.PythonContextManager;
-import org.eclipse.python4j.PythonExecutioner;
+import org.nd4j.python4j.Python;
+import org.nd4j.python4j.PythonContextManager;
+import org.nd4j.python4j.PythonExecutioner;
import org.junit.Assert;
import org.junit.Test;
import javax.annotation.concurrent.NotThreadSafe;
diff --git a/python4j/python4j-core/src/test/java/PythonGCTest.java b/python4j/python4j-core/src/test/java/PythonGCTest.java
index 80b2e7f3c..11dd8e93a 100644
--- a/python4j/python4j-core/src/test/java/PythonGCTest.java
+++ b/python4j/python4j-core/src/test/java/PythonGCTest.java
@@ -14,9 +14,9 @@
* SPDX-License-Identifier: Apache-2.0
******************************************************************************/
-import org.eclipse.python4j.Python;
-import org.eclipse.python4j.PythonGC;
-import org.eclipse.python4j.PythonObject;
+import org.nd4j.python4j.Python;
+import org.nd4j.python4j.PythonGC;
+import org.nd4j.python4j.PythonObject;
import org.junit.Assert;
import org.junit.Test;
diff --git a/python4j/python4j-core/src/test/java/PythonJobTest.java b/python4j/python4j-core/src/test/java/PythonJobTest.java
index b0f4233c9..4dad7f24f 100644
--- a/python4j/python4j-core/src/test/java/PythonJobTest.java
+++ b/python4j/python4j-core/src/test/java/PythonJobTest.java
@@ -14,10 +14,10 @@
* SPDX-License-Identifier: Apache-2.0
******************************************************************************/
-import org.eclipse.python4j.PythonContextManager;
-import org.eclipse.python4j.PythonJob;
-import org.eclipse.python4j.PythonTypes;
-import org.eclipse.python4j.PythonVariable;
+import org.nd4j.python4j.PythonContextManager;
+import org.nd4j.python4j.PythonJob;
+import org.nd4j.python4j.PythonTypes;
+import org.nd4j.python4j.PythonVariable;
import org.junit.Test;
import java.util.ArrayList;
diff --git a/python4j/python4j-core/src/test/java/PythonMultiThreadTest.java b/python4j/python4j-core/src/test/java/PythonMultiThreadTest.java
index ec544b65f..b2f9089fa 100644
--- a/python4j/python4j-core/src/test/java/PythonMultiThreadTest.java
+++ b/python4j/python4j-core/src/test/java/PythonMultiThreadTest.java
@@ -14,10 +14,9 @@
* SPDX-License-Identifier: Apache-2.0
******************************************************************************/
-import org.eclipse.python4j.*;
+import org.nd4j.python4j.*;
import org.junit.Assert;
import org.junit.Test;
-
import javax.annotation.concurrent.NotThreadSafe;
import java.util.ArrayList;
import java.util.Arrays;
diff --git a/python4j/python4j-core/src/test/java/PythonPrimitiveTypesTest.java b/python4j/python4j-core/src/test/java/PythonPrimitiveTypesTest.java
index ae10ed8dc..94423f7de 100644
--- a/python4j/python4j-core/src/test/java/PythonPrimitiveTypesTest.java
+++ b/python4j/python4j-core/src/test/java/PythonPrimitiveTypesTest.java
@@ -15,12 +15,13 @@
******************************************************************************/
-import org.eclipse.python4j.PythonException;
-import org.eclipse.python4j.PythonObject;
-import org.eclipse.python4j.PythonTypes;
+import org.nd4j.python4j.*;
import org.junit.Assert;
import org.junit.Test;
+import java.util.ArrayList;
+import java.util.List;
+
public class PythonPrimitiveTypesTest {
@Test
@@ -78,5 +79,18 @@ public class PythonPrimitiveTypesTest {
Assert.assertEquals(b, b3);
}
+ @Test
+ public void testBytes() {
+ byte[] bytes = new byte[]{97, 98, 99};
+ List inputs = new ArrayList<>();
+ inputs.add(new PythonVariable<>("buff", PythonTypes.BYTES, bytes));
+ List outputs = new ArrayList<>();
+ outputs.add(new PythonVariable<>("s1", PythonTypes.STR));
+ outputs.add(new PythonVariable<>("buff2", PythonTypes.BYTES));
+ String code = "s1 = ''.join(chr(c) for c in buff)\nbuff2=b'def'";
+ PythonExecutioner.exec(code, inputs, outputs);
+ Assert.assertEquals("abc", outputs.get(0).getValue());
+ Assert.assertArrayEquals(new byte[]{100, 101, 102}, (byte[])outputs.get(1).getValue());
+ }
}
diff --git a/python4j/python4j-numpy/pom.xml b/python4j/python4j-numpy/pom.xml
index bcce739ce..c631f67e3 100644
--- a/python4j/python4j-numpy/pom.xml
+++ b/python4j/python4j-numpy/pom.xml
@@ -4,7 +4,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
python4j-parent
- org.eclipse
+ org.nd4j
1.0.0-SNAPSHOT
4.0.0
@@ -29,7 +29,7 @@
test
- org.eclipse
+ org.nd4j
python4j-core
1.0.0-SNAPSHOT
diff --git a/python4j/python4j-numpy/src/main/java/org/eclipse/python4j/NumpyArray.java b/python4j/python4j-numpy/src/main/java/org/nd4j/python4j/NumpyArray.java
similarity index 97%
rename from python4j/python4j-numpy/src/main/java/org/eclipse/python4j/NumpyArray.java
rename to python4j/python4j-numpy/src/main/java/org/nd4j/python4j/NumpyArray.java
index 66fb76d23..b21dabd7c 100644
--- a/python4j/python4j-numpy/src/main/java/org/eclipse/python4j/NumpyArray.java
+++ b/python4j/python4j-numpy/src/main/java/org/nd4j/python4j/NumpyArray.java
@@ -15,26 +15,22 @@
******************************************************************************/
-package org.eclipse.python4j;
+package org.nd4j.python4j;
import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.lang3.ArrayUtils;
import org.bytedeco.cpython.PyObject;
import org.bytedeco.cpython.PyTypeObject;
import org.bytedeco.javacpp.Pointer;
import org.bytedeco.javacpp.SizeTPointer;
import org.bytedeco.numpy.PyArrayObject;
import org.bytedeco.numpy.global.numpy;
-import org.nd4j.linalg.api.buffer.BaseDataBuffer;
import org.nd4j.linalg.api.buffer.DataBuffer;
import org.nd4j.linalg.api.buffer.DataType;
import org.nd4j.linalg.api.concurrency.AffinityManager;
import org.nd4j.linalg.api.memory.MemoryWorkspace;
-import org.nd4j.linalg.api.memory.MemoryWorkspaceManager;
import org.nd4j.linalg.api.ndarray.INDArray;
import org.nd4j.linalg.api.shape.Shape;
import org.nd4j.linalg.factory.Nd4j;
-import org.nd4j.nativeblas.NativeOps;
import org.nd4j.nativeblas.NativeOpsHolder;
import java.io.File;
diff --git a/python4j/python4j-numpy/src/main/resources/META-INF/services/org.eclipse.python4j.PythonType b/python4j/python4j-numpy/src/main/resources/META-INF/services/org.eclipse.python4j.PythonType
deleted file mode 100644
index ae4d4640b..000000000
--- a/python4j/python4j-numpy/src/main/resources/META-INF/services/org.eclipse.python4j.PythonType
+++ /dev/null
@@ -1 +0,0 @@
-org.eclipse.python4j.NumpyArray
\ No newline at end of file
diff --git a/python4j/python4j-numpy/src/main/resources/META-INF/services/org.nd4j.python4j.PythonType b/python4j/python4j-numpy/src/main/resources/META-INF/services/org.nd4j.python4j.PythonType
new file mode 100644
index 000000000..b0d2f1256
--- /dev/null
+++ b/python4j/python4j-numpy/src/main/resources/META-INF/services/org.nd4j.python4j.PythonType
@@ -0,0 +1 @@
+org.nd4j.python4j.NumpyArray
\ No newline at end of file
diff --git a/python4j/python4j-numpy/src/test/java/PythonNumpyBasicTest.java b/python4j/python4j-numpy/src/test/java/PythonNumpyBasicTest.java
index b7bd838b5..d76f759a6 100644
--- a/python4j/python4j-numpy/src/test/java/PythonNumpyBasicTest.java
+++ b/python4j/python4j-numpy/src/test/java/PythonNumpyBasicTest.java
@@ -15,13 +15,12 @@
******************************************************************************/
-import org.eclipse.python4j.*;
+import org.nd4j.python4j.*;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.nd4j.linalg.api.buffer.DataType;
-import org.nd4j.linalg.api.concurrency.AffinityManager;
import org.nd4j.linalg.api.ndarray.INDArray;
import org.nd4j.linalg.factory.Nd4j;
import org.nd4j.nativeblas.OpaqueDataBuffer;
diff --git a/python4j/python4j-numpy/src/test/java/PythonNumpyCollectionsTest.java b/python4j/python4j-numpy/src/test/java/PythonNumpyCollectionsTest.java
index 99a050f63..64c417905 100644
--- a/python4j/python4j-numpy/src/test/java/PythonNumpyCollectionsTest.java
+++ b/python4j/python4j-numpy/src/test/java/PythonNumpyCollectionsTest.java
@@ -15,9 +15,9 @@
******************************************************************************/
-import org.eclipse.python4j.PythonException;
-import org.eclipse.python4j.PythonObject;
-import org.eclipse.python4j.PythonTypes;
+import org.nd4j.python4j.PythonException;
+import org.nd4j.python4j.PythonObject;
+import org.nd4j.python4j.PythonTypes;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
diff --git a/python4j/python4j-numpy/src/test/java/PythonNumpyGCTest.java b/python4j/python4j-numpy/src/test/java/PythonNumpyGCTest.java
index d1c5ba761..96dd7274c 100644
--- a/python4j/python4j-numpy/src/test/java/PythonNumpyGCTest.java
+++ b/python4j/python4j-numpy/src/test/java/PythonNumpyGCTest.java
@@ -14,9 +14,9 @@
* SPDX-License-Identifier: Apache-2.0
******************************************************************************/
-import org.eclipse.python4j.Python;
-import org.eclipse.python4j.PythonGC;
-import org.eclipse.python4j.PythonObject;
+import org.nd4j.python4j.Python;
+import org.nd4j.python4j.PythonGC;
+import org.nd4j.python4j.PythonObject;
import org.junit.Assert;
import org.junit.Test;
import org.nd4j.linalg.factory.Nd4j;
diff --git a/python4j/python4j-numpy/src/test/java/PythonNumpyImportTest.java b/python4j/python4j-numpy/src/test/java/PythonNumpyImportTest.java
index 580f8643b..941072e45 100644
--- a/python4j/python4j-numpy/src/test/java/PythonNumpyImportTest.java
+++ b/python4j/python4j-numpy/src/test/java/PythonNumpyImportTest.java
@@ -1,7 +1,7 @@
-import org.eclipse.python4j.NumpyArray;
-import org.eclipse.python4j.Python;
-import org.eclipse.python4j.PythonGC;
-import org.eclipse.python4j.PythonObject;
+import org.nd4j.python4j.NumpyArray;
+import org.nd4j.python4j.Python;
+import org.nd4j.python4j.PythonGC;
+import org.nd4j.python4j.PythonObject;
import org.junit.Assert;
import org.junit.Test;
import org.nd4j.linalg.api.buffer.DataType;
diff --git a/python4j/python4j-numpy/src/test/java/PythonNumpyJobTest.java b/python4j/python4j-numpy/src/test/java/PythonNumpyJobTest.java
index 399b87fb1..dc087d0f8 100644
--- a/python4j/python4j-numpy/src/test/java/PythonNumpyJobTest.java
+++ b/python4j/python4j-numpy/src/test/java/PythonNumpyJobTest.java
@@ -14,7 +14,6 @@
* SPDX-License-Identifier: Apache-2.0
******************************************************************************/
-import org.eclipse.python4j.*;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -22,6 +21,7 @@ import org.junit.runners.Parameterized;
import org.nd4j.linalg.api.buffer.DataType;
import org.nd4j.linalg.api.ndarray.INDArray;
import org.nd4j.linalg.factory.Nd4j;
+import org.nd4j.python4j.*;
import java.util.ArrayList;
import java.util.List;
diff --git a/python4j/python4j-numpy/src/test/java/PythonNumpyMultiThreadTest.java b/python4j/python4j-numpy/src/test/java/PythonNumpyMultiThreadTest.java
index 52ccd1fd0..02eb99551 100644
--- a/python4j/python4j-numpy/src/test/java/PythonNumpyMultiThreadTest.java
+++ b/python4j/python4j-numpy/src/test/java/PythonNumpyMultiThreadTest.java
@@ -14,7 +14,7 @@
* SPDX-License-Identifier: Apache-2.0
******************************************************************************/
-import org.eclipse.python4j.*;
+import org.nd4j.python4j.*;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
diff --git a/python4j/python4j-numpy/src/test/java/PythonNumpyServiceLoaderTest.java b/python4j/python4j-numpy/src/test/java/PythonNumpyServiceLoaderTest.java
index d3c649c8d..bd13a99d9 100644
--- a/python4j/python4j-numpy/src/test/java/PythonNumpyServiceLoaderTest.java
+++ b/python4j/python4j-numpy/src/test/java/PythonNumpyServiceLoaderTest.java
@@ -15,18 +15,14 @@
******************************************************************************/
-import org.eclipse.python4j.*;
import org.junit.Assert;
import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.nd4j.linalg.api.buffer.DataType;
import org.nd4j.linalg.api.ndarray.INDArray;
import org.nd4j.linalg.factory.Nd4j;
+import org.nd4j.python4j.NumpyArray;
+import org.nd4j.python4j.PythonTypes;
import javax.annotation.concurrent.NotThreadSafe;
-import java.util.ArrayList;
-import java.util.List;
@NotThreadSafe
public class PythonNumpyServiceLoaderTest {
@@ -36,6 +32,4 @@ public class PythonNumpyServiceLoaderTest {
Assert.assertEquals(NumpyArray.INSTANCE, PythonTypes.get("numpy.ndarray"));
Assert.assertEquals(NumpyArray.INSTANCE, PythonTypes.getPythonTypeForJavaObject(Nd4j.zeros(1)));
}
-
-
}