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

cached_jit.py -> justintime.py

parent 70c0c11de545
0.1.1 (?)
---------
0.1.1 (2018-11-28)
------------------
- :code:`wait_for_all_extensions`
- Bug fixes
......
%% Cell type:markdown id: tags:
Note that this has no effect on coverage :-(
%% Cell type:code id: tags:
``` python
from fluidpythran.cached_jit import path_cachedjit, modules, make_hex
from fluidpythran.justintime import path_cachedjit, modules, make_hex
from pathlib import Path
from time import sleep
try:
import pythran
except ImportError:
pythran = None
from fluidpythran import cachedjit, Type
src = """T = Type(float, str)
@cachedjit
def test(a: T):
return "hello", a"""
hex_src = make_hex(src)
module_name = "__ipython__" + hex_src
path_dir = path_cachedjit / module_name
paths = path_dir.glob("*")
for path in paths:
path.unlink()
```
%% Cell type:code id: tags:
``` python
hex_src
```
%%%% Output: execute_result
'e5eaa495a98bbe52223768c805961912'
%% Cell type:code id: tags:
``` python
T = Type(float, str)
@cachedjit
def test(a: T):
return "hello", a
```
%%%% Output: stream
Make new function to replace test (__ipython__e5eaa495a98bbe52223768c805961912)
write code in file /home/pierre/.fluidpythran/__cachedjit__/__ipython__e5eaa495a98bbe52223768c805961912/test.py
%% Cell type:code id: tags:
``` python
if pythran:
key, mod = list(modules.items())[0]
cjit = mod.cachedjit_functions["test"]
cjit.compiling
```
%% Cell type:code id: tags:
``` python
test(1.)
```
%%%% Output: stream
write Pythran signature in file /home/pierre/.fluidpythran/__cachedjit__/__ipython__e5eaa495a98bbe52223768c805961912/test.pythran with types
['float']
%%%% Output: execute_result
('hello', 1.0)
%% Cell type:code id: tags:
``` python
if pythran:
cjit.compiling
```
%% Cell type:code id: tags:
``` python
if pythran:
assert key == module_name
```
%% Cell type:code id: tags:
``` python
if pythran:
for _ in range(100):
test(1.)
sleep(0.1)
if not cjit.compiling:
break
```
%% Cell type:code id: tags:
``` python
if pythran:
cjit.compiling
```
%% Cell type:code id: tags:
``` python
test(1.)
```
%%%% Output: execute_result
('hello', 1.0)
%% Cell type:code id: tags:
``` python
test("world")
```
%%%% Output: execute_result
('hello', 'world')
......
......@@ -27,7 +27,7 @@ of the modules, classes and functions.
fluidpythran.aheadoftime
fluidpythran.transpiler
fluidpythran.annotation
fluidpythran.cached_jit
fluidpythran.justintime
fluidpythran.pythranizer
fluidpythran.dist
fluidpythran.run
......
from ._version import __version__
from .cached_jit import cachedjit, used_by_cachedjit
from .justintime import cachedjit, used_by_cachedjit
try:
from ._path_data_tests import path_data_tests
......
......@@ -179,18 +179,40 @@ class ArrayMeta(type):
dtype = None
ndim = None
params_filtered = []
for param in parameters:
if isinstance(param, Type):
if isinstance(param, (Type, type)):
if dtype is not None:
raise ValueError
dtype = param
dtype = param
if isinstance(param, NDim):
if ndim is not None:
raise ValueError
ndim = param
parameters = {p.__name__: p for p in parameters}
if (
isinstance(param, str)
and param[-1] == "d"
and param[0].isnumeric()
):
try:
tmp = int(param[:-1])
except ValueError:
pass
else:
if ndim is not None:
raise ValueError
param = ndim = NDim(
tmp, _fp=_get_fluidpythran_calling_module()
)
if isinstance(param, str):
raise ValueError(f"{param} cannot be interpretted...")
params_filtered.append(param)
parameters = {p.__name__: p for p in params_filtered}
ArrayBis = type(
"ArrayBis",
......
......@@ -57,6 +57,11 @@ import os
import sys
import time
try:
import numpy as np
except ImportError:
np = None
from .pythranizer import compile_pythran_file, ext_suffix_short
from .util import (
......@@ -165,10 +170,10 @@ def make_pythran_type_name(obj: object):
"""return the Pythran type name"""
name = type(obj).__name__
if name == "ndarray":
if np and isinstance(obj, np.ndarray):
name = obj.dtype.name
if obj.ndim != 0:
name += "[" + ",".join([":"] * obj.ndim) + "]"
name += "[" + ", ".join([":"] * obj.ndim) + "]"
if name in ("list", "set", "dict"):
if not obj:
......
......@@ -8,12 +8,12 @@ try:
except ImportError:
pythran = None
from .cached_jit import path_cachedjit, modules
from .justintime import path_cachedjit, modules
from .pythranizer import scheduler, wait_for_all_extensions
scheduler.nb_cpus = 2
module_name = "fluidpythran.for_test_cached_jit"
module_name = "fluidpythran.for_test_justintime"
path_pythran_dir = path_cachedjit / module_name.replace(".", os.path.sep)
......@@ -32,7 +32,7 @@ delete_pythran_files("func_dict")
def test_cachedjit():
from time import sleep
from .for_test_cached_jit import func1
from .for_test_justintime import func1
a = np.arange(2)
b = [1, 2]
......@@ -45,7 +45,7 @@ def test_cachedjit():
def test_cachedjit_simple():
from time import sleep
from .for_test_cached_jit import func2
from .for_test_justintime import func2
func2(1)
......@@ -66,14 +66,14 @@ def test_cachedjit_simple():
del sys.modules[module_name]
del modules[module_name]
from .for_test_cached_jit import func2
from .for_test_justintime import func2
func2(1)
def test_cachedjit_dict():
from time import sleep
from .for_test_cached_jit import func_dict
from .for_test_justintime import func_dict
d = dict(a=1, b=2)
func_dict(d)
......
......@@ -42,10 +42,8 @@ import importlib.util
from distutils.util import strtobool
import shutil
from typing import Callable
import astunparse
try:
......@@ -237,7 +235,7 @@ def clear_cached_extensions(module_name: str, force: bool = False):
"""
from .cached_jit import path_cachedjit
from .justintime import path_cachedjit
if module_name.endswith(".py"):
module_name = module_name[:-3]
......
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