Skip to main content

SciPy fixes and extensions

Project description

scipyx

PyPi Version PyPI pyversions GitHub stars PyPi downloads

gh-actions codecov LGTM Code style: black

SciPy is large library used everywhere in scientific computing. That's why breaking backwards-compatibility comes as a significant cost and is almost always avoided, even if the API of some methods is arguably lacking. This package provides drop-in wrappers "fixing" those.

npx does the same for NumPy.

If you have a fix for a SciPy method that can't go upstream for some reason, feel free to PR here.

Krylov methods

import numpy as np
import scipy.sparse
import scipyx as spx

# create tridiagonal (-1, 2, -1) matrix
n = 100
data = -np.ones((3, n))
data[1] = 2.0
A = scipy.sparse.spdiags(data, [-1, 0, 1], n, n)
A = A.tocsr()
b = np.ones(n)


sol, info = spx.cg(A, b, tol=1.0e-10)
sol, info = spx.minres(A, b, tol=1.0e-10)
sol, info = spx.gmres(A, b, tol=1.0e-10)
sol, info = spx.bicg(A, b, tol=1.0e-10)
sol, info = spx.bicgstab(A, b, tol=1.0e-10)
sol, info = spx.cgs(A, b, tol=1.0e-10)
sol, info = spx.qmr(A, b, tol=1.0e-10)

sol is the solution of the linear system A @ x = b (or None if no convergence), and info contains some useful data, e.g., info.resnorms. The methods are wrappers around SciPy's iterative solvers.

Relevant issues:

Minimization

import scipyx as spx


def f(x):
    return (x ** 2 - 2) ** 2


x0 = 1.5
out = spx.minimize(f, x0)

In SciPy, the result from a minimization out.x will always have shape (n,), no matter the input vector. scipyx changes this to respect the input vector shape.

Relevant issues:

Root-finding

import scipyx as spx


def f(x):
    return x ** 2 - 2

a, b = spx.bisect(f, 0.0, 5.0, tol=1.0e-12)
a, b = spx.regula_falsi(f, 0.0, 5.0, tol=1.0e-12)

scipyx provides some basic nonlinear root-findings algorithms: bisection and regula falsi. They're not as fast-converging as other methods, but are very robust and work with almost any function.

License

scipyx is published under the MIT license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

scipyx-0.0.12.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

scipyx-0.0.12-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file scipyx-0.0.12.tar.gz.

File metadata

  • Download URL: scipyx-0.0.12.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for scipyx-0.0.12.tar.gz
Algorithm Hash digest
SHA256 4bf09c003dbf9ae449f9dadf3c35ab4e86d22e7b6a052dce8f725834b0415d8a
MD5 9f8726ca1a024072693080848bd70804
BLAKE2b-256 6071305ef26c97166a96714286c940a7592c0f1663209935bab90278b59d14b8

See more details on using hashes here.

File details

Details for the file scipyx-0.0.12-py3-none-any.whl.

File metadata

  • Download URL: scipyx-0.0.12-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for scipyx-0.0.12-py3-none-any.whl
Algorithm Hash digest
SHA256 5bc721ff983417807169049adde3fede38ee1d969efbaf3e1a46ecd95ff44055
MD5 e488358a96af35820ac9f54a55111592
BLAKE2b-256 33e97fe301ef81a7a479b4e42459663a3c962f44ce21b5f8b180942ae01b3d3b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page