01: //Copyright (c) Corporation for National Research Initiatives
02: package org.python.modules;
03:
04: import org.python.core.ClassDictInit;
05: import org.python.core.PyArray;
06: import org.python.core.PyObject;
07: import org.python.core.PyString;
08: import org.python.core.PyType;
09:
10: /**
11: * The python array module, plus jython extensions from jarray.
12: */
13: public class ArrayModule implements ClassDictInit {
14:
15: public static PyString __doc__ = new PyString(
16: "This module defines a new object type which can efficiently represent\n"
17: + "an array of basic values: characters, integers, floating point\n"
18: + "numbers. Arrays are sequence types and behave very much like lists,\n"
19: + "except that the type of objects stored in them is constrained. The\n"
20: + "type is specified at object creation time by using a type code, which\n"
21: + "is a single character. The following type codes are defined:\n"
22: + "\n"
23: + " Type code C Type Minimum size in bytes \n"
24: + " 'z' boolean 1 \n"
25: + " 'c' character 1 \n"
26: + " 'b' signed integer 1 \n"
27: +
28: //" 'B' unsigned integer 1 \n" +
29: " 'h' signed integer 2 \n"
30: +
31: //" 'H' unsigned integer 2 \n" +
32: " 'i' signed integer 2 \n"
33: +
34: //" 'I' unsigned integer 2 \n" +
35: " 'l' signed integer 4 \n"
36: +
37: //" 'L' unsigned integer 4 \n" +
38: " 'f' floating point 4 \n"
39: + " 'd' floating point 8 \n"
40: + "\n"
41: + "Functions:\n"
42: + "\n"
43: + "array(typecode [, initializer]) -- create a new array\n"
44: + "\n" + "Special Objects:\n" + "\n"
45: + "ArrayType -- type object for array objects\n");
46:
47: public static void classDictInit(PyObject dict) {
48: dict.__setitem__("array", PyType.fromClass(PyArray.class));
49: dict.__setitem__("ArrayType", PyType.fromClass(PyArray.class));
50: }
51:
52: /*
53: * These are jython extensions (from jarray module).
54: * Note that the argument order is consistent with
55: * python array module, but is reversed from jarray module.
56: */
57: public static PyArray zeros(char typecode, int n) {
58: return PyArray.zeros(n, typecode);
59: }
60:
61: public static PyArray zeros(Class type, int n) {
62: return PyArray.zeros(n, type);
63: }
64: }
|