Re: [Numpy-discussion] using scalar and tuple/list input on np.PyArray_MultiIterNew2

2021-01-11 Thread zoj613
No, The function is what I ended up with, I just forgot to change (h, z) to (a, b). It works fine. Yes, I want to ensure that I end up with a double type even if an integer value is passed. I didn't think of unconditionally using np.PyArray_From_OT() even for scalars. I guess that is probably a

Re: [Numpy-discussion] using scalar input on np.PyArray_MultiIterNew2

2021-01-10 Thread zoj613
Sebastian Berg wrote > On Sun, 2021-01-10 at 09:59 -0700, zoj613 wrote: >> Hi all, >> >> I am looking for a way to use `np.PyArray_MultiIterNew2` in Cython to >> broadcast parameters of a function. The requirement is that the two >> arguments can be scalar

Re: [Numpy-discussion] using scalar and tuple/list input on np.PyArray_MultiIterNew2

2021-01-10 Thread zoj613
For what it's worth, I ended up defining a function like: cdef np.broadcast broadcast(object a, object b): """ Broadcast the inputs into a multiIterator object. the input can be a scalar, list, tuple or numpy array or array_like object. """ cdef bint is_a_seq = is_sequence(h)

[Numpy-discussion] Checking if all array elements are whole numbers using the C-API

2021-06-12 Thread zoj613
Hi All, Is there a C-API analogue for `np.asarray(a, dtype=int) != np.asarray(a)` assuming that `a` is an array or python sequence object of whole numbers but is assigned the float type (e.g a=array([1., 2., 3.]) or [1., 2., 3.])? I tried `np.PyArray_FROM_OT(a, np.NPY_LONG) !=

Re: [Numpy-discussion] Checking if all array elements are whole numbers using the C-API

2021-06-13 Thread zoj613
After reading the docs, it turns out that `np.PyArray_FROM_OTF(a, np.NPY_LONG, np.NPY_ARRAY_FORCECAST) != np.PyArray_FROM_O(a)` prevents the error from occurring. -- Sent from: http://numpy-discussion.10968.n7.nabble.com/ ___ NumPy-Discussion mailing

Re: [Numpy-discussion] Addition of new distributions: Polya-gamma

2021-01-27 Thread zoj613
As a follow-up to my last post here and comments from Robert Kern. I have just released version 1.0.0 of the sampler on PyPI. The work is pretty much done (I hope). Feedback would be very much appreciated. -- Sent from: http://numpy-discussion.10968.n7.nabble.com/

Re: [Numpy-discussion] How to get Boolean matrix for similar lists in two different-size numpy arrays of lists

2021-03-14 Thread zoj613
The following seems to produce what you want using the data provided ``` In [31]: dF = np.genfromtxt('/home/F.csv', delimiter=',').tolist() In [32]: dS = np.genfromtxt('/home/S.csv', delimiter=',').tolist() In [33]: r = [True if i in lS else False for i in dF] In [34]: sum(r) Out[34]: 300

[Numpy-discussion] Using logfactorial instead of loggamma in random_poisson sampler

2021-03-06 Thread zoj613
Hi All, I noticed that the transformed rejection method for generating Poisson random variables used in numpy makes use of the `random_loggam` function which directly calculates the log-gamma function. It appears that a log-factorial lookup table was added a few years back which could be used in

Re: [Numpy-discussion] guide for downstream package authors & setting version constraints

2021-03-06 Thread zoj613
Thanks you, this looks very informative. Is there a best practice guide somewhere in the docs on how to correctly expose C-level code to third parties via .pxd files, similarly to how one can access the c_distributions of numpy via cython? I tried this previously and failed miserably. It seemed

Re: [Numpy-discussion] Using logfactorial instead of loggamma in random_poisson sampler

2021-03-06 Thread zoj613
Ah, I had a suspicion that it was to preserve the random stream but wasn't too sure. Thanks for the clarification. -- Sent from: http://numpy-discussion.10968.n7.nabble.com/ ___ NumPy-Discussion mailing list NumPy-Discussion@python.org

Re: [Numpy-discussion] guide for downstream package authors & setting version constraints

2021-03-08 Thread zoj613
Thanks for the suggestion. However I was able to solve the issue I had by just creating inline wrapper functions in cython for the C functions so I dont have to link them when importing in other 3rd party cython modules. -- Sent from: http://numpy-discussion.10968.n7.nabble.com/

Re: [Numpy-discussion] Using logfactorial instead of loggamma in random_poisson sampler

2021-03-08 Thread zoj613
What do you think is the explanation for that? I had assumed that using a lookup table would be faster considering that the loggam implementation has loops and makes calls to elementary functions in it. -- Sent from: http://numpy-discussion.10968.n7.nabble.com/

Re: [Numpy-discussion] Improving performance of the `numpy.any` function.

2021-04-15 Thread zoj613
Although still much slower than the builtin `any`, this is an interesting and strange alternative way to improve the timing. My speeds are a result of using a _very_ old machine with a low-grade processor so maybe these times are more exaggerated to me than others. -- Sent from:

[Numpy-discussion] Improving performance of the `numpy.any` function.

2021-04-14 Thread zoj613
Hi All, I was using numpy's `any` function earlier and realized that it might not be as performant as I assumed. See the code below: ``` In [1]: import numpy as np In [2]: a = np.zeros(1_000_000) In [3]: a[100] = 1 In [4]: b = np.zeros(2_000_000) In [5]: b[100] = 1 In [6]: %timeit np.any(a)

[Numpy-discussion] Inaccurate documentation of the random c-api

2021-04-18 Thread zoj613
Hi All, https://numpy.org/devdocs/reference/random/c-api.html has an inaccurate description of the API that goes as follows: "/zig in the name are based on a ziggurat lookup algorithm is used instead of calculating the log, which is significantly faster. The non-ziggurat variants are used in