nulapack 0.1.0__cp312-cp312-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- _nulapack.cp312-win_amd64.dll.a +0 -0
- _nulapack.cp312-win_amd64.pyd +0 -0
- nulapack/__init__.py +16 -0
- nulapack/cholesky.py +46 -0
- nulapack/doolittle.py +44 -0
- nulapack/gauss_seidel.py +50 -0
- nulapack/jacobi.py +50 -0
- nulapack/thomas.py +44 -0
- nulapack-0.1.0.dist-info/LICENSE +674 -0
- nulapack-0.1.0.dist-info/METADATA +870 -0
- nulapack-0.1.0.dist-info/RECORD +12 -0
- nulapack-0.1.0.dist-info/WHEEL +4 -0
|
Binary file
|
|
Binary file
|
nulapack/__init__.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
2
|
+
|
|
3
|
+
from .cholesky import cholesky
|
|
4
|
+
from .doolittle import doolittle
|
|
5
|
+
from .gauss_seidel import gauss_seidel
|
|
6
|
+
from .jacobi import jacobi
|
|
7
|
+
from .thomas import thomas
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
try:
|
|
11
|
+
__version__ = version("nulapack")
|
|
12
|
+
except PackageNotFoundError:
|
|
13
|
+
# package is not installed
|
|
14
|
+
pass
|
|
15
|
+
|
|
16
|
+
__all__ = ["__version__", "cholesky", "doolittle", "gauss_seidel", "jacobi", "thomas"]
|
nulapack/cholesky.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import _nulapack
|
|
2
|
+
import numpy as np
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def cholesky(a: np.ndarray):
|
|
6
|
+
"""
|
|
7
|
+
Compute the Cholesky factorization of a symmetric/Hermitian
|
|
8
|
+
positive-definite matrix A using NULAPACK.
|
|
9
|
+
|
|
10
|
+
Parameters
|
|
11
|
+
----------
|
|
12
|
+
a : ndarray
|
|
13
|
+
Coefficient matrix (n x n) stored as a full matrix. Real matrices
|
|
14
|
+
should be symmetric, complex matrices should be Hermitian and
|
|
15
|
+
positive-definite.
|
|
16
|
+
|
|
17
|
+
Returns
|
|
18
|
+
-------
|
|
19
|
+
L : ndarray
|
|
20
|
+
Lower-triangular matrix from the factorization (A = L * L^T or
|
|
21
|
+
A = L * L^H).
|
|
22
|
+
info : int
|
|
23
|
+
0 if success, >0 if the matrix is not positive-definite.
|
|
24
|
+
"""
|
|
25
|
+
a = np.ascontiguousarray(a)
|
|
26
|
+
n = a.shape[0]
|
|
27
|
+
lda = n
|
|
28
|
+
|
|
29
|
+
a_flat = a.ravel(order="C")
|
|
30
|
+
l_flat = np.zeros_like(a_flat)
|
|
31
|
+
info = np.zeros(1, dtype=np.int32)
|
|
32
|
+
|
|
33
|
+
if np.issubdtype(a.dtype, np.floating):
|
|
34
|
+
if a.dtype == np.float32:
|
|
35
|
+
_nulapack.spoctrf(n, a_flat, l_flat, lda, info)
|
|
36
|
+
else: # float64
|
|
37
|
+
_nulapack.dpoctrf(n, a_flat, l_flat, lda, info)
|
|
38
|
+
elif np.issubdtype(a.dtype, np.complexfloating):
|
|
39
|
+
if a.dtype == np.complex64:
|
|
40
|
+
_nulapack.cpoctrf(n, a_flat, l_flat, lda, info)
|
|
41
|
+
else: # complex128
|
|
42
|
+
_nulapack.zpoctrf(n, a_flat, l_flat, lda, info)
|
|
43
|
+
else:
|
|
44
|
+
raise TypeError(f"Unsupported array dtype: {a.dtype}")
|
|
45
|
+
|
|
46
|
+
return np.tril(l_flat.reshape(n, n, order="C")), int(info[0])
|
nulapack/doolittle.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import _nulapack
|
|
2
|
+
import numpy as np
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def doolittle(a: np.ndarray):
|
|
6
|
+
"""
|
|
7
|
+
Compute the LU Doolittle decomposition of a general matrix A.
|
|
8
|
+
|
|
9
|
+
Parameters
|
|
10
|
+
----------
|
|
11
|
+
a : ndarray
|
|
12
|
+
Coefficient matrix (n x n) stored as a full matrix.
|
|
13
|
+
|
|
14
|
+
Returns
|
|
15
|
+
-------
|
|
16
|
+
L : ndarray
|
|
17
|
+
Lower triangular matrix from the factorization.
|
|
18
|
+
U : ndarray
|
|
19
|
+
Upper triangular matrix from the factorization.
|
|
20
|
+
info : int
|
|
21
|
+
0 if success, <0 if a zero diagonal in U was detected.
|
|
22
|
+
"""
|
|
23
|
+
a = np.ascontiguousarray(a)
|
|
24
|
+
n = a.shape[0]
|
|
25
|
+
|
|
26
|
+
a_flat = a.ravel(order="C")
|
|
27
|
+
l_flat = np.zeros_like(a_flat)
|
|
28
|
+
u_flat = np.zeros_like(a_flat)
|
|
29
|
+
info = np.zeros(1, dtype=np.int32)
|
|
30
|
+
|
|
31
|
+
if np.issubdtype(a.dtype, np.floating):
|
|
32
|
+
if a.dtype == np.float32:
|
|
33
|
+
_nulapack.sgedtrf(n, a_flat, l_flat, u_flat, info)
|
|
34
|
+
else: # float64
|
|
35
|
+
_nulapack.dgedtrf(n, a_flat, l_flat, u_flat, info)
|
|
36
|
+
elif np.issubdtype(a.dtype, np.complexfloating):
|
|
37
|
+
if a.dtype == np.complex64:
|
|
38
|
+
_nulapack.cgedtrf(n, a_flat, l_flat, u_flat, info)
|
|
39
|
+
else: # complex128
|
|
40
|
+
_nulapack.zgedtrf(n, a_flat, l_flat, u_flat, info)
|
|
41
|
+
else:
|
|
42
|
+
raise TypeError(f"Unsupported array dtype: {a.dtype}")
|
|
43
|
+
|
|
44
|
+
return l_flat.reshape(n, n, order="C"), u_flat.reshape(n, n, order="C"), int(info[0])
|
nulapack/gauss_seidel.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import _nulapack
|
|
2
|
+
import numpy as np
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def gauss_seidel(a, b, max_iter=1000, tol=1e-8, omega=1.0):
|
|
6
|
+
"""
|
|
7
|
+
Solve the linear system ax = b using the Gauss-Seidel method.
|
|
8
|
+
|
|
9
|
+
Parameters
|
|
10
|
+
----------
|
|
11
|
+
a : ndarray
|
|
12
|
+
Coefficient matrix (n x n)
|
|
13
|
+
b : ndarray
|
|
14
|
+
Right-hand side vector (n,)
|
|
15
|
+
max_iter : int, optional
|
|
16
|
+
Maximum number of iterations
|
|
17
|
+
tol : float, optional
|
|
18
|
+
Convergence tolerance
|
|
19
|
+
omega : float, optional
|
|
20
|
+
Relaxation factor
|
|
21
|
+
|
|
22
|
+
Returns
|
|
23
|
+
-------
|
|
24
|
+
x : ndarray
|
|
25
|
+
Solution vector
|
|
26
|
+
status : int
|
|
27
|
+
0 if converged, non-zero otherwise
|
|
28
|
+
"""
|
|
29
|
+
a = np.ascontiguousarray(a)
|
|
30
|
+
b = np.asfortranarray(b)
|
|
31
|
+
n = a.shape[0]
|
|
32
|
+
|
|
33
|
+
x = np.zeros_like(b)
|
|
34
|
+
|
|
35
|
+
a_flat = a.ravel()
|
|
36
|
+
|
|
37
|
+
if np.issubdtype(a.dtype, np.floating):
|
|
38
|
+
if a.dtype == np.float32:
|
|
39
|
+
status = _nulapack.sgegssv(a_flat, b, x, max_iter, tol, omega, 0, n)
|
|
40
|
+
else: # float64
|
|
41
|
+
status = _nulapack.dgegssv(a_flat, b, x, max_iter, tol, omega, 0, n)
|
|
42
|
+
elif np.issubdtype(a.dtype, np.complexfloating):
|
|
43
|
+
if a.dtype == np.complex64:
|
|
44
|
+
status = _nulapack.cgegssv(a_flat, b, x, max_iter, tol, omega, 0, n)
|
|
45
|
+
else: # complex128
|
|
46
|
+
status = _nulapack.zgegssv(a_flat, b, x, max_iter, tol, omega, 0, n)
|
|
47
|
+
else:
|
|
48
|
+
raise TypeError(f"Unsupported array dtype: {a.dtype}")
|
|
49
|
+
|
|
50
|
+
return x, int(status) if status is not None else 0
|
nulapack/jacobi.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import _nulapack
|
|
2
|
+
import numpy as np
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def jacobi(a, b, max_iter=1000, tol=1e-8, omega=1.0):
|
|
6
|
+
"""
|
|
7
|
+
Solve the linear system ax = b using the Jacobi method.
|
|
8
|
+
|
|
9
|
+
Parameters
|
|
10
|
+
----------
|
|
11
|
+
a : ndarray
|
|
12
|
+
Coefficient matrix (n x n)
|
|
13
|
+
b : ndarray
|
|
14
|
+
Right-hand side vector (n,)
|
|
15
|
+
max_iter : int, optional
|
|
16
|
+
Maximum number of iterations
|
|
17
|
+
tol : float, optional
|
|
18
|
+
Convergence tolerance
|
|
19
|
+
omega : float, optional
|
|
20
|
+
Relaxation factor
|
|
21
|
+
|
|
22
|
+
Returns
|
|
23
|
+
-------
|
|
24
|
+
x : ndarray
|
|
25
|
+
Solution vector
|
|
26
|
+
status : int
|
|
27
|
+
0 if converged, non-zero otherwise
|
|
28
|
+
"""
|
|
29
|
+
a = np.ascontiguousarray(a)
|
|
30
|
+
b = np.asfortranarray(b)
|
|
31
|
+
n = a.shape[0]
|
|
32
|
+
|
|
33
|
+
x = np.zeros_like(b)
|
|
34
|
+
|
|
35
|
+
a_flat = a.ravel()
|
|
36
|
+
|
|
37
|
+
if np.issubdtype(a.dtype, np.floating):
|
|
38
|
+
if a.dtype == np.float32:
|
|
39
|
+
status = _nulapack.sgejsv(a_flat, b, x, max_iter, tol, omega, 0, n)
|
|
40
|
+
else: # float64
|
|
41
|
+
status = _nulapack.dgejsv(a_flat, b, x, max_iter, tol, omega, 0, n)
|
|
42
|
+
elif np.issubdtype(a.dtype, np.complexfloating):
|
|
43
|
+
if a.dtype == np.complex64:
|
|
44
|
+
status = _nulapack.cgejsv(a_flat, b, x, max_iter, tol, omega, 0, n)
|
|
45
|
+
else: # complex128
|
|
46
|
+
status = _nulapack.zgejsv(a_flat, b, x, max_iter, tol, omega, 0, n)
|
|
47
|
+
else:
|
|
48
|
+
raise TypeError(f"Unsupported array dtype: {a.dtype}")
|
|
49
|
+
|
|
50
|
+
return x, int(status) if status is not None else 0
|
nulapack/thomas.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import _nulapack
|
|
2
|
+
import numpy as np
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def thomas(a: np.ndarray, b: np.ndarray):
|
|
6
|
+
"""
|
|
7
|
+
Solve a tridiagonal linear system A * X = B using the Thomas algorithm.
|
|
8
|
+
|
|
9
|
+
Parameters
|
|
10
|
+
----------
|
|
11
|
+
a : ndarray
|
|
12
|
+
Coefficient matrix (n x n) stored as a full matrix.
|
|
13
|
+
b : ndarray
|
|
14
|
+
Right-hand side vector (n,)
|
|
15
|
+
|
|
16
|
+
Returns
|
|
17
|
+
-------
|
|
18
|
+
x : ndarray
|
|
19
|
+
Solution vector
|
|
20
|
+
info : int
|
|
21
|
+
0 if success, <0 if zero diagonal detected
|
|
22
|
+
"""
|
|
23
|
+
a = np.ascontiguousarray(a)
|
|
24
|
+
b = np.asfortranarray(b)
|
|
25
|
+
n = a.shape[0]
|
|
26
|
+
|
|
27
|
+
x = np.zeros_like(b)
|
|
28
|
+
|
|
29
|
+
a_flat = a.ravel()
|
|
30
|
+
|
|
31
|
+
if np.issubdtype(a.dtype, np.floating):
|
|
32
|
+
if a.dtype == np.float32:
|
|
33
|
+
status = _nulapack.sgttsv(a_flat, b, x, 0, n)
|
|
34
|
+
else: # float64
|
|
35
|
+
status = _nulapack.dgttsv(a_flat, b, x, 0, n)
|
|
36
|
+
elif np.issubdtype(a.dtype, np.complexfloating):
|
|
37
|
+
if a.dtype == np.complex64:
|
|
38
|
+
status = _nulapack.cgttsv(a_flat, b, x, 0, n)
|
|
39
|
+
else: # complex128
|
|
40
|
+
status = _nulapack.zgttsv(a_flat, b, x, 0, n)
|
|
41
|
+
else:
|
|
42
|
+
raise TypeError(f"Unsupported array dtype: {a.dtype}")
|
|
43
|
+
|
|
44
|
+
return x, int(status) if status is not None else 0
|