From b4347ab905e4b74416a4a26c1ac6b343dab35647 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Mon, 20 Apr 2026 00:09:26 +0500 Subject: [PATCH 1/2] feat: add ndarray/base/reinterpret-complex128 --- 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 --- --- .../base/reinterpret-complex128/README.md | 118 +++++++++++ .../benchmark/benchmark.js | 115 ++++++++++ .../base/reinterpret-complex128/docs/repl.txt | 33 +++ .../docs/types/index.d.ts | 50 +++++ .../reinterpret-complex128/docs/types/test.ts | 54 +++++ .../reinterpret-complex128/examples/index.js | 33 +++ .../base/reinterpret-complex128/lib/index.js | 44 ++++ .../base/reinterpret-complex128/lib/main.js | 81 ++++++++ .../base/reinterpret-complex128/package.json | 68 ++++++ .../base/reinterpret-complex128/test/test.js | 196 ++++++++++++++++++ 10 files changed, 792 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/reinterpret-complex128/README.md create mode 100644 lib/node_modules/@stdlib/ndarray/base/reinterpret-complex128/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/reinterpret-complex128/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/ndarray/base/reinterpret-complex128/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/ndarray/base/reinterpret-complex128/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/ndarray/base/reinterpret-complex128/examples/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/reinterpret-complex128/lib/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/reinterpret-complex128/lib/main.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/reinterpret-complex128/package.json create mode 100644 lib/node_modules/@stdlib/ndarray/base/reinterpret-complex128/test/test.js diff --git a/lib/node_modules/@stdlib/ndarray/base/reinterpret-complex128/README.md b/lib/node_modules/@stdlib/ndarray/base/reinterpret-complex128/README.md new file mode 100644 index 000000000000..fbee1650943d --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/reinterpret-complex128/README.md @@ -0,0 +1,118 @@ + + +# reinterpretComplex128 + +> Reinterpret a [`complex128`][@stdlib/array/complex128] [ndarray][@stdlib/ndarray/base/ctor] as a double-precision floating-point [ndarray][@stdlib/ndarray/base/ctor]. + +
+ +
+ + + +
+ +## Usage + +```javascript +var reinterpretComplex128 = require( '@stdlib/ndarray/base/reinterpret-complex128' ); +``` + +#### reinterpretComplex128( x ) + +Reinterprets a [`complex128`][@stdlib/array/complex128] [ndarray][@stdlib/ndarray/base/ctor] as a double-precision floating-point [ndarray][@stdlib/ndarray/base/ctor]. + +```javascript +var ones = require( '@stdlib/ndarray/base/ones' ); + +var x = ones( 'complex128', [ 2, 2 ], 'row-major' ); +// returns [ [ [ 1.0, 0.0 ], [ 1.0, 0.0 ] ], [ [ 1.0, 0.0 ], [ 1.0, 0.0 ] ] ] + +var out = reinterpretComplex128( x ); +// returns [ [ [ 1.0, 0.0 ], [ 1.0, 0.0 ] ], [ [ 1.0, 0.0 ], [ 1.0, 0.0 ] ] ] +``` + +
+ + + +
+ +## Notes + +- The returned [ndarray][@stdlib/ndarray/base/ctor] is a view on the input [ndarray][@stdlib/ndarray/base/ctor] data buffer. +- The returned [ndarray][@stdlib/ndarray/base/ctor] is a "base" [ndarray][@stdlib/ndarray/base/ctor], and, thus, the returned [ndarray][@stdlib/ndarray/base/ctor] does not perform bounds checking or afford any of the guarantees of the non-base [ndarray][@stdlib/ndarray/ctor] constructor. The primary intent of this function is to reinterpret an ndarray-like object within internal implementations and to do so with minimal overhead. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var reinterpretComplex128 = require( '@stdlib/ndarray/base/reinterpret-complex128' ); + +// Create a complex128 ndarray: +var buf = new Complex128Array( discreteUniform( 8, -5, 5 ) ); +var x = ndarray( 'complex128', buf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + +// Reinterpret as a double-precision floating-point ndarray: +var out = reinterpretComplex128( x ); +console.log( ndarray2array( out ) ); +``` + +
+ + + +
+ +
+ + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ndarray/base/reinterpret-complex128/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/base/reinterpret-complex128/benchmark/benchmark.js new file mode 100644 index 000000000000..be51b9f75f90 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/reinterpret-complex128/benchmark/benchmark.js @@ -0,0 +1,115 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var ndarrayBase = require( '@stdlib/ndarray/base/ctor' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var reinterpretComplex128 = require( './../lib' ); + + +// MAIN // + +bench( format( '%s::base_ndarray,2d', pkg ), function benchmark( b ) { + var strides; + var values; + var buffer; + var offset; + var dtype; + var shape; + var order; + var out; + var i; + + dtype = 'complex128'; + buffer = new Complex128Array( 4 ); + shape = [ 2, 2 ]; + strides = [ 2, 1 ]; + offset = 0; + order = 'row-major'; + + values = [ + ndarrayBase( dtype, buffer, shape, strides, offset, order ), + ndarrayBase( dtype, buffer, shape, strides, offset, order ), + ndarrayBase( dtype, buffer, shape, strides, offset, order ), + ndarrayBase( dtype, buffer, shape, strides, offset, order ), + ndarrayBase( dtype, buffer, shape, strides, offset, order ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = reinterpretComplex128( values[ i%values.length ] ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isndarrayLike( out ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::ndarray,2d', pkg ), function benchmark( b ) { + var strides; + var values; + var buffer; + var offset; + var dtype; + var shape; + var order; + var out; + var i; + + dtype = 'complex128'; + buffer = new Complex128Array( 4 ); + shape = [ 2, 2 ]; + strides = [ 2, 1 ]; + offset = 0; + order = 'row-major'; + + values = [ + ndarray( dtype, buffer, shape, strides, offset, order ), + ndarray( dtype, buffer, shape, strides, offset, order ), + ndarray( dtype, buffer, shape, strides, offset, order ), + ndarray( dtype, buffer, shape, strides, offset, order ), + ndarray( dtype, buffer, shape, strides, offset, order ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = reinterpretComplex128( values[ i%values.length ] ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isndarrayLike( out ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/reinterpret-complex128/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/reinterpret-complex128/docs/repl.txt new file mode 100644 index 000000000000..7d2becaf524e --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/reinterpret-complex128/docs/repl.txt @@ -0,0 +1,33 @@ + +{{alias}}( x ) + Reinterprets a complex128 ndarray as a double-precision floating-point + ndarray. + + The returned ndarray is a view on the input ndarray data buffer. + + The returned ndarray is a "base" ndarray, and, thus, the returned ndarray + does not perform bounds checking or afford any of the guarantees of the + non-base ndarray constructor. The primary intent of this function is to + reinterpret an ndarray-like object within internal implementations and to + do so with minimal overhead. + + Parameters + ---------- + x: ndarray + Input ndarray. + + Returns + ------- + out: ndarray + Double-precision floating-point ndarray view. + + Examples + -------- + > var dt = 'complex128'; + > var x = {{alias:@stdlib/ndarray/base/zeros}}( dt, [ 2, 2 ], 'row-major' ); + > var out = {{alias}}( x ) + [ [ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ], [ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ] ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/ndarray/base/reinterpret-complex128/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/reinterpret-complex128/docs/types/index.d.ts new file mode 100644 index 000000000000..324c251746c1 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/reinterpret-complex128/docs/types/index.d.ts @@ -0,0 +1,50 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +import { complex128ndarray, float64ndarray } from '@stdlib/types/ndarray'; + +/** +* Reinterprets a complex128 ndarray as a double-precision floating-point ndarray. +* +* ## Notes +* +* - The returned ndarray is a view on the input ndarray data buffer. +* - The returned ndarray is a "base" ndarray, and, thus, the returned ndarray does not perform bounds checking or afford any of the guarantees of the non-base ndarray constructor. The primary intent of this function is to reinterpret an ndarray-like object within internal implementations and to do so with minimal overhead. +* +* @param x - input ndarray +* @returns double-precision floating-point ndarray view +* +* @example +* var ones = require( '@stdlib/ndarray/base/ones' ); +* +* var x = ones( 'complex128', [ 2, 2 ], 'row-major' ); +* // returns [ [ [ 1.0, 0.0 ], [ 1.0, 0.0 ] ], [ [ 1.0, 0.0 ], [ 1.0, 0.0 ] ] ] +* +* var out = reinterpretComplex128( x ); +* // returns [ [ [ 1.0, 0.0 ], [ 1.0, 0.0 ] ], [ [ 1.0, 0.0 ], [ 1.0, 0.0 ] ] ] +*/ +declare function reinterpretComplex128( x: complex128ndarray ): float64ndarray; + + +// EXPORTS // + +export = reinterpretComplex128; diff --git a/lib/node_modules/@stdlib/ndarray/base/reinterpret-complex128/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/base/reinterpret-complex128/docs/types/test.ts new file mode 100644 index 000000000000..ece0c9c9e34c --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/reinterpret-complex128/docs/types/test.ts @@ -0,0 +1,54 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import zeros = require( '@stdlib/ndarray/base/zeros' ); +import reinterpretComplex128 = require( './index' ); + + +// TESTS // + +// The function returns a float64 ndarray... +{ + const x = zeros( 'complex128', [ 2, 2 ], 'row-major' ); + + reinterpretComplex128( x ); // $ExpectType float64ndarray +} + +// The compiler throws an error if the function is not provided a first argument which is a complex128 ndarray... +{ + reinterpretComplex128( '5' ); // $ExpectError + reinterpretComplex128( 5 ); // $ExpectError + reinterpretComplex128( true ); // $ExpectError + reinterpretComplex128( false ); // $ExpectError + reinterpretComplex128( null ); // $ExpectError + reinterpretComplex128( {} ); // $ExpectError + reinterpretComplex128( [ '5' ] ); // $ExpectError + reinterpretComplex128( ( x: number ): number => x ); // $ExpectError + reinterpretComplex128( zeros( 'float64', [ 2, 2 ], 'row-major' ) ); // $ExpectError + reinterpretComplex128( zeros( 'float32', [ 2, 2 ], 'row-major' ) ); // $ExpectError + reinterpretComplex128( zeros( 'int32', [ 2, 2 ], 'row-major' ) ); // $ExpectError + reinterpretComplex128( zeros( 'complex64', [ 2, 2 ], 'row-major' ) ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = zeros( 'complex128', [ 2, 2 ], 'row-major' ); + + reinterpretComplex128(); // $ExpectError + reinterpretComplex128( x, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/ndarray/base/reinterpret-complex128/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/reinterpret-complex128/examples/index.js new file mode 100644 index 000000000000..ae6a1790f2c7 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/reinterpret-complex128/examples/index.js @@ -0,0 +1,33 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var reinterpretComplex128 = require( './../lib' ); + +// Create a complex128 ndarray: +var buf = new Complex128Array( discreteUniform( 8, -5, 5 ) ); +var x = ndarray( 'complex128', buf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + +// Reinterpret as a double-precision floating-point ndarray: +var out = reinterpretComplex128( x ); +console.log( ndarray2array( out ) ); diff --git a/lib/node_modules/@stdlib/ndarray/base/reinterpret-complex128/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/reinterpret-complex128/lib/index.js new file mode 100644 index 000000000000..a8ff9df5c493 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/reinterpret-complex128/lib/index.js @@ -0,0 +1,44 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Reinterpret a complex128 ndarray as a double-precision floating-point ndarray. +* +* @module @stdlib/ndarray/base/reinterpret-complex128 +* +* @example +* var ones = require( '@stdlib/ndarray/base/ones' ); +* var reinterpretComplex128 = require( '@stdlib/ndarray/base/reinterpret-complex128' ); +* +* var x = ones( 'complex128', [ 2, 2 ], 'row-major' ); +* // returns [ [ [ 1.0, 0.0 ], [ 1.0, 0.0 ] ], [ [ 1.0, 0.0 ], [ 1.0, 0.0 ] ] ] +* +* var out = reinterpretComplex128( x ); +* // returns [ [ [ 1.0, 0.0 ], [ 1.0, 0.0 ] ], [ [ 1.0, 0.0 ], [ 1.0, 0.0 ] ] ] +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/ndarray/base/reinterpret-complex128/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/reinterpret-complex128/lib/main.js new file mode 100644 index 000000000000..91679583fd4e --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/reinterpret-complex128/lib/main.js @@ -0,0 +1,81 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var reinterpret = require( '@stdlib/strided/base/reinterpret-complex128' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var getShape = require( '@stdlib/ndarray/base/shape' ); +var getStrides = require( '@stdlib/ndarray/base/strides' ); +var getOffset = require( '@stdlib/ndarray/base/offset' ); +var getOrder = require( '@stdlib/ndarray/base/order' ); +var getData = require( '@stdlib/ndarray/base/data-buffer' ); +var gscal = require( '@stdlib/blas/base/gscal' ); + + +// MAIN // + +/** +* Reinterprets a complex128 ndarray as a double-precision floating-point ndarray. +* +* ## Notes +* +* - The returned ndarray is a view on the input ndarray data buffer. +* - The returned ndarray is a "base" ndarray, and, thus, the returned ndarray does not perform bounds checking or afford any of the guarantees of the non-base ndarray constructor. The primary intent of this function is to reinterpret an ndarray-like object within internal implementations and to do so with minimal overhead. +* +* @param {ndarray} x - input ndarray +* @returns {ndarray} double-precision floating-point ndarray view +* +* @example +* var ones = require( '@stdlib/ndarray/base/ones' ); +* +* var x = ones( 'complex128', [ 2, 2 ], 'row-major' ); +* // returns [ [ [ 1.0, 0.0 ], [ 1.0, 0.0 ] ], [ [ 1.0, 0.0 ], [ 1.0, 0.0 ] ] ] +* +* var out = reinterpretComplex128( x ); +* // returns [ [ [ 1.0, 0.0 ], [ 1.0, 0.0 ] ], [ [ 1.0, 0.0 ], [ 1.0, 0.0 ] ] ] +*/ +function reinterpretComplex128( x ) { + var strides; + var shape; + var ndims; + + shape = getShape( x, true ); + strides = getStrides( x, true ); + ndims = shape.length; + + gscal( ndims, 2, strides, 1 ); + + // Append a trailing dimension where each element is the real and imaginary component for a corresponding element in the input ndarray... + shape.push( 2 ); + + // Augment the strides, assuming that real and imaginary components are adjacent in memory... + if ( ndims === 0 ) { + strides[ 0 ] = 1; + } else { + strides.push( 1 ); + } + return ndarray( 'float64', reinterpret( getData( x ), 0 ), shape, strides, getOffset( x )*2, getOrder( x ) ); +} + + +// EXPORTS // + +module.exports = reinterpretComplex128; diff --git a/lib/node_modules/@stdlib/ndarray/base/reinterpret-complex128/package.json b/lib/node_modules/@stdlib/ndarray/base/reinterpret-complex128/package.json new file mode 100644 index 000000000000..26bae0ca72a2 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/reinterpret-complex128/package.json @@ -0,0 +1,68 @@ +{ + "name": "@stdlib/ndarray/base/reinterpret-complex128", + "version": "0.0.0", + "description": "Reinterpret a complex128 ndarray as a double-precision floating-point ndarray.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdtypes", + "types", + "base", + "ndarray", + "reinterpret", + "cast", + "complex", + "complex128", + "cmplx", + "float64", + "double", + "view", + "real" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/ndarray/base/reinterpret-complex128/test/test.js b/lib/node_modules/@stdlib/ndarray/base/reinterpret-complex128/test/test.js new file mode 100644 index 000000000000..b63ff378da2a --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/reinterpret-complex128/test/test.js @@ -0,0 +1,196 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var Float64Array = require( '@stdlib/array/float64' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var getStrides = require( '@stdlib/ndarray/strides' ); +var getOffset = require( '@stdlib/ndarray/offset' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var reinterpretComplex128 = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof reinterpretComplex128, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns a "base" ndarray instance', function test( t ) { + var buf; + var x; + var y; + + buf = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + x = ndarray( 'complex128', buf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + y = reinterpretComplex128( x ); + + t.notEqual( y, x, 'returns new instance' ); + t.strictEqual( y instanceof ndarray, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a reinterpreted ndarray view (row-major)', function test( t ) { + var expected; + var buf; + var x; + var y; + + buf = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + x = ndarray( 'complex128', buf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + y = reinterpretComplex128( x ); + + expected = [ + [ + [ 1.0, 2.0 ], + [ 3.0, 4.0 ] + ], + [ + [ 5.0, 6.0 ], + [ 7.0, 8.0 ] + ] + ]; + + t.strictEqual( getData( y ) instanceof Float64Array, true, 'returns expected value' ); + t.strictEqual( getData( y ).buffer, buf.buffer, 'returns expected value' ); + t.strictEqual( String( getDType( y ) ), 'float64', 'returns expected value' ); + t.strictEqual( getOrder( y ), 'row-major', 'returns expected value' ); + t.deepEqual( getShape( y ), [ 2, 2, 2 ], 'returns expected value' ); + t.deepEqual( getStrides( y ), [ 4, 2, 1 ], 'returns expected value' ); + t.strictEqual( getOffset( y ), 0, 'returns expected value' ); + t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a reinterpreted ndarray view (column-major)', function test( t ) { + var expected; + var buf; + var x; + var y; + + buf = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + x = ndarray( 'complex128', buf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + y = reinterpretComplex128( x ); + + expected = [ + [ + [ 1.0, 2.0 ], + [ 5.0, 6.0 ] + ], + [ + [ 3.0, 4.0 ], + [ 7.0, 8.0 ] + ] + ]; + + t.strictEqual( getOrder( y ), 'column-major', 'returns expected value' ); + t.deepEqual( getShape( y ), [ 2, 2, 2 ], 'returns expected value' ); + t.deepEqual( getStrides( y ), [ 2, 4, 1 ], 'returns expected value' ); + t.strictEqual( getOffset( y ), 0, 'returns expected value' ); + t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function doubles the input ndarray offset', function test( t ) { + var expected; + var buf; + var x; + var y; + + buf = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + x = ndarray( 'complex128', buf, [ 2 ], [ 1 ], 1, 'row-major' ); + + y = reinterpretComplex128( x ); + + expected = [ + [ 3.0, 4.0 ], + [ 5.0, 6.0 ] + ]; + + t.strictEqual( getOffset( y ), 2, 'returns expected value' ); + t.deepEqual( getStrides( y ), [ 2, 1 ], 'returns expected value' ); + t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports zero-dimensional input ndarrays', function test( t ) { + var buf; + var x; + var y; + + buf = new Complex128Array( [ 1.0, 2.0 ] ); + x = ndarray( 'complex128', buf, [], [ 0 ], 0, 'row-major' ); + + y = reinterpretComplex128( x ); + + t.strictEqual( String( getDType( y ) ), 'float64', 'returns expected value' ); + t.strictEqual( getOrder( y ), 'row-major', 'returns expected value' ); + t.deepEqual( getShape( y ), [ 2 ], 'returns expected value' ); + t.deepEqual( getStrides( y ), [ 1 ], 'returns expected value' ); + t.strictEqual( getOffset( y ), 0, 'returns expected value' ); + t.deepEqual( ndarray2array( y ), [ 1.0, 2.0 ], 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports negative strides', function test( t ) { + var expected; + var buf; + var x; + var y; + + buf = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + x = ndarray( 'complex128', buf, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); + + y = reinterpretComplex128( x ); + + expected = [ + [ + [ 7.0, 8.0 ], + [ 5.0, 6.0 ] + ], + [ + [ 3.0, 4.0 ], + [ 1.0, 2.0 ] + ] + ]; + + t.deepEqual( getStrides( y ), [ -4, -2, 1 ], 'returns expected value' ); + t.strictEqual( getOffset( y ), 6, 'returns expected value' ); + t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); + + t.end(); +}); From aabd11a4278fa0c8e7cf0b46dbc5e327fe641679 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Mon, 20 Apr 2026 15:58:44 +0500 Subject: [PATCH 2/2] fix: apply suggestions from code review --- 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: 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: passed - task: lint_license_headers status: passed --- --- .../ndarray/base/reinterpret-complex128/README.md | 9 ++++----- .../ndarray/base/reinterpret-complex128/docs/repl.txt | 9 +++++++-- .../base/reinterpret-complex128/docs/types/index.d.ts | 3 ++- .../base/reinterpret-complex128/docs/types/test.ts | 4 ++-- .../base/reinterpret-complex128/examples/index.js | 2 +- .../ndarray/base/reinterpret-complex128/lib/index.js | 2 +- .../ndarray/base/reinterpret-complex128/lib/main.js | 5 +++-- .../ndarray/base/reinterpret-complex128/package.json | 2 +- 8 files changed, 21 insertions(+), 15 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/reinterpret-complex128/README.md b/lib/node_modules/@stdlib/ndarray/base/reinterpret-complex128/README.md index fbee1650943d..6d025f446dfa 100644 --- a/lib/node_modules/@stdlib/ndarray/base/reinterpret-complex128/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/reinterpret-complex128/README.md @@ -20,7 +20,7 @@ limitations under the License. # reinterpretComplex128 -> Reinterpret a [`complex128`][@stdlib/array/complex128] [ndarray][@stdlib/ndarray/base/ctor] as a double-precision floating-point [ndarray][@stdlib/ndarray/base/ctor]. +> Reinterpret a double-precision complex floating-point [ndarray][@stdlib/ndarray/base/ctor] as a real-valued double-precision floating-point [ndarray][@stdlib/ndarray/base/ctor] containing interleaved real and imaginary components.
@@ -38,7 +38,7 @@ var reinterpretComplex128 = require( '@stdlib/ndarray/base/reinterpret-complex12 #### reinterpretComplex128( x ) -Reinterprets a [`complex128`][@stdlib/array/complex128] [ndarray][@stdlib/ndarray/base/ctor] as a double-precision floating-point [ndarray][@stdlib/ndarray/base/ctor]. +Reinterprets a double-precision complex floating-point [ndarray][@stdlib/ndarray/base/ctor] as a real-valued double-precision floating-point [ndarray][@stdlib/ndarray/base/ctor] containing interleaved real and imaginary components. ```javascript var ones = require( '@stdlib/ndarray/base/ones' ); @@ -59,6 +59,7 @@ var out = reinterpretComplex128( x ); ## Notes - The returned [ndarray][@stdlib/ndarray/base/ctor] is a view on the input [ndarray][@stdlib/ndarray/base/ctor] data buffer. +- The returned [ndarray][@stdlib/ndarray/base/ctor] has an additional trailing dimension of size two whose elements correspond to the real and imaginary components, respectively, of each complex-valued element in the input [ndarray][@stdlib/ndarray/base/ctor]. - The returned [ndarray][@stdlib/ndarray/base/ctor] is a "base" [ndarray][@stdlib/ndarray/base/ctor], and, thus, the returned [ndarray][@stdlib/ndarray/base/ctor] does not perform bounds checking or afford any of the guarantees of the non-base [ndarray][@stdlib/ndarray/ctor] constructor. The primary intent of this function is to reinterpret an ndarray-like object within internal implementations and to do so with minimal overhead.
@@ -78,7 +79,7 @@ var ndarray = require( '@stdlib/ndarray/base/ctor' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); var reinterpretComplex128 = require( '@stdlib/ndarray/base/reinterpret-complex128' ); -// Create a complex128 ndarray: +// Create a double-precision complex floating-point ndarray: var buf = new Complex128Array( discreteUniform( 8, -5, 5 ) ); var x = ndarray( 'complex128', buf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); @@ -107,8 +108,6 @@ console.log( ndarray2array( out ) );