-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathembedpy-issues.txt
More file actions
73 lines (57 loc) · 2.19 KB
/
embedpy-issues.txt
File metadata and controls
73 lines (57 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
Ways the embedPy feature/object gets used:
Import a module -
np:.p.import`numpy - returns a embedPy object with pointers to all methods inside numpy
npar:.p.import[`numpy;`array;* or < or >] - returns a embedPy, q or foreign(python) object with the array() method as callable,qcallable, or pycallable - automatically happens.
equivalent to
np:.p.import `numpy
npar:.p.callable np`array; / or qcallable or pycallable
can also be used as
np:.p.import`numpy;
np[`array;*;(1000 1000 1000;1000 1000 1000)]
Another example :
drf:.p.import[`dicom;`read_file;*] / .p.callable return of method read_file inside dicom
drf <filename> / - string file name
Instantiating objects
pd:.p.import `pandas
pd[`DataFrame;*][] - calls default constructor
without parens, returns an embedPy <class DataFframe>
or
.p.import[`pandas;`DataFrame;*][] - calls default constructor
df:..p.import[`pandas;`DataFrame;*] - get class , then instantiate later by
df[<appropriate object>];
Chaining embedpy objects
q)np:.p.import`numpy
q)v:np[`arange;*;12]
q)v`
0 1 2 3 4 5 6 7 8 9 10 11
q)v[`mean;<][]
5.5
q)rs:v[`reshape;<]
q)rs[3;4]
0 1 2 3
4 5 6 7
8 9 10 11
q)rs[2;6]
0 1 2 3 4 5
6 7 8 9 10 11
q)np[`arange;*;12][`reshape;*;3;4]`
0 1 2 3
4 5 6 7
8 9 10 11
q)np[`arange;*;12][`reshape;*;3;4][`T]`
0 1 2
3 4 5
6 7 8
9 10 11
Equivalence of .p.import[] and .p.callable -
q)stdout:.p.callable(.p.import[`sys]`stdout.write)
q)stdout"hello\n";
hello
q)stderr:.p.import[`sys;`stderr.write;*]
q)stderr"goodbye\n";
goodbye
*** if a method returns a foreign and one wants to access its methods, .p.wrap the foreign and then access methods.
**** In order to bring a python object and access its methods inside q, use an embedPy object, via either .p.import, .p.get or .p.eval, r .p.wrap. An embedPy object is effectively the representation of a python object inside q, with behaviour just like in the python world.
**** Once an embedPy object is created, one can either access attributes, or call methods and get q objects
*** therefore, from foreign->embedPy->q.??
-> EmbedPy objects can be viewed as a representation of a python object inside q, with access to both attributes and methods of the python object inside q, in a q fashion.