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
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
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)
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) !=
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
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/
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
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
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
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
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/
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/
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:
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)
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
15 matches
Mail list logo