Skip to content

Commit 14e3c3c

Browse files
committed
Wrote test that default rcond creates numerical errors for, and fixed problem by removing default rcond value.
1 parent 1333385 commit 14e3c3c

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/linsolve/linsolve.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ def _invert_solve(self, A, y, rcond):
568568
"""Use np.linalg.solve to solve a system of equations.
569569
570570
Requires a fully constrained system of equations (i.e. doesn't deal with
571-
singular matrices). Can by ~1.5x faster that lstsq for this case. 'rcond'
571+
singular matrices). Can be ~1.5x faster than lstsq for this case. 'rcond'
572572
is unused, but passed as an argument to match the interface of other _invert
573573
methods.
574574
"""
@@ -644,8 +644,8 @@ def solve(self, rcond=None, mode="default"):
644644
a dictionary of solutions with variables as keys
645645
"""
646646
assert mode in ["default", "lsqr", "pinv", "solve"]
647-
if rcond is None:
648-
rcond = np.finfo(self.dtype).resolution
647+
#if rcond is None:
648+
# rcond = np.finfo(self.dtype).resolution
649649
y = self.get_weighted_data()
650650
if self.sparse:
651651
xs, ys, vals = self.get_A_sparse()

tests/test_linsolve.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,25 @@ def test_eval_const_term(self):
297297
result = ls.eval(sol, "a*b+a*x+b*y")
298298
np.testing.assert_almost_equal(3 * 1 + 3 * 1 + 1 * 2, list(result.values())[0])
299299

300+
def test_specific_system(self):
301+
eqs = {
302+
'Ii_R1 + Io_R1': 0.,
303+
'Vi_R1 - Io_R1 * Z_R1 - Vo_R1': 0.,
304+
'Ii_R2 + Io_R2': 0.,
305+
'Vi_R2 - Io_R2 * Z_R2 - Vo_R2': 0.,
306+
'I_s + Ii_R1': 0.,
307+
'V_s - Vi_R1': 0.,
308+
'Io_R1 + Ii_R2': 0.,
309+
'Vo_R1 - Vi_R2': 0.,
310+
'Io_R2 + I_GND': 0.,
311+
'Vo_R2 - V_GND': 0.,
312+
}
313+
consts = {'Z_R1': 50., 'Z_R2': 50., 'V_GND': 0., 'V_s': 1.}
314+
ls = linsolve.LinearSolver(eqs, **consts)
315+
for mode in ('solve', 'lsqr', 'pinv', 'default'):
316+
sol = ls.solve(mode=mode)
317+
np.testing.assert_almost_equal(sol['Vo_R1'], 0.5, 4)
318+
300319
def test_chisq(self):
301320
x = 1.0
302321
d = {"x": 1, "a*x": 2}

0 commit comments

Comments
 (0)