Anonymous avatar Anonymous committed cf6fa0b

Add array_class to jarray. array_class returns the "Array of type" class.

Useful for clamp and other places where a class of an array needs to be passed.

Comments (0)

Files changed (3)

 Jython NEWS
 
+Jython 2.7a3
+    - array_class in jarray module returns the "Array of a type" class
+
 Jython 2.7a2
     - [ 1892 ] site-packages is not in sys.path
 

src/org/python/core/PyArray.java

         array.typecode = Character.toString(typecode);
         return array;
     }
+    
+    public static Class<?> array_class(Class<?> type) {
+         return Array.newInstance(type, 0).getClass();
+    }
 
     /**
      * Create a PyArray storing <em>ctype</em> types and being initialised

src/org/python/modules/jarray.java

     public static PyArray zeros(int n, Class type) {
         return PyArray.zeros(n, type);
     }
+    
+    public static Class<?> array_class(PyObject type) {
+        return PyArray.array_class((Class<?>)type.__tojava__(Class.class));
+    }
 }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.