Commit 024ef1e6 authored by Martin Reinecke's avatar Martin Reinecke
Browse files

test for reality

parent 707ea130
......@@ -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
......
......@@ -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
......
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