KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > python > modules > ArrayModule


1 //Copyright (c) Corporation for National Research Initiatives
2
package org.python.modules;
3
4 import org.python.core.*;
5
6 /**
7  * The python array module, plus jython extensions from jarray.
8  */

9 public class ArrayModule {
10     
11     public static PyString __doc__ = new PyString(
12         "This module defines a new object type which can efficiently represent\n" +
13         "an array of basic values: characters, integers, floating point\n" +
14         "numbers. Arrays are sequence types and behave very much like lists,\n" +
15         "except that the type of objects stored in them is constrained. The\n" +
16         "type is specified at object creation time by using a type code, which\n" +
17         "is a single character. The following type codes are defined:\n" +
18         "\n" +
19         " Type code C Type Minimum size in bytes \n" +
20         " 'z' boolean 1 \n" +
21         " 'c' character 1 \n" +
22         " 'b' signed integer 1 \n" +
23       //" 'B' unsigned integer 1 \n" +
24
" 'h' signed integer 2 \n" +
25       //" 'H' unsigned integer 2 \n" +
26
" 'i' signed integer 2 \n" +
27       //" 'I' unsigned integer 2 \n" +
28
" 'l' signed integer 4 \n" +
29       //" 'L' unsigned integer 4 \n" +
30
" 'f' floating point 4 \n" +
31         " 'd' floating point 8 \n" +
32         "\n" +
33         "Functions:\n" +
34         "\n" +
35         "array(typecode [, initializer]) -- create a new array\n" +
36         "\n" +
37         "Special Objects:\n" +
38         "\n" +
39         "ArrayType -- type object for array objects\n"
40     );
41     
42     public static PyString __name__ = new PyString("array");
43     
44     /*
45      * These are python array methods.
46      */

47     
48     public static PyArray ArrayType(char TypeCode) {
49             return PyArray.array(new PyList(), TypeCode);
50     }
51     
52     public static PyObject ArrayType(char TypeCode, PyObject sequence) {
53             return PyArray.array(sequence, TypeCode);
54     }
55
56     public static PyObject array(char TypeCode) {
57             return PyArray.array(new PyList(), TypeCode);
58     }
59     
60     public static PyObject array(char TypeCode, PyObject sequence) {
61              return PyArray.array(sequence, TypeCode);
62     }
63
64     /*
65      * These are jython extensions (from jarray module).
66      * Note that the argument order is consistent with
67      * python array module, but is reversed from jarray module.
68      */

69
70     public static PyArray array(Class JavaDoc type, PyObject seq) {
71         return PyArray.array(seq, type);
72     }
73     
74     public static PyArray zeros(char typecode, int n) {
75         return PyArray.zeros(n, typecode);
76     }
77
78     public static PyArray zeros(Class JavaDoc type, int n) {
79         return PyArray.zeros(n, type);
80     }
81 }
82
Popular Tags