Unverified 提交 3f960ded authored 作者: Louis Maddox's avatar Louis Maddox 提交者: GitHub

Add aliases for arithmetic inequality function equivalents in NumPy (#533)

* feat(numpy logical aliases): add aliases for logical function equivalents in NumPy (#462) * fix(logical): bitwise and logical are distinct operators * doc(aliases): Document the new NumPy inequality aliases in the same style as existing bitwise ones. * refactor(numpy-aliases): collect all NumPy aliases in one block at the end of the file
上级 89fe939f
......@@ -1292,6 +1292,30 @@ The six usual equality and inequality operators share the same interface.
Returns a variable representing the result of logical inequality (a!=b).
.. function:: greater(a, b)
Alias for `gt`. greater is the NumPy name.
.. function:: greater_equal(a, b)
Alias for `ge`. greater_equal is the NumPy name.
.. function:: less(a, b)
Alias for `lt`. less is the NumPy name.
.. function:: less_equal(a, b)
Alias for `le`. less_equal is the NumPy name.
.. function:: equal(a, b)
Alias for `eq`. equal is the NumPy name.
.. function:: not_equal(a, b)
Alias for `neq`. not_equal is the NumPy name.
.. function:: isnan(a)
Returns a variable representing the comparison of ``a`` elements with nan.
......
......@@ -1013,32 +1013,21 @@ def and_(a, b):
"""bitwise a & b"""
bitwise_and = and_ # numpy name for it
@scalar_elemwise
def or_(a, b):
"""bitwise a | b"""
bitwise_or = or_ # numpy name for it
@scalar_elemwise
def xor(a, b):
"""bitwise a ^ b"""
bitwise_xor = xor # numpy name for it
@scalar_elemwise
def invert(a):
"""bitwise ~a"""
bitwise_not = invert # numpy alias for it
##########################
# Math
##########################
......@@ -1167,10 +1156,6 @@ def sqr(a):
"""square of a"""
# alias to sqr, included to maintain similarity with numpy interface
square = sqr
def cov(m, y=None, rowvar=True, bias=False, ddof=None, fweights=None, aweights=None):
"""Calculate the covariance matrix.
......@@ -2956,6 +2941,21 @@ def vectorize_node_to_matmul(op, node, batched_x, batched_y):
return vectorize_node_fallback(op, node, batched_x, batched_y)
# NumPy logical aliases
square = sqr
bitwise_and = and_
bitwise_or = or_
bitwise_xor = xor
bitwise_not = invert
greater = gt
greater_equal = ge
less = lt
less_equal = le
equal = eq
not_equal = neq
__all__ = [
"max_and_argmax",
"max",
......@@ -2966,11 +2966,17 @@ __all__ = [
"smallest",
"largest",
"lt",
"less",
"gt",
"greater",
"le",
"less_equal",
"ge",
"greater_equal",
"eq",
"equal",
"neq",
"not_equal",
"isnan",
"isinf",
"allclose",
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论