From 0e6aca3262a5d41bacca7e4a855380ef74872f44 Mon Sep 17 00:00:00 2001 From: Gunj Joshi Date: Fri, 18 Sep 2026 21:21:31 +0530 Subject: [PATCH] refactor!: update `fft/base/fftpack/float32/cosqi` to use integer array view BREAKING CHANGE: migrate from `Float32Array` to `Uint32Array` for reading radix factorization results To migrate, users should read the radix factor table section of the workspace via a `Uint32Array` view over the underlying buffer, rather than reading directly from the `Float32Array` workspace. Ref: https://github.com/stdlib-js/metr-issue-tracker/issues/1321 --- 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: na - 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: 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: passed - task: lint_license_headers status: passed --- --- .../fft/base/fftpack/float32/cosqi/README.md | 14 +++++++---- .../base/fftpack/float32/cosqi/docs/repl.txt | 23 ++++++++++--------- .../float32/cosqi/docs/types/index.d.ts | 6 +++-- .../fftpack/float32/cosqi/examples/index.js | 8 +++++-- .../base/fftpack/float32/cosqi/lib/index.js | 6 +++-- .../base/fftpack/float32/cosqi/lib/main.js | 6 +++-- .../base/fftpack/float32/cosqi/test/test.js | 13 +++++++---- 7 files changed, 49 insertions(+), 27 deletions(-) diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/float32/cosqi/README.md b/lib/node_modules/@stdlib/fft/base/fftpack/float32/cosqi/README.md index c7c2b3af91fb..332abddcb09b 100644 --- a/lib/node_modules/@stdlib/fft/base/fftpack/float32/cosqi/README.md +++ b/lib/node_modules/@stdlib/fft/base/fftpack/float32/cosqi/README.md @@ -46,6 +46,7 @@ Initializes a single-precision floating-point workspace array for performing a q ```javascript var Float32Array = require( '@stdlib/array/float32' ); +var Uint32Array = require( '@stdlib/array/uint32' ); var N = 8; var workspace = new Float32Array( ( 3*N ) + 34 ); @@ -62,8 +63,9 @@ var cosineTable = workspace.slice( 0, N ); var twiddleFactors = workspace.slice( 2*N, 3*N ); // returns [ ~0.707, ~0.707, 0, 0, 0, 0, 0, 0 ] -var factors = workspace.slice( 3*N, ( 3*N ) + 4 ); -// returns [ 8, 2, 2, 4 ] +var fview = new Uint32Array( workspace.buffer, workspace.byteOffset, workspace.length ); // eslint-disable-line max-len +var factors = fview.slice( 3*N, ( 3*N ) + 4 ); +// returns [ 8, 2, 2, 4 ] ``` The function accepts the following arguments: @@ -118,6 +120,7 @@ The function accepts the following arguments: ```javascript var Float32Array = require( '@stdlib/array/float32' ); +var Uint32Array = require( '@stdlib/array/uint32' ); var zeroTo = require( '@stdlib/array/zero-to' ); var logEach = require( '@stdlib/console/log-each' ); var cosqi = require( '@stdlib/fft/base/fftpack/float32/cosqi' ); @@ -136,12 +139,15 @@ console.log( 'Twiddle factors:' ); idx = zeroTo( N, 'float32' ); logEach( ' workspace[ %d ] = %0.4f', idx, workspace.slice( 2*N, 3*N ) ); +// Create an unsigned integer view over the workspace to read the factorization section: +var fview = new Uint32Array( workspace.buffer, workspace.byteOffset, workspace.length ); // eslint-disable-line max-len + console.log( 'Factorization:' ); -var nf = workspace[ (3*N)+1 ]; +var nf = fview[ (3*N)+1 ]; console.log( ' number of factors: %d', nf ); idx = zeroTo( nf, 'float32' ); -logEach( ' factor[ %d ]: %d', idx, workspace.slice( (3*N)+2, (3*N)+2+nf ) ); +logEach( ' factor[ %d ]: %d', idx, fview.slice( (3*N)+2, (3*N)+2+nf ) ); ``` diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/float32/cosqi/docs/repl.txt b/lib/node_modules/@stdlib/fft/base/fftpack/float32/cosqi/docs/repl.txt index fa0fb3cacf31..ea85cdd9139b 100644 --- a/lib/node_modules/@stdlib/fft/base/fftpack/float32/cosqi/docs/repl.txt +++ b/lib/node_modules/@stdlib/fft/base/fftpack/float32/cosqi/docs/repl.txt @@ -1,5 +1,5 @@ -{{alias}}( N, workspace, strideW, offsetW ) +{{alias}}( N, w, strideW, offsetW ) Initializes a single-precision floating-point workspace array for performing a quarter-wave cosine transform. @@ -27,14 +27,14 @@ N: integer Length of the sequence. - workspace: Float32Array + w: Float32Array Workspace array. strideW: integer - Stride length for `workspace`. + Stride length for `w`. offsetW: integer - Starting index for `workspace`. + Starting index for `w`. Returns ------- @@ -44,17 +44,18 @@ Examples -------- > var N = 8; - > var workspace = new {{alias:@stdlib/array/float32}}( ( 3*N ) + 34 ); - > var out = {{alias}}( N, workspace, 1, 0 ) + > var w = new {{alias:@stdlib/array/float32}}( ( 3*N ) + 34 ); + > var out = {{alias}}( N, w, 1, 0 ) - > var bool = ( out === workspace ) + > var bool = ( out === w ) true - > var cosineTable = workspace.slice( 0, N ) + > var cosineTable = w.slice( 0, N ) [ ~0.98, ~0.92, ~0.83, ~0.7, ~0.56, ~0.38, ~0.2, ~0.0 ] - > var twiddleFactors = workspace.slice( 2*N, 3*N ) + > var twiddleFactors = w.slice( 2*N, 3*N ) [ ~0.707, ~0.707, 0, 0, 0, 0, 0, 0 ] - > var factors = workspace.slice( 3*N, ( 3*N ) + 4 ) - [ 8, 2, 2, 4 ] + > var fview = new {{alias:@stdlib/array/uint32}}( w.buffer, w.byteOffset, w.length ); + > var factors = fview.slice( 3*N, ( 3*N ) + 4 ) + [ 8, 2, 2, 4 ] See Also -------- diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/float32/cosqi/docs/types/index.d.ts b/lib/node_modules/@stdlib/fft/base/fftpack/float32/cosqi/docs/types/index.d.ts index 96c8db03acaf..8d4afc9436bc 100644 --- a/lib/node_modules/@stdlib/fft/base/fftpack/float32/cosqi/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/fft/base/fftpack/float32/cosqi/docs/types/index.d.ts @@ -33,6 +33,7 @@ * * @example * var Float32Array = require( '@stdlib/array/float32' ); +* var Uint32Array = require( '@stdlib/array/uint32' ); * * var N = 8; * var workspace = new Float32Array( ( 3*N ) + 34 ); @@ -49,8 +50,9 @@ * var twiddleFactors = workspace.slice( 2*N, 3*N ); * // returns [ ~0.707, ~0.707, 0, 0, 0, 0, 0, 0 ] * -* var factors = workspace.slice( 3*N, ( 3*N ) + 4 ); -* // returns [ 8, 2, 2, 4 ] +* var fview = new Uint32Array( workspace.buffer, workspace.byteOffset, workspace.length ); +* var factors = fview.slice( 3*N, ( 3*N ) + 4 ); +* // returns [ 8, 2, 2, 4 ] */ declare function cosqi( N: number, workspace: Float32Array, strideW: number, offsetW: number ): Float32Array; diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/float32/cosqi/examples/index.js b/lib/node_modules/@stdlib/fft/base/fftpack/float32/cosqi/examples/index.js index 76b99bdada35..b02226d5d712 100644 --- a/lib/node_modules/@stdlib/fft/base/fftpack/float32/cosqi/examples/index.js +++ b/lib/node_modules/@stdlib/fft/base/fftpack/float32/cosqi/examples/index.js @@ -19,6 +19,7 @@ 'use strict'; var Float32Array = require( '@stdlib/array/float32' ); +var Uint32Array = require( '@stdlib/array/uint32' ); var zeroTo = require( '@stdlib/array/zero-to' ); var logEach = require( '@stdlib/console/log-each' ); var cosqi = require( './../lib' ); @@ -37,9 +38,12 @@ console.log( 'Twiddle factors:' ); idx = zeroTo( N, 'float32' ); logEach( ' workspace[ %d ] = %0.4f', idx, workspace.slice( 2*N, 3*N ) ); +// Create an unsigned integer view over the workspace to read the factorization section: +var fview = new Uint32Array( workspace.buffer, workspace.byteOffset, workspace.length ); // eslint-disable-line max-len + console.log( 'Factorization:' ); -var nf = workspace[ (3*N)+1 ]; +var nf = fview[ (3*N)+1 ]; console.log( ' number of factors: %d', nf ); idx = zeroTo( nf, 'float32' ); -logEach( ' factor[ %d ]: %d', idx, workspace.slice( (3*N)+2, (3*N)+2+nf ) ); +logEach( ' factor[ %d ]: %d', idx, fview.slice( (3*N)+2, (3*N)+2+nf ) ); diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/float32/cosqi/lib/index.js b/lib/node_modules/@stdlib/fft/base/fftpack/float32/cosqi/lib/index.js index 525c61a19005..e465e342dc8a 100644 --- a/lib/node_modules/@stdlib/fft/base/fftpack/float32/cosqi/lib/index.js +++ b/lib/node_modules/@stdlib/fft/base/fftpack/float32/cosqi/lib/index.js @@ -25,6 +25,7 @@ * * @example * var Float32Array = require( '@stdlib/array/float32' ); +* var Uint32Array = require( '@stdlib/array/uint32' ); * var cosqi = require( '@stdlib/fft/base/fftpack/float32/cosqi' ); * * var N = 8; @@ -42,8 +43,9 @@ * var twiddleFactors = workspace.slice( 2*N, 3*N ); * // returns [ ~0.707, ~0.707, 0, 0, 0, 0, 0, 0 ] * -* var factors = workspace.slice( 3*N, ( 3*N ) + 4 ); -* // returns [ 8, 2, 2, 4 ] +* var fview = new Uint32Array( workspace.buffer, workspace.byteOffset, workspace.length ); +* var factors = fview.slice( 3*N, ( 3*N ) + 4 ); +* // returns [ 8, 2, 2, 4 ] */ // MODULES // diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/float32/cosqi/lib/main.js b/lib/node_modules/@stdlib/fft/base/fftpack/float32/cosqi/lib/main.js index c854199e964a..fd72c7b4c851 100644 --- a/lib/node_modules/@stdlib/fft/base/fftpack/float32/cosqi/lib/main.js +++ b/lib/node_modules/@stdlib/fft/base/fftpack/float32/cosqi/lib/main.js @@ -140,6 +140,7 @@ var rffti = require( '@stdlib/fft/base/fftpack/float32/rffti' ); * * @example * var Float32Array = require( '@stdlib/array/float32' ); +* var Uint32Array = require( '@stdlib/array/uint32' ); * * var N = 8; * var workspace = new Float32Array( ( 3*N ) + 34 ); @@ -156,8 +157,9 @@ var rffti = require( '@stdlib/fft/base/fftpack/float32/rffti' ); * var twiddleFactors = workspace.slice( 2*N, 3*N ); * // returns [ ~0.707, ~0.707, 0, 0, 0, 0, 0, 0 ] * -* var factors = workspace.slice( 3*N, ( 3*N ) + 4 ); -* // returns [ 8, 2, 2, 4 ] +* var fview = new Uint32Array( workspace.buffer, workspace.byteOffset, workspace.length ); +* var factors = fview.slice( 3*N, ( 3*N ) + 4 ); +* // returns [ 8, 2, 2, 4 ] */ function cosqi( N, workspace, strideW, offsetW ) { var offsetR; diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/float32/cosqi/test/test.js b/lib/node_modules/@stdlib/fft/base/fftpack/float32/cosqi/test/test.js index 3a69f920ea14..9b6b593747a3 100644 --- a/lib/node_modules/@stdlib/fft/base/fftpack/float32/cosqi/test/test.js +++ b/lib/node_modules/@stdlib/fft/base/fftpack/float32/cosqi/test/test.js @@ -22,6 +22,7 @@ var tape = require( 'tape' ); var Float32Array = require( '@stdlib/array/float32' ); +var Uint32Array = require( '@stdlib/array/uint32' ); var isAlmostSameValue = require( '@stdlib/number/float32/base/assert/is-almost-same-value' ); var cosqi = require( './../lib' ); @@ -286,6 +287,7 @@ tape( 'the function correctly handles stride and offset parameters', function te var expected; var stride; var offset; + var fview; var nf; var N; var i; @@ -297,12 +299,15 @@ tape( 'the function correctly handles stride and offset parameters', function te cosqi( N, workspace, stride, offset ); - t.strictEqual( workspace[ offset + ( 3*N * stride ) ], N, 'returns expected value' ); + // Create an unsigned integer view over the workspace to read the factorization section: + fview = new Uint32Array( workspace.buffer, workspace.byteOffset, workspace.length ); // eslint-disable-line max-len - nf = workspace[ offset + ( ( ( 3*N ) + 1 ) * stride ) ]; + t.strictEqual( fview[ offset + ( 3*N * stride ) ], N, 'returns expected value' ); + + nf = fview[ offset + ( ( ( 3*N ) + 1 ) * stride ) ]; t.strictEqual( nf, 2, 'returns expected value' ); - t.strictEqual( workspace[ offset + ( ( ( 3*N ) + 2 ) * stride ) ], 2, 'returns expected value' ); - t.strictEqual( workspace[ offset + ( ( ( 3*N ) + 3 ) * stride ) ], 4, 'returns expected value' ); + t.strictEqual( fview[ offset + ( ( ( 3*N ) + 2 ) * stride ) ], 2, 'returns expected value' ); + t.strictEqual( fview[ offset + ( ( ( 3*N ) + 3 ) * stride ) ], 4, 'returns expected value' ); expected = new Float32Array( ( 3*N ) + 34 ); cosqi( N, expected, 1, 0 );