Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/scipy/__init__.py: 83%

76 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2023-12-12 06:31 +0000

1""" 

2SciPy: A scientific computing package for Python 

3================================================ 

4 

5Documentation is available in the docstrings and 

6online at https://docs.scipy.org. 

7 

8Contents 

9-------- 

10SciPy imports all the functions from the NumPy namespace, and in 

11addition provides: 

12 

13Subpackages 

14----------- 

15Using any of these subpackages requires an explicit import. For example, 

16``import scipy.cluster``. 

17 

18:: 

19 

20 cluster --- Vector Quantization / Kmeans 

21 datasets --- Dataset methods 

22 fft --- Discrete Fourier transforms 

23 fftpack --- Legacy discrete Fourier transforms 

24 integrate --- Integration routines 

25 interpolate --- Interpolation Tools 

26 io --- Data input and output 

27 linalg --- Linear algebra routines 

28 linalg.blas --- Wrappers to BLAS library 

29 linalg.lapack --- Wrappers to LAPACK library 

30 misc --- Various utilities that don't have 

31 another home. 

32 ndimage --- N-D image package 

33 odr --- Orthogonal Distance Regression 

34 optimize --- Optimization Tools 

35 signal --- Signal Processing Tools 

36 signal.windows --- Window functions 

37 sparse --- Sparse Matrices 

38 sparse.linalg --- Sparse Linear Algebra 

39 sparse.linalg.dsolve --- Linear Solvers 

40 sparse.linalg.dsolve.umfpack --- :Interface to the UMFPACK library: 

41 Conjugate Gradient Method (LOBPCG) 

42 sparse.linalg.eigen --- Sparse Eigenvalue Solvers 

43 sparse.linalg.eigen.lobpcg --- Locally Optimal Block Preconditioned 

44 Conjugate Gradient Method (LOBPCG) 

45 spatial --- Spatial data structures and algorithms 

46 special --- Special functions 

47 stats --- Statistical Functions 

48 

49Utility tools 

50------------- 

51:: 

52 

53 test --- Run scipy unittests 

54 show_config --- Show scipy build configuration 

55 show_numpy_config --- Show numpy build configuration 

56 __version__ --- SciPy version string 

57 __numpy_version__ --- Numpy version string 

58 

59""" 

60 

61from numpy import show_config as show_numpy_config 

62if show_numpy_config is None: 

63 raise ImportError( 

64 "Cannot import SciPy when running from NumPy source directory.") 

65from numpy import __version__ as __numpy_version__ 

66 

67# Import numpy symbols to scipy name space (DEPRECATED) 

68from ._lib.deprecation import _deprecated 

69import numpy as np 

70_msg = ('scipy.{0} is deprecated and will be removed in SciPy 2.0.0, ' 

71 'use numpy.{0} instead') 

72 

73# deprecate callable objects from numpy, skipping classes and modules 

74import types as _types # noqa: E402 

75for _key in np.__all__: 

76 if _key.startswith('_'): 

77 continue 

78 _fun = getattr(np, _key) 

79 if isinstance(_fun, _types.ModuleType): 

80 continue 

81 if callable(_fun) and not isinstance(_fun, type): 

82 _fun = _deprecated(_msg.format(_key))(_fun) 

83 globals()[_key] = _fun 

84del np, _types 

85 

86from numpy.random import rand, randn 

87_msg = ('scipy.{0} is deprecated and will be removed in SciPy 2.0.0, ' 

88 'use numpy.random.{0} instead') 

89rand = _deprecated(_msg.format('rand'))(rand) 

90randn = _deprecated(_msg.format('randn'))(randn) 

91 

92# fft is especially problematic, so was removed in SciPy 1.6.0 

93from numpy.fft import ifft 

94ifft = _deprecated('scipy.ifft is deprecated and will be removed in SciPy ' 

95 '2.0.0, use scipy.fft.ifft instead')(ifft) 

96 

97from numpy.lib import scimath # noqa: E402 

98_msg = ('scipy.{0} is deprecated and will be removed in SciPy 2.0.0, ' 

99 'use numpy.lib.scimath.{0} instead') 

100for _key in scimath.__all__: 

101 _fun = getattr(scimath, _key) 

102 if callable(_fun): 

103 _fun = _deprecated(_msg.format(_key))(_fun) 

104 globals()[_key] = _fun 

105del scimath 

106del _msg, _fun, _key, _deprecated 

107 

108# We first need to detect if we're being called as part of the SciPy 

109# setup procedure itself in a reliable manner. 

110try: 

111 __SCIPY_SETUP__ 

112except NameError: 

113 __SCIPY_SETUP__ = False 

114 

115 

116if __SCIPY_SETUP__: 

117 import sys 

118 sys.stderr.write('Running from SciPy source directory.\n') 

119 del sys 

120else: 

121 try: 

122 from scipy.__config__ import show as show_config 

123 except ImportError as e: 

124 msg = """Error importing SciPy: you cannot import SciPy while 

125 being in scipy source directory; please exit the SciPy source 

126 tree first and relaunch your Python interpreter.""" 

127 raise ImportError(msg) from e 

128 

129 from scipy.version import version as __version__ 

130 

131 # Allow distributors to run custom init code 

132 from . import _distributor_init 

133 del _distributor_init 

134 

135 from scipy._lib import _pep440 

136 # In maintenance branch, change to np_maxversion N+3 if numpy is at N 

137 # See setup.py for more details 

138 np_minversion = '1.19.5' 

139 np_maxversion = '1.27.0' 

140 if (_pep440.parse(__numpy_version__) < _pep440.Version(np_minversion) or 

141 _pep440.parse(__numpy_version__) >= _pep440.Version(np_maxversion)): 

142 import warnings 

143 warnings.warn(f"A NumPy version >={np_minversion} and <{np_maxversion}" 

144 f" is required for this version of SciPy (detected " 

145 f"version {__numpy_version__})", 

146 UserWarning) 

147 del _pep440 

148 

149 # This is the first import of an extension module within SciPy. If there's 

150 # a general issue with the install, such that extension modules are missing 

151 # or cannot be imported, this is where we'll get a failure - so give an 

152 # informative error message. 

153 try: 

154 from scipy._lib._ccallback import LowLevelCallable 

155 except ImportError as e: 

156 msg = "The `scipy` install you are using seems to be broken, " + \ 

157 "(extension modules cannot be imported), " + \ 

158 "please try reinstalling." 

159 raise ImportError(msg) from e 

160 

161 from scipy._lib._testutils import PytestTester 

162 test = PytestTester(__name__) 

163 del PytestTester 

164 

165 submodules = [ 

166 'cluster', 

167 'datasets', 

168 'fft', 

169 'fftpack', 

170 'integrate', 

171 'interpolate', 

172 'io', 

173 'linalg', 

174 'misc', 

175 'ndimage', 

176 'odr', 

177 'optimize', 

178 'signal', 

179 'sparse', 

180 'spatial', 

181 'special', 

182 'stats' 

183 ] 

184 

185 __all__ = submodules + [ 

186 'LowLevelCallable', 

187 'test', 

188 'show_config', 

189 '__version__', 

190 '__numpy_version__' 

191 ] 

192 

193 def __dir__(): 

194 return __all__ 

195 

196 import importlib as _importlib 

197 

198 def __getattr__(name): 

199 if name in submodules: 

200 return _importlib.import_module(f'scipy.{name}') 

201 else: 

202 try: 

203 return globals()[name] 

204 except KeyError: 

205 raise AttributeError( 

206 f"Module 'scipy' has no attribute '{name}'" 

207 )