-
-
Notifications
You must be signed in to change notification settings - Fork 1k
feat: add complex/float32/base/div
#9371
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
base: develop
Are you sure you want to change the base?
feat: add complex/float32/base/div
#9371
Conversation
Coverage Report
The above coverage report was generated for the changes in this PR. |
|
/stdlib update-copyright-years |
---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
- task: lint_filenames
status: passed
- task: lint_editorconfig
status: passed
- task: lint_markdown
status: passed
- task: lint_package_json
status: passed
- task: lint_repl_help
status: passed
- task: lint_javascript_src
status: passed
- task: lint_javascript_cli
status: na
- task: lint_javascript_examples
status: passed
- task: lint_javascript_tests
status: passed
- task: lint_javascript_benchmarks
status: passed
- task: lint_python
status: na
- task: lint_r
status: na
- task: lint_c_src
status: na
- task: lint_c_examples
status: passed
- task: lint_c_benchmarks
status: passed
- task: lint_c_tests_fixtures
status: na
- task: lint_shell
status: na
- task: lint_typescript_declarations
status: passed
- task: lint_typescript_tests
status: passed
- task: lint_license_headers
status: passed
---
---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
- task: lint_filenames
status: passed
- task: lint_editorconfig
status: passed
- task: lint_markdown
status: na
- task: lint_package_json
status: na
- task: lint_repl_help
status: na
- task: lint_javascript_src
status: na
- task: lint_javascript_cli
status: na
- task: lint_javascript_examples
status: na
- task: lint_javascript_tests
status: passed
- task: lint_javascript_benchmarks
status: na
- task: lint_python
status: na
- task: lint_r
status: na
- task: lint_c_src
status: na
- task: lint_c_examples
status: na
- task: lint_c_benchmarks
status: na
- task: lint_c_tests_fixtures
status: na
- task: lint_shell
status: na
- task: lint_typescript_declarations
status: passed
- task: lint_typescript_tests
status: na
- task: lint_license_headers
status: passed
---
| var out; | ||
| var v; | ||
|
|
||
| // Note: test cases adapted from Figure 6 of https://arxiv.org/pdf/1210.4539.pdf for float32. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iampratik13 You say that these test cases were adapted from Figure 6. How were they adapted?
| re1 = pow( 2.0, -80.0 ); | ||
| im1 = pow( 2.0, -20.0 ); | ||
| re2 = pow( 2.0, -130.0 ); | ||
| im2 = pow( 2.0, -140.0 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iampratik13 How did you derive these test cases? Can you provide the mathematics?
| q = cdiv( z1, z2 ); | ||
|
|
||
| idx = bitdiff( real( q ), pow( 2.0, -127.0 ) ); | ||
| t.ok( idx === -1 || idx >= 2, 'real component has expected binary representation' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iampratik13 Do you see any problems with this sort of assertion?
| t.strictEqual( imag( v ), expected[ 1 ], 'returns expected values' ); | ||
|
|
||
| z1 = new Complex64( 1.0, 0.5 ); | ||
| z2 = new Complex64( float64ToFloat32( 1.0e38 ), float64ToFloat32( 5.0e37 ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we wrapping these values in an f32 call before passing to Complex64?
| z1 = new Complex64( 1.0e-38, 2.0e-38 ); | ||
| z2 = new Complex64( 1.0, 2.0 ); | ||
| v = cdiv( z1, z2 ); | ||
| expected = [ 9.999999350456404e-39, 0.0 ]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How did you compute this value (and similar values below)?
| q = cdiv( z1, 1, 0, z2, 1, 0, new Float32Array( 2 ), 1, 0 ); | ||
|
|
||
| idx = bitdiff( q[ 0 ], pow( 2.0, -127.0 ) ); | ||
| t.ok( idx === -1 || idx >= 0, 'real component has expected binary representation' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iampratik13 See any problems with this assertion?
kgryte
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iampratik13 A few comments:
- Single-precision arithmetic implementations need to emulate single-precision arithmetic, as performed in C. See other
float32implementations. - Given how the tests were written, it looks like you used AI, which you did not disclose in the OP. Furthermore, you did not check that the generated assertions made sense, with some test cases always returning
trueregardless of the actual test result. This smells of having AI attempt to resolve failing test cases. The most surefire way to do so is to author the tests such that they always pass. This is disappointing. I suggest revisiting the tests in this PR and actually implementing them by hand. And for those tests which appear to diverge from Julia, well, I suggest digging in to figure out why they differ. Perhaps, even read Julia's source code (ref: https://github.com/JuliaLang/julia/blob/966d0af0fdffc727eb240e2e4c908fdd46697e57/base/complex.jl#L357). It is possible that their single-precision implementation differs from their double-precision implementation. You might also consider whether the algorithm from Scilab is appropriate for single-precision by actually reading the paper (ref: https://arxiv.org/pdf/1210.4539). It is possible that it is, but it may also require tweaks. You should understand what those are.
Resolves none
Description
This pull request:
feat: add
complex/float32/base/divRelated Issues
This pull request has the following related issues:
none
Questions
No.
Other
No.
Checklist
AI Assistance
If you answered "yes" above, how did you use AI assistance?
Disclosure
{{TODO: add disclosure if applicable}}
@stdlib-js/reviewers