Commit 966a1f43 authored by Steven Cordwell's avatar Steven Cordwell
Browse files

use assert for checking parameters

parent bf04775e
......@@ -291,22 +291,17 @@ def checkSquareStochastic(Z):
except ValueError:
raise InvalidMDPError(mdperr["mat_square"])
# check that the matrix is square, and that each row sums to one
if s1 != s2:
raise InvalidMDPError(mdperr["mat_square"])
elif (absolute(Z.sum(axis=1) - ones(s2))).max() > SMALLNUM:
raise InvalidMDPError(mdperr["mat_stoch"])
assert s1 == s2, mdperr["mat_square"]
assert (absolute(Z.sum(axis=1) - ones(s2))).max() < SMALLNUM, \
# make sure that there are no values less than zero
if (Z < 0).any():
raise InvalidMDPError(mdperr["mat_nonneg"])
except AttributeError:
assert (Z >= 0).all(), mdperr["mat_nonneg"]
except (AttributeError, TypeError):
if ( < 0).any():
raise InvalidMDPError(mdperr["mat_nonneg"])
assert ( >= 0).all(), mdperr["mat_nonneg"]
except AttributeError:
raise TypeError("Matrix should be a numpy type.")
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