Quantcast

[SciPy-User] Using special functions with keyword arguments

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[SciPy-User] Using special functions with keyword arguments

Lutz Maibaum-3
I am having difficulties calling the spherical harmonics function with keyword arguments. This works in older versions (for example Numpy 1.8 / SciPy 0.14):

>>> from scipy.special import sph_harm
>>> sph_harm(m=0,n=0,theta=0,phi=0)
array((0.28209479177387814+0j))

In newer versions, such as NumPy 1.10 / SciPy 0.15, I get

>>> from scipy.special import sph_harm
>>> sph_harm(m=0,n=0,theta=0,phi=0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: invalid number of arguments

Is it still possible to call sph_harm (and presumably other special functions) with keyword arguments? The reason I am trying to do this is that I would like to wrap sph_harm in a functools.partial object that takes only a single argument, and that I can then pass to multiprocessing.Pool.map.

Thanks,

Lutz

_______________________________________________
SciPy-User mailing list
[hidden email]
https://mail.scipy.org/mailman/listinfo/scipy-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Using special functions with keyword arguments

Pauli Virtanen-3
Mon, 07 Mar 2016 17:00:57 -0800, Lutz Maibaum kirjoitti:
[clip]
> Is it still possible to call sph_harm (and presumably other special
> functions) with keyword arguments?

Ufuncs in general don't support keyword arguments, so no.

> The reason I am trying to do this is
> that I would like to wrap sph_harm in a functools.partial object that
> takes only a single argument, and that I can then pass to
> multiprocessing.Pool.map.

You can probably still achieve that in some way.

--
Pauli Virtanen

_______________________________________________
SciPy-User mailing list
[hidden email]
https://mail.scipy.org/mailman/listinfo/scipy-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Using special functions with keyword arguments

dhirschfeld
Pauli Virtanen <pav <at> iki.fi> writes:

>
> Mon, 07 Mar 2016 17:00:57 -0800, Lutz
Maibaum kirjoitti:
> [clip]
> > Is it still possible to call sph_harm
(and presumably other special
> > functions) with keyword arguments?
>
> Ufuncs in general don't support keyword
arguments, so no.
>
> > The reason I am trying to do this is
> > that I would like to wrap sph_harm in
a functools.partial object that
> > takes only a single argument, and that
I can then pass to
> > multiprocessing.Pool.map.
>
> You can probably still achieve that in
some way.
>

I've run into this restriction before in
the context of numba generated ufuncs. Is
there some fundamental problem supporting
kwargs in ufuncs or is it technically
possible to do?

Thanks,
Dave

_______________________________________________
SciPy-User mailing list
[hidden email]
https://mail.scipy.org/mailman/listinfo/scipy-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Using special functions with keyword arguments

Gary Ruben

I haven't tried but I'd look at numpy.vectorize and functools.partial as possible ways to do this.

Gary

On 11 Mar 2016 7:30 am, "Dave" <[hidden email]> wrote:
Pauli Virtanen <pav <at> iki.fi> writes:

>
> Mon, 07 Mar 2016 17:00:57 -0800, Lutz
Maibaum kirjoitti:
> [clip]
> > Is it still possible to call sph_harm
(and presumably other special
> > functions) with keyword arguments?
>
> Ufuncs in general don't support keyword
arguments, so no.
>
> > The reason I am trying to do this is
> > that I would like to wrap sph_harm in
a functools.partial object that
> > takes only a single argument, and that
I can then pass to
> > multiprocessing.Pool.map.
>
> You can probably still achieve that in
some way.
>

I've run into this restriction before in
the context of numba generated ufuncs. Is
there some fundamental problem supporting
kwargs in ufuncs or is it technically
possible to do?

Thanks,
Dave

_______________________________________________
SciPy-User mailing list
[hidden email]
https://mail.scipy.org/mailman/listinfo/scipy-user

_______________________________________________
SciPy-User mailing list
[hidden email]
https://mail.scipy.org/mailman/listinfo/scipy-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Using special functions with keyword arguments

Gary Ruben
Please ignore my previous comment; I hadn't read the earlier thread messages.

On 11 March 2016 at 08:49, gary ruben <[hidden email]> wrote:

I haven't tried but I'd look at numpy.vectorize and functools.partial as possible ways to do this.

Gary

On 11 Mar 2016 7:30 am, "Dave" <[hidden email]> wrote:
Pauli Virtanen <pav <at> iki.fi> writes:

>
> Mon, 07 Mar 2016 17:00:57 -0800, Lutz
Maibaum kirjoitti:
> [clip]
> > Is it still possible to call sph_harm
(and presumably other special
> > functions) with keyword arguments?
>
> Ufuncs in general don't support keyword
arguments, so no.
>
> > The reason I am trying to do this is
> > that I would like to wrap sph_harm in
a functools.partial object that
> > takes only a single argument, and that
I can then pass to
> > multiprocessing.Pool.map.
>
> You can probably still achieve that in
some way.
>

I've run into this restriction before in
the context of numba generated ufuncs. Is
there some fundamental problem supporting
kwargs in ufuncs or is it technically
possible to do?

Thanks,
Dave

_______________________________________________
SciPy-User mailing list
[hidden email]
https://mail.scipy.org/mailman/listinfo/scipy-user


_______________________________________________
SciPy-User mailing list
[hidden email]
https://mail.scipy.org/mailman/listinfo/scipy-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Using special functions with keyword arguments

Lutz Maibaum-3
In reply to this post by Pauli Virtanen-3

> On Mar 10, 2016, at 2:21 AM, Pauli Virtanen <[hidden email]> wrote:
>
> Mon, 07 Mar 2016 17:00:57 -0800, Lutz Maibaum kirjoitti:
> [clip]
>> Is it still possible to call sph_harm (and presumably other special
>> functions) with keyword arguments?
>
> Ufuncs in general don't support keyword arguments, so no.

Thanks -- I thought so. I was mainly surprised that this used to work in older versions of SciPy; probably because sph_harm wasn’t a ufunc then.

>> The reason I am trying to do this is
>> that I would like to wrap sph_harm in a functools.partial object that
>> takes only a single argument, and that I can then pass to
>> multiprocessing.Pool.map.
>
> You can probably still achieve that in some way.

Yes, certainly. This would have been the simplest way to parallelize my code. On the plus side, the sph_harm function got so much faster in the newer versions that evaluating it in parallel isn’t even that important anymore in my application.

Best,

Lutz


_______________________________________________
SciPy-User mailing list
[hidden email]
https://mail.scipy.org/mailman/listinfo/scipy-user
Loading...