Skip to content
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

[ufuncs] Subtract + broadcast: Fixed tuple comparison for view shapes #267

Merged
merged 1 commit into from
Mar 24, 2024
Merged
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
7 changes: 4 additions & 3 deletions pykokkos/lib/ufuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1142,7 +1142,8 @@ def broadcast_view(val, viewB):
val = val[0] if len(val.shape) == 1 else val[0][0]

if is_view:
if not check_broadcastable_impl(val, viewB) or not val.shape < viewB.shape:
is_first_small = len(val.shape) < len(viewB.shape) or ((len(val.shape) == len(viewB.shape)) and val.shape < viewB.shape)
if not check_broadcastable_impl(val, viewB) or not is_first_small:
raise ValueError("Incompatible broadcast")
if not val.dtype == viewB.dtype:
raise ValueError("Broadcastable views must have same dtypes")
Expand Down Expand Up @@ -1235,9 +1236,9 @@ def subtract(viewA, valB):
raise ValueError("Views must be broadcastable")

# check if size is same otherwise broadcast and fix
if viewA.shape < valB.shape:
if len(viewA.shape) < len(valB.shape) or (len(viewA.shape) == len(valB.shape) and viewA.shape < valB.shape):
viewA = broadcast_view(viewA, valB)
elif valB.shape < viewA.shape:
elif len(valB.shape) < len(viewA.shape) or (len(viewA.shape) == len(valB.shape) and valB.shape < viewA.shape):
valB = broadcast_view(valB, viewA)

if viewA.dtype.__name__ == "float64" and valB.dtype.__name__ == "float64":
Expand Down
Loading