@@ -856,7 +856,7 @@ def taylor_expand(terms, consts=None, prepend="d"):
856856# XXX make a version of linproductsolver that taylor expands in e^{a+bi} form
857857# see https://github.com/HERA-Team/linsolve/issues/15
858858class LinProductSolver :
859- def __init__ (self , data , sol0 , wgts = {}, sparse = False , ** kwargs ):
859+ def __init__ (self , data , sol0 , wgts = {}, sparse = False , build_solver = True , ** kwargs ):
860860 """Set up a nonlinear system of equations of the form a*b + c*d = 1.0.
861861
862862 Linearize via Taylor expansion and solve iteratively using the Gauss-Newton
@@ -882,6 +882,9 @@ def __init__(self, data, sol0, wgts={}, sparse=False, **kwargs):
882882 sparse : bool
883883 If True, represents A matrix sparsely (though AtA, Aty end up dense)
884884 May be faster for certain systems of equations.
885+ build_solver : bool
886+ Advanced users can turn this off to save memory when using only LinProductSolver
887+ infrastructure but not solve() or solve_iteratively(), as in omnical.
885888 **kwargs: keyword arguments of constants (python variables in keys of data that
886889 are not to be solved for)
887890 """
@@ -894,8 +897,14 @@ def __init__(self, data, sol0, wgts={}, sparse=False, **kwargs):
894897 self .init_kwargs , self .sols_kwargs = constants , deepcopy (constants )
895898 self .sols_kwargs .update (sol0 )
896899 self .all_terms , self .taylors , self .taylor_keys = self .gen_taylors ()
897- self .build_solver (sol0 )
898- self .dtype = self .ls .dtype
900+ if build_solver :
901+ self .build_solver (sol0 )
902+ self .dtype = self .ls .dtype
903+ else :
904+ self .sol0 = sol0
905+ self .dtype = infer_dtype (list (self .data .values ())
906+ + list (self .sol0 .values ())
907+ + list (self .wgts .values ()))
899908
900909 def gen_taylors (self , keys = None ):
901910 """Perform Taylor expansion, and map eq. keys to taylor expansion keys."""
0 commit comments