Commit 6b9d5cb4 authored by Philipp Arras's avatar Philipp Arras
Browse files

Cosmetics

parent 8d1d3793
...@@ -131,24 +131,24 @@ class Energy(NiftyMetaBase()): ...@@ -131,24 +131,24 @@ class Energy(NiftyMetaBase()):
def __mul__(self, factor): def __mul__(self, factor):
from .energy_sum import EnergySum from .energy_sum import EnergySum
if not isinstance(factor, (float, int)): if isinstance(factor, (float, int)):
raise TypeError("Factor must be a real-valued scalar") return EnergySum.make([self], [factor])
return EnergySum.make([self], [factor]) return NotImplemented
def __rmul__(self, factor): def __rmul__(self, factor):
return self.__mul__(factor) return self.__mul__(factor)
def __add__(self, other): def __add__(self, other):
from .energy_sum import EnergySum from .energy_sum import EnergySum
if not isinstance(other, Energy): if isinstance(other, Energy):
raise TypeError("can only add Energies to Energies") return EnergySum.make([self, other])
return EnergySum.make([self, other]) return NotImplemented
def __sub__(self, other): def __sub__(self, other):
from .energy_sum import EnergySum from .energy_sum import EnergySum
if not isinstance(other, Energy): if isinstance(other, Energy):
raise TypeError("can only subtract Energies from Energies") return EnergySum.make([self, other], [1., -1.])
return EnergySum.make([self, other], [1., -1.]) return NotImplemented
def __neg__(self): def __neg__(self):
from .energy_sum import EnergySum from .energy_sum import EnergySum
......
...@@ -16,8 +16,8 @@ ...@@ -16,8 +16,8 @@
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik # NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes. # and financially supported by the Studienstiftung des deutschen Volkes.
from .energy import Energy
from ..utilities import memo from ..utilities import memo
from .energy import Energy
class EnergySum(Energy): class EnergySum(Energy):
......
...@@ -16,11 +16,12 @@ ...@@ -16,11 +16,12 @@
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik # NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes. # and financially supported by the Studienstiftung des deutschen Volkes.
import nifty5 as ift
import numpy as np
import unittest import unittest
from itertools import product from itertools import product
from test.common import expand from test.common import expand
import nifty5 as ift
import numpy as np
from numpy.testing import assert_allclose, assert_raises from numpy.testing import assert_allclose, assert_raises
......
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