[Numpy-discussion] New experimental DType example (for physical Unit handling)

2022-01-27 Thread Sebastian Berg
Hi all,

I have created a new prototype showcasing the new experimental DType
and ufunc API here:

https://github.com/seberg/unitdtype

Aside from showing Units, this is also a good resource to get an idea
of how the new (including very complicated) DTypes will look like, as
well as how UFuncs should look like.

This time it is in C and much more full featured (although some
convenience methods are missing) -- expect more of those to be added
over time.
As of now, it requires a custom NumPy branch (I hope that goes away
quickly, but it may always be necessary as new things gets added).

It does use `unyt` under-the-hood in order to calculate conversion
factors and result units. [1]

The code should be able to do quite a lot of things, but of course is
not meant to be full-featured yet and bugs are likely if you do
stranger things.

A main thing is that a good chunk of ufuncs are now supported by
"reusing" NumPy's existing ufuncs:

* negative, positive
* add, subtract
* multiple, divide
* matmul
* fmod
* hypot (not sure if this is quite right)
* maximum, minimum, fmax, fmin
* comparisons (note that we never compare to 0 scalars, unlike some 
  implementations) – that also allows `np.min` and `np.max`.
* Logical ufuncs (via casting to boolean)


More common things that are definitely not support (as of now!):

* `sum` is clunky requiring `initial=QuantityScalar(0, correct_unit)`
  to work.  This is a problem with NumPy's design of the "identity",
  and the (always known) fix is to improve the identity machinery in
  NumPy.  – I am looking into it, but as usual it requires more cleanup
  elsewhere for a good solution.
* `prod` is more tricky, because its result unit would depend on the
  number of elements.  This (and gufuncs for such operations) would
  require a specialized, new, API.
  (I do not think this is hard, but I will not throw myself at it.)
* sorting/parititioning and many other functions.  Those two can be
  made to work easily (by using the old API, we should make a new one
  but that is a different issue).
* `arange` and `linspace` each have their problems (linspace just
  because the `scalar` is not really usable yet).
  (again, nothing major, although `arange` could use a new machinery)
* printing is not great, this requires a cleanup of how NumPy prints...
* …

Cheers,

Sebastian


[1] Completely arbitrary and easily replaceable choice, I just found
how to get the conversion factors quickly in `unyt`. Plus, without
using a dev-version of `astropy`, `astropy.units` sometimes clashes
with NumPy `main`.


signature.asc
Description: This is a digitally signed message part
___
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: arch...@mail-archive.com


[Numpy-discussion] Re: Numpy array

2022-01-27 Thread bigfixforum
Thanks Robert. I though about the same that boolean must be dropping the 
elements but i wasn't sure about it. Thanks for the confirmation. Appreciate 
your help.
___
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: arch...@mail-archive.com


[Numpy-discussion] Re: Numpy array

2022-01-27 Thread Robert Kern
On Thu, Jan 27, 2022 at 8:18 AM  wrote:

> Hi, i am new to numpy. This is first time i am using numpy.
>
> https://github.com/mspieg/dynamical-systems/blob/master/Bifurcations.ipynb
>
> This code i found to create bifurcation graph. There is section of code
> which i am not able to understand
>
> vr[stable], vx[stable]
>
> vr and vx is array of 150 elements.
> unstable and stable array also has 150 elements
>
> But vr[stable], vx[stable] becomes 75 elements in the array. Which i am
> not able to umderstand how 150 elements in array drops to 75
>

`stable` is a boolean array which is True where `f_x(vr, vx) < 0` and False
otherwise. When a boolean array is used as an index, the resulting array
only has the elements where the boolean value in the index array is True
and dropping all of the elements where it is False. That is why the number
of elements changes.

https://numpy.org/doc/stable/user/basics.indexing.html#boolean-array-indexing

-- 
Robert Kern
___
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: arch...@mail-archive.com


[Numpy-discussion] Re: Numpy array

2022-01-27 Thread Lev Maximov
Yes, this page has a ton of interesting stuff, too! I gave just one link
because it might take time to
choose between 10 excellent tutorials. It's just my personal preference :)

Btw, is it possible to automate the detection of dead links on that page?

Lev

On Thu, Jan 27, 2022 at 11:25 PM Rohit Goswami 
wrote:

> Agreed, however, the NumPy learn section of the official documentation
>  is probably a better place to point to (though
> your article is justifiably also linked from there).
> --
>
> Rohit
>
> On 27 Jan 2022, at 16:15, Lev Maximov wrote:
>
> Hi,
>
> I believe this question fits Stack Overflow better.
>
> Here're SO guidelines on how to create a minimal reproducible example:
> https://stackoverflow.com/help/minimal-reproducible-example
>
> If you're new to NumPy I'd recommend this visual guide:
>
> https://betterprogramming.pub/numpy-illustrated-the-visual-guide-to-numpy-3b1d4976de1d
>
> Best regards,
> Lev
>
> On Thu, Jan 27, 2022 at 8:19 PM  wrote:
>
>> Hi, i am new to numpy. This is first time i am using numpy.
>>
>> https://github.com/mspieg/dynamical-systems/blob/master/Bifurcations.ipynb
>>
>> This code i found to create bifurcation graph. There is section of code
>> which i am not able to understand
>>
>> vr[stable], vx[stable]
>>
>> vr and vx is array of 150 elements.
>> unstable and stable array also has 150 elements
>>
>> But vr[stable], vx[stable] becomes 75 elements in the array. Which i am
>> not able to umderstand how 150 elements in array drops to 75
>> ___
>> NumPy-Discussion mailing list -- numpy-discussion@python.org
>> To unsubscribe send an email to numpy-discussion-le...@python.org
>> https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
>> Member address: lev.maxi...@gmail.com
>>
> ___
> NumPy-Discussion mailing list -- numpy-discussion@python.org
> To unsubscribe send an email to numpy-discussion-le...@python.org
> https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
>
> Member address: rgosw...@quansight.com
>
> ___
> NumPy-Discussion mailing list -- numpy-discussion@python.org
> To unsubscribe send an email to numpy-discussion-le...@python.org
> https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
> Member address: lev.maxi...@gmail.com
>
___
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: arch...@mail-archive.com


[Numpy-discussion] Re: Numpy array

2022-01-27 Thread Rohit Goswami
Agreed, however, the[ NumPy learn section of the official 
documentation](https://numpy.org/learn/) is probably a better place to 
point to (though your article is justifiably also linked from there).


---
Rohit

On 27 Jan 2022, at 16:15, Lev Maximov wrote:


Hi,

I believe this question fits Stack Overflow better.

Here're SO guidelines on how to create a minimal reproducible example:
https://stackoverflow.com/help/minimal-reproducible-example

If you're new to NumPy I'd recommend this visual guide:
https://betterprogramming.pub/numpy-illustrated-the-visual-guide-to-numpy-3b1d4976de1d

Best regards,
Lev

On Thu, Jan 27, 2022 at 8:19 PM  wrote:


Hi, i am new to numpy. This is first time i am using numpy.

https://github.com/mspieg/dynamical-systems/blob/master/Bifurcations.ipynb

This code i found to create bifurcation graph. There is section of 
code

which i am not able to understand

vr[stable], vx[stable]

vr and vx is array of 150 elements.
unstable and stable array also has 150 elements

But vr[stable], vx[stable] becomes 75 elements in the array. Which i 
am

not able to umderstand how 150 elements in array drops to 75
___
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: lev.maxi...@gmail.com




___
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: rgosw...@quansight.com___
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: arch...@mail-archive.com


[Numpy-discussion] Re: Numpy array

2022-01-27 Thread Lev Maximov
Hi,

I believe this question fits Stack Overflow better.

Here're SO guidelines on how to create a minimal reproducible example:
https://stackoverflow.com/help/minimal-reproducible-example

If you're new to NumPy I'd recommend this visual guide:
https://betterprogramming.pub/numpy-illustrated-the-visual-guide-to-numpy-3b1d4976de1d

Best regards,
Lev

On Thu, Jan 27, 2022 at 8:19 PM  wrote:

> Hi, i am new to numpy. This is first time i am using numpy.
>
> https://github.com/mspieg/dynamical-systems/blob/master/Bifurcations.ipynb
>
> This code i found to create bifurcation graph. There is section of code
> which i am not able to understand
>
> vr[stable], vx[stable]
>
> vr and vx is array of 150 elements.
> unstable and stable array also has 150 elements
>
> But vr[stable], vx[stable] becomes 75 elements in the array. Which i am
> not able to umderstand how 150 elements in array drops to 75
> ___
> NumPy-Discussion mailing list -- numpy-discussion@python.org
> To unsubscribe send an email to numpy-discussion-le...@python.org
> https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
> Member address: lev.maxi...@gmail.com
>
___
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: arch...@mail-archive.com


[Numpy-discussion] Numpy array

2022-01-27 Thread bigfixforum
Hi, i am new to numpy. This is first time i am using numpy.

https://github.com/mspieg/dynamical-systems/blob/master/Bifurcations.ipynb

This code i found to create bifurcation graph. There is section of code which i 
am not able to understand

vr[stable], vx[stable]

vr and vx is array of 150 elements.
unstable and stable array also has 150 elements

But vr[stable], vx[stable] becomes 75 elements in the array. Which i am not 
able to umderstand how 150 elements in array drops to 75
___
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: arch...@mail-archive.com