Last change
on this file since 804 was
804,
checked in by dubos, 5 years ago
|
devel/Python : introduced Python/dynamico/dev/ subdirectory
|
File size:
987 bytes
|
Line | |
---|
1 | from __future__ import absolute_import |
---|
2 | from __future__ import print_function |
---|
3 | |
---|
4 | import numpy as np |
---|
5 | from numba import int32, float64 |
---|
6 | import numba |
---|
7 | |
---|
8 | def store_data(obj,*args): |
---|
9 | """Returns a jitclass instance containing attributes copied from obj. *args is of the form type,names,type,names ... where names is a string 'attr1 attr2 attr3' containing space-separated names of attributes of obj. Those attributes are declared to numba with the type preceding them. The result of store_data can be used as argument to a @jit function.""" |
---|
10 | spec = [] |
---|
11 | for item in args: |
---|
12 | if isinstance(item,str): |
---|
13 | spec = spec + [(name,thetype) for name in item.split(' ')] |
---|
14 | else: |
---|
15 | thetype=item |
---|
16 | @numba.jitclass(spec) |
---|
17 | class JitClass(object): |
---|
18 | def __init__(self): pass |
---|
19 | data=JitClass() |
---|
20 | for name,thetype in spec: setattr(data, name, getattr(obj,name)) |
---|
21 | return data |
---|
22 | |
---|
23 | jit=numba.jit(nopython=True, nogil=True, error_model='numpy', fastmath=True) |
---|
Note: See
TracBrowser
for help on using the repository browser.