import warnings import numpy as np from numba import unittest_support as unittest from numba import jit, errors from .support import TestCase, tag from .matmul_usecase import matmul_usecase, needs_matmul, needs_blas try: import scipy.linalg.cython_lapack has_lapack = True except ImportError: has_lapack = False needs_lapack = unittest.skipUnless(has_lapack, "LAPACK needs Scipy 0.16+") def dot2(a, b): return np.dot(a, b) def dot3(a, b, out): return np.dot(a, b, out=out) def vdot(a, b): return np.vdot(a, b) class TestProduct(TestCase): """ Tests for dot products. """
import math import numpy as np import subprocess import numbers import importlib import sys import re from itertools import chain, combinations import numba from numba import prange, unittest_support as unittest from numba.compiler import compile_isolated, Flags from numba.six import exec_ from .support import TestCase, tag, override_env_config needs_svml = unittest.skipUnless(numba.config.USING_SVML, "SVML tests need SVML to be present") # a map of float64 vector lenghs with corresponding CPU architecture vlen2cpu = {2: 'nehalem', 4: 'haswell', 8: 'skylake-avx512'} # K: SVML functions, V: python functions which are expected to be SIMD-vectorized # using SVML, explicit references to Python functions here are mostly for sake of # instant import checks. # TODO: [] and comments below mean unused/untested SVML function, it's to be # either enabled or to be replaced with the explanation why the function # cannot be used in Numba # TODO: this test does not support functions with more than 1 arguments yet # The test logic should be modified if there is an SVML function being used under # different name or module from Python svml_funcs = { "sin": [np.sin, math.sin],
def skip_unless_cudasim(reason): return unittest.skipUnless(config.ENABLE_CUDASIM, reason)
def imatmul_usecase(x, y): x @= y return x """ co = compile(code, "<string>", "exec") ns = {} eval(co, globals(), ns) globals().update(ns) del code, co, ns else: matmul_usecase = None imatmul_usecase = None needs_matmul = unittest.skipUnless( has_matmul, "the matrix multiplication operator needs Python 3.5+ and Numpy 1.10+") needs_blas = unittest.skipUnless(has_blas, "BLAS needs Scipy 0.16+") class DumbMatrix(object): def __init__(self, value): self.value = value def __matmul__(self, other): if isinstance(other, DumbMatrix): return DumbMatrix(self.value * other.value) return NotImplemented
def skip_unless_conda_cudatoolkit(reason): return unittest.skipUnless(get_conda_ctk() is not None, reason)
# Check that the cause of the exception is due to access/permission # as per https://github.com/conda/conda/blob/4.5.0/conda/gateways/disk/permissions.py#L35-L37 eno = getattr(e, 'errno', None) if eno in (errno.EACCES, errno.EPERM): # errno reports access/perm fail so access prevention via # `chmod 500` works for this user. ret = True finally: os.chmod(test_dir, 0o775) shutil.rmtree(test_dir) return ret _access_preventable = check_access_is_preventable() _access_msg = "Cannot create a directory to which writes are preventable" skip_bad_access = unittest.skipUnless(_access_preventable, _access_msg) class TestDispatcher(BaseTest): def test_dyn_pyfunc(self): @jit def foo(x): return x foo(1) [cr] = foo.overloads.values() # __module__ must be match that of foo self.assertEqual(cr.entry_point.__module__, foo.py_func.__module__) def test_no_argument(self): @jit
_HAVE_TBB_POOL = False try: from numba.npyufunc import omppool _HAVE_OMP_POOL = True except ImportError: _HAVE_OMP_POOL = False try: import scipy.linalg.cython_lapack # noqa: F401 _HAVE_LAPACK = True except ImportError: _HAVE_LAPACK = False # test skipping decorators skip_no_omp = unittest.skipUnless(_HAVE_OMP_POOL, "OpenMP threadpool required") skip_no_tbb = unittest.skipUnless(_HAVE_TBB_POOL, "TBB threadpool required") _gnuomp = _HAVE_OMP_POOL and omppool.openmp_vendor == "GNU" skip_unless_gnu_omp = unittest.skipUnless(_gnuomp, "GNU OpenMP only tests") _windows = sys.platform.startswith('win') _osx = sys.platform.startswith('darwin') _32bit = sys.maxsize <= 2**32 _parfors_unsupported = _32bit _HAVE_OS_FORK = not _windows # some functions to jit
_HAVE_TBB_POOL = False try: from numba.npyufunc import omppool _HAVE_OMP_POOL = True except ImportError: _HAVE_OMP_POOL = False try: import scipy.linalg.cython_lapack _HAVE_LAPACK = True except ImportError: _HAVE_LAPACK = False # test skipping decorators skip_no_omp = unittest.skipUnless(_HAVE_OMP_POOL, "OpenMP threadpool required") skip_no_tbb = unittest.skipUnless(_HAVE_TBB_POOL, "TBB threadpool required") _gnuomp = _HAVE_OMP_POOL and omppool.openmp_vendor == "GNU" skip_unless_gnu_omp = unittest.skipUnless(_gnuomp, "GNU OpenMP only tests") skip_unless_py3 = unittest.skipUnless(utils.PYVERSION >= (3, 0), "Test runs on Python 3 only") _windows = sys.platform.startswith('win') _osx = sys.platform.startswith('darwin') _windows_py27 = (sys.platform.startswith('win32') and sys.version_info[:2] == (2, 7)) _32bit = sys.maxsize <= 2 ** 32 _parfors_unsupported = _32bit or _windows_py27
import ctypes import os import subprocess import sys from collections import namedtuple import numpy as np from numba import unittest_support as unittest from numba import cfunc, carray, farray, types, typing, utils, njit from numba import cffi_support, numpy_support from .support import TestCase, tag, captured_stderr from .test_dispatcher import BaseCacheTest skip_cffi_unsupported = unittest.skipUnless( cffi_support.SUPPORTED, "CFFI not supported -- please install the cffi module", ) def add_usecase(a, b): return a + b def div_usecase(a, b): c = a / b return c def square_usecase(a): return a ** 2 add_sig = "float64(float64, float64)"
import sys import numpy as np from numba import unittest_support as unittest from numba import jit, errors from .support import TestCase from .matmul_usecase import matmul_usecase, needs_matmul, needs_blas try: import scipy.linalg.cython_lapack has_lapack = True except ImportError: has_lapack = False needs_lapack = unittest.skipUnless(has_lapack, "LAPACK needs Scipy 0.16+") def dot2(a, b): return np.dot(a, b) def dot3(a, b, out): return np.dot(a, b, out=out) def vdot(a, b): return np.vdot(a, b) class TestProduct(TestCase):
_msg = "SciPy needed for test" skip_unless_scipy = unittest.skipIf(scipy is None, _msg) _lnx_reason = 'linux only test' linux_only = unittest.skipIf(not sys.platform.startswith('linux'), _lnx_reason) _is_armv7l = platform.machine() == 'armv7l' try: import scipy.linalg.cython_lapack has_lapack = True except ImportError: has_lapack = False needs_lapack = unittest.skipUnless(has_lapack, "LAPACK needs SciPy 1.0+") try: import scipy.linalg.cython_blas has_blas = True except ImportError: has_blas = False needs_blas = unittest.skipUnless(has_blas, "BLAS needs SciPy 1.0+") class CompilationCache(object): """ A cache of compilation results for various signatures and flags. This can make tests significantly faster (or less slow). """
from numba import njit, gdb, gdb_init, gdb_breakpoint, prange, errors from numba import jit from numba import unittest_support as unittest from numba.targets.gdb_hook import _confirm_gdb from .support import (TestCase, captured_stdout, tag) from .test_parfors import skip_unsupported as parfors_skip_unsupported _platform = sys.platform _unix_like = (_platform.startswith('linux') or _platform.startswith('darwin') or ('bsd' in _platform)) unix_only = unittest.skipUnless(_unix_like, "unix-like OS is required") not_unix = unittest.skipIf(_unix_like, "non unix-like OS is required") _arch_name = platform.machine() _is_arm = _arch_name in {'aarch64', 'armv7l'} not_arm = unittest.skipIf(_is_arm, "testing disabled on ARM") _gdb_cond = os.environ.get('GDB_TEST', None) == '1' needs_gdb_harness = unittest.skipUnless(_gdb_cond, "needs gdb harness") # check if gdb is present and working try: _confirm_gdb() _HAVE_GDB = True except Exception: _HAVE_GDB = False
def imatmul_usecase(x, y): x @= y return x """ co = compile(code, "<string>", "exec") ns = {} eval(co, globals(), ns) globals().update(ns) del code, co, ns else: matmul_usecase = None imatmul_usecase = None needs_matmul = unittest.skipUnless( has_matmul, "the matrix multiplication operator needs Python 3.5+") needs_blas = unittest.skipUnless(has_blas, "BLAS needs Scipy 0.16+") class DumbMatrix(object): def __init__(self, value): self.value = value def __matmul__(self, other): if isinstance(other, DumbMatrix): return DumbMatrix(self.value * other.value) return NotImplemented def __imatmul__(self, other):
_HAVE_TBB_POOL = False try: from numba.npyufunc import omppool _HAVE_OMP_POOL = True except ImportError: _HAVE_OMP_POOL = False try: import scipy.linalg.cython_lapack _HAVE_LAPACK = True except ImportError: _HAVE_LAPACK = False # test skipping decorators skip_no_omp = unittest.skipUnless(_HAVE_OMP_POOL, "OpenMP threadpool required") skip_no_tbb = unittest.skipUnless(_HAVE_TBB_POOL, "TBB threadpool required") _gnuomp = _HAVE_OMP_POOL and omppool.openmp_vendor == "GNU" skip_unless_gnu_omp = unittest.skipUnless(_gnuomp, "GNU OpenMP only tests") skip_unless_py3 = unittest.skipUnless(utils.PYVERSION >= (3, 0), "Test runs on Python 3 only") _windows = sys.platform.startswith('win') _osx = sys.platform.startswith('darwin') _windows_py27 = (sys.platform.startswith('win32') and sys.version_info[:2] == (2, 7)) _32bit = sys.maxsize <= 2**32 _parfors_unsupported = _32bit or _windows_py27
except (OSError, IOError) as e: # Check that the cause of the exception is due to access/permission # as per https://github.com/conda/conda/blob/4.5.0/conda/gateways/disk/permissions.py#L35-L37 eno = getattr(e, 'errno', None) if eno in (errno.EACCES, errno.EPERM): # errno reports access/perm fail so access prevention via # `chmod 500` works for this user. ret = True finally: os.chmod(test_dir, 0o775) shutil.rmtree(test_dir) return ret _access_preventable = check_access_is_preventable() _access_msg = "Cannot create a directory to which writes are preventable" skip_bad_access = unittest.skipUnless(_access_preventable, _access_msg) class TestDispatcher(BaseTest): def test_dyn_pyfunc(self): @jit def foo(x): return x foo(1) [cr] = foo.overloads.values() # __module__ must be match that of foo self.assertEqual(cr.entry_point.__module__, foo.py_func.__module__) def test_no_argument(self):