Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Neel Shah
NIFTy
Commits
024ef1e6
Commit
024ef1e6
authored
Jun 10, 2021
by
Martin Reinecke
Browse files
test for reality
parent
707ea130
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/library/variational_models.py
View file @
024ef1e6
...
...
@@ -224,6 +224,13 @@ class GaussianEntropy(EnergyOperator):
def
apply
(
self
,
x
):
self
.
_check_input
(
x
)
if
isinstance
(
x
,
Field
):
if
not
(
np
.
issubdtype
(
x
.
dtype
,
np
.
floating
)):
raise
NotImplementedError
(
"only real fields are allowed"
)
if
isinstance
(
x
,
MultiField
):
for
key
in
x
.
keys
():
if
not
(
np
.
issubdtype
(
x
[
key
].
dtype
,
np
.
floating
)):
raise
NotImplementedError
(
"only real fields are allowed"
)
res
=
(
x
*
x
).
scale
(
2
*
np
.
pi
*
np
.
e
).
log
().
sum
().
scale
(
-
0.5
)
if
not
isinstance
(
x
,
Linearization
):
return
res
...
...
src/operators/multifield2vector.py
View file @
024ef1e6
...
...
@@ -27,7 +27,9 @@ class Multifield2Vector(LinearOperator):
"""Flatten a MultiField and return a Field with unstructured domain and the
same number of degrees of freedom.
FIXME
Notes
-----
Currently only works with fields that are real-valued
"""
def
__init__
(
self
,
domain
):
...
...
@@ -43,10 +45,14 @@ class Multifield2Vector(LinearOperator):
if
mode
==
self
.
TIMES
:
res
=
np
.
empty
(
self
.
target
.
shape
)
for
key
in
self
.
domain
.
keys
():
if
not
(
np
.
issubdtype
(
x
[
key
].
dtype
,
np
.
floating
)):
raise
NotImplementedError
(
"only real fields are allowed"
)
arr
=
x
[
key
].
flatten
()
res
[
ii
:
ii
+
arr
.
size
]
=
arr
ii
+=
arr
.
size
else
:
if
not
(
np
.
issubdtype
(
x
.
dtype
,
np
.
floating
)):
raise
NotImplementedError
(
"only real fields are allowed"
)
res
=
{}
for
key
in
self
.
domain
.
keys
():
n
=
self
.
domain
[
key
].
size
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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