feat: add fft/base/fftpack/ndarray/rffti#13527
Conversation
---
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_pkg_readmes
status: na
- task: lint_markdown_docs
status: na
- task: lint_markdown
status: na
- task: lint_package_json
status: na
- task: lint_repl_help
status: na
- task: lint_javascript_src
status: passed
- task: lint_javascript_cli
status: na
- task: lint_javascript_examples
status: na
- task: lint_javascript_tests
status: na
- 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
---
|
Opening a draft PR to discuss the implementation here, since this seems to be a bit different from existing ndarray wrappers. |
| function rffti( arrays ) { | ||
| var workspace; | ||
| var N; | ||
|
|
||
| N = ndarraylike2scalar( arrays[ 0 ] ); | ||
| workspace = arrays[ 1 ]; | ||
| strided( N, getData( workspace ), getStride( workspace, 0 ), getOffset( workspace ) ); // eslint-disable-line max-len | ||
| return workspace; | ||
| } |
There was a problem hiding this comment.
We can't directly send numelDimension( workspace, 0 ) here, as the length of the sequence to transform (N) is different from the size of the workspace array (2*N + 34).
|
@kgryte Let me know if the above looks good, or if I should make any changes here. I'll work on adding other files meanwhile. |
---
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_pkg_readmes
status: na
- task: lint_markdown_docs
status: na
- task: lint_markdown
status: na
- task: lint_package_json
status: na
- task: lint_repl_help
status: na
- task: lint_javascript_src
status: passed
- task: lint_javascript_cli
status: na
- task: lint_javascript_examples
status: na
- task: lint_javascript_tests
status: na
- 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
---
---
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_pkg_readmes
status: passed
- task: lint_markdown_docs
status: na
- task: lint_markdown
status: na
- 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. |
---
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_pkg_readmes
status: na
- task: lint_markdown_docs
status: na
- 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: na
- 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: na
- task: lint_license_headers
status: passed
---
| * var factors = slice( workspace, new Slice( 2*N, ( 2*N ) + 4 ) ); | ||
| * // returns <ndarray>[ 8, 2, 2, 4 ] | ||
| */ | ||
| declare function rffti( arrays: [ ndarray, float64ndarray ] ): float64ndarray; |
There was a problem hiding this comment.
I have used ndarray here (for N) instead of something like int32ndarray, since I didn't saw a similar use anywhere.
| expectedTwiddles = new Float64Array( [ 0.7071067811865476, 0.7071067811865475, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); | ||
| expectedFactors = new Float64Array( [ 8, 2, 2, 4 ] ); |
There was a problem hiding this comment.
Instead of using the full expected workspace array (which would be of length 2N+34), I have just initialized the twiddle and integer factors.
| expectedTwiddles = new Float64Array( [ 0.7071067811865476, 0.7071067811865475, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); | ||
| expectedFactors = new Float64Array( [ 8, 2, 2, 4 ] ); |
There was a problem hiding this comment.
Since I am using these same 2 arrays in most of the tests, would it be better to move these to a separate // VARIABLES // section at the top? Or do we prefer this current way?
| * | ||
| * var workspace = new Float64Vector( ( 2*N ) + 34 ); | ||
| * | ||
| * var out = rffti( [ len, workspace ] ); |
There was a problem hiding this comment.
| * var out = rffti( [ len, workspace ] ); | |
| * var out = rffti( [ workspace, len ] ); |
| * | ||
| * - The function expects the following ndarrays: | ||
| * | ||
| * - a zero-dimensional ndarray containing the length of the sequence to transform. |
There was a problem hiding this comment.
You'll want to update this order here and elsewhere.
| e = expectedFactors[ i ]; | ||
| t.strictEqual( isAlmostSameValue( y, e, ulps ), true, 'within ' + ulps + ' ULPs. N: ' + N + '. y: ' + y + '. E: ' + e ); | ||
| } | ||
|
|
There was a problem hiding this comment.
Add loop where you test that the non-indexed values are all zero.
There was a problem hiding this comment.
Both the scratch space and all the elements which are in-between the indexed strided elements.
| > var twiddleFactors = {{alias:@stdlib/ndarray/slice}}( workspace, new {{alias:@stdlib/slice/ctor}}( N, 2*N ) ) | ||
| <ndarray>[ ~0.707, ~0.707, 0, 0, 0, 0, 0, 0 ] | ||
| > var factors = {{alias:@stdlib/ndarray/slice}}( workspace, new {{alias:@stdlib/slice/ctor}}( 2*N, ( 2*N ) + 4 ) ) |
There was a problem hiding this comment.
| > var twiddleFactors = {{alias:@stdlib/ndarray/slice}}( workspace, new {{alias:@stdlib/slice/ctor}}( N, 2*N ) ) | |
| <ndarray>[ ~0.707, ~0.707, 0, 0, 0, 0, 0, 0 ] | |
| > var factors = {{alias:@stdlib/ndarray/slice}}( workspace, new {{alias:@stdlib/slice/ctor}}( 2*N, ( 2*N ) + 4 ) ) | |
| > var s = new {{alias:@stdlib/slice/ctor}}( N, 2*N ); | |
| > var twiddleFactors = {{alias:@stdlib/ndarray/slice}}( workspace, s ) | |
| <ndarray>[ ~0.707, ~0.707, 0, 0, 0, 0, 0, 0 ] | |
| > s = new {{alias:@stdlib/slice/ctor}}( 2*N, ( 2*N ) + 4 ); | |
| > var factors = {{alias:@stdlib/ndarray/slice}}( workspace, s ) |
| * var factors = slice( workspace, new Slice( 2*N, ( 2*N ) + 4 ) ); | ||
| * // returns <ndarray>[ 8, 2, 2, 4 ] | ||
| */ | ||
| declare function rffti( arrays: [ ndarray, float64ndarray ] ): float64ndarray; |
There was a problem hiding this comment.
| declare function rffti( arrays: [ ndarray, float64ndarray ] ): float64ndarray; | |
| declare function rffti<T extends InputArray = InputArray>( arrays: [ T, typedndarray<number> ] ): T; |
|
|
||
| /// <reference types="@stdlib/types"/> | ||
|
|
||
| import { ndarray, float64ndarray } from '@stdlib/types/ndarray'; |
There was a problem hiding this comment.
| import { ndarray, float64ndarray } from '@stdlib/types/ndarray'; | |
| import { typedndarray, floatndarray, genericndarray } from '@stdlib/types/ndarray'; |
|
|
||
| import { ndarray, float64ndarray } from '@stdlib/types/ndarray'; | ||
|
|
||
| /** |
There was a problem hiding this comment.
| /** | |
| /** | |
| * Input array. | |
| */ | |
| type InputArray = floatndarray | genericndarray<number>; | |
| /** |
| // VARIABLES // | ||
|
|
||
| var options = { | ||
| 'dtype': 'int32' | ||
| }; | ||
|
|
||
|
|
There was a problem hiding this comment.
| // VARIABLES // | |
| var options = { | |
| 'dtype': 'int32' | |
| }; |
| var len = scalar2ndarray( N, options ); | ||
|
|
There was a problem hiding this comment.
| var len = scalar2ndarray( N, options ); | |
| var len = scalar2ndarray( N, { | |
| 'dtype': 'int32' | |
| }); |
| var workspace = new Float64Vector( ( 2*N ) + 34 ); | ||
| console.log( ndarray2array( workspace ) ); | ||
|
|
||
| var len = scalar2ndarray( N, opts ); |
There was a problem hiding this comment.
| var len = scalar2ndarray( N, opts ); | |
| var len = scalar2ndarray( N, { | |
| 'dtype': 'int32' | |
| }); |
| var opts = { | ||
| 'dtype': 'int32' | ||
| }; | ||
|
|
There was a problem hiding this comment.
| var opts = { | |
| 'dtype': 'int32' | |
| }; |
Applies to README, as well.
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes. report:
Resolves stdlib-js/metr-issue-tracker#1070.
Description
This pull request:
fft/base/fftpack/ndarray/rffti, which will be the one-dimensional ndarry wrapper forfft/base/fftpack/rffti.Related Issues
This pull request has the following related issues:
fft/base/fftpack/ndarray/rfftimetr-issue-tracker#1070Questions
No.
Other
No.
Checklist
AI Assistance
If you answered "yes" above, how did you use AI assistance?
Disclosure
Used
Gemini 3.5 Flashto search and understand working of ndarray wrappers.@stdlib-js/reviewers