numpy.float128 absence yield bugs
hi all, if numpy.float128 type is absent (BTW does it related to OS or something else?), it yields bugs even if the type is never used (while importing from a py-file). For example: from numpy import ..., float64, float128 if (some_cond): <use float128> else: <use float64> So numpy turns out not being 100% cross-platform. Maybe it would be better to raise a warning like "float128 is absent, float64 will be used instead"? Or, better, implement float128 being always present at all? (I.e. connect a library that will take care of float128 type provided native machine support is absent)? Regars, D.
2008/3/10, dmitrey <dmitrey.kroshko@scipy.org>:
hi all, if numpy.float128 type is absent (BTW does it related to OS or something else?), it yields bugs even if the type is never used (while importing from a py-file). For example:
from numpy import ..., float64, float128 if (some_cond): <use float128> else: <use float64>
If you do not need a direct call to float128 in your condition, you can easily make it compatible on all platforms. Do not import numpy with "from numpy import ...", but only "import numpy", make your decision based on cond and the presence of float128 ('float128' in dir(numpy)) and everything will be fine ;) Matthieu -- French PhD student Website : http://matthieu-brucher.developpez.com/ Blogs : http://matt.eifelle.com and http://blog.developpez.com/?blog=92 LinkedIn : http://www.linkedin.com/in/matthieubrucher
Matthieu Brucher wrote:
2008/3/10, dmitrey <dmitrey.kroshko@scipy.org <mailto:dmitrey.kroshko@scipy.org>>:
hi all, if numpy.float128 type is absent (BTW does it related to OS or something else?), it yields bugs even if the type is never used (while importing from a py-file). For example:
from numpy import ..., float64, float128 if (some_cond): <use float128> else: <use float64>
If you do not need a direct call to float128 in your condition, you can easily make it compatible on all platforms. Do not import numpy with "from numpy import ...", but only "import numpy", make your decision based on cond and the presence of float128 ('float128' in dir(numpy)) and everything will be fine ;)
Matthieu
I still think if something is wrong with from numpy import ... than it should be found and fixed instead of avoiding the one and proposing the solution to other numpy users/programmers. I guess putting the checks ... in dir(numpy) or hasattr(numpy, float128) everywhere isn't a best solution. Regards, D.
If you do not need a direct call to float128 in your condition, you can easily make it compatible on all platforms. Do not import numpy with "from numpy import ...", but only "import numpy", make your decision based on cond and the presence of float128 ('float128' in dir(numpy)) and everything will be fine ;)
Matthieu
I still think if something is wrong with from numpy import ... than it should be found and fixed instead of avoiding the one and proposing the solution to other numpy users/programmers. I guess putting the checks ... in dir(numpy) or hasattr(numpy, float128) everywhere isn't a best solution.
The issue is that not every platform has a float128 library, so either you make it available to noone so that such error cannot be raised, either you add some code in case you really need it and it is available. If float128 is implemented in a bogus way and your condition is true, there will be another issue and you will ask for a complete implementation, which will never be the case. I think that your best shot is with making with what is available, with its advantages and drawbacks, and that means testing for the existence of float128 if you need it. Matthieu -- French PhD student Website : http://matthieu-brucher.developpez.com/ Blogs : http://matt.eifelle.com and http://blog.developpez.com/?blog=92 LinkedIn : http://www.linkedin.com/in/matthieubrucher
dmitrey wrote:
hi all, if numpy.float128 type is absent (BTW does it related to OS or something else?), it yields bugs even if the type is never used (while importing from a py-file). For example:
I suggest using numpy.longdouble if you are interested in cross-platform use of float128. There will always be a longdouble, but on some platforms it is 128-bit, on others 96-bit, and on others 64-bit (i.e. the same as double). -Travis O.
As for numpy.longdouble (and related types if they are intended to be implemented), I suppose numpy also should have a function to return number of bites used (128, 96, 64 etc). Ok. Another one question: does numpy have function(s), that accepts a numpy type (float32, float64, uint16 etc) and yields: max value (like 1e300); min value (like -1e300); min positive value (for floats) like 1e-300? Thank you in advance, D. Travis E. Oliphant wrote:
dmitrey wrote:
hi all, if numpy.float128 type is absent (BTW does it related to OS or something else?), it yields bugs even if the type is never used (while importing from a py-file). For example:
I suggest using numpy.longdouble if you are interested in cross-platform use of float128. There will always be a longdouble, but on some platforms it is 128-bit, on others 96-bit, and on others 64-bit (i.e. the same as double).
-Travis O.
_______________________________________________ Scipy-dev mailing list Scipy-dev@scipy.org http://projects.scipy.org/mailman/listinfo/scipy-dev
You mean like : numpy.float64.nbytes and : numpy.finfo(numpy.float64) ? Matthieu 2008/3/10, dmitrey <dmitrey.kroshko@scipy.org>:
As for numpy.longdouble (and related types if they are intended to be implemented), I suppose numpy also should have a function to return number of bites used (128, 96, 64 etc).
Ok. Another one question: does numpy have function(s), that accepts a numpy type (float32, float64, uint16 etc) and yields: max value (like 1e300); min value (like -1e300); min positive value (for floats) like 1e-300?
Thank you in advance, D.
Travis E. Oliphant wrote:
dmitrey wrote:
hi all, if numpy.float128 type is absent (BTW does it related to OS or something else?), it yields bugs even if the type is never used (while importing from a py-file). For example:
I suggest using numpy.longdouble if you are interested in cross-platform use of float128. There will always be a longdouble, but on some platforms it is 128-bit, on others 96-bit, and on others 64-bit (i.e. the same as double).
-Travis O.
_______________________________________________ Scipy-dev mailing list Scipy-dev@scipy.org http://projects.scipy.org/mailman/listinfo/scipy-dev
_______________________________________________ Scipy-dev mailing list Scipy-dev@scipy.org http://projects.scipy.org/mailman/listinfo/scipy-dev
-- French PhD student Website : http://matthieu-brucher.developpez.com/ Blogs : http://matt.eifelle.com and http://blog.developpez.com/?blog=92 LinkedIn : http://www.linkedin.com/in/matthieubrucher
On Mon, Mar 10, 2008 at 12:37 PM, dmitrey <dmitrey.kroshko@scipy.org> wrote:
As for numpy.longdouble (and related types if they are intended to be implemented), I suppose numpy also should have a function to return number of bites used (128, 96, 64 etc).
In [6]: numpy.dtype(numpy.longdouble).itemsize Out[6]: 16
Ok. Another one question: does numpy have function(s), that accepts a numpy type (float32, float64, uint16 etc) and yields: max value (like 1e300); min value (like -1e300); min positive value (for floats) like 1e-300?
In [7]: i = numpy.finfo(numpy.longdouble) In [8]: i. i.__class__ i.__module__ i.__weakref__ i._str_tiny i.max i.precision i.__delattr__ i.__new__ i._finfo_cache i.dtype i.maxexp i.resolution i.__dict__ i.__reduce__ i._init i.eps i.min i.tiny i.__doc__ i.__reduce_ex__ i._str_eps i.epsneg i.minexp i.__getattribute__ i.__repr__ i._str_epsneg i.iexp i.negep i.__hash__ i.__setattr__ i._str_max i.machar i.nexp i.__init__ i.__str__ i._str_resolution i.machep i.nmant In [8]: i.min Out[8]: -1.189731495357231765021e+4932 In [9]: i.max Out[9]: 1.189731495357231765021e+4932 In [10]: i.tiny Out[10]: array(3.362103143112093506263e-4932, dtype=float128) -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco
participants (4)
-
dmitrey
-
Matthieu Brucher
-
Robert Kern
-
Travis E. Oliphant