(self, rhs : BaseVector, sol : BaseVector)
| 261 | return self.residuals |
| 262 | |
| 263 | def _SolveImpl(self, rhs : BaseVector, sol : BaseVector): |
| 264 | d, w, s = [sol.CreateVector() for i in range(3)] |
| 265 | conjugate = self.conjugate |
| 266 | d.data = rhs - self.mat * sol |
| 267 | w.data = self.pre * d |
| 268 | s.data = w |
| 269 | wdn = w.InnerProduct(d, conjugate=conjugate) |
| 270 | if self.CheckResidual(sqrt(abs(wdn))): |
| 271 | return |
| 272 | |
| 273 | while True: |
| 274 | w.data = self.mat * s |
| 275 | wd = wdn |
| 276 | as_s = s.InnerProduct(w, conjugate=conjugate) |
| 277 | if as_s == 0 or wd == 0: break |
| 278 | alpha = wd / as_s |
| 279 | sol.data += alpha * s |
| 280 | d.data += (-alpha) * w |
| 281 | |
| 282 | w.data = self.pre * d |
| 283 | |
| 284 | wdn = w.InnerProduct(d, conjugate=conjugate) |
| 285 | if self.CheckResidual(sqrt(abs(wdn))): |
| 286 | return |
| 287 | |
| 288 | beta = wdn / wd |
| 289 | s *= beta |
| 290 | s.data += w |
| 291 | |
| 292 | |
| 293 | def CG(mat, rhs, pre=None, sol=None, tol=1e-12, maxsteps = 100, printrates = True, plotrates = False, initialize = True, conjugate=False, callback=None, **kwargs): |
no test coverage detected