Skip to content

Closes #5415: Performance regresion from divide by zero check - #5416

Merged
ajpotts merged 3 commits into
Bears-R-Us:mainfrom
ajpotts:5415_Performance_regresion_from_divide_by_zero_check
Feb 19, 2026
Merged

ajpotts merged 3 commits into
Bears-R-Us:mainfrom
ajpotts:5415_Performance_regresion_from_divide_by_zero_check

Conversation

@ajpotts

@ajpotts ajpotts commented Feb 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR fixes a performance regression introduced by divide-by-zero handling in pdarray binary operations. The previous implementation eagerly scanned denominators (e.g., any(x2 == 0)) on every vector/vector divide and reverse-divide, adding an extra full-array pass (and typically allocating a temporary boolean array) even when the divide error mode is set to ignore.

Problem

  • Divide-by-zero checks were performed eagerly at the Python level for array denominators.
  • In the common/default configuration (divide="ignore"), these checks should be a no-op, but the eager scan still occurred, causing unnecessary work and a measurable slowdown.

Solution

  • Rewrite _dbz_check to:
    • Return early when divide mode is ignore (fast path).
    • Accept either a boolean or a callable (lazy evaluation) so expensive checks are only computed when needed.
    • Use centralized error handling via arkouda.numpy.err.handle to support all configured behaviors (warn, raise, call, print, log) consistently.

Key changes

  • arkouda/numpy/pdarrayclass.py
    • Replace eager _dbz_check(op, flag) with lazy-capable _dbz_check(op: str, has_zero).
    • Remove direct warnings usage and dispatch via akerr.handle("divide", msg).
    • Update call site for vv division to pass lambda: any(x2 == 0) so the scan only runs when mode != ignore.

Why this is safe

  • When divide="ignore": behavior remains a no-op, now without extra scanning.
  • When divide!="ignore": behavior is preserved (and broadened) through err.handle, which is the standard place for error-mode semantics.
  • The lazy callable is only invoked for division operations (/ and //) and only when a check is required.

Testing

  • Existing test suite should cover divide behavior; this change is primarily performance-oriented.

Notes

This PR intentionally avoids backend changes. The improvement comes from eliminating unnecessary Python-level scans in the common ignore mode while preserving correct behavior for warn/raise and other configured error actions.

Closes #5415: Performance regresion from divide by zero check

Comment thread arkouda/numpy/pdarrayclass.py Resolved
@ajpotts
ajpotts force-pushed the 5415_Performance_regresion_from_divide_by_zero_check branch from 6debb8a to 2684656 Compare February 18, 2026 18:19
@ajpotts
ajpotts force-pushed the 5415_Performance_regresion_from_divide_by_zero_check branch 2 times, most recently from 54d3209 to 2d66581 Compare February 18, 2026 20:17
@ajpotts
ajpotts force-pushed the 5415_Performance_regresion_from_divide_by_zero_check branch from 2d66581 to 2a9f4be Compare February 18, 2026 21:09
@ajpotts
ajpotts marked this pull request as ready for review February 19, 2026 09:09
@ajpotts
ajpotts merged commit b65442a into Bears-R-Us:main Feb 19, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Performance regresion from divide by zero check

2 participants