Coverage for /home/martinb/.local/share/virtualenvs/camcops/lib/python3.6/site-packages/numpy/core/__init__.py : 83%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""
2Contains the core of NumPy: ndarray, ufuncs, dtypes, etc.
4Please note that this module is private. All functions and objects
5are available in the main ``numpy`` namespace - use that instead.
7"""
9from numpy.version import version as __version__
11import os
13# disables OpenBLAS affinity setting of the main thread that limits
14# python threads or processes to one core
15env_added = []
16for envkey in ['OPENBLAS_MAIN_FREE', 'GOTOBLAS_MAIN_FREE']:
17 if envkey not in os.environ:
18 os.environ[envkey] = '1'
19 env_added.append(envkey)
21try:
22 from . import multiarray
23except ImportError as exc:
24 import sys
25 msg = """
27IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
29Importing the numpy C-extensions failed. This error can happen for
30many reasons, often due to issues with your setup or how NumPy was
31installed.
33We have compiled some common reasons and troubleshooting tips at:
35 https://numpy.org/devdocs/user/troubleshooting-importerror.html
37Please note and check the following:
39 * The Python version is: Python%d.%d from "%s"
40 * The NumPy version is: "%s"
42and make sure that they are the versions you expect.
43Please carefully study the documentation linked above for further help.
45Original error was: %s
46""" % (sys.version_info[0], sys.version_info[1], sys.executable,
47 __version__, exc)
48 raise ImportError(msg)
49finally:
50 for envkey in env_added:
51 del os.environ[envkey]
52del envkey
53del env_added
54del os
56from . import umath
58# Check that multiarray,umath are pure python modules wrapping
59# _multiarray_umath and not either of the old c-extension modules
60if not (hasattr(multiarray, '_multiarray_umath') and
61 hasattr(umath, '_multiarray_umath')):
62 import sys
63 path = sys.modules['numpy'].__path__
64 msg = ("Something is wrong with the numpy installation. "
65 "While importing we detected an older version of "
66 "numpy in {}. One method of fixing this is to repeatedly uninstall "
67 "numpy until none is found, then reinstall this version.")
68 raise ImportError(msg.format(path))
70from . import numerictypes as nt
71multiarray.set_typeDict(nt.sctypeDict)
72from . import numeric
73from .numeric import *
74from . import fromnumeric
75from .fromnumeric import *
76from . import defchararray as char
77from . import records as rec
78from .records import *
79from .memmap import *
80from .defchararray import chararray
81from . import function_base
82from .function_base import *
83from . import machar
84from .machar import *
85from . import getlimits
86from .getlimits import *
87from . import shape_base
88from .shape_base import *
89from . import einsumfunc
90from .einsumfunc import *
91del nt
93from .fromnumeric import amax as max, amin as min, round_ as round
94from .numeric import absolute as abs
96# do this after everything else, to minimize the chance of this misleadingly
97# appearing in an import-time traceback
98from . import _add_newdocs
99# add these for module-freeze analysis (like PyInstaller)
100from . import _dtype_ctypes
101from . import _internal
102from . import _dtype
103from . import _methods
105__all__ = ['char', 'rec', 'memmap']
106__all__ += numeric.__all__
107__all__ += fromnumeric.__all__
108__all__ += rec.__all__
109__all__ += ['chararray']
110__all__ += function_base.__all__
111__all__ += machar.__all__
112__all__ += getlimits.__all__
113__all__ += shape_base.__all__
114__all__ += einsumfunc.__all__
116# Make it possible so that ufuncs can be pickled
117# Here are the loading and unloading functions
118# The name numpy.core._ufunc_reconstruct must be
119# available for unpickling to work.
120def _ufunc_reconstruct(module, name):
121 # The `fromlist` kwarg is required to ensure that `mod` points to the
122 # inner-most module rather than the parent package when module name is
123 # nested. This makes it possible to pickle non-toplevel ufuncs such as
124 # scipy.special.expit for instance.
125 mod = __import__(module, fromlist=[name])
126 return getattr(mod, name)
128def _ufunc_reduce(func):
129 from pickle import whichmodule
130 name = func.__name__
131 return _ufunc_reconstruct, (whichmodule(func, name), name)
134import copyreg
136copyreg.pickle(ufunc, _ufunc_reduce, _ufunc_reconstruct)
137# Unclutter namespace (must keep _ufunc_reconstruct for unpickling)
138del copyreg
139del _ufunc_reduce
141from numpy._pytesttester import PytestTester
142test = PytestTester(__name__)
143del PytestTester