]> gerrit.simantics Code Review - simantics/python.git/blobdiff - org.simantics.pythonlink/test/org/simantics/pythonlink/test/scripts/NDArray.sts
Added support for dynamically typed data access and a Variable interface.
[simantics/python.git] / org.simantics.pythonlink / test / org / simantics / pythonlink / test / scripts / NDArray.sts
diff --git a/org.simantics.pythonlink/test/org/simantics/pythonlink/test/scripts/NDArray.sts b/org.simantics.pythonlink/test/org/simantics/pythonlink/test/scripts/NDArray.sts
new file mode 100644 (file)
index 0000000..84d0ac2
--- /dev/null
@@ -0,0 +1,24 @@
+> import "Python"\r
+> ndarray (vector [1, 2, 3])\r
+ndarray(3) [1.0, 2.0, 3.0]\r
+> ndarrayM 2 2 (vector [1, 2, 3, 4])\r
+ndarray(2x2) [[1.0, 2.0], [3.0, 4.0]]\r
+> a = ndarrayN (vector [2, 2, 3]) (vector [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])\r
+> a\r
+ndarray(2x2x3) [[[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]], [[7.0, 8.0, 9.0], [10.0, 11.0, 12.0]]]\r
+> ndarrayDims a\r
+vector [2, 2, 3]\r
+> ndarrayValues a\r
+vector [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0]\r
+> ndarrayElement a 5\r
+6.0\r
+> ndarrayElementN a (vector [0, 1, 2])\r
+6.0\r
+> b = ndarrayFromList ([[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]] :: [[[Double]]])\r
+> b\r
+ndarray(2x2x3) [[[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]], [[7.0, 8.0, 9.0], [10.0, 11.0, 12.0]]]\r
+> runPython do\r
+>     setPythonNDArrayVariable "foo" (ndarrayM 2 3 (vector [1, 2, 3,  4, 5, 6]))\r
+>     executePythonStatement "bar = foo.cumsum(1)"\r
+>     getPythonNDArrayVariable "bar"\r
+ndarray(2x3) [[1.0, 3.0, 6.0], [4.0, 9.0, 15.0]]\r