Commit 12eeaaab authored by Martin Reinecke's avatar Martin Reinecke
Browse files

small tweaks, probably temporary

parent 598439f1
Pipeline #17924 passed with stage
in 3 minutes and 22 seconds
...@@ -8,21 +8,23 @@ class QuadraticEnergy(Energy): ...@@ -8,21 +8,23 @@ class QuadraticEnergy(Energy):
position-independent. position-independent.
""" """
def __init__(self, position, A, b, grad=None): def __init__(self, position, A, b, _grad=None, _bnorm=None):
super(QuadraticEnergy, self).__init__(position=position) super(QuadraticEnergy, self).__init__(position=position)
self._A = A self._A = A
self._b = b self._b = b
if grad is not None: self._bnorm = _bnorm
self._Ax = grad + self._b if _grad is not None:
self._Ax = _grad + self._b
else: else:
self._Ax = self._A(self.position) self._Ax = self._A(self.position)
def at(self, position): def at(self, position):
return self.__class__(position=position, A=self._A, b=self._b) return self.__class__(position=position, A=self._A, b=self._b,
def at_with_grad(self, position, grad): def at_with_grad(self, position, grad):
return self.__class__(position=position, A=self._A, b=self._b, return self.__class__(position=position, A=self._A, b=self._b,
grad=grad) _grad=grad, _bnorm=self.norm_b)
@property @property
@memo @memo
...@@ -40,4 +42,6 @@ class QuadraticEnergy(Energy): ...@@ -40,4 +42,6 @@ class QuadraticEnergy(Energy):
@property @property
def norm_b(self): def norm_b(self):
return self._b.norm() if self._bnorm is None:
self._bnorm = self._b.norm()
return self._bnorm
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment