[Numpy-discussion] Numpy 1.6 schedule

Mark Wiebe mwwiebe@gmail....
Mon Mar 7 11:50:43 CST 2011


On Mon, Mar 7, 2011 at 9:23 AM, Robert Kern <robert.kern@gmail.com> wrote:

> On Mon, Mar 7, 2011 at 11:08, Christopher Barker <Chris.Barker@noaa.gov>
> wrote:
> > On 3/6/11 5:54 AM, Charles R Harris wrote:
> >> I suppose this might cause a problem with lazy/quick c extensions that
> >> expected elements in a certain order, so some breakage could occur.
> >
> > absolutely!
> >
> > (I've gotten a bit confused about this thread, but if this is about the
> > question of whether structured dtypes are dtypes are assumed to always
> > keep order, read on -- otherwise, ignore)..
>
> Can someone explain exactly what changed? Or point to the changeset
> that made it? It's not clear to me what operations are different under
> Mark's changes.


Here is the structured data type difference, in an example where the 1.5
behavior is problematic. In 1.5, because values are copied 'tuple-like', the
previous X coordinate which is thrown away for saving but needed during
simulation, gets copied into the velocity.

>>> import numpy as np
>>> np.__version__
'1.5.1'
>>> sim_particles = np.zeros((2,), dtype=[('X', 'f4', 3), ('X_prev', 'f4',
3), ('V', 'f4', 3)]).view(np.recarray)
>>> save_particles = np.zeros((2,), dtype=[('X', 'f4', 3), ('V', 'f4', 3),
('Color', 'u8', 3)]).view(np.recarray)
>>> # Some particle data
... sim_particles.X_prev = 0.5
>>> sim_particles.V = 1.0
>>> sim_particles.X = sim_particles.X_prev + sim_particles.V
>>> # Save the particles with a solid color
... save_particles[...] = sim_particles
>>> save_particles.Color = [0,255,128]
>>> save_particles
rec.array([([1.5, 1.5, 1.5], [0.5, 0.5, 0.5], [0L, 255L, 128L]),
       ([1.5, 1.5, 1.5], [0.5, 0.5, 0.5], [0L, 255L, 128L])],
      dtype=[('X', '<f4', 3), ('V', '<f4', 3), ('Color', '<u8', 3)])

>>> import numpy as np
>>> np.__version__
'1.6.0.dev-766cac0'
>>> sim_particles = np.zeros((2,), dtype=[('X', 'f4', 3), ('X_prev', 'f4',
3), ('V', 'f4', 3)]).view(np.recarray)
>>> save_particles = np.zeros((2,), dtype=[('X', 'f4', 3), ('V', 'f4', 3),
('Color', 'u8', 3)]).view(np.recarray)
>>> # Some particle data
... sim_particles.X_prev = 0.5
>>> sim_particles.V = 1.0
>>> sim_particles.X = sim_particles.X_prev + sim_particles.V
>>> # Save the particles with a solid color
... save_particles[...] = sim_particles
>>> save_particles.Color = [0,255,128]
>>> save_particles
rec.array([([1.5, 1.5, 1.5], [1.0, 1.0, 1.0], [0L, 255L, 128L]),
       ([1.5, 1.5, 1.5], [1.0, 1.0, 1.0], [0L, 255L, 128L])],
      dtype=[('X', '<f4', (3,)), ('V', '<f4', (3,)), ('Color', '<u8',
(3,))])

Cheers,
Mark
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20110307/63dccc40/attachment.html 


More information about the NumPy-Discussion mailing list