[docs]classLinearSolver(Protocol):""" Solve a linear system of the form `A @ x = y`. """def__call__(self,A:Float[np.ndarray,"A B"],y:Float[np.ndarray,"N"],)->Float[np.ndarray,"N"]:...
[docs]@ensure_2d("A")defvanilla(A,y):"""Use the standard `np.linalg.solve` method to solve the linear system."""returnnp.linalg.solve(A,y)
[docs]@ensure_2d("A")defleast_squares(A,y):"""Use `np.linalg.lstsq` method to solve the linear system: slower than ``vanilla`` but more stable."""returnnp.linalg.lstsq(A,y,rcond=None)[0]