File: examples.rst

package info (click to toggle)
numba 0.61.2%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 17,316 kB
  • sloc: python: 211,580; ansic: 15,233; cpp: 6,544; javascript: 424; sh: 322; makefile: 173
file content (52 lines) | stat: -rw-r--r-- 1,536 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
========
Examples
========


Mandelbrot
----------

.. literalinclude:: ../../../numba/tests/doc_examples/test_examples.py
   :language: python
   :caption: from ``test_mandelbrot`` of ``numba/tests/doc_examples/test_examples.py``
   :start-after: magictoken.ex_mandelbrot.begin
   :end-before: magictoken.ex_mandelbrot.end
   :dedent: 12
   :linenos:

.. _example-movemean:

Moving average
--------------

.. literalinclude:: ../../../numba/tests/doc_examples/test_examples.py
   :language: python
   :caption: from ``test_moving_average`` of ``numba/tests/doc_examples/test_examples.py``
   :start-after: magictoken.ex_moving_average.begin
   :end-before: magictoken.ex_moving_average.end
   :dedent: 12
   :linenos:

Multi-threading
---------------

The code below showcases the potential performance improvement when
using the :ref:`nogil <jit-nogil>` feature.  For example, on a 4-core machine,
the following results were printed::

   numpy (1 thread)       145 ms
   numba (1 thread)       128 ms
   numba (4 threads)       35 ms

.. note::
   If preferred it's possible to use the standard `concurrent.futures
   <https://docs.python.org/3/library/concurrent.futures.html>`_ module
   rather than spawn threads and dispatch tasks by hand.

.. literalinclude:: ../../../numba/tests/doc_examples/test_examples.py
   :language: python
   :caption: from ``test_no_gil`` of ``numba/tests/doc_examples/test_examples.py``
   :start-after: magictoken.ex_no_gil.begin
   :end-before: magictoken.ex_no_gil.end
   :dedent: 12
   :linenos: