提交 50387206 authored 作者: David Warde-Farley's avatar David Warde-Farley

Simplify multiple isinstance calls.

上级 9bd63617
......@@ -38,7 +38,7 @@ def _is_sparse_variable(x):
@rtype: boolean
@return: True iff x is a L{SparseVariable} (and not a L{tensor.TensorType})
"""
if not isinstance(x.type, SparseType) and not isinstance(x.type, tensor.TensorType):
if not isinstance(x.type, (SparseType, tensor.TensorType)):
raise NotImplementedError("this function should only be called on *variables* (of type sparse.SparseType or tensor.TensorType), not,", x)
return isinstance(x.type, SparseType)
def _is_dense_variable(x):
......@@ -46,7 +46,7 @@ def _is_dense_variable(x):
@rtype: boolean
@return: True unless x is a L{SparseVariable} (and not a L{tensor.TensorType})
"""
if not isinstance(x.type, SparseType) and not isinstance(x.type, tensor.TensorType):
if not isinstance(x.type, (SparseType, tensor.TensorType)):
raise NotImplementedError("this function should only be called on *variables* (of type sparse.SparseType or tensor.TensorType), not,", x)
return isinstance(x.type, tensor.TensorType)
......@@ -55,7 +55,7 @@ def _is_sparse(x):
@rtype: boolean
@return: True iff x is a L{scipy.sparse.spmatrix} (and not a L{numpy.ndarray})
"""
if not isinstance(x, scipy.sparse.spmatrix) and not isinstance(x, numpy.ndarray):
if not isinstance(x, (scipy.sparse.spmatrix, numpy.ndarray)):
raise NotImplementedError("this function should only be called on sparse.scipy.sparse.spmatrix or numpy.ndarray, not,", x)
return isinstance(x, scipy.sparse.spmatrix)
def _is_dense(x):
......@@ -63,7 +63,7 @@ def _is_dense(x):
@rtype: boolean
@return: True unless x is a L{scipy.sparse.spmatrix} (and not a L{numpy.ndarray})
"""
if not isinstance(x, scipy.sparse.spmatrix) and not isinstance(x, numpy.ndarray):
if not isinstance(x, (scipy.sparse.spmatrix, numpy.ndarray)):
raise NotImplementedError("this function should only be called on sparse.scipy.sparse.spmatrix or numpy.ndarray, not,", x)
return isinstance(x, numpy.ndarray)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论