[Matrix-SIG] Patches for improved single precision handling in NumPy

Travis Oliphant Oliphant.Travis@mayo.edu
Wed, 12 Jan 2000 13:49:57 -0600 (CST)


  This message is in MIME format.  The first part should be readable text,
  while the remaining parts are likely unreadable without MIME-aware tools.
  Send mail to mime@docserver.cac.washington.edu for more info.

---1463811840-820702757-947706597=:3782
Content-Type: TEXT/PLAIN; charset=US-ASCII


For anyone interested I'm attaching a patch against Numerical-14 which
changes NumPy to alleviate some of the difficulty with single precision
work.  I implemented the changes I proposed previously plus altered
array_compare so that comparisons of rank-0 arrays work as expected.  

I've tested the change and it appears to work nicely.  With this change, I
can use single precision rank-0 arrays and not worry about operations with
them returning double precision scalars automatically.  The rank-0 scalars
also act nicely in other contexts. 

If anyone has comments or suggestions, I'd appreciate them.

Travis


---1463811840-820702757-947706597=:3782
Content-Type: TEXT/PLAIN; charset=US-ASCII; name="mypatch.diff"
Content-Transfer-Encoding: BASE64
Content-ID: <Pine.LNX.4.10.10001121349570.3782@us2.mayo.edu>
Content-Description: Patch against Numerical-14 for single precision improvement
Content-Disposition: attachment; filename="mypatch.diff"

ZGlmZiAtY3IgTnVtZXJpY2FsLTE0Lm9yaWcvU3JjL2FycmF5b2JqZWN0LmMg
TnVtZXJpY2FsLTE0L1NyYy9hcnJheW9iamVjdC5jDQoqKiogTnVtZXJpY2Fs
LTE0Lm9yaWcvU3JjL2FycmF5b2JqZWN0LmMJTW9uIEphbiAxMCAxNjo0NTow
MyAyMDAwDQotLS0gTnVtZXJpY2FsLTE0L1NyYy9hcnJheW9iamVjdC5jCVdl
ZCBKYW4gMTIgMTM6NDI6NDEgMjAwMA0KKioqKioqKioqKioqKioqDQoqKiog
NDQ0LDQ1MSAqKioqDQogIAkJaWYgKG1wICE9IE5VTEwpIFB5X0RFQ1JFRiht
cCk7DQogIAkJcmV0dXJuIE5VTEw7DQogIAl9DQohIAlpZiAobXAtPm5kID09
IDApIHsNCiEgCQlvcCA9IGFycmF5X2l0ZW0obXAsIDApOw0KICAJCV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