Re: [Numpy-discussion] Nasty bug using pre-initialized arrays

2008-01-07 Thread Charles R Harris
On Jan 7, 2008 12:08 PM, Anne Archibald <[EMAIL PROTECTED]> wrote: > On 07/01/2008, Charles R Harris <[EMAIL PROTECTED]> wrote: > > > > One place where Numpy differs from MatLab is the way memory is handled. > > MatLab is always generating new arrays, so for efficiency it is worth > > preallocatin

Re: [Numpy-discussion] Nasty bug using pre-initialized arrays

2008-01-07 Thread Anne Archibald
On 07/01/2008, Charles R Harris <[EMAIL PROTECTED]> wrote: > > One place where Numpy differs from MatLab is the way memory is handled. > MatLab is always generating new arrays, so for efficiency it is worth > preallocating arrays and then filling in the parts. This is not the case in > Numpy where

Re: [Numpy-discussion] Nasty bug using pre-initialized arrays

2008-01-07 Thread Ryan May
Zachary Pincus wrote: >>> For large arrays, it makes since to do automatic >>> conversions, as is also the case in functions taking output arrays, >>> because the typecast can be pushed down into C where it is time and >>> space efficient, whereas explicitly converting the array uses up >>> tempora

Re: [Numpy-discussion] Nasty bug using pre-initialized arrays

2008-01-07 Thread Zachary Pincus
>> For large arrays, it makes since to do automatic >> conversions, as is also the case in functions taking output arrays, >> because the typecast can be pushed down into C where it is time and >> space efficient, whereas explicitly converting the array uses up >> temporary space. However, I can im

Re: [Numpy-discussion] Nasty bug using pre-initialized arrays

2008-01-07 Thread Ryan May
Charles R Harris wrote: > > > On Jan 7, 2008 8:47 AM, Ryan May <[EMAIL PROTECTED] PROTECTED]>> wrote: > > Stuart Brorson wrote: > >>> I realize NumPy != Matlab, but I'd wager that most users would think > >>> that this is the natural behavior.. > >> Well, th

Re: [Numpy-discussion] Nasty bug using pre-initialized arrays

2008-01-07 Thread Charles R Harris
On Jan 7, 2008 8:47 AM, Ryan May <[EMAIL PROTECTED]> wrote: > Stuart Brorson wrote: > >>> I realize NumPy != Matlab, but I'd wager that most users would think > >>> that this is the natural behavior.. > >> Well, that behavior won't happen. We won't mutate the dtype of the > array because > >>

Re: [Numpy-discussion] Nasty bug using pre-initialized arrays

2008-01-07 Thread Ryan May
Stuart Brorson wrote: >>> I realize NumPy != Matlab, but I'd wager that most users would think >>> that this is the natural behavior.. >> Well, that behavior won't happen. We won't mutate the dtype of the array >> because >> of assignment. Matlab has copy(-on-write) semantics for things like s

Re: [Numpy-discussion] Nasty bug using pre-initialized arrays

2008-01-05 Thread Zachary Pincus
> There are two related hierarchies of datatypes: different kinds > (integer, > floating point, complex floating point) and different precisions > within a given > kind (int8, int16, int32, int64). The term "downcasting" should > probably be > reserved for the latter only. > > It seems to me

Re: [Numpy-discussion] Nasty bug using pre-initialized arrays

2008-01-05 Thread Stuart Brorson
>> I wasn't at all arguing that having complex data chopped and >> downcast into an int or float container was the right thing to do. > > indeed, it is an clearly bad thing to do -- but a bug magnet? I'm not so > sure, surely, anyone that had any idea at all what they were doing with > complex numb

Re: [Numpy-discussion] Nasty bug using pre-initialized arrays

2008-01-04 Thread Chris Barker
Scott Ransom wrote: > I wasn't at all arguing that having complex data chopped and > downcast into an int or float container was the right thing to do. indeed, it is an clearly bad thing to do -- but a bug magnet? I'm not so sure, surely, anyone that had any idea at all what they were doing with

Re: [Numpy-discussion] Nasty bug using pre-initialized arrays

2008-01-04 Thread Scott Ransom
On Fri, Jan 04, 2008 at 04:31:53PM -0700, Timothy Hochberg wrote: > On Jan 4, 2008 3:28 PM, Scott Ransom <[EMAIL PROTECTED]> wrote: > > > On Friday 04 January 2008 05:17:56 pm Stuart Brorson wrote: > > > >> I realize NumPy != Matlab, but I'd wager that most users would > > > >> think that this is

Re: [Numpy-discussion] Nasty bug using pre-initialized arrays

2008-01-04 Thread Robert Kern
Zachary Pincus wrote: > Hello all, > >> That's well and good. But NumPy should *never* automatically -- and >> silently -- chop the imaginary part off your complex array elements, >> particularly if you are just doing an innocent assignment! >> Doing something drastic like silently throwing half

Re: [Numpy-discussion] Nasty bug using pre-initialized arrays

2008-01-04 Thread Zachary Pincus
Hello all, > That's well and good. But NumPy should *never* automatically -- and > silently -- chop the imaginary part off your complex array elements, > particularly if you are just doing an innocent assignment! > Doing something drastic like silently throwing half your data away can > lead to a

Re: [Numpy-discussion] Nasty bug using pre-initialized arrays

2008-01-04 Thread Stuart Brorson
I realize NumPy != Matlab, but I'd wager that most users would think that this is the natural behavior.. >>> >>> Well, that behavior won't happen. We won't mutate the dtype of the >>> array because of assignment. Matlab has copy(-on-write) semantics >>> for things like slices while we

Re: [Numpy-discussion] Nasty bug using pre-initialized arrays

2008-01-04 Thread Timothy Hochberg
On Jan 4, 2008 3:28 PM, Scott Ransom <[EMAIL PROTECTED]> wrote: > On Friday 04 January 2008 05:17:56 pm Stuart Brorson wrote: > > >> I realize NumPy != Matlab, but I'd wager that most users would > > >> think that this is the natural behavior.. > > > > > > Well, that behavior won't happen. We

Re: [Numpy-discussion] Nasty bug using pre-initialized arrays

2008-01-04 Thread Gael Varoquaux
On Fri, Jan 04, 2008 at 03:53:41PM -0700, Charles R Harris wrote: >Matlab support for different types was sort of kludged on. Matlab was >intended for computational convenience, not control of data types, and >started out as pretty much all doubles and double complex, it didn't >(do

Re: [Numpy-discussion] Nasty bug using pre-initialized arrays

2008-01-04 Thread Charles R Harris
On Jan 4, 2008 2:37 PM, Stuart Brorson <[EMAIL PROTECTED]> wrote: > On Fri, 4 Jan 2008, Stuart Brorson wrote: > > > > I realize NumPy != Matlab, but I'd wager that most users would think > that this is the natural behavior.. Matlab support for different types was sort of kludged on. Matlab

Re: [Numpy-discussion] Nasty bug using pre-initialized arrays

2008-01-04 Thread Scott Ransom
On Friday 04 January 2008 05:17:56 pm Stuart Brorson wrote: > >> I realize NumPy != Matlab, but I'd wager that most users would > >> think that this is the natural behavior.. > > > > Well, that behavior won't happen. We won't mutate the dtype of the > > array because of assignment. Matlab has c

Re: [Numpy-discussion] Nasty bug using pre-initialized arrays

2008-01-04 Thread Stuart Brorson
>> I realize NumPy != Matlab, but I'd wager that most users would think >> that this is the natural behavior.. > > Well, that behavior won't happen. We won't mutate the dtype of the array > because > of assignment. Matlab has copy(-on-write) semantics for things like slices > while > we have

Re: [Numpy-discussion] Nasty bug using pre-initialized arrays

2008-01-04 Thread Robert Kern
Stuart Brorson wrote: > On Fri, 4 Jan 2008, Stuart Brorson wrote: > >>> I just discovered this today. It looks like a bug to me. Please >>> flame me mercilessly if I am wrong! :-) > > FWIW, here's what Matlab does: > >>> A = rand(1, 4) + rand(1, 4)*i > > A = > >Columns 1 through 3 > >

Re: [Numpy-discussion] Nasty bug using pre-initialized arrays

2008-01-04 Thread Stuart Brorson
>> Sometimes you need to initialize an array using zeros() before doing >> an assignment to it in a loop. If you assign a complex value to the >> initialized array, the imaginary part of the array is dropped. Does >> NumPy do a silent type-cast which causes this behavior? Is this >> typecast a f

Re: [Numpy-discussion] Nasty bug using pre-initialized arrays

2008-01-04 Thread Stuart Brorson
On Fri, 4 Jan 2008, Stuart Brorson wrote: >> I just discovered this today. It looks like a bug to me. Please >> flame me mercilessly if I am wrong! :-) FWIW, here's what Matlab does: >> A = rand(1, 4) + rand(1, 4)*i A = Columns 1 through 3 0.7833 + 0.7942i 0.6808 + 0.0592i 0.461

Re: [Numpy-discussion] Nasty bug using pre-initialized arrays

2008-01-04 Thread Stuart Brorson
> I just discovered this today. It looks like a bug to me. Please > flame me mercilessly if I am wrong! :-) H after a little more playing around, I think it's indeed true that NumPy does a typecast to make the resulting assignment have the same type as the LHS, regardless of the type of

Re: [Numpy-discussion] Nasty bug using pre-initialized arrays

2008-01-04 Thread Pierre GM
On Friday 04 January 2008 16:08:54 Stuart Brorson wrote: > Sometimes you need to initialize an array using zeros() before doing > an assignment to it in a loop. If you assign a complex value to the > initialized array, the imaginary part of the array is dropped. Does > NumPy do a silent type-cast

[Numpy-discussion] Nasty bug using pre-initialized arrays

2008-01-04 Thread Stuart Brorson
NumPy gurus -- I just discovered this today. It looks like a bug to me. Please flame me mercilessly if I am wrong! :-) Sometimes you need to initialize an array using zeros() before doing an assignment to it in a loop. If you assign a complex value to the initialized array, the imaginary part