__init__.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. """
  2. Linear Solvers
  3. ==============
  4. The default solver is SuperLU (included in the scipy distribution),
  5. which can solve real or complex linear systems in both single and
  6. double precisions. It is automatically replaced by UMFPACK, if
  7. available. Note that UMFPACK works in double precision only, so
  8. switch it off by::
  9. >>> use_solver(useUmfpack=False)
  10. to solve in the single precision. See also use_solver documentation.
  11. Example session::
  12. >>> from scipy.sparse import csc_matrix, spdiags
  13. >>> from numpy import array
  14. >>> from scipy.sparse.linalg import spsolve, use_solver
  15. >>>
  16. >>> print("Inverting a sparse linear system:")
  17. >>> print("The sparse matrix (constructed from diagonals):")
  18. >>> a = spdiags([[1, 2, 3, 4, 5], [6, 5, 8, 9, 10]], [0, 1], 5, 5)
  19. >>> b = array([1, 2, 3, 4, 5])
  20. >>> print("Solve: single precision complex:")
  21. >>> use_solver( useUmfpack = False )
  22. >>> a = a.astype('F')
  23. >>> x = spsolve(a, b)
  24. >>> print(x)
  25. >>> print("Error: ", a@x-b)
  26. >>>
  27. >>> print("Solve: double precision complex:")
  28. >>> use_solver( useUmfpack = True )
  29. >>> a = a.astype('D')
  30. >>> x = spsolve(a, b)
  31. >>> print(x)
  32. >>> print("Error: ", a@x-b)
  33. >>>
  34. >>> print("Solve: double precision:")
  35. >>> a = a.astype('d')
  36. >>> x = spsolve(a, b)
  37. >>> print(x)
  38. >>> print("Error: ", a@x-b)
  39. >>>
  40. >>> print("Solve: single precision:")
  41. >>> use_solver( useUmfpack = False )
  42. >>> a = a.astype('f')
  43. >>> x = spsolve(a, b.astype('f'))
  44. >>> print(x)
  45. >>> print("Error: ", a@x-b)
  46. """
  47. #import umfpack
  48. #__doc__ = '\n\n'.join( (__doc__, umfpack.__doc__) )
  49. #del umfpack
  50. from .linsolve import *
  51. from ._superlu import SuperLU
  52. from . import _add_newdocs
  53. from . import linsolve
  54. __all__ = [
  55. 'MatrixRankWarning', 'SuperLU', 'factorized',
  56. 'spilu', 'splu', 'spsolve',
  57. 'spsolve_triangular', 'use_solver'
  58. ]
  59. from scipy._lib._testutils import PytestTester
  60. test = PytestTester(__name__)
  61. del PytestTester