Commit 4d0eace3 authored by theos's avatar theos

Fixed the memoization for Energy.

parent 7bb88123
......@@ -34,6 +34,7 @@ class WienerFilterEnergy(Energy):
return_g.val = g.val.real
return return_g
@memo
def D_inverse_x(self):
return D.inverse_times(self.position)
......@@ -88,7 +89,7 @@ if __name__ == "__main__":
minimizer = VL_BFGS(convergence_tolerance=0,
iteration_limit=50,
callback=distance_measure,
max_history_length=5)
max_history_length=3)
m0 = Field(s_space, val=1)
......
......@@ -2,3 +2,4 @@
from energy import Energy
from line_energy import LineEnergy
from memoization import memo
......@@ -24,15 +24,3 @@ class Energy(object):
@property
def curvature(self):
raise NotImplementedError
def memo(f):
name = id(f)
def wrapped_f(self):
try:
return self._cache[name]
except KeyError:
self._cache[name] = f(self)
return self._cache[name]
return wrapped_f
# -*- coding: utf-8 -*-
def memo(f):
name = id(f)
def wrapped_f(self):
try:
return self._cache[name]
except KeyError:
self._cache[name] = f(self)
return self._cache[name]
return wrapped_f
Markdown is supported
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