patch in Python?
Fernando Perez
fperez at pizero.colorado.edu
Wed Oct 2 14:58:34 EDT 2002
More information about the Python-list mailing list
Wed Oct 2 14:58:34 EDT 2002
- Previous message (by thread): patch in Python?
- Next message (by thread): patch in Python?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Wed, 2 Oct 2002, Gerhard Häring wrote: > > - How does this compare to gmpy? > > No idea. It doesn't have rationals, which GPM has (not sure about gmpy). > Btw. I think mxNumber from MAL is the GMP wrapper that has the most > momentum nowadays. His aim is a similar one: NUMERIC support for his > mxODBC library. Great. I'll have to look at mxNumber when I get around to working on this problem. It would be great if the Numpy support was in already, but if needed that's something I could work on. > > - And http://www.nersc.gov/~dhbailey/mpdist/mpdist.html? This one is supposed > > to be first rate. > > These are written in Fortran and C++, it seems. See above. In my tries > to wrap MAPM I have found, however, that creating a new Python number > type is relatively easy. So if these are worth wrapping, I think it > should be a matter of days, rather than weeks. This one is a strong candidate b/c the algorithms for extended (_not_ arbitrary) precision have been very carefully tuned. > > I'd love to have the ability not only to define extended/arbitrary precision > > scalars, but especially to have them carry over to Numeric. One could then > > develop a difficult algorithm in arbitrary precision and then move it over to > > only extended (or even normal) precision once everything is working reliably. > > Yeah, this sounds like a neat idea. > > One "problem" I currently have is this: > > Under MAPM, certain operations (division, exponentiation, ...) require > an additional parameter for the precision. My current API is this: > > module mapm: > def set_default_div_precision(n) > def set_default_pow_precision(n) > > class MAPM: > ... > def __div__(self, other, precision=None) > def __pow__(self, other, precision=None) > > But under normal operation, such as in: > > a = mapm.MAPM("27.34") > b = mapm.MAPM("3.17") > c = a / b > > you can't give the precision operator to __div__, so you'd have to set > the precision before with something like: > > mapm.set_default_div_precision(10) > > alternatively, you can do without the "/" operator: > > c = a.__div__(b, 10) > > but this feels clumsy. > > To put it short: do you have any suggestion for a better API wrt. > precision? Well, you could extend your MAPM class so that _each_ number in it carries a precision flag with it. Operations would then be done with the precision of the lower of the two operands. Pseudocode: class MAPM: def __init__(self,data,precision=16): ... Then, a = mapm.MAPM("27.34",32) b = mapm.MAPM("3.17",48) c = a/b # c would be a mapm number with 32 digits. You could have an overall flag for warnings, so that anytime that there is a loss of precision (like in the above case) a warning is printed. Cheers, f.
- Previous message (by thread): patch in Python?
- Next message (by thread): patch in Python?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list