C Module's '1.#INF' changes to 'inf' at Python

CELEN Erman Erman.CELEN at 3ds.com
Mon Jan 11 15:31:15 EST 2010


>> (I also noticed that this behavior is same under standard NumPy 1.4 
>> with standard Python 2.6 on Windows. If you call numpy.log10(0.0) you 
>> will get an "-inf" and no exceptions will be raised. Which is not the 
>> case with Python's standard math.log10(0.0) which will raise a 
>> ValueError)
>
> Correct. This is numpy's intended behavior. See numpy.seterr() to enable
> exceptions if you want them.

Numpy.seterr() doesn't seem to be working in case of log10(0.0) (output with all standard: Python2.6 with NumPy1.4 on Windows-32bit is below)

  Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] on win32
  Type "help", "copyright", "credits" or "license" for more information.
  >>> import numpy
  >>> numpy.seterr()
  {'over': 'ignore', 'divide': 'ignore', 'invalid': 'ignore', 'under': 'ignore'}
  >>> numpy.int16(32000) * numpy.int16(3)
  30464
  >>> numpy.log10(0.0)
  -inf
  >>> numpy.seterr(all='raise')
  {'over': 'ignore', 'divide': 'ignore', 'invalid': 'ignore', 'under': 'ignore'}
  >>> numpy.int16(32000) * numpy.int16(3)
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
  FloatingPointError: overflow encountered in short_scalars
  >>> numpy.log10(0.0)
  -inf
  >>> numpy.log10(-1.0)
  nan
  >>> numpy.seterr()
  {'over': 'raise', 'divide': 'raise', 'invalid': 'raise', 'under': 'raise'}
  >>>

Also I'm pretty sure C's log10 (math.h) still sets errno to ERANGE (34) with both msvc8 and msvc9. That's why I thought a Numeric/Numpy wrapper might be involved but you are saying, if I'm not mistaken, math library's log10() function is called directly (without any special log10 wrappers) and only time Numeric changes errno is where it sets errno=0 before calling C's log10. Somehow, errno is not being set or gets changed/masked during this whole log10 call procedure and this might also be the reason why current version of Numpy is missing the error even if we do numpy.seterr(all='raise').

So, why do you think errno is not being set under Python with Numeric.log10 (or numpy.log10() which also seems to have the same 'letting overflow error through' issue) ?

Thanks for your help,

Best Regards,

Ali Erman CELEN
Platform Specialists / Porting



This email and any attachments are intended solely for the use of the individual or entity to whom it is addressed and may be confidential and/or privileged.  If you are not one of the named recipients or have received this email in error, (i) you should not read, disclose, or copy it, (ii) please notify sender of your receipt by reply email and delete this email and all attachments, (iii) Dassault Systemes does not accept or assume any liability or responsibility for any use of or reliance on this email.For other languages, go to http://www.3ds.com/terms/email-disclaimer.



More information about the Python-list mailing list