Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/linsolve/linsolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ def _invert_solve(self, A, y, rcond):
"""Use np.linalg.solve to solve a system of equations.

Requires a fully constrained system of equations (i.e. doesn't deal with
singular matrices). Can by ~1.5x faster that lstsq for this case. 'rcond'
singular matrices). Can be ~1.5x faster than lstsq for this case. 'rcond'
is unused, but passed as an argument to match the interface of other _invert
methods.
"""
Expand Down Expand Up @@ -644,8 +644,8 @@ def solve(self, rcond=None, mode="default"):
a dictionary of solutions with variables as keys
"""
assert mode in ["default", "lsqr", "pinv", "solve"]
if rcond is None:
rcond = np.finfo(self.dtype).resolution
#if rcond is None:
# rcond = np.finfo(self.dtype).resolution
y = self.get_weighted_data()
if self.sparse:
xs, ys, vals = self.get_A_sparse()
Expand Down
19 changes: 19 additions & 0 deletions tests/test_linsolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,25 @@ def test_eval_const_term(self):
result = ls.eval(sol, "a*b+a*x+b*y")
np.testing.assert_almost_equal(3 * 1 + 3 * 1 + 1 * 2, list(result.values())[0])

def test_specific_system(self):
eqs = {
'Ii_R1 + Io_R1': 0.,
'Vi_R1 - Io_R1 * Z_R1 - Vo_R1': 0.,
'Ii_R2 + Io_R2': 0.,
'Vi_R2 - Io_R2 * Z_R2 - Vo_R2': 0.,
'I_s + Ii_R1': 0.,
'V_s - Vi_R1': 0.,
'Io_R1 + Ii_R2': 0.,
'Vo_R1 - Vi_R2': 0.,
'Io_R2 + I_GND': 0.,
'Vo_R2 - V_GND': 0.,
}
consts = {'Z_R1': 50., 'Z_R2': 50., 'V_GND': 0., 'V_s': 1.}
ls = linsolve.LinearSolver(eqs, **consts)
for mode in ('solve', 'lsqr', 'pinv', 'default'):
sol = ls.solve(mode=mode)
np.testing.assert_almost_equal(sol['Vo_R1'], 0.5, 4)

def test_chisq(self):
x = 1.0
d = {"x": 1, "a*x": 2}
Expand Down
Loading