提交 5cbd3dfa authored 作者: Virgile Andreani's avatar Virgile Andreani 提交者: Ricardo Vieira

Fix more double negatives

上级 f9f930c3
......@@ -65,7 +65,7 @@ def cleanup():
have_npy_abi_version = False
break
if not have_npy_abi_version or not have_c_compiler:
if not (have_npy_abi_version and have_c_compiler):
try:
# This can happen when we move the compiledir.
if keydata.key_pkl != filename:
......
......@@ -980,7 +980,7 @@ def _check_preallocated_output(
changed_inner_mode = False
if isinstance(getattr(node, "op", None), HasInnerGraph):
fn = node.op.fn
if not fn or not hasattr(fn, "maker") or not hasattr(fn.maker, "mode"):
if not (fn and hasattr(fn, "maker") and hasattr(fn.maker, "mode")):
_logger.warning(f"Expected pytensor function not found in {node.op}.fn")
else:
if isinstance(fn.maker.mode, DebugMode):
......
......@@ -3073,7 +3073,7 @@ def check_stack_trace(f_or_fgraph, ops_to_check="last", bug_print="raise"):
for node in apply_nodes_to_check:
for output in node.outputs:
if not hasattr(output.tag, "trace") or not output.tag.trace:
if not (hasattr(output.tag, "trace") and output.tag.trace):
return False
return True
......@@ -3092,7 +3092,7 @@ class CheckStackTraceFeature(Feature):
apply_nodes_to_check = fgraph.apply_nodes
for node in apply_nodes_to_check:
for output in node.outputs:
if not hasattr(output.tag, "trace") or not output.tag.trace:
if not (hasattr(output.tag, "trace") and output.tag.trace):
output.tag.trace = [
[
(
......
......@@ -62,7 +62,7 @@ class Container:
allow_downcast: bool | None = None,
name: str | None = None,
) -> None:
if not isinstance(storage, list) or not len(storage) >= 1:
if not (isinstance(storage, list) and len(storage) >= 1):
raise TypeError("storage must be a list of length at least one")
if isinstance(r, Variable):
self.type = r.type
......
......@@ -2288,7 +2288,7 @@ class GCC_compiler(Compiler):
default_compilation_result, default_execution_result = try_march_flag(
GCC_compiler.march_flags
)
if not default_compilation_result or not default_execution_result:
if not (default_compilation_result and default_execution_result):
march_success = False
march_ind = None
mtune_ind = None
......
......@@ -30,7 +30,7 @@ def may_share_memory(a, b, raise_other_type=True):
a_sparse = _is_sparse(a)
b_sparse = _is_sparse(b)
if not (a_ndarray or a_sparse) or not (b_ndarray or b_sparse):
if not ((a_ndarray or a_sparse) and (b_ndarray or b_sparse)):
if raise_other_type:
raise TypeError("may_share_memory support only ndarray and scipy.sparse")
return False
......
......@@ -653,8 +653,8 @@ def _debugprint(
else:
print(var_output, file=file)
if not already_done and (
not stop_on_name or not (hasattr(var, "name") and var.name is not None)
if not already_done and not (
stop_on_name and hasattr(var, "name") and var.name is not None
):
new_prefix = prefix_child + " ├─ "
new_prefix_child = prefix_child + " │ "
......
......@@ -187,7 +187,7 @@ class SparseTensorType(TensorType, HasDataType):
# WARNING: equality comparison of sparse matrices is not fast or easy
# we definitely do not want to be doing this un-necessarily during
# a FAST_RUN computation..
if not scipy.sparse.issparse(a) or not scipy.sparse.issparse(b):
if not (scipy.sparse.issparse(a) and scipy.sparse.issparse(b)):
return False
diff = abs(a - b)
if diff.nnz == 0:
......
......@@ -769,7 +769,7 @@ def blas_header_text():
"npy_float": "NPY_FLOAT64",
"precision": "d",
}
if not common_code or not template_code:
if not (common_code and template_code):
raise OSError(
"Unable to load NumPy implementation of BLAS functions from C source files."
)
......
......@@ -1016,7 +1016,7 @@ class AlgebraicCanonizer(NodeRewriter):
for v in inter:
num.remove(v)
denum.remove(v)
if not redo or not inter:
if not (redo and inter):
break
else:
for v in list(num):
......
......@@ -246,7 +246,7 @@ class Shape_i(COp):
return "%s{%i}" % (self.__class__.__name__, self.i)
def make_node(self, x):
if not isinstance(x, Variable) or not hasattr(x.type, "ndim"):
if not (isinstance(x, Variable) and hasattr(x.type, "ndim")):
raise TypeError(
f"{x} must be `Variable` with a `Type` having an ndim attribute"
)
......
......@@ -2274,7 +2274,7 @@ class TestRemove0(utt.InferShapeTester):
unsorted_indices=unsor,
)
assert 0 in mat.data or not zero
assert not mat.has_sorted_indices or not unsor
assert not (mat.has_sorted_indices and unsor)
# the In thingy has to be there because pytensor has as rule not
# to optimize inputs
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论