.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_build/auto_examples/benchmarks/Inplace_conjugate.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr__build_auto_examples_benchmarks_Inplace_conjugate.py: Benchmark of inplace conjugation of arrays ========================================== .. GENERATED FROM PYTHON SOURCE LINES 7-8 This is a benchmark of different ways to perform inplace conjugation of a complex numpy array. .. GENERATED FROM PYTHON SOURCE LINES 9-91 .. code-block:: Python import numpy as np import numba as nb import pyquickbench numba_opt_dict = { 'nopython':True , 'cache':True , 'fastmath':True , 'nogil':True , } def numpy_ufunc_outofplace(x): x = np.conjugate(x) def numpy_ufunc_inplace(x): np.conjugate(x, out=x) def numpy_inplace_mul(x): x.imag *= -1 def numpy_subs(x): x.imag = -x.imag @nb.jit("void(complex128[::1])", **numba_opt_dict) def numba_loop_typedef(x): for i in range(x.shape[0]): x.imag[i] = -x.imag[i] @nb.jit(**numba_opt_dict) def numba_loop(x): for i in range(x.shape[0]): x.imag[i] = -x.imag[i] @nb.jit(**numba_opt_dict, parallel=True) def numba_loop_parallel(x): for i in nb.prange(x.shape[0]): x.imag[i] = -x.imag[i] all_funs = [ numpy_ufunc_outofplace , numpy_ufunc_inplace , numpy_inplace_mul , numpy_subs , numba_loop_typedef , numba_loop , numba_loop_parallel , ] all_sizes = np.array([2**n for n in range(25)]) def prepare_x(n): x = np.random.random(n) + 1j*np.random.random(n) return [('x', x)] basename = 'Inplace_conjugation_bench' timings_filename = os.path.join(timings_folder, basename+'.npz') n_repeat = 10 all_values = pyquickbench.run_benchmark( all_sizes , all_funs , setup = prepare_x , n_repeat = n_repeat , filename = timings_filename , ShowProgress = True , # ForceBenchmark = True , ) pyquickbench.plot_benchmark( all_values , all_sizes , all_funs , show = True , title = 'Inplace conjugation' , ) .. image-sg:: /_build/auto_examples/benchmarks/images/sphx_glr_Inplace_conjugate_001.png :alt: Inplace conjugation :srcset: /_build/auto_examples/benchmarks/images/sphx_glr_Inplace_conjugate_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 123-137 .. code-block:: Python relative_to_val = {pyquickbench.fun_ax_name:"numpy_ufunc_inplace"} pyquickbench.plot_benchmark( all_values , all_sizes , all_funs , relative_to_val = relative_to_val , show = True , title = 'Inplace conjugation' , ylabel = 'Time relative to numpy_ufunc_inplace' , ) .. image-sg:: /_build/auto_examples/benchmarks/images/sphx_glr_Inplace_conjugate_002.png :alt: Inplace conjugation :srcset: /_build/auto_examples/benchmarks/images/sphx_glr_Inplace_conjugate_002.png :class: sphx-glr-single-img .. _sphx_glr_download__build_auto_examples_benchmarks_Inplace_conjugate.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: Inplace_conjugate.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: Inplace_conjugate.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: Inplace_conjugate.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_