Fix complex π expression parsing in special case tests #7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR #3 added infrastructure for complex special case parsing but failed to handle π expressions in imaginary components like
πj/2,3πj/4, causing 14 test failures.Changes
Regex pattern
r_complex_valueto match two formats: πj expressions wherejis embedded (πj/2) and plain values followed byj(NaN j)\dto\d+to support multi-digit denominatorsParse logic
parse_complex_value: Extract coefficients from both πj format (stripj) and plain format (strip trailingj)parse_complex_result: Detect π symbols and use approximate equality (make_rough_eq) for π-based values_check_component_with_tolerancehelper to eliminate duplicated comparison logicBug fix
make_andoperator (was usingorinstead ofand)Example
Before:
After:
Results
Remaining 10 failures are unrelated implementation bugs in
array_api_strict(e.g.,expm1returning NaN instead of spec values).Original prompt
Fix PR #3: Implement Complete Complex Special Case Parsing
Current Problem
PR #3 (branch
copilot/add-complex-special-case-support) claims to add complex special case parsing but does not actually work. Running tests shows:AssertionError: out=1.5707963267948966j, but should be +0 + πj/2Success Criteria
After fixing, running
ARRAY_API_TESTS_MODULE=array_api_strict pytest array_api_tests/test_special_cases.py::test_unarymust:Root Cause Analysis
The PR description claims these functions were added, but they are missing from the actual code:
parse_complex_value()- to parse"+0 + πj/2"intocomplex(0, π/2)parse_complex_cond()- to parse"If a is +0 and b is +0"conditionsparse_complex_result()- to parse complex result expressionsmake_strict_eq_complex()- to check complex equality with sign awarenessparse_unary_case_block()test_unary()Required Implementation
1. Add Complex Value Parser (after line 493)
2. Add Complex Equality Checker (after parse_complex_value)
3. Add Complex Condition Parser (after make_strict_eq_complex)
4. Add Complex Result Parser (after parse_complex_cond)