Skip to content

Add aliases for arithmetic inequality function equivalents in NumPy #533

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions doc/library/tensor/basic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
36 changes: 21 additions & 15 deletions pytensor/tensor/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
##########################
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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",
Expand All @@ -2966,11 +2966,17 @@ def vectorize_node_to_matmul(op, node, batched_x, batched_y):
"smallest",
"largest",
"lt",
"less",
"gt",
"greater",
"le",
"less_equal",
"ge",
"greater_equal",
"eq",
"equal",
"neq",
"not_equal",
"isnan",
"isinf",
"allclose",
Expand Down