feat: add ndarray/base/reinterpret-complex#11779
feat: add ndarray/base/reinterpret-complex#11779headlessNode wants to merge 1 commit intostdlib-js:developfrom
ndarray/base/reinterpret-complex#11779Conversation
---
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: 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: passed
- task: lint_license_headers
status: passed
---
Coverage Report
The above coverage report was generated for the changes in this PR. |
| * | ||
| * ## Notes | ||
| * | ||
| * - If provided an ndarray whose underlying data buffer is neither a `Complex128Array` nor a `Complex64Array`, the function returns the input ndarray unchanged. |
There was a problem hiding this comment.
This is not what we do in
.If a user provides a non-complex valued array, that suggests that the user is doing something wrong. This package should be refactored accordingly.
There was a problem hiding this comment.
In fact, just look at your type definitions. You require strict support for complex number ndarrays. If you try to pass a non-complex array to this function, it will choke because you have no fallback overload. That inconsistency should have been a smell that this API is currently confused.
| * | ||
| * ## Notes | ||
| * | ||
| * - If provided an ndarray whose underlying data buffer is neither a `Complex128Array` nor a `Complex64Array`, the function returns the input ndarray unchanged. |
| Reinterprets a complex-valued floating-point ndarray as a real-valued | ||
| floating-point ndarray having the same precision. | ||
|
|
||
| If provided an ndarray whose underlying data buffer is neither a |
| Examples | ||
| -------- | ||
| > var dt = 'complex128'; | ||
| > var x = {{alias:@stdlib/ndarray/base/zeros}}( dt, [ 2, 2 ], 'row-major' ); |
There was a problem hiding this comment.
| > var x = {{alias:@stdlib/ndarray/base/zeros}}( dt, [ 2, 2 ], 'row-major' ); | |
| > var x = {{alias:@stdlib/ndarray/zeros}}( [ 2, 2 ], { 'dtype': dt } ); |
There was a problem hiding this comment.
Let's try to use top-level utilities in examples and benchmarks, where possible.
|
|
||
| 'use strict'; | ||
|
|
||
| var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); |
There was a problem hiding this comment.
| var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); | |
| var discreteUniform = require( '@stdlib/random/discrete-uniform' ); |
Update the example accordingly below.
| * @module @stdlib/ndarray/base/reinterpret-complex | ||
| * | ||
| * @example | ||
| * var ones = require( '@stdlib/ndarray/base/ones' ); |
There was a problem hiding this comment.
Ideally, let's replace with a top-level API (e.g., blas/ext/zero-to).
| * | ||
| * ## Notes | ||
| * | ||
| * - If provided an ndarray whose underlying data buffer is neither a `Complex128Array` nor a `Complex64Array`, the function returns the input ndarray unchanged. |
| if ( isComplex64Array( buf ) ) { | ||
| return reinterpret64( x ); | ||
| } | ||
| return x; |
| function reinterpretComplex( x ) { | ||
| var buf; | ||
|
|
||
| buf = getData( x ); |
There was a problem hiding this comment.
You're assuming here that simply because an input ndarray has a complex-valued data buffer that means that it is a complex number array. I don't this that is an appropriate assumption. You should validate that x has a complex-valued dtype and then check the underlying buffer.
|
|
||
| ## Notes | ||
|
|
||
| - If provided an [ndarray][@stdlib/ndarray/base/ctor] whose underlying data buffer is neither a `Complex128Array` nor a `Complex64Array`, the function returns the input [ndarray][@stdlib/ndarray/base/ctor] unchanged. |
| <!-- eslint no-undef: "error" --> | ||
|
|
||
| ```javascript | ||
| var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); |
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes. report:
Resolves stdlib-js/metr-issue-tracker#272.
Description
This pull request:
ndarray/base/reinterpret-complexRelated Issues
This pull request has the following related issues:
ndarray/base/reinterpret-complexmetr-issue-tracker#272Questions
No.
Other
No.
Checklist
AI Assistance
If you answered "yes" above, how did you use AI assistance?
Disclosure
Primarily written by Claude Code.
@stdlib-js/reviewers