← Back to team overview

python-quantities-developers team mailing list archive

Re: Welcome

 

I worked on the wrapper function generator a bit, and I got it working well
with a basic case (scipy.integration.quad), but I have run up against
something rather tricky. The way it works now is that all arguments are
simplified (rescaled to their base units) and then recast as ndarrays. The
simplification is necessary so that if the base function adds two quantities
together (in say a fortran module where they will be treated as ndarrays)
the units work out. The problem comes up when the user passes an object that
the base function will call a member function from and return a quantity
(maybe this is totally contrived). Since we don't have access to the object
we can't perpare it to be used in the base_function (simplifying etc.).

I don't know if this is fixable, but perhaps you have and idea.

John


On Fri, Jan 2, 2009 at 4:35 PM, John Salvatier <jsalvatier@xxxxxxxxx> wrote:

> I added the ability to add quantities with different (but reconcilable)
> units.
>
> I also started playing around with a way to create wrapper functions for
> functions that you want to have work correctly with Quantities. It currently
> works like this:
>
> from quantities import *
>
> from scipy.integrate import quad
>
> def integrate_units(function, x1, x2):
>     return (function(x1) * x2,function(x1) * x2)
>
> #generate a wrapper function
> integrator =  quantitizer( quad, integrate_units)
>
> #try it out
> func = lambda x: x
>
> #integrate f(x) = x between 1 and 5 m
> print integrator(func, 1 * m, 5 * m)
>
> See the __doc__ for quantitizer for a little bit of detail.
>
> I'll push the changes out a bit later.
>
> John
>
> On Fri, Jan 2, 2009 at 4:29 PM, Darren Dale <dsdale24@xxxxxxxxx> wrote:
>
>> Welcome to the python-quantities-developers mailing list!
>>
>> _______________________________________________
>> Mailing list: https://launchpad.net/~python-quantities-developers<https://launchpad.net/%7Epython-quantities-developers>
>> Post to     : python-quantities-developers@xxxxxxxxxxxxxxxxxxx
>> Unsubscribe : https://launchpad.net/~python-quantities-developers<https://launchpad.net/%7Epython-quantities-developers>
>> More help   : https://help.launchpad.net/ListHelp
>>
>>
>

Follow ups

References