Re: Scipy and information theory

Ralf Gommers <[email protected]> Sun, 10 Nov 2019 18:26:58 -0800
Newsgroups gmane.comp.python.scientific.user
Message-ID <CABL7CQh9TkKyUH3cn4V=vC-cCvzVoQCBcrLdZeUxcK7izAtUdQ@mail.gmail.com>
On Sun, Nov 10, 2019 at 5:25 PM Robert Lucente - Pipeline.Com <
[email protected]> wrote:

> > Because I want to avoid long (and slow) for loops and take advantage of
> numpy/ scipy element wise operations
> I am embarrassed
>
> That was an amateur mistake on my part :-(
>
> -----Original Message-----
> From: SciPy-User <[email protected]> On
> Behalf Of Iyán Méndez Veiga
> Sent: Sunday, November 10, 2019 7:30 AM
> To: SciPy Users List <[email protected]>
> Subject: Re: [SciPy-User] Scipy and information theory
>
> El viernes, 8 de noviembre de 2019 18:13:32 (CET) Robert Lucente -
> Pipeline.Com escribió:
> > Why not use Python's built in fcn?
> >
> > https://docs.python.org/3/library/math.html#math.log2
> >
> > math.log2(x)
>
> Because I want to avoid long (and slow) for loops and take advantage of
> numpy/ scipy element wise operations. That is why I prefer numpy.log2(x)
> over math.log2(x). My x is a high dimension array, not a scalar.
>
> > This does sound like a useful feature to add to these functions. I'm
> > not sure how easy it is to add a keyword to those functions though,
> > since the ufunc machinery may be limited in flexibility. Maybe someone
> > else can say straight away. If you want to start looking into
> > implementing this, here are some notes of where to start:
> > http://scipy.github.io/devdocs/dev/core-dev/index.html#scipy-special
>
> Thanks Ralf, I'll have a look. Also waiting if someone else can say if it
> would be easy or hard to implement.
>

Right after I wrote that Josh just posted
https://github.com/scipy/scipy/issues/11029#issuecomment-551968035, which
states "to add a keyword argument ... and the current Cython special
codegen can’t handle that automatically". So I think that confirms what I
suspected: it's not really doable right now. Adding a new function is not
justified; a Python wrapper could be but it's not great for performance -
you could try that and keep the overhead for the current default behavior
is low as possible, then report some benchmark result. That should help us
decide. Probably best to open an issue or PR for that for further
discussion.

Cheers,
Ralf

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