Skip to content

Reject arrays in deeply nested asarray inputs - #247

Open
mikamikasuki wants to merge 1 commit into
data-apis:mainfrom
mikamikasuki:fix-nested-asarray-validation
Open

mikamikasuki wants to merge 1 commit into
data-apis:mainfrom
mikamikasuki:fix-nested-asarray-validation

Conversation

@mikamikasuki

Copy link
Copy Markdown

asarray([xp.asarray(1)]) rejects nested Arrays, but asarray([[xp.asarray(1)]]) silently accepts them because the check only examines the outer sequence.

Recursively inspect lists and tuples so the existing strictness applies at every nesting level. Standalone Array and buffer inputs continue through their existing conversion paths. This extends the behavior introduced in #147; it does not impose a new requirement on the Array API specification.

Added 17 rejecting cases and four scalar-sequence controls. The full suite passes with NumPy 2.5.3 (791 passed) and NumPy 1.26.4 (790 passed, 1 skipped), and Ruff passes. Independent checks cover 378 nested Array inputs, 126 nested scalar inputs, and three buffer inputs.

Fixes #245.

Prepared with AI assistance.

@mikamikasuki

Copy link
Copy Markdown
Author

The Python 3.14 / development-NumPy failure in test_linalg.test_trace also occurs on the clean base. I replayed the captured Hypothesis case on both 4d92880 and 56c1084 with Python 3.14.7 and NumPy 2.6.0.dev0 on Linux x86-64: both produce the same Array(4, uint32) != Array(0, uint32) assertion. The input is a float64 matrix filled with 4294967297.0, above the uint32 range; the trace result differs from the test’s stacked-diagonal conversion and sum.

Side-by-side reproduction logs.

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.

array_api_strict.asarray does not raise for nested sequence of arrays

1 participant