-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathArrayModule.java
More file actions
79 lines (71 loc) · 2.37 KB
/
Copy pathArrayModule.java
File metadata and controls
79 lines (71 loc) · 2.37 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
69
70
71
72
73
74
75
76
77
78
79
//Copyright (c) Corporation for National Research Initiatives
package org.python.modules;
import org.python.core.BuiltinDocs;
import org.python.core.ClassDictInit;
import org.python.core.PyArray;
import org.python.core.PyBytes;
import org.python.core.PyObject;
import org.python.core.PyType;
import org.python.core.PyUnicode;
import org.python.expose.ExposedConst;
import org.python.expose.ExposedFunction;
import org.python.expose.ExposedModule;
import org.python.expose.ModuleInit;
/**
* The python array module, plus jython extensions from jarray.
*/
@ExposedModule(name = "array", doc = BuiltinDocs.array_doc)
public class ArrayModule {
enum machine_format_code {
UNSIGNED_INT8(0),
SIGNED_INT8(1),
UNSIGNED_INT16_LE(2),
UNSIGNED_INT16_BE(3),
SIGNED_INT16_LE(4),
SIGNED_INT16_BE(5),
UNSIGNED_INT32_LE(6),
UNSIGNED_INT32_BE(7),
SIGNED_INT32_LE(8),
SIGNED_INT32_BE(9),
UNSIGNED_INT64_LE(10),
UNSIGNED_INT64_BE(11),
SIGNED_INT64_LE(12),
SIGNED_INT64_BE(13),
IEEE_754_FLOAT_LE(14),
IEEE_754_FLOAT_BE(15),
IEEE_754_DOUBLE_LE(16),
IEEE_754_DOUBLE_BE(7),
UTF16_LE(18),
UTF16_BE(19),
UTF32_LE(20),
UTF32_BE(21);
private int n;
machine_format_code(int x) {
n = x;
}
}
@ExposedConst(name = "typecodes")
public static final String TYPE_CODES = "bBuhHiIlLqQfd";
@ModuleInit
public static void classDictInit(PyObject dict) {
dict.__setitem__("array", PyType.fromClass(PyArray.class));
dict.__setitem__("ArrayType", PyType.fromClass(PyArray.class));
}
@ExposedFunction
public static final PyObject _array_reconstructor(PyObject arraytype, PyObject typecode, PyObject mformat_code,
PyObject items) {
// TODO: currently a placeholder to make the tests run
return new PyArray((PyType) arraytype);
}
/*
* These are jython extensions (from jarray module).
* Note that the argument order is consistent with
* python array module, but is reversed from jarray module.
*/
public static PyArray zeros(char typecode, int n) {
return PyArray.zeros(n, typecode);
}
public static PyArray zeros(Class type, int n) {
return PyArray.zeros(n, type);
}
}