From 83c74e7b3d25e548e8bfc27630a10b8a8434bc71 Mon Sep 17 00:00:00 2001 From: Martin Reinecke <martin@mpa-garching.mpg.de> Date: Thu, 22 Mar 2018 16:51:44 +0100 Subject: [PATCH] allow QuadraticEnergy without 'b' term --- nifty4/minimization/quadratic_energy.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/nifty4/minimization/quadratic_energy.py b/nifty4/minimization/quadratic_energy.py index 203db0ec3..fc3d4191f 100644 --- a/nifty4/minimization/quadratic_energy.py +++ b/nifty4/minimization/quadratic_energy.py @@ -31,12 +31,14 @@ class QuadraticEnergy(Energy): self._b = b if _grad is not None: self._grad = _grad - Ax = _grad + self._b + Ax = _grad if b is None else _grad + b else: Ax = self._A(self.position) - self._grad = Ax - self._b + self._grad = Ax if b is None else Ax - b self._grad.lock() - self._value = 0.5*self.position.vdot(Ax) - b.vdot(self.position) + self._value = 0.5*self.position.vdot(Ax) + if b is not None: + self._value -= b.vdot(self.position) def at(self, position): return QuadraticEnergy(position=position, A=self._A, b=self._b) -- GitLab