]> gerrit.simantics Code Review - simantics/python.git/blob - org.simantics.pythonlink/test/org/simantics/pythonlink/test/scripts/Python.sts
50c0423ab0763d465e15c965070179d3773221b0
[simantics/python.git] / org.simantics.pythonlink / test / org / simantics / pythonlink / test / scripts / Python.sts
1 > import "Python"\r
2\r
3 > runPython do\r
4 >     executePythonStatement "foo = 'bar'\nd = dir()"\r
5 >     getPythonStringArrayVariable "d"\r
6 vector ["__builtins__", "__doc__", "__loader__", "__name__", "__package__", "__spec__", "foo"]\r
7 > runPython do\r
8 >     setPythonDoubleVariable "foo" 1\r
9 >     executePythonStatement "foo = foo + 1"\r
10 >     getPythonDoubleVariable "foo"\r
11 2.0\r
12 > runPython do\r
13 >     setPythonDoubleArrayVariable "foo" (vector [1.0, 2.0, 3.0])\r
14 >     executePythonStatement "foo = foo + [4.0]"\r
15 >     getPythonDoubleArrayVariable "foo"\r
16 vector [1.0, 2.0, 3.0, 4.0]\r
17 > runPython do\r
18 >     setPythonIntegerVariable "foo" 5\r
19 >     executePythonStatement "import math"\r
20 >     executePythonStatement "bar = math.factorial(foo)"\r
21 >     getPythonIntegerVariable "bar"\r
22 120\r
23 > runPython do\r
24 >     setPythonIntegerArrayVariable "foo" (vector [1, 2, 3, 4])\r
25 >     executePythonStatement "foo.append(sum(foo))"\r
26 >     getPythonIntegerArrayVariable "foo"\r
27 vector [1, 2, 3, 4, 10]\r
28 > ndarray (vector [1, 2, 3])\r
29 ndarray(3) [1.0, 2.0, 3.0]\r
30 > ndarrayM 2 2 (vector [1, 2, 3, 4])\r
31 ndarray(2x2) [[1.0, 2.0], [3.0, 4.0]]\r
32 > a = ndarrayN (vector [2, 2, 3]) (vector [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])\r
33 > a\r
34 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
35 > ndarrayDims a\r
36 vector [2, 2, 3]\r
37 > ndarrayValues a\r
38 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
39 > ndarrayElement a 5\r
40 6.0\r
41 > ndarrayElementN a (vector [0, 1, 2])\r
42 6.0\r
43 > runPython do\r
44 >     setPythonNDArrayVariable "foo" (ndarrayM 2 3 (vector [1, 2, 3,  4, 5, 6]))\r
45 >     executePythonStatement "bar = foo.cumsum(1)"\r
46 >     getPythonNDArrayVariable "bar"\r
47 ndarray(2x3) [[1.0, 3.0, 6.0], [4.0, 9.0, 15.0]]\r
48 > runPython do\r
49 >     setPythonVariable "foo" ([1.0, 2.0, 3.0, 4.0] :: [Double])\r
50 >     executePythonStatement "foo.append(sum(foo))"\r
51 >     getPythonVariable "foo" :: [Double]\r
52 [1.0, 2.0, 3.0, 4.0, 10.0]\r