From: Filip W. <fi...@ft...> - 2006-07-11 23:36:16
|
Hi, the way of accessing data with __array_interface__, as shown by Travis in [1], also works nicely when used with builtin array.array (if someone here is still using it;). Time to convert array.array to ndarray is O(N) but can be made O(1) just by simple subclassing. [1] http://aspn.activestate.com/ASPN/Mail/Message/numpy-discussion/3191164 cheers, fw ----------------------------------------------------------------------- #!/usr/bin/env python # -*- coding: utf-8 -*- import array as _array import sys if sys.byteorder == 'little': _ENDIAN = '<' else: _ENDIAN = '>' _TYPES_CONV ={ 'c': '|u%%d', #character 1 'b': '|i%%d', #signed integer 1 'B': '|u%%d', #unsigned integer 1 'u': '%su%%d' % _ENDIAN, #Unicode character 2 'h': '%si%%d' % _ENDIAN, #signed integer 2 'H': '%su%%d' % _ENDIAN, #unsigned integer 2 'i': '%si%%d' % _ENDIAN, #signed integer 2 (4?) 'I': '%su%%d' % _ENDIAN, #unsigned integer 2 (4?) 'l': '%si%%d' % _ENDIAN, #signed integer 4 'L': '%su%%d' % _ENDIAN, #unsigned integer 4 'f': '%sf%%d' % _ENDIAN, #floating point 4 'd': '%sf%%d' % _ENDIAN, #floating point 8 } class array(_array.array): def __get_array_interface__(self): new = {} shape, typestr = (self.__len__(),), (_TYPES_CONV[self.typecode] % self.itemsize) new['shape'] = shape new['typestr'] = typestr new['data'] = (self.buffer_info()[0], False) # writable return new __array_interface__ = property(__get_array_interface__, None, doc="array interface") if __name__ == '__main__': size = 1000000 typecode = 'f' new = array(typecode, xrange(size)) old = _array.array(typecode, xrange(size)) import numpy from time import clock as time t1 = time() nd = numpy.asarray(new) t1 = time() - t1 #print nd t2 = time() nd = numpy.asarray(old) t2 = time() - t2 #print nd print "new:", t1 print "old:", t2 #EOF |
From: Travis O. <oli...@ee...> - 2006-07-11 23:43:11
|
Filip Wasilewski wrote: >Hi, > >the way of accessing data with __array_interface__, as shown by Travis >in [1], also works nicely when used with builtin array.array (if someone >here is still using it;). > >Time to convert array.array to ndarray is O(N) but can be made O(1) just >by simple subclassing. > >[1] http://aspn.activestate.com/ASPN/Mail/Message/numpy-discussion/3191164 > > > This is exactly the kind of thing I'd like to see get into Python. Thanks for picking up the ball.. -Travis |
From: Sasha <nd...@ma...> - 2006-07-12 02:38:34
|
I had similar hopes when I submited the array interface patch <https://sourceforge.net/tracker/index.php?func=detail&aid=1452906&group_id=5470&atid=305470> and announced it on python-dev <http://aspn.activestate.com/ASPN/Mail/Message/python-dev/3068813>. I am still waiting for anyone to comment on it :-( On 7/11/06, Travis Oliphant <oli...@ee...> wrote: > Filip Wasilewski wrote: > > >Hi, > > > >the way of accessing data with __array_interface__, as shown by Travis > >in [1], also works nicely when used with builtin array.array (if someone > >here is still using it;). > > > >Time to convert array.array to ndarray is O(N) but can be made O(1) just > >by simple subclassing. > > > >[1] http://aspn.activestate.com/ASPN/Mail/Message/numpy-discussion/3191164 > > > > > > > This is exactly the kind of thing I'd like to see get into Python. > Thanks for picking up the ball.. > > > -Travis > > > > ------------------------------------------------------------------------- > 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 > Num...@li... > https://lists.sourceforge.net/lists/listinfo/numpy-discussion > |
From: Thomas H. <th...@py...> - 2006-07-12 11:30:14
|
Sasha schrieb: > I had similar hopes when I submited the array interface patch > <https://sourceforge.net/tracker/index.php?func=detail&aid=1452906&group_id=5470&atid=305470> > and announced it on python-dev > <http://aspn.activestate.com/ASPN/Mail/Message/python-dev/3068813>. > > I am still waiting for anyone to comment on it :-( > The *relevant* comment is here: http://aspn.activestate.com/ASPN/Mail/Message/python-dev/3078372 Thomas |
From: Karol L. <kar...@kn...> - 2006-07-12 13:41:18
|
On Wednesday 12 July 2006 13:29, Thomas Heller wrote: > Sasha schrieb: > > I had similar hopes when I submited the array interface patch > > <https://sourceforge.net/tracker/index.php?func=3Ddetail&aid=3D1452906&= group_ > >id=3D5470&atid=3D305470> and announced it on python-dev > > <http://aspn.activestate.com/ASPN/Mail/Message/python-dev/3068813>. > > > > I am still waiting for anyone to comment on it :-( > > The *relevant* comment is here: > > http://aspn.activestate.com/ASPN/Mail/Message/python-dev/3078372 > > Thomas A related PEP _is_ being prepared - it can be found at=20 http://svn.scipy.org/svn/PEP/ (created by Travis). In fact, I am working on= =20 it for Google Summer of Code, as I wrote in a different thread. I think tha= t=20 if everyone interested in getting some kind of array interface into Python= =20 core focused on a common effort, it would be more effecient and probably ma= ke=20 a stronger impression. I created a page about it at http://scipy.org/BaseArray, and will be adding= =20 more information very soon. Contribution and comments from annyone interest= ed=20 are very welcome. I really hope we can get this moving allong, and do it right. Karol =2D-=20 written by Karol Langner =B6ro lip 12 15:31:09 CEST 2006 |
From: Thomas H. <th...@py...> - 2006-07-12 14:01:40
|
Karol Langner schrieb: > On Wednesday 12 July 2006 13:29, Thomas Heller wrote: >> Sasha schrieb: >> > I had similar hopes when I submited the array interface patch >> > <https://sourceforge.net/tracker/index.php?func=detail&aid=1452906&group_ >> >id=5470&atid=305470> and announced it on python-dev >> > <http://aspn.activestate.com/ASPN/Mail/Message/python-dev/3068813>. >> > >> > I am still waiting for anyone to comment on it :-( >> >> The *relevant* comment is here: >> >> http://aspn.activestate.com/ASPN/Mail/Message/python-dev/3078372 >> >> Thomas > > A related PEP _is_ being prepared - it can be found at > http://svn.scipy.org/svn/PEP/ (created by Travis). I know. But, hiding it somewhere on the internet doesn't lead anywhere. You (the authors) should follow the official PEP process, instead: submit an official PEP, post it for feedback, and so on. Thomas |
From: Karol L. <kar...@kn...> - 2006-07-12 14:16:04
|
On Wednesday 12 July 2006 16:00, Thomas Heller wrote: > Karol Langner schrieb: > > On Wednesday 12 July 2006 13:29, Thomas Heller wrote: > >> Sasha schrieb: > >> > I had similar hopes when I submited the array interface patch > >> > <https://sourceforge.net/tracker/index.php?func=3Ddetail&aid=3D14529= 06&gro > >> >up_ id=3D5470&atid=3D305470> and announced it on python-dev > >> > <http://aspn.activestate.com/ASPN/Mail/Message/python-dev/3068813>. > >> > > >> > I am still waiting for anyone to comment on it :-( > >> > >> The *relevant* comment is here: > >> > >> http://aspn.activestate.com/ASPN/Mail/Message/python-dev/3078372 > >> > >> Thomas > > > > A related PEP _is_ being prepared - it can be found at > > http://svn.scipy.org/svn/PEP/ (created by Travis). > > I know. But, hiding it somewhere on the internet doesn't lead anywhere. > You (the authors) should follow the official PEP process, instead: > submit an official PEP, post it for feedback, and so on. I haven't actually thought about this, but I guess that is will happen soon= er=20 or later. I started working on the code in the scipt svn repository, and I'= m=20 not to well oriented how the dev procedure works. Maybe Travis can tell us= =20 about long-term strategy for the PEP, if there already is some? There was a PEP back in 2001 concerning MD-arrays=20 (http://www.python.org/dev/peps/pep-0209/), which is was even featured in t= he=20 "PEP parade" (http://www.python.org/doc/essays/pepparade.html), but got=20 deferred, abandoned, withdrawn, or something else. Karol =2D-=20 written by Karol Langner =B6ro lip 12 16:04:22 CEST 2006 |