Read about our upcoming Code of Conduct on this issue

Commit e8a1eda2 authored by Pierre Augier's avatar Pierre Augier
Browse files

fluidpythran.boost

--HG--
branch : dev
parent 8fb0a77e6ba3
......@@ -8,8 +8,8 @@ Future
0.1.4 (2018-12-06)
------------------
- :code:`pythran_def` for simple methods (without assignation to attributes
and call of other methods)
- :code:`boost` decorator for functions, simple methods (without assignation to
attributes and call of other methods) and classes
- Bugfixes
- :code:`FLUIDPYTHRAN_DIR`
......
......@@ -25,7 +25,7 @@ FluidPythran: easily speedup your Python code with Pythran
FluidPythran is used in `FluidSim
<https://bitbucket.org/fluiddyn/fluidsim>`_ (see examples for `blocks
<https://bitbucket.org/fluiddyn/fluidsim/src/default/fluidsim/base/time_stepping/pseudo_spect.py>`_,
`@pythran_def
`@boost
<https://bitbucket.org/fluiddyn/fluidsim/src/default/fluidsim/operators/operators3d.py>`_
and `@cachedjit
<https://bitbucket.org/fluiddyn/fluidsim/src/default/fluidsim/solvers/plate2d/output/correlations_freq.py>`_).
......@@ -124,11 +124,11 @@ Command :code:`# pythran def`
import h5py
import mpi4py
from fluidpythran import pythran_def
from fluidpythran import boost
# pythran def myfunc(int, float)
@pythran_def
@boost
def myfunc(a, b):
return a * b
......@@ -142,7 +142,7 @@ Most of this code looks familiar to Pythran users. The differences:
- :code:`# pythran def` instead of :code:`# pythran export` (to stress that it
is not the same command).
- A tiny bit of Python... The decorator :code:`@pythran_def` replaces the
- A tiny bit of Python... The decorator :code:`@boost` replaces the
Python function by the pythranized function if FluidPythran has been used to
produced the associated Pythran file.
......@@ -157,9 +157,9 @@ The previous example can be rewritten without Pythran commands:
import h5py
import mpi4py
from fluidpythran import pythran_def
from fluidpythran import boost
@pythran_def
@boost
def myfunc(a: int, b: float):
return a * b
......@@ -268,8 +268,8 @@ export`.
<https://fluidpythran.readthedocs.io/en/latest/examples/blocks.html>`_
Python classes: :code:`@pythran_def` for methods
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Python classes: :code:`@boost` for methods
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
For simple methods **only using attributes**, we can write:
......@@ -277,11 +277,11 @@ For simple methods **only using attributes**, we can write:
import numpy as np
from fluidpythran import pythran_def, pythran_class
from fluidpythran import boost
A = "float[:]"
@pythran_class
@boost
class MyClass:
arr0: A
......@@ -291,7 +291,7 @@ For simple methods **only using attributes**, we can write:
self.arr0 = np.zeros(n)
self.arr1 = np.zeros(n)
@pythran_def
@boost
def compute(self, alpha: float):
return (self.arr0 + self.arr1).mean() ** alpha
......
import numpy as np
from fluidpythran import pythran_def
from fluidpythran import boost
# FLUIDPYTHRAN_NO_IMPORT
......@@ -14,6 +14,6 @@ from fluidpythran import pythran_def
# pythran def func(int[][], float[][])
@pythran_def
@boost
def func(a, b):
return (a * np.log(b)).max()
......@@ -2,10 +2,10 @@ import numpy as np
# pythran import numpy as np
from fluidpythran import pythran_class, pythran_def
from fluidpythran import boost
@pythran_class
@boost
class Transmitter:
freq: float
......@@ -13,7 +13,7 @@ class Transmitter:
def __init__(self, freq):
self.freq = float(freq)
@pythran_def
@boost
def __call__(self, inp: "float[]"):
"""My docstring"""
return inp * np.exp(np.arange(len(inp)) * self.freq * 1j)
......
import numpy as np
from fluidpythran import pythran_def
from fluidpythran import boost
# pythran import numpy as np
......@@ -8,11 +8,11 @@ from fluidpythran import pythran_def
# pythran def func(int[][], float[][])
@pythran_def
@boost
def func(a: float, b: float):
return (a * np.log(b)).max()
@pythran_def
@boost
def func1(a: int, b: float):
return a * np.cos(b)
......@@ -14,7 +14,7 @@ assert repr(N - 1) == "N - 1"
print(repr(A1))
@fp.pythran_def
@fp.boost
def compute(a: A, b: A1, c: T, d: A, e: str):
print(e)
tmp = a + b
......
......@@ -15,7 +15,7 @@ N1 = NDim(4, 5)
T = Type(int, np.complex128)
@fp.pythran_def
@fp.boost
def compute(a: A, b: A, c: T, d: A1, e: str):
print(e)
tmp = a + b
......
......@@ -3,7 +3,7 @@ import numpy as np
# don't import any random modules in a Pythran file. Here, no problem!
from fluiddyn.util import mpi
from fluidpythran import pythran_def
from fluidpythran import boost
# FLUIDPYTHRAN_NO_IMPORT
......@@ -13,7 +13,7 @@ from fluidpythran import pythran_def
# pythran def func(int[][], float[][])
@pythran_def
@boost
def func(a, b):
return (a * np.log(b)).max()
......
......@@ -14,7 +14,7 @@ Most of this code looks familiar to Pythran users. The differences:
- :code:`# pythran def` instead of :code:`# pythran export` (to stress that it
is not the same command).
- A tiny bit of Python... The decorator :code:`@pythran_def` replaces the
- A tiny bit of Python... The decorator :code:`@boost` replaces the
Python function by the pythranized function if FluidPythran has been used to
produced the associated Pythran file.
......
......@@ -2,10 +2,10 @@ import numpy as np
# pythran import numpy as np
from fluidpythran import pythran_class, pythran_def
from fluidpythran import boost
@pythran_class
@boost
class Transmitter:
freq: float
......@@ -13,7 +13,7 @@ class Transmitter:
def __init__(self, freq):
self.freq = float(freq)
@pythran_def
@boost
def __call__(self, inp: "float[]"):
"""My docstring"""
return inp * np.exp(np.arange(len(inp)) * self.freq * 1j)
......
......@@ -3,7 +3,7 @@ import numpy as np
# don't import skimage in a Pythran file. Here, no problem!
from skimage.filters import sobel
from fluidpythran import pythran_def
from fluidpythran import boost
# pythran import numpy as np
......@@ -11,11 +11,11 @@ from fluidpythran import pythran_def
# pythran def func(int[][], float[][])
@pythran_def
@boost
def func(a: float, b: float):
return (a * np.log(b)).max()
@pythran_def
@boost
def func1(a: int, b: float):
return a * np.cos(b)
import numpy as np
from fluidpythran import pythran_def
from fluidpythran import boost
# pythran import numpy as np
......@@ -12,6 +12,6 @@ def mylog(arr):
# pythran def func(int[][], float[][])
@pythran_def
@boost
def func(a, b):
return (a * mylog(b)).max()
\ No newline at end of file
from fluidpythran import Type, NDim, Array, pythran_def
from fluidpythran import Type, NDim, Array, boost
import numpy as np
......@@ -9,7 +9,7 @@ N = NDim(1)
A1 = Array[T, N]
A2 = Array[float, N+1]
@boost
class MyClass:
arr0: A1
......@@ -21,7 +21,7 @@ class MyClass:
self.arr1 = np.zeros(n, dtype=dtype)
self.arr2 = np.zeros(n)
@pythran_def
@boost
def compute(self, alpha: int):
tmp = (self.arr0 + self.arr1).mean()
return tmp ** alpha * self.arr2
......@@ -15,7 +15,7 @@ case in `pythran_class.py` and more complicated than what is needed for
"""
from fluidpythran import Type, NDim, Array, pythran_def
from fluidpythran import Type, NDim, Array, boost
import numpy as np
......@@ -42,7 +42,7 @@ class MyClass:
self.arr1 = np.zeros(n, dtype=dtype)
self.arr2 = np.zeros(n)
@pythran_def
@boost
def compute(self, alpha: float):
tmp = self.sum_arrays().mean()
return tmp ** alpha * self.arr2
......@@ -50,7 +50,7 @@ class MyClass:
def sum_arrays(self):
return self.arr0 + self.arr1
@pythran_def
@boost
def compute1(self, alpha: float):
tmp = sum_arrays(self.arr0, self.arr1).mean()
return tmp ** alpha * self.arr2
......
......@@ -9,7 +9,7 @@ We could also express these concepts in strings, mainly following Pythran...
"""
from fluidpythran import pythran_def, Type, NDim, Shape, Array
from fluidpythran import boost, Type, NDim, Shape, Array
T = Type(int, float)
......@@ -17,7 +17,7 @@ T = Type(int, float)
A = Array[T, Shape("[3, :]", "[3, :, :]", "[::, ::]", "[::, ::, ::]")]
@pythran_def
@boost
def compute(a: A, b: A, c: T):
return a + b
......@@ -26,6 +26,6 @@ def compute(a: A, b: A, c: T):
A1 = Array[T, NDim(1, 3), Shape("[3, ...]", "[::, ...]")]
@pythran_def
@boost
def compute1(a: A1, b: A1, c: T):
return c * (a + b)
......@@ -9,7 +9,7 @@ A = Array[T, N]
A1 = Array[np.int8, N + 1]
@fp.pythran_def
@fp.boost
def compute(a: A, b: A, c: T, d: A1, e: str):
print(e)
tmp = a + b
......
......@@ -23,11 +23,11 @@ Yes, this one is neat!
Note that one can also just write Pythran type-string in type annotations::
@pythran_def
@boost
def myfunc(a: "float[3, :]", b: float):
...
Finally, array types with only one number of dimension can simply be
Finally, array types with only one number of dimension can simply be
defined like this::
from fluidpythran import Array
......
import numpy as np
from fluidpythran import Type, NDim, Array, pythran_def
from fluidpythran import Type, NDim, Array, boost
T = Type(int, np.complex128)
N = NDim(1, 3)
......@@ -8,7 +8,7 @@ A = Array[T, N]
A1 = Array[np.float32, N + 1]
@pythran_def
@boost
def compute(a: A, b: A, c: T, d: A1, e: str):
print(e)
tmp = a + b
......
......@@ -2,8 +2,8 @@
import h5py
import mpi4py
from fluidpythran import pythran_def
from fluidpythran import boost
@pythran_def
@boost
def myfunc(a: int, b: float):
return a * b
\ No newline at end of file
......@@ -24,16 +24,7 @@
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Make new function to replace laplace_pythran (__ipython__2823fa65cda0fe3f58b60391a9d2e13b)\n",
"write code in file /home/users/augier3pi/.fluidpythran/__cachedjit__/__ipython__2823fa65cda0fe3f58b60391a9d2e13b/laplace_pythran.py\n"
]
}
],
"outputs": [],
"source": [
"# pythran import numpy as np\n",
"\n",
......@@ -54,11 +45,11 @@
"metadata": {},
"outputs": [
{
"name": "stdout",
"name": "stderr",
"output_type": "stream",
"text": [
"write Pythran signature in file /home/users/augier3pi/.fluidpythran/__cachedjit__/__ipython__2823fa65cda0fe3f58b60391a9d2e13b/laplace_pythran.pythran with types\n",
"['float64[:,:]']\n"
"\u001b[32mINFO \u001b[0m \u001b[34mwrite Pythran signature in file /home/users/augier3pi/.fluidpythran/__cachedjit__/__ipython__2823fa65cda0fe3f58b60391a9d2e13b/laplace_pythran.pythran with types\n",
"['float64[:, :]']\u001b[0m\n"
]
},
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment