After a fashion anyway. I implemented the simplest thing that could possibly work and I've left out some stuff that even I think we need (docstring, repr and str). Still it exists, ndarray inherits from it and some stuff seems to work automagically.
import numpy as n ba = n.basearray([3,3], int, n.arange(9)) ba <numpy.basearray object at 0x00B29690> a = asarray(ba) a array([[0, 1, 2], [3, 4, 5], [6, 7, 8]]) a + ba array([[ 0, 2, 4], [ 6, 8, 10], [12, 14, 16]]) isinstance(a, n.basearray) True type(ba) <type 'numpy.basearray'> type(a) <type 'numpy.ndarray'> len(dir(ba)) 19 len(dir(a)) 156
Travis: should I go ahead and check this into the trunk? It shouldn't interfear with anything. The only change to ndarray is the tp_base, which sets up the inheritance. -tim
Let me add my $.02. I am very much in favor of a basic array object. I would probably go much further than Tim in simplifying it. No need for repr/str. No number protocol. No sequence/mapping protocol either. Maybe even no dimensions/striding etc. What is left? Not much on top of buffer protocol: the type description. I've expressed this opinion several times before (and was criticised for not supporting it:-): I don't think a basearray should be a base class. The main reason is that in most cases subclasses will need to adapt all the array methods. In many cases (speaking from ma experience, but probably matrix folks can relate) the adaptation is not automatic and has to be done on the method by method bases. Exposure of the base class methods without adaptation or with wrong adaptation leads to errors. Unless the base array is truly minimalistic and stays this way, methods that are added to the base class in the future will likely not work unadapted. The only implementation that uses inheritance that I will like would be something similar to python's object type: rich C API and no Python API. Would you consider checking your implementation in without modifying ndarray's tp_base? On 4/30/06, Tim Hochberg <tim.hochberg@cox.net> wrote:
After a fashion anyway. I implemented the simplest thing that could possibly work and I've left out some stuff that even I think we need (docstring, repr and str). Still it exists, ndarray inherits from it and some stuff seems to work automagically.
import numpy as n ba = n.basearray([3,3], int, n.arange(9)) ba <numpy.basearray object at 0x00B29690> a = asarray(ba) a array([[0, 1, 2], [3, 4, 5], [6, 7, 8]]) a + ba array([[ 0, 2, 4], [ 6, 8, 10], [12, 14, 16]]) isinstance(a, n.basearray) True type(ba) <type 'numpy.basearray'> type(a) <type 'numpy.ndarray'> len(dir(ba)) 19 len(dir(a)) 156
Travis: should I go ahead and check this into the trunk? It shouldn't interfear with anything. The only change to ndarray is the tp_base, which sets up the inheritance.
-tim
------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ Numpy-discussion mailing list Numpy-discussion@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/numpy-discussion
Tim Hochberg wrote:
After a fashion anyway. I implemented the simplest thing that could possibly work and I've left out some stuff that even I think we need (docstring, repr and str). Still it exists, ndarray inherits from it and some stuff seems to work automagically.
import numpy as n ba = n.basearray([3,3], int, n.arange(9)) ba <numpy.basearray object at 0x00B29690> a = asarray(ba) a array([[0, 1, 2], [3, 4, 5], [6, 7, 8]]) a + ba array([[ 0, 2, 4], [ 6, 8, 10], [12, 14, 16]]) isinstance(a, n.basearray) True type(ba) <type 'numpy.basearray'> type(a) <type 'numpy.ndarray'> len(dir(ba)) 19 len(dir(a)) 156
Travis: should I go ahead and check this into the trunk? It shouldn't interfear with anything. The only change to ndarray is the tp_base, which sets up the inheritance.
I say go ahead. We can then all deal with it there and improve upon it. The ndarray used to inherit from another array and things worked. Python's inheritance in C is actually quite slick. Especially for structural issues. I agree that the basearray should have minimal operations (I would not even define several of the protocols for it). I'd probably only keep the buffer and mapping protocol but even then probably only a simple mapping protocol (i.e. no fancy-indexing) that then gets enhanced by the ndarray. Thanks for the work. -Travis
participants (3)
-
Sasha -
Tim Hochberg -
Travis Oliphant