Skip to content

Commit

Permalink
[parameters.base] do not alter input arguments in from_parameter_type
Browse files Browse the repository at this point in the history
This fixes pymor#197.
  • Loading branch information
ftschindler committed May 27, 2016
1 parent 0a589e1 commit 69a6339
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/pymor/parameters/base.py
Expand Up @@ -235,19 +235,21 @@ def from_parameter_type(cls, mu, parameter_type=None):
elif set(mu.keys()) != set(parameter_type.keys()):
raise ValueError('Provided parameter with keys {} does not match parameter type {}.'
.format(mu.keys(), parameter_type))
for k, v in mu.iteritems():

def parse_value(k, v):
if not isinstance(v, np.ndarray):
v = np.array(v)
try:
v = v.reshape(parameter_type[k])
except ValueError:
raise ValueError('Shape mismatch for parameter component {}: got {}, expected {}'
.format(k, v.shape, parameter_type[k]))
mu[k] = v
if v.shape != parameter_type[k]:
raise ValueError('Shape mismatch for parameter component {}: got {}, expected {}'
.format(k, v.shape, parameter_type[k]))
return cls(mu)
return v

return cls({k: parse_value(k, v) for k, v in mu.iteritems()})

def allclose(self, mu):
"""Compare to |Parameters| using :meth:`~pymor.tools.floatcmp.float_cmp_all`.
Expand Down

0 comments on commit 69a6339

Please sign in to comment.