def _update(self): with self.device: xp = self.device.xp Ap = self.A(self.p) pAp = xp.real(xp.vdot(self.p, Ap)).item() if pAp <= 0: self.not_positive_definite = True return self.alpha = self.rzold / pAp util.axpy(self.x, self.alpha, self.p) if self.iter < self.max_iter - 1: util.axpy(self.r, -self.alpha, Ap) if self.P is not None: z = self.P(self.r) else: z = self.r rznew = xp.real(xp.vdot(self.r, z)) beta = rznew / self.rzold util.xpay(self.p, beta, z) self.rzold = rznew self.resid = self.rzold.item()**0.5
def _update(self): with self.device: xp = self.device.xp Ap = self.A(self.p) pAp = xp.real(xp.vdot(self.p, Ap)) if pAp == 0: self.zero_gradient = True return self.alpha = self.rzold / pAp util.axpy(self.x, self.alpha, self.p) if self.iter < self.max_iter - 1: util.axpy(self.r, -self.alpha, Ap) if self.P is not None: z = self.P(self.r) else: z = self.r rznew = xp.real(xp.vdot(self.r, z)) beta = rznew / self.rzold util.xpay(self.p, beta, z) self.rzold = rznew self.resid = util.asscalar(self.rzold)**0.5