Skip to content

Commit ec220ff

Browse files
committed
[TEST] Cleaning pre-conditioner code and tests
1 parent b647cc3 commit ec220ff

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

gempy_engine/core/data/internal_structs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ def __init__(self, sp_internal: SurfacePointsInternals, ori_internal: Orientatio
2222
xyz_to_interpolate: np.ndarray=None, fault_internal=None):
2323
self.sp_internal = sp_internal
2424
self.ori_internal = ori_internal
25-
26-
self.xyz_to_interpolate = xyz_to_interpolate
25+
if xyz_to_interpolate is not None:
26+
self.xyz_to_interpolate = xyz_to_interpolate.astype(BackendTensor.dtype)
2727
self._fault_internal = fault_internal
2828

2929
def __hash__(self):

gempy_engine/modules/solver/_numpy_solvers.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import numpy as np
2+
3+
from gempy_engine import optional_dependencies
24
from gempy_engine.core.backend_tensor import BackendTensor
35

46
bt = BackendTensor
@@ -14,31 +16,30 @@ def pykeops_numpy_cg(b, cov, dtype):
1416
backend="CPU"
1517
)
1618

17-
1819
return w
1920

2021

2122
def numpy_solve(b, cov, dtype):
2223
w = BackendTensor.tfnp.linalg.solve(cov.astype(dtype), b[:, 0])
2324
return w
2425

25-
def numpy_cg(b, cov, ):
26-
global i
26+
27+
def numpy_cg(b, cov):
2728
if bt.use_gpu is False and BackendTensor.pykeops_enabled is True:
2829
cov.backend = 'CPU'
2930

3031
from ._pykeops_solvers.incomplete_cholesky import ichol
3132
from ._pykeops_solvers.cg import cg
32-
from scipy.sparse.linalg import aslinearoperator
33-
import scipy.sparse as sps
33+
34+
scipy = optional_dependencies.require_scipy()
3435

3536
sparse_cov = cov.copy()
3637
sparse_cov[np.abs(cov) < 1e-10] = 0
3738

38-
sparse_cov = sps.csc_matrix(sparse_cov,)
39+
sparse_cov = scipy.sparse.csc_matrix(sparse_cov, )
3940
conditioner = ichol(sparse_cov)
4041

41-
A = aslinearoperator(cov)
42+
A = scipy.sparse.linalg.aslinearoperator(cov)
4243
print(f'A size: {A.shape}')
4344

4445
w = cg(
@@ -65,7 +66,3 @@ def numpy_gmres(b, cov):
6566
)
6667
w = np.atleast_2d(w).T
6768
return w
68-
69-
70-
71-

gempy_engine/modules/solver/_pykeops_solvers/incomplete_cholesky.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def __call__(self, b):
186186
def ichol(
187187
A,
188188
discard_threshold=1e-4,
189-
shifts=[0.0, 1e-4, 1e-3, 1e-2, 0.1, 0.5, 1.0, 10.0, 100, 1e3, 1e4, 1e5],
189+
shifts=None,
190190
max_nnz=int(4e9 / 16),
191191
relative_discard_threshold=0.0,
192192
diag_keep_discarded=True,
@@ -238,7 +238,13 @@ def ichol(
238238
>>> cholesky_decomposition(np.array([1.0, 2.0]))
239239
array([-1., 1.])
240240
"""
241+
242+
# Check A is float64 and raise and NotImplementedError if not
243+
if A.dtype != np.float64:
244+
raise NotImplementedError( "Matrix A must be of dtype np.float64.")
241245

246+
if shifts is None:
247+
shifts = [0.0, 1e-4, 1e-3, 1e-2, 0.1, 0.5, 1.0, 10.0, 100, 1e3, 1e4, 1e5]
242248
if isinstance(A, scipy.sparse.csr_matrix):
243249
A = A.T
244250

0 commit comments

Comments
 (0)