1
1
.. _jitclass :
2
2
3
- =======================================
4
- Compiling python classes with @jitclass
5
- =======================================
3
+ ===========================================
4
+ Compiling Python classes with `` @jitclass ``
5
+ ===========================================
6
6
7
7
.. note ::
8
8
@@ -13,7 +13,7 @@ Compiling python classes with @jitclass
13
13
Numba supports code generation for classes via the :func: `numba.jitclass `
14
14
decorator. A class can be marked for optimization using this decorator along
15
15
with a specification of the types of each field. We call the resulting class
16
- object a jitclass. All methods of a jitclass are compiled into nopython
16
+ object a * jitclass * . All methods of a jitclass are compiled into nopython
17
17
functions. The data of a jitclass instance is allocated on the heap as a
18
18
C-compatible structure so that any compiled functions can have direct access
19
19
to the underlying data, bypassing the interpreter.
@@ -52,8 +52,8 @@ Here's an example of a jitclass::
52
52
(see full example at `examples/jitclass.py ` from the source tree)
53
53
54
54
In the above example, a ``spec `` is provided as a list of 2-tuples. The tuples
55
- contain the name of the field and the numba type of the field. Alternatively,
56
- user can use a dictionary (an ``OrderedDict `` preferrably for stable field
55
+ contain the name of the field and the Numba type of the field. Alternatively,
56
+ user can use a dictionary (an ``OrderedDict `` preferably for stable field
57
57
ordering), which maps field names to types.
58
58
59
59
The definition of the class requires at least a ``__init__ `` method for
@@ -65,21 +65,21 @@ automatically compiled.
65
65
Support operations
66
66
==================
67
67
68
- The following operations of jitclasses work in both the interpreter and numba
68
+ The following operations of jitclasses work in both the interpreter and Numba
69
69
compiled functions:
70
70
71
71
* calling the jitclass class object to construct a new instance
72
72
(e.g. ``mybag = Bag(123) ``);
73
73
* read/write access to attributes and properties (e.g. ``mybag.value ``);
74
74
* calling methods (e.g. ``mybag.increment(3) ``);
75
75
76
- Using jitclasses in numba compiled function is more efficient.
76
+ Using jitclasses in Numba compiled function is more efficient.
77
77
Short methods can be inlined (at the discretion of LLVM inliner).
78
78
Attributes access are simply reading from a C structure.
79
79
Using jitclasses from the intpreter has the same overhead of calling any
80
- numba compiled function from the interpreter. Arguments and return values
81
- must be unboxed or boxed between python objects and native representation.
82
- Values encapsulated by a jitclass does not get boxed into python object when
80
+ Numba compiled function from the interpreter. Arguments and return values
81
+ must be unboxed or boxed between Python objects and native representation.
82
+ Values encapsulated by a jitclass does not get boxed into Python object when
83
83
the jitclass instance is handed to the interpreter. It is during attribute
84
84
access to the field values that they are boxed.
85
85
@@ -88,7 +88,7 @@ Limitations
88
88
===========
89
89
90
90
* A jitclass class object is treated as a function (the constructor) inside
91
- a numba compiled function.
91
+ a Numba compiled function.
92
92
* ``isinstance() `` only works in the interpreter.
93
93
* Manipulating jitclass instances in the interpreter is not optimized, yet.
94
94
* Support for jitclasses are available on CPU only.
0 commit comments