Commit 36600a91 authored by Martin Reinecke's avatar Martin Reinecke
Browse files

PEP8

parent b87abe36
Pipeline #16755 passed with stage
in 25 minutes and 7 seconds
...@@ -27,10 +27,10 @@ import nifty.nifty_utilities as utilities ...@@ -27,10 +27,10 @@ import nifty.nifty_utilities as utilities
class LaplaceOperator(EndomorphicOperator): class LaplaceOperator(EndomorphicOperator):
"""A irregular LaplaceOperator with free boundary and excluding monopole. """A irregular LaplaceOperator with free boundary and excluding monopole.
This LaplaceOperator implements the second derivative of a Field in PowerSpace This LaplaceOperator implements the second derivative of a Field in
on logarithmic or linear scale with vanishing curvature at the boundary, starting PowerSpace on logarithmic or linear scale with vanishing curvature at the
at the second entry of the Field. The second derivative of the Field on the irregular grid boundary, starting at the second entry of the Field. The second derivative
is calculated using finite differences. of the Field on the irregular grid is calculated using finite differences.
Parameters Parameters
---------- ----------
...@@ -60,9 +60,9 @@ class LaplaceOperator(EndomorphicOperator): ...@@ -60,9 +60,9 @@ class LaplaceOperator(EndomorphicOperator):
# for convenience, but they will never affect the result) # for convenience, but they will never affect the result)
self._dposc = np.empty_like(pos) self._dposc = np.empty_like(pos)
self._dposc[:-1] = self._dpos self._dposc[:-1] = self._dpos
self._dposc[-1]=0. self._dposc[-1] = 0.
self._dposc[1:]+=self._dpos self._dposc[1:] += self._dpos
self._dposc*=0.5 self._dposc *= 0.5
@property @property
def target(self): def target(self):
...@@ -100,8 +100,8 @@ class LaplaceOperator(EndomorphicOperator): ...@@ -100,8 +100,8 @@ class LaplaceOperator(EndomorphicOperator):
axis = axes[0] axis = axes[0]
nval = len(self._dposc) nval = len(self._dposc)
prefix = (slice(None),) * axis prefix = (slice(None),) * axis
sl_l = prefix + (slice(None,-1),) # "left" slice sl_l = prefix + (slice(None, -1),) # "left" slice
sl_r = prefix + (slice(1,None),) # "right" slice sl_r = prefix + (slice(1, None),) # "right" slice
dpos = self._dpos.reshape((1,)*axis + (nval-1,)) dpos = self._dpos.reshape((1,)*axis + (nval-1,))
dposc = self._dposc.reshape((1,)*axis + (nval,)) dposc = self._dposc.reshape((1,)*axis + (nval,))
deriv = (x.val[sl_r]-x.val[sl_l])/dpos # defined between points deriv = (x.val[sl_r]-x.val[sl_l])/dpos # defined between points
...@@ -110,7 +110,7 @@ class LaplaceOperator(EndomorphicOperator): ...@@ -110,7 +110,7 @@ class LaplaceOperator(EndomorphicOperator):
ret[prefix + (-1,)] = 0. ret[prefix + (-1,)] = 0.
ret[sl_r] -= deriv ret[sl_r] -= deriv
ret /= sqrt(dposc) ret /= sqrt(dposc)
ret[prefix + (slice(None,2),)] = 0. ret[prefix + (slice(None, 2),)] = 0.
ret[prefix + (-1,)] = 0. ret[prefix + (-1,)] = 0.
return Field(self.domain, val=ret).weight(power=-0.5, spaces=spaces) return Field(self.domain, val=ret).weight(power=-0.5, spaces=spaces)
...@@ -126,8 +126,8 @@ class LaplaceOperator(EndomorphicOperator): ...@@ -126,8 +126,8 @@ class LaplaceOperator(EndomorphicOperator):
axis = axes[0] axis = axes[0]
nval = len(self._dposc) nval = len(self._dposc)
prefix = (slice(None),) * axis prefix = (slice(None),) * axis
sl_l = prefix + (slice(None,-1),) # "left" slice sl_l = prefix + (slice(None, -1),) # "left" slice
sl_r = prefix + (slice(1,None),) # "right" slice sl_r = prefix + (slice(1, None),) # "right" slice
dpos = self._dpos.reshape((1,)*axis + (nval-1,)) dpos = self._dpos.reshape((1,)*axis + (nval-1,))
dposc = self._dposc.reshape((1,)*axis + (nval,)) dposc = self._dposc.reshape((1,)*axis + (nval,))
y = x.copy().weight(power=0.5).val y = x.copy().weight(power=0.5).val
......
...@@ -19,19 +19,17 @@ ...@@ -19,19 +19,17 @@
import unittest import unittest
import numpy as np import numpy as np
import nifty as ift import nifty as ift
from numpy.testing import assert_equal,\ from numpy.testing import assert_allclose
assert_allclose
from itertools import product from itertools import product
from test.common import expand from test.common import expand
from nose.plugins.skip import SkipTest
class LaplaceOperatorTests(unittest.TestCase): class LaplaceOperatorTests(unittest.TestCase):
@expand(product([None,False,True], [False,True], [10,100,1000])) @expand(product([None, False, True], [False, True], [10, 100, 1000]))
def test_Laplace(self, log1, log2, sz): def test_Laplace(self, log1, log2, sz):
s=ift.RGSpace(sz,harmonic=True) s = ift.RGSpace(sz, harmonic=True)
p=ift.PowerSpace(s,logarithmic=log1) p = ift.PowerSpace(s, logarithmic=log1)
L=ift.LaplaceOperator(p,logarithmic=log2) L = ift.LaplaceOperator(p, logarithmic=log2)
arr=np.random.random(p.shape[0]) arr = np.random.random(p.shape[0])
fp=ift.Field(p,val=arr) fp = ift.Field(p, val=arr)
assert_allclose (L(fp).vdot(L(fp)),L.adjoint_times(L(fp)).vdot(fp)) assert_allclose(L(fp).vdot(L(fp)), L.adjoint_times(L(fp)).vdot(fp))
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