Commit 6eab956c authored by Pierre Augier's avatar Pierre Augier
Browse files

Update doc packaging

parent 96f865185015
......@@ -27,6 +27,7 @@ doc/ipynb/*.rst
.mypy_cache
*.egg-info/*
**/.eggs/*
**/__pythran__/*
**/__cython__/*
......
......@@ -403,8 +403,8 @@ setup.py like this:
Note that :code:`make_backend_files` does not compile the backend files. The
compilation has to be done after the call of this function (see for example how
it is done in the example package `pack_using_transonic
<https://bitbucket.org/fluiddyn/transonic/src/default/doc/examples/pack_using_transonic/>`_
it is done in the `example packages
<https://bitbucket.org/fluiddyn/transonic/src/default/doc/examples/packages/>`_
or in `fluidsim's setup.py
<https://bitbucket.org/fluiddyn/fluidsim/src/default/setup.py>`_).
......
Short term (Milestones for 0.4.0)
---------------------------------
- alternative make_header_from_fdef_annotations for Cython
Short term (Milestone for 0.4.0)
--------------------------------
setup.py & more than one backend at runtime
-------------------------------------------
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Good example: https://github.com/martibosch/pylandstats/pull/1
- [done?] ``make_backend_files(backend_default="cython")``
- [done?] More than one backend at runtime
- [done] "python" backend (equivalent to NO_REPLACE)
- [done] ``make_backend_files(backend_default="cython")``
- [done] More than one backend at runtime
- [done] "python" backend
- [done] ``TRANSONIC_BACKEND`` changes only ``backend_default``
- [done] Examples setup.py in documentation
- Warnings if file not compiled
- [done?] ``TRANSONIC_BACKEND`` changes only ``backend_default``
- Examples setup.py in documentation
- "compilation" of "numba pure-python files"?
[done?] Specify backend in code
-------------------------------
Short term (Milestone for 0.4.1)
--------------------------------
.. code:: python
def func():
return 1
func_pythran = @jit(backend="pythran")(func)
func_cython = @jit(backend="cython")(func)
func_numba = @jit(backend="numba")(func)
And same with ``boost``.
- alternative make_header_from_fdef_annotations for Cython
- [done] Rewrite the comparison Numba / Pythran with Transonic
Cython backend (beta version)
-----------------------------
......
......@@ -7,9 +7,9 @@ Compiled with:
.. code:: bash
TRANSONIC_BACKEND="pythran" transonic add.py
TRANSONIC_BACKEND="numba" transonic add.py
TRANSONIC_BACKEND="cython" transonic add.py
transonic -b pythran add.py
transonic -b numba add.py
transonic -b cython add.py
Gives:
......
# A package using Transonic (for extensions using Pythran and Cython)
```
virtualenv /tmp/venv_package_cythran
. /tmp/venv_package_cythran/bin/activate
pip install -e .
```
import numpy as np
from transonic.aheadoftime import modules_backends
from package_cythran.calcul import laplace
from package_cythran.util import func
laplace(np.ones((2, 2), dtype=np.int32))
func(1)
func(2.)
ts = modules_backends["pythran"]["package_cythran.calcul"]
assert ts.backend.name == "pythran"
ts = modules_backends["cython"]["package_cythran.util"]
assert ts.backend.name == "cython"
print("everything looks alright!")
import numpy as np
from transonic import boost, Type, Array, NDim, set_backend_for_this_module
set_backend_for_this_module("pythran")
T = Type(np.int32, np.float64, np.float32)
A = Array[T, NDim(2)]
@boost
def laplace(image: A):
"""Laplace operator in NumPy for 2D images."""
laplacian = (
image[:-2, 1:-1]
+ image[2:, 1:-1]
+ image[1:-1, :-2]
+ image[1:-1, 2:]
- 4 * image[1:-1, 1:-1]
)
thresh = np.abs(laplacian) > 0.05
return thresh
import numpy as np
import matplotlib.pyplot as plt
from transonic import boost, Type, set_backend_for_this_module
set_backend_for_this_module("cython")
T = Type(float, int)
@boost
def func(a: T):
b = 1
return a * np.sin(b)
[metadata]
name = pack_using_transonic
name = mypack
description = A package using Transonic
long_description = file: README.rst
classifiers =
......
......@@ -30,14 +30,14 @@ import numpy as np
here = Path(__file__).parent.absolute()
pack_name = "pack_using_transonic"
pack_name = "package_cythran"
pack_dir = here / pack_name
# Get the version from the relevant file
version = run_path(pack_name + "/_version.py")
__version__ = version["__version__"]
install_requires = ["transonic"]
install_requires = ["transonic", "numpy", "matplotlib"]
relative_paths = ["calcul.py"]
make_backend_files([pack_dir / path for path in relative_paths], backend="pythran")
......
# A package using Transonic (for extensions using Pythran or Cython)
```
virtualenv /tmp/venv_package_simple
. /tmp/venv_package_simple/bin/activate
pip install -e .
```
import numpy as np
from transonic.aheadoftime import modules_backends
from package_simple.calcul import laplace
from package_simple.util import func
laplace(np.ones((2, 2), dtype=np.int32))
func(1)
func(2.)
modules = modules_backends["pythran"]
ts = modules["package_simple.calcul"]
assert ts.backend.name == "pythran"
ts = modules["package_simple.util"]
assert ts.backend.name == "pythran"
print("everything looks alright!")
__version__ = "0.0.1"
\ No newline at end of file
......@@ -8,7 +8,7 @@ A = Array[T, NDim(2)]
@boost
def laplace_pythran(image: A):
def laplace(image: A):
"""Laplace operator in NumPy for 2D images."""
laplacian = (
image[:-2, 1:-1]
......
import numpy as np
import matplotlib.pyplot as plt
import h5netcdf
from transonic import boost, Type
......
[metadata]
name = package_simple
description = A package using Transonic
long_description = file: README.rst
classifiers =
Programming Language :: Python :: 3
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
[options]
python_requires = >= 3.6
setup_requires =
setuptools
numpy
transonic
pythran
......@@ -30,14 +30,14 @@ import numpy as np
here = Path(__file__).parent.absolute()
pack_name = "pack_using_transonic"
pack_name = "package_simple"
pack_dir = here / pack_name
# Get the version from the relevant file
version = run_path(pack_name + "/_version.py")
__version__ = version["__version__"]
install_requires = ["transonic"]
install_requires = ["transonic", "numpy", "matplotlib"]
relative_paths = ["util.py", "calcul.py"]
make_backend_files([pack_dir / path for path in relative_paths])
......
......@@ -25,10 +25,10 @@ To compile this file with different backends, one can run:
.. code:: bash
TRANSONIC_BACKEND="python" transonic row_sum_boost.py
TRANSONIC_BACKEND="cython" transonic row_sum_boost.py
TRANSONIC_BACKEND="numba" transonic row_sum_boost.py
TRANSONIC_BACKEND="pythran" transonic row_sum_boost.py -pf "-march=native -DUSE_XSIMD"
transonic -b python row_sum_boost.py
transonic -b cython row_sum_boost.py
transonic -b numba row_sum_boost.py
transonic -b pythran row_sum_boost.py -pf "-march=native -DUSE_XSIMD"
Then, on my PC (meige8pcpa79), I get::
......
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