Skip to content

Commit

Permalink
Cleaned up setter function.
Browse files Browse the repository at this point in the history
It better handles scalar and one dimensional values now.
  • Loading branch information
rlabbe committed Oct 21, 2015
1 parent 6938e8c commit 5379bf2
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions filterpy/common/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,16 @@ def setter_scalar(value, dim_x):
type which converts to numpy.array (list, np.array, np.matrix, etc),
or a scalar, in which case we create a diagonal matrix with each
diagonal element == value.
dim_x is used iff value is scalar, otherwise it is determined from the
shape of value
"""
if isscalar(value):
v = eye(dim_x) * value
else:
v = asarray(value, dtype=float)
v = array(value, dtype=float)
dim_x = v.shape[0]

if v is value:
v = value.copy()
if v.shape != (dim_x, dim_x):
raise Exception('must have shape ({},{})'.format(dim_x, dim_x))
return v

0 comments on commit 5379bf2

Please sign in to comment.