Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ift
NIFTy
Commits
6b9d5cb4
Commit
6b9d5cb4
authored
Jun 28, 2018
by
Philipp Arras
Browse files
Cosmetics
parent
8d1d3793
Changes
3
Hide whitespace changes
Inline
Side-by-side
nifty5/minimization/energy.py
View file @
6b9d5cb4
...
...
@@ -131,24 +131,24 @@ class Energy(NiftyMetaBase()):
def
__mul__
(
self
,
factor
):
from
.energy_sum
import
EnergySum
if
not
isinstance
(
factor
,
(
float
,
int
)):
r
aise
TypeError
(
"Factor must be a real-valued scalar"
)
return
EnergySum
.
make
([
self
],
[
factor
])
if
isinstance
(
factor
,
(
float
,
int
)):
r
eturn
EnergySum
.
make
([
self
],
[
factor
]
)
return
NotImplemented
def
__rmul__
(
self
,
factor
):
return
self
.
__mul__
(
factor
)
def
__add__
(
self
,
other
):
from
.energy_sum
import
EnergySum
if
not
isinstance
(
other
,
Energy
):
r
aise
TypeError
(
"can only add Energies to Energies"
)
return
EnergySum
.
make
([
self
,
other
])
if
isinstance
(
other
,
Energy
):
r
eturn
EnergySum
.
make
([
self
,
other
]
)
return
NotImplemented
def
__sub__
(
self
,
other
):
from
.energy_sum
import
EnergySum
if
not
isinstance
(
other
,
Energy
):
r
aise
TypeError
(
"can only subtract Energies from Energies"
)
return
EnergySum
.
make
([
self
,
other
],
[
1.
,
-
1.
])
if
isinstance
(
other
,
Energy
):
r
eturn
EnergySum
.
make
([
self
,
other
],
[
1.
,
-
1.
]
)
return
NotImplemented
def
__neg__
(
self
):
from
.energy_sum
import
EnergySum
...
...
nifty5/minimization/energy_sum.py
View file @
6b9d5cb4
...
...
@@ -16,8 +16,8 @@
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.
from
.energy
import
Energy
from
..utilities
import
memo
from
.energy
import
Energy
class
EnergySum
(
Energy
):
...
...
test/test_energies/test_energy_sum.py
View file @
6b9d5cb4
...
...
@@ -16,11 +16,12 @@
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.
import
nifty5
as
ift
import
numpy
as
np
import
unittest
from
itertools
import
product
from
test.common
import
expand
import
nifty5
as
ift
import
numpy
as
np
from
numpy.testing
import
assert_allclose
,
assert_raises
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment