Re: [Numpy-discussion] NumPy in PyPy

2016-08-08 Thread Chris Barker
>
> On Fri, Aug 5, 2016 at 3:42 AM, Papa, Florin 
>> wrote:
>>
>>>  Does anyone have knowledge of real life workloads that use NumPy and
>>> cannot be run using PyPy?
>>>
>>>
>>>
>>> We are also interested in creating a repository with relevant benchmarks
>>> for real world usage of NumPy,
>>>
>>
We have a numpy --  heavy app. bu tit, like many others, I'm sure, also
relies heavily on Cython-wrapped C++ code, as well as pure Cython
extensions.

As well as many other packages that are also wrappers around C libs, Cython
-optimized, etc.

I've never tried to run it under PyPy I've always assumed it's a
non-starter.

Is there any hope?


If you are curious:

https://github.com/NOAA-ORR-ERD/PyGnome

-CHB



-- 

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR(206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115   (206) 526-6317   main reception

chris.bar...@noaa.gov
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
https://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Views and Increments

2016-08-08 Thread Stephan Hoyer
On Mon, Aug 8, 2016 at 6:11 AM, Anakim Border  wrote:

> Alternative version:
>
> >>> a = np.arange(10)
> >>> a[np.array([1,6,5])] += 1
> >>> a
> array([0, 2, 2, 3, 4, 6, 7, 7, 8, 9])
>

I haven't checked, but a likely explanation is that Python itself
interprets a[b] += c as a[b] = a[b] + c.

Python has special methods for inplace assignment (__setitem__) and inplace
arithmetic (__iadd__) but no special methods for inplace arithmetic and
assignment at the same time, so this is really out of NumPy's control here.
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
https://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Views and Increments

2016-08-08 Thread Marten van Kerkwijk
Hi Anakim,

The difference is really in the code path that gets taken: in the first
case, you go through `a.__getitem__(np.array([1,6,5])`, in the second
through `a.__setitem__(...)`. The increments would not work if you added an
extra indexing to it, as in:
```
a[np.array([1,6,5])][:] += 1
```

​(which would do `a.__getitem__(...).__setitem__(slice(None))`)

Hope this clarifies it,

Marten
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
https://mail.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] PR 7918 apply_along_axis()

2016-08-08 Thread Ben Rowland
Hi list,

This is both my first post to this list and first pull request for numpy so 
apologies if this is not the right list or for any other mistakes.

Here is the link to my pull request: https://github.com/numpy/numpy/pull/7918 


It is a simple modification to the numpy.apply_along_axis() function in 
numpy/lib/shape_base.py to allow it to deal better with ndarray subclasses. My 
use case is this: I have an ndarray subclass storing sets of temporal data 
which has additional metadata properties such as the time between data points. 
I frequently want to apply the same function to each time course in a set and 
apply_along_axis() is a compact and efficient way to do this. However there are 
two behaviours that I require which are not provided by the current numpy 
master:
1) apply_along_axis returns the same subclass as it was called upon, so that I 
don’t lose all the metadata that it went in with.
2) fund1d calls inside apply_along_axis should receive 1d slices of the same 
subclass as the supplied whole array, so that they can make use of the metadata 
in performing their function.

To achieve these two behaviours requires modifying only three lines of code:
1) At the start of the function, the input is converted to a bare ndarray by 
the function numpy.asarray(), I replace this with the subclass friendly 
numpy.asanyarray()
2) Depending on whether func1d returns a scalar or a vector there are two 
different code paths constructing and returning the output array. In each case 
I call __array_wrap__ on the input array, passing the output array to allow it 
to be updated with all the metadata of the original array.

I have also implemented two new tests for this functionality. The first is very 
simple and merely calls apply_along_axis on a numpy.matrix class and checks 
that the result is also a numpy.matrix. The second is slightly more involved as 
it requires defining a MinimalSubclass class which adds a data member to the 
bare ndarray, then a function which returns that member. apply_along_axis() is 
then called passing in an instance of the subclass and the function to show 
that the slices passed to func1d preserve the data member.

I would welcome any comment or constructive criticism.

Ben Rowland___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
https://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Views and Increments

2016-08-08 Thread Sebastian Berg
On Mo, 2016-08-08 at 15:11 +0200, Anakim Border wrote:
> Dear List,
> 
> I'm experimenting with views and array indexing. I have written two
> code blocks that I was expecting to produce the same result.
> 
> First try:
> 
> >>> a = np.arange(10)
> >>> b = a[np.array([1,6,5])]
> >>> b += 1
> >>> a
> array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
> 
> 
> Alternative version:
> 
> >>> a = np.arange(10)
> >>> a[np.array([1,6,5])] += 1
> >>> a
> array([0, 2, 2, 3, 4, 6, 7, 7, 8, 9])
> 
> 
> I understand what is happening in the first case. In fact, the
> documentation is quite clear on the subject:
> 
> For all cases of index arrays, what is returned is a copy of the
> original data, not a view as one gets for slices.
> 
> What about the second case? There, I'm not keeping a reference to the
> intermediate copy (b, in the first example). Still, I don't see why
> the update (to the copy) is propagating to the original array. Is
> there any implementation detail that I'm missing?
> 

The second case translates to:

tmp = a[np.array([1,6,5])] + 1
a[np.array([1,6,5])] = tmp

this is done by python, without any interplay of numpy at all. Which is
different from `arr += 1`, which is specifically defined and translates
to `np.add(arr, 1, out=arr)`.

- Sebastian


> Best,
>   ab
> ___
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> https://mail.scipy.org/mailman/listinfo/numpy-discussion

signature.asc
Description: This is a digitally signed message part
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
https://mail.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] Views and Increments

2016-08-08 Thread Anakim Border
Dear List,

I'm experimenting with views and array indexing. I have written two code
blocks that I was expecting to produce the same result.

First try:

>>> a = np.arange(10)
>>> b = a[np.array([1,6,5])]
>>> b += 1
>>> a
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])


Alternative version:

>>> a = np.arange(10)
>>> a[np.array([1,6,5])] += 1
>>> a
array([0, 2, 2, 3, 4, 6, 7, 7, 8, 9])


I understand what is happening in the first case. In fact, the
documentation is quite clear on the subject:

For all cases of index arrays, what is returned is a copy of the original
data, not a view as one gets for slices.

What about the second case? There, I'm not keeping a reference to the
intermediate copy (b, in the first example). Still, I don't see why the
update (to the copy) is propagating to the original array. Is there any
implementation detail that I'm missing?

Best,
  ab
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
https://mail.scipy.org/mailman/listinfo/numpy-discussion