Skip to content

fix(lshift): shift element-wise for array shift amounts (#120) - #121

Open
umutKaracelebi wants to merge 1 commit into
francof2a:developfrom
umutKaracelebi:120-lshift-array-shift
Open

umutKaracelebi wants to merge 1 commit into
francof2a:developfrom
umutKaracelebi:120-lshift-array-shift

Conversation

@umutKaracelebi

Copy link
Copy Markdown

Summary

  • Fxp.__lshift__ / __ilshift__ now accept an array of shift amounts instead of raising ValueError.

Related issue(s)

Type of change

  • Bug fix

What changed

  • The result n_word was sized with max(self.n_word, bits + self.signed + n). With an array n that sum is an array, so the scalar max() compared an array and raised ValueError: The truth value of an array with more than one element is ambiguous. The size now comes from the largest shift amount (int(np.max(n))), so self.val << n shifts element-wise (NumPy semantics) while the result word still fits the largest shift. Scalar shift amounts take the same path as before; __ilshift__ shares this code.

Testing

  • Added/updated tests
  • Ran test suite locally (pytest -q)
  • Added/updated issue regression test in tests/test_issues.py (when applicable)
  • pytest -q -> 219 passed. The new tests/test_issues.py::test_issue_120_v0_5_0 fails on develop with the exact traceback from the issue and passes with the fix: a << np.array([1, 2, 3]) -> fxp-u8/0([ 2 8 24]).

Compatibility and risk

  • Backward-compatible
  • No signature or API change. Scalar shifts behave as before. Array shift amounts for >> and for shifting='keep' are out of scope here and remain unsupported.

Checklist

  • Updated docs/readme if behavior changed
  • Updated changelog entry if needed

Copilot AI balanced review requested due to automatic review settings November 15, 2026 19:34

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

This branch has not been deployed

No deployments
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.

[Bug]: Fxp.__lshift__ and __ilshift__ crash when shift amount is an array (ValueError: truth value of array is ambiguous)

2 participants