[pythran] Re: ND arrays

  • From: Pierre Augier <pierre.augier@xxxxxxxxxxxxxxxxxxxxxx>
  • To: pythran@xxxxxxxxxxxxx
  • Date: Tue, 27 Nov 2018 13:36:52 +0100

Le 26/11/2018 à 22:53, serge guelton a écrit :

On Mon, Nov 26, 2018 at 03:32:13PM -0500, Neal Becker wrote:
I have an algorithm that accepts ND arrays.  I suppose pythran cannot
accelerate ND algorithms, only for known number of dimensions, correct?
Correct. The number of dimension is fixed, but you can instanciate your 
function for different size:


.. code:: python

     #pythran export foo(float64)
     #pythran export foo(float64[:])
     #pythran export foo(float64[:,:])
     #pythran export foo(float64[:,:,:])

     def foo(x):
         return x *3.5 + 4.7

2 alternative solutions with https://fluidpythran.readthedocs.io :-)

In the 2 cases, no need for compilation commands...

Ahead-Of-Time compilation (pythranized at first import and then just when 
needed):

```
from fluidpythran import Array, NDim, pythran_def, set_pythranize_at_import

set_pythranize_at_import()

A = Array[float, NDim(1, 2, 3)]

@pythran_def
def foo(x: A):
   return x *3.5 + 4.7
```

set_pythranize_at_import is of course not mandatory.


Cached Just-In-Time (compiled after the first call):

```
from fluidpythran import Array, NDim, cachedjit

A = Array[float, NDim(1, 2, 3)]

@cachedjit
def foo(x: A):
   return x *3.5 + 4.7
```


To get more than one type for the ndarrays,

```
from fluidpythran import Array, NDim, Type

A = Array[Type(np.float32, complex, int), NDim(1, 2, 3)]

```

Pierre

--
Pierre Augier - CR CNRS                 http://www.legi.grenoble-inp.fr
LEGI (UMR 5519) Laboratoire des Ecoulements Geophysiques et Industriels
BP53, 38041 Grenoble Cedex, France                tel:+33.4.56.52.86.16

Other related posts: