Skip to content

Commit

Permalink
bug: ensure array shape consistency in leastsquares solvers
Browse files Browse the repository at this point in the history
PyLops solvers output the solution as a nd-shaped array
if the initial model is fed as nd-arrays or if the initial
model is not fed (x0=0) and the operator has forceflat=False. As a side
effect, if x0 is NOT passed as a kwarg (but just as the third arg of
the solver) and the operator forceflat=False, the output is reshaped
even if x0 is a flattened array. I fix this inconsistency making x0
a kwarg when basic solvers are called within a leastsquares solver.
  • Loading branch information
mrava87 committed Nov 25, 2024
1 parent 2d749a2 commit 2102533
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pylops/optimization/cls_leastsquares.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def run(
xinv = cg(
self.Op_normal,
self.y_normal,
self.ncp.zeros(self.Op_normal.shape[1], dtype=self.Op_normal.dtype),
x0=self.ncp.zeros(self.Op_normal.shape[1], dtype=self.Op_normal.dtype),
**kwargs_solver,
)[0]
istop = None
Expand Down Expand Up @@ -594,7 +594,7 @@ def run(
xinv, istop, itn, r1norm, r2norm = cgls(
self.RegOp,
self.datatot,
self.ncp.zeros(self.RegOp.shape[1], dtype=self.RegOp.dtype),
x0=self.ncp.zeros(self.RegOp.shape[1], dtype=self.RegOp.dtype),
**kwargs_solver,
)[0:5]
else:
Expand Down Expand Up @@ -816,7 +816,7 @@ def run(
pinv, istop, itn, r1norm, r2norm = cgls(
self.POp,
self.y,
self.ncp.zeros(self.POp.shape[1], dtype=self.POp.dtype),
x0=self.ncp.zeros(self.POp.shape[1], dtype=self.POp.dtype),
**kwargs_solver,
)[0:5]
# force it 1d as we decorate this method with disable_ndarray_multiplication
Expand Down

0 comments on commit 2102533

Please sign in to comment.