Commit b400978c authored by Theo Steininger's avatar Theo Steininger
Browse files

Fixed PowerSpace.total_volume. Moved memoization.py to package directory root.

parent a6a8de75
......@@ -46,6 +46,8 @@ from .field_types import *
from .energies import *
from .memoization import memo
from .minimization import *
from .spaces import *
......
......@@ -19,4 +19,3 @@
from .energy import Energy
from .quadratic_energy import QuadraticEnergy
from .line_energy import LineEnergy
from .memoization import memo
......@@ -17,7 +17,7 @@
# and financially supported by the Studienstiftung des deutschen Volkes.
from ..nifty_meta import NiftyMeta
from .memoization import memo
from ..memoization import memo
from keepers import Loggable
from future.utils import with_metaclass
......
from .energy import Energy
from .memoization import memo
from ..memoization import memo
class QuadraticEnergy(Energy):
......
......@@ -2,7 +2,7 @@ from ...energies.energy import Energy
from ...operators.smoothness_operator import SmoothnessOperator
from ...operators.diagonal_operator import DiagonalOperator
from . import CriticalPowerCurvature
from ...energies.memoization import memo
from ...memoization import memo
from ...minimization import ConjugateGradient
from ...sugar import generate_posterior_sample
......
from ...operators import EndomorphicOperator,\
InvertibleOperatorMixin
from ...energies.memoization import memo
from ...memoization import memo
from ...basic_arithmetics import clipped_exp
from ...sugar import create_composed_fft_operator
from ...minimization import ConjugateGradient
......
from ...energies.energy import Energy
from ...energies.memoization import memo
from ...memoization import memo
from ...minimization import ConjugateGradient
from . import WienerFilterCurvature
......
......@@ -21,6 +21,7 @@ import numpy as np
from d2o import distributed_data_object,\
STRATEGIES as DISTRIBUTION_STRATEGIES
from ...memoization import memo
from ...spaces.space import Space
from functools import reduce
from ...config import nifty_configuration as gc
......@@ -187,9 +188,9 @@ class PowerSpace(Space):
return self.shape[0]
@property
@memo
def total_volume(self):
# every power-pixel has a volume of 1
return float(reduce(lambda x, y: x*y, self.pindex.shape))
return np.sum(self._volume_weight)
def copy(self):
distribution_strategy = self.pindex.distribution_strategy
......@@ -198,15 +199,7 @@ class PowerSpace(Space):
binbounds=self._binbounds)
def weight(self, x, power, axes, inplace=False):
try:
weight = self._volume_weight
except AttributeError:
from ...field import Field
weight_field = Field(domain=self.harmonic_partner, val=1).weight()
self._volume_weight = \
self.pindex.bincount(weights=weight_field.val).get_full_data()
weight = self._volume_weight
weight = self._volume_weight
reshaper = [1, ] * len(x.shape)
# we know len(axes) is always 1
reshaper[axes[0]] = self.shape[0]
......@@ -223,6 +216,13 @@ class PowerSpace(Space):
return result_x
@property
@memo
def _volume_weight(self):
from ...field import Field
weight_field = Field(domain=self.harmonic_partner, val=1).weight()
return self.pindex.bincount(weights=weight_field.val).get_full_data()
def get_distance_array(self, distribution_strategy):
return distributed_data_object(
self.kindex, dtype=np.float64,
......
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