From a581550f0197c21610288c148d2a15a743f0ad89 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sat, 17 Oct 2026 15:18:51 +0500 Subject: [PATCH 1/4] feat: add blas/ext/base/ghelmert --- .../@stdlib/blas/ext/base/ghelmert/README.md | 180 ++++ .../ext/base/ghelmert/benchmark/benchmark.js | 103 ++ .../ghelmert/benchmark/benchmark.ndarray.js | 103 ++ .../blas/ext/base/ghelmert/docs/repl.txt | 96 ++ .../ext/base/ghelmert/docs/types/index.d.ts | 112 +++ .../blas/ext/base/ghelmert/docs/types/test.ts | 212 +++++ .../blas/ext/base/ghelmert/examples/index.js | 34 + .../blas/ext/base/ghelmert/lib/accessors.js | 88 ++ .../blas/ext/base/ghelmert/lib/index.js | 73 ++ .../blas/ext/base/ghelmert/lib/main.js | 91 ++ .../blas/ext/base/ghelmert/lib/ndarray.js | 98 ++ .../blas/ext/base/ghelmert/package.json | 70 ++ .../blas/ext/base/ghelmert/test/test.js | 38 + .../blas/ext/base/ghelmert/test/test.main.js | 843 +++++++++++++++++ .../ext/base/ghelmert/test/test.ndarray.js | 888 ++++++++++++++++++ 15 files changed, 3029 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ghelmert/README.md create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ghelmert/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ghelmert/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ghelmert/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ghelmert/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ghelmert/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ghelmert/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ghelmert/lib/accessors.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ghelmert/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ghelmert/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ghelmert/lib/ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ghelmert/package.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ghelmert/test/test.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ghelmert/test/test.main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ghelmert/test/test.ndarray.js diff --git a/lib/node_modules/@stdlib/blas/ext/base/ghelmert/README.md b/lib/node_modules/@stdlib/blas/ext/base/ghelmert/README.md new file mode 100644 index 000000000000..7568ebe9161f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ghelmert/README.md @@ -0,0 +1,180 @@ + + +# ghelmert + +> Generate a Helmert matrix. + +
+ +
+ + + +
+ +## Usage + +```javascript +var ghelmert = require( '@stdlib/blas/ext/base/ghelmert' ); +``` + +#### ghelmert( order, full, N, out, ldo ) + +Generates a Helmert matrix. + +```javascript +var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + +ghelmert( 'row-major', true, 3, out, 3 ); +// out => [ ~0.577, ~0.577, ~0.577, ~0.707, ~-0.707, 0.0, ~0.408, ~0.408, ~-0.816 ] +``` + +The function has the following parameters: + +- **order**: row-major (C-style) or column-major (Fortran-style) order. +- **full**: boolean indicating whether to include the first row of `1/√N` values. +- **N**: order of the Helmert matrix. +- **out**: output matrix. +- **ldo**: stride between successive contiguous vectors of the matrix `out` (a.k.a., leading dimension of the matrix `out`). + +To exclude the constant first row and retain only the `N-1` orthogonal contrast rows, set `full` to `false`, resulting in an `(N-1)`-by-`N` matrix: + +```javascript +var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + +ghelmert( 'row-major', false, 3, out, 3 ); +// out => [ ~0.707, ~-0.707, 0.0, ~0.408, ~0.408, ~-0.816 ] +``` + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +// Initial array: +var out0 = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + +// Create an offset view: +var out1 = new Float64Array( out0.buffer, out0.BYTES_PER_ELEMENT*1 ); + +ghelmert( 'row-major', true, 2, out1, 2 ); +// out0 => [ 0.0, ~0.707, ~0.707, ~0.707, ~-0.707 ] +``` + +#### ghelmert.ndarray( full, N, out, strideOut1, strideOut2, offsetOut ) + +Generates a Helmert matrix using alternative indexing semantics. + +```javascript +var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + +ghelmert.ndarray( true, 3, out, 3, 1, 0 ); +// out => [ ~0.577, ~0.577, ~0.577, ~0.707, ~-0.707, 0.0, ~0.408, ~0.408, ~-0.816 ] +``` + +The function has the following additional parameters: + +- **strideOut1**: stride length for the first dimension of `out`. +- **strideOut2**: stride length for the second dimension of `out`. +- **offsetOut**: starting index for `out`. + +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to start writing matrix elements from the second element of the output array: + +```javascript +var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + +ghelmert.ndarray( false, 3, out, 3, 1, 1 ); +// out => [ 0.0, ~0.707, ~-0.707, 0.0, ~0.408, ~0.408, ~-0.816 ] +``` + +
+ + + +
+ +## Notes + +- If the number of output rows is less than or equal to `0`, both functions return `out` unchanged. +- Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]). + +
+ + + +
+ +## Examples + + + +```javascript +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var zeros = require( '@stdlib/array/zeros' ); +var ghelmert = require( '@stdlib/blas/ext/base/ghelmert' ); + +var N = 4; +var order = 'row-major'; +var shape = [ N, N ]; +var strides = shape2strides( shape, order ); + +var out = zeros( N*N, 'generic' ); + +ghelmert( order, true, N, out, N ); +console.log( ndarray2array( out, shape, strides, 0, order ) ); +``` + +
+ + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/ghelmert/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/ghelmert/benchmark/benchmark.js new file mode 100644 index 000000000000..326eb9b25354 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ghelmert/benchmark/benchmark.js @@ -0,0 +1,103 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var zeros = require( '@stdlib/array/zeros' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var ghelmert = require( './../lib/main.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var out = zeros( len * len, options.dtype ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = ghelmert( 'row-major', true, len, out, len ); + if ( isnan( v[ i%v.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v[ i%v.length ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 2; // 2^min + max = 10; // 2^max + + for ( i = min; i <= max; i += 2 ) { + len = pow( 2, i ); + f = createBenchmark( len ); + bench( format( '%s:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ghelmert/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/ghelmert/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..0244dada5770 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ghelmert/benchmark/benchmark.ndarray.js @@ -0,0 +1,103 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var zeros = require( '@stdlib/array/zeros' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var ghelmert = require( './../lib/ndarray.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var out = zeros( len * len, options.dtype ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = ghelmert( true, len, out, len, 1, 0 ); + if ( isnan( v[ i%v.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v[ i%v.length ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 2; // 2^min + max = 10; // 2^max + + for ( i = min; i <= max; i += 2 ) { + len = pow( 2, i ); + f = createBenchmark( len ); + bench( format( '%s:ndarray:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ghelmert/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ghelmert/docs/repl.txt new file mode 100644 index 000000000000..e6b538bfb8ab --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ghelmert/docs/repl.txt @@ -0,0 +1,96 @@ +{{alias}}( order, full, N, out, ldo ) + Generates a Helmert matrix. + + To exclude the constant first row and retain only the `N-1` orthogonal + contrast rows, set `full` to `false`, resulting in an `(N-1)xN` matrix. + + If the number of output rows is less than or equal to `0`, the function + returns `out` unchanged. + + Parameters + ---------- + order: string + Storage layout. + + full: boolean + Boolean indicating whether to include the first row of `1/sqrt(N)` + values. + + N: integer + Order of the Helmert matrix. + + out: ArrayLikeObject + Output array. + + ldo: integer + Stride length between successive contiguous vectors of the matrix + `out` (a.k.a., leading dimension of `out`). + + Returns + ------- + out: ArrayLikeObject + Output array. + + Examples + -------- + // Standard usage: + > var out = new {{alias:@stdlib/array/float64}}( 9 ); + > {{alias}}( 'row-major', true, 3, out, 3 ) + [ ~0.577, ~0.577, ~0.577, ~0.707, ~-0.707, 0.0, ~0.408, ~0.408, ~-0.816 ] + + // Excluding the first row: + > out = new {{alias:@stdlib/array/float64}}( 6 ); + > {{alias}}( 'row-major', false, 3, out, 3 ) + [ ~0.707, ~-0.707, 0.0, ~0.408, ~0.408, ~-0.816 ] + + +{{alias}}.ndarray( full, N, out, so1, so2, oo ) + Generates a Helmert matrix using alternative indexing semantics. + + To exclude the constant first row and retain only the `N-1` orthogonal + contrast rows, set `full` to `false`, resulting in an `(N-1)xN` matrix. + + While typed array views mandate a view offset based on the underlying + buffer, the offset parameter supports indexing semantics based on a starting + index. + + Parameters + ---------- + full: boolean + Boolean indicating whether to include the first row of `1/sqrt(N)` + values. + + N: integer + Order of the Helmert matrix. + + out: ArrayLikeObject + Output array. + + so1: integer + Stride length for the first dimension of `out`. + + so2: integer + Stride length for the second dimension of `out`. + + oo: integer + Starting index for `out`. + + Returns + ------- + out: ArrayLikeObject + Output array. + + Examples + -------- + // Standard Usage: + > var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + > {{alias}}.ndarray( true, 3, out, 3, 1, 0 ) + [ ~0.577, ~0.577, ~0.577, ~0.707, ~-0.707, 0.0, ~0.408, ~0.408, ~-0.816 ] + + // Using an index offset: + > out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + > {{alias}}.ndarray( true, 3, out, 3, 1, 1 ) + [ 0.0, ~0.577, ~0.577, ~0.577, ~0.707, ~-0.707, 0.0, ~0.408, ~0.408, ~-0.816 ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/blas/ext/base/ghelmert/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ghelmert/docs/types/index.d.ts new file mode 100644 index 000000000000..585c44c0bdae --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ghelmert/docs/types/index.d.ts @@ -0,0 +1,112 @@ +/* +* @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 { Collection, AccessorArrayLike } from '@stdlib/types/array'; +import { Layout } from '@stdlib/types/blas'; + +/** +* Output array. +*/ +type OutputArray = Collection | AccessorArrayLike; + +/** +* Interface describing `ghelmert`. +*/ +interface Routine { + /** + * Generates a Helmert matrix. + * + * @param order - storage layout + * @param full - boolean indicating whether to include the first row + * @param N - order of the Helmert matrix + * @param out - output array + * @param ldo - stride length between successive contiguous vectors of the matrix `out` (a.k.a., leading dimension of `out`) + * @returns output array + * + * @example + * var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + * + * ghelmert( 'row-major', true, 3, out, 3 ); + * // out => [ ~0.577, ~0.577, ~0.577, ~0.707, ~-0.707, 0.0, ~0.408, ~0.408, ~-0.816 ] + * + * @example + * var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + * + * ghelmert( 'row-major', false, 3, out, 3 ); + * // out => [ ~0.707, ~-0.707, 0.0, ~0.408, ~0.408, ~-0.816 ] + */ + = OutputArray>( order: Layout, full: boolean, N: number, out: V, ldo: number ): V; + + /** + * Generates a Helmert matrix using alternative indexing semantics. + * + * @param full - boolean indicating whether to include the first row + * @param N - order of the Helmert matrix + * @param out - output array + * @param strideOut1 - stride length for the first dimension of `out` + * @param strideOut2 - stride length for the second dimension of `out` + * @param offsetOut - starting index for `out` + * @returns output array + * + * @example + * var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + * + * ghelmert.ndarray( true, 3, out, 3, 1, 0 ); + * // out => [ ~0.577, ~0.577, ~0.577, ~0.707, ~-0.707, 0.0, ~0.408, ~0.408, ~-0.816 ] + * + * @example + * var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + * + * ghelmert.ndarray( false, 3, out, 3, 1, 0 ); + * // out => [ ~0.707, ~-0.707, 0.0, ~0.408, ~0.408, ~-0.816 ] + */ + ndarray = OutputArray>( full: boolean, N: number, out: V, strideOut1: number, strideOut2: number, offsetOut: number ): V; +} + +/** +* Generates a Helmert matrix. +* +* @param order - storage layout +* @param full - boolean indicating whether to include the first row +* @param N - order of the Helmert matrix +* @param out - output array +* @param ldo - stride length between successive contiguous vectors of the matrix `out` (a.k.a., leading dimension of `out`) +* @returns output array +* +* @example +* var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* ghelmert( 'row-major', true, 3, out, 3 ); +* // out => [ ~0.577, ~0.577, ~0.577, ~0.707, ~-0.707, 0.0, ~0.408, ~0.408, ~-0.816 ] +* +* @example +* var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* ghelmert.ndarray( false, 3, out, 3, 1, 0 ); +* // out => [ ~0.707, ~-0.707, 0.0, ~0.408, ~0.408, ~-0.816 ] +*/ +declare var ghelmert: Routine; + + +// EXPORTS // + +export = ghelmert; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ghelmert/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/ghelmert/docs/types/test.ts new file mode 100644 index 000000000000..9d8919c06745 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ghelmert/docs/types/test.ts @@ -0,0 +1,212 @@ +/* +* @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. +*/ + +/* eslint-disable space-in-parens */ + +import AccessorArray = require( '@stdlib/array/base/accessor' ); +import ghelmert = require( './index' ); + + +// TESTS // + +// The function returns a collection... +{ + const out = new Float64Array( 16 ); + + ghelmert( 'row-major', true, 4, out, 4 ); // $ExpectType Float64Array + ghelmert( 'row-major', true, 4, new AccessorArray( out ), 4 ); // $ExpectType AccessorArray +} + +// The compiler throws an error if the function is provided a first argument which is not a valid order... +{ + const out = new Float64Array( 16 ); + + ghelmert( 10, true, 4, out, 4 ); // $ExpectError + ghelmert( true, true, 4, out, 4 ); // $ExpectError + ghelmert( false, true, 4, out, 4 ); // $ExpectError + ghelmert( null, true, 4, out, 4 ); // $ExpectError + ghelmert( undefined, true, 4, out, 4 ); // $ExpectError + ghelmert( [], true, 4, out, 4 ); // $ExpectError + ghelmert( {}, true, 4, out, 4 ); // $ExpectError + ghelmert( ( x: number ): number => x, true, 4, out, 4 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a boolean... +{ + const out = new Float64Array( 16 ); + + ghelmert( 'row-major', '10', 4, out, 4 ); // $ExpectError + ghelmert( 'row-major', 10, 4, out, 4 ); // $ExpectError + ghelmert( 'row-major', null, 4, out, 4 ); // $ExpectError + ghelmert( 'row-major', undefined, 4, out, 4 ); // $ExpectError + ghelmert( 'row-major', [], 4, out, 4 ); // $ExpectError + ghelmert( 'row-major', {}, 4, out, 4 ); // $ExpectError + ghelmert( 'row-major', ( x: number ): number => x, 4, out, 4 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a number... +{ + const out = new Float64Array( 16 ); + + ghelmert( 'row-major', true, '10', out, 4 ); // $ExpectError + ghelmert( 'row-major', true, true, out, 4 ); // $ExpectError + ghelmert( 'row-major', true, false, out, 4 ); // $ExpectError + ghelmert( 'row-major', true, null, out, 4 ); // $ExpectError + ghelmert( 'row-major', true, undefined, out, 4 ); // $ExpectError + ghelmert( 'row-major', true, [], out, 4 ); // $ExpectError + ghelmert( 'row-major', true, {}, out, 4 ); // $ExpectError + ghelmert( 'row-major', true, ( x: number ): number => x, out, 4 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a collection... +{ + ghelmert( 'row-major', true, 4, 10, 4 ); // $ExpectError + ghelmert( 'row-major', true, 4, true, 4 ); // $ExpectError + ghelmert( 'row-major', true, 4, false, 4 ); // $ExpectError + ghelmert( 'row-major', true, 4, null, 4 ); // $ExpectError + ghelmert( 'row-major', true, 4, undefined, 4 ); // $ExpectError + ghelmert( 'row-major', true, 4, {}, 4 ); // $ExpectError + ghelmert( 'row-major', true, 4, ( x: number ): number => x, 4 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not a number... +{ + const out = new Float64Array( 16 ); + + ghelmert( 'row-major', true, 4, out, '10' ); // $ExpectError + ghelmert( 'row-major', true, 4, out, true ); // $ExpectError + ghelmert( 'row-major', true, 4, out, false ); // $ExpectError + ghelmert( 'row-major', true, 4, out, null ); // $ExpectError + ghelmert( 'row-major', true, 4, out, undefined ); // $ExpectError + ghelmert( 'row-major', true, 4, out, [] ); // $ExpectError + ghelmert( 'row-major', true, 4, out, {} ); // $ExpectError + ghelmert( 'row-major', true, 4, out, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const out = new Float64Array( 16 ); + + ghelmert(); // $ExpectError + ghelmert( 'row-major' ); // $ExpectError + ghelmert( 'row-major', true ); // $ExpectError + ghelmert( 'row-major', true, 4 ); // $ExpectError + ghelmert( 'row-major', true, 4, out ); // $ExpectError + ghelmert( 'row-major', true, 4, out, 4, 10 ); // $ExpectError +} + +// Attached to the main export is an `ndarray` method which returns a collection... +{ + const out = new Float64Array( 16 ); + + ghelmert.ndarray( true, 4, out, 4, 1, 0 ); // $ExpectType Float64Array + ghelmert.ndarray( true, 4, new AccessorArray( out ), 4, 1, 0 ); // $ExpectType AccessorArray +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a boolean... +{ + const out = new Float64Array( 16 ); + + ghelmert.ndarray( '10', 4, out, 4, 1, 0 ); // $ExpectError + ghelmert.ndarray( 10, 4, out, 4, 1, 0 ); // $ExpectError + ghelmert.ndarray( null, 4, out, 4, 1, 0 ); // $ExpectError + ghelmert.ndarray( undefined, 4, out, 4, 1, 0 ); // $ExpectError + ghelmert.ndarray( [], 4, out, 4, 1, 0 ); // $ExpectError + ghelmert.ndarray( {}, 4, out, 4, 1, 0 ); // $ExpectError + ghelmert.ndarray( ( x: number ): number => x, 4, out, 4, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a number... +{ + const out = new Float64Array( 16 ); + + ghelmert.ndarray( true, '10', out, 4, 1, 0 ); // $ExpectError + ghelmert.ndarray( true, true, out, 4, 1, 0 ); // $ExpectError + ghelmert.ndarray( true, false, out, 4, 1, 0 ); // $ExpectError + ghelmert.ndarray( true, null, out, 4, 1, 0 ); // $ExpectError + ghelmert.ndarray( true, undefined, out, 4, 1, 0 ); // $ExpectError + ghelmert.ndarray( true, [], out, 4, 1, 0 ); // $ExpectError + ghelmert.ndarray( true, {}, out, 4, 1, 0 ); // $ExpectError + ghelmert.ndarray( true, ( x: number ): number => x, out, 4, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a collection... +{ + ghelmert.ndarray( true, 4, 10, 4, 1, 0 ); // $ExpectError + ghelmert.ndarray( true, 4, true, 4, 1, 0 ); // $ExpectError + ghelmert.ndarray( true, 4, false, 4, 1, 0 ); // $ExpectError + ghelmert.ndarray( true, 4, null, 4, 1, 0 ); // $ExpectError + ghelmert.ndarray( true, 4, undefined, 4, 1, 0 ); // $ExpectError + ghelmert.ndarray( true, 4, {}, 4, 1, 0 ); // $ExpectError + ghelmert.ndarray( true, 4, ( x: number ): number => x, 4, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... +{ + const out = new Float64Array( 16 ); + + ghelmert.ndarray( true, 4, out, '10', 1, 0 ); // $ExpectError + ghelmert.ndarray( true, 4, out, true, 1, 0 ); // $ExpectError + ghelmert.ndarray( true, 4, out, false, 1, 0 ); // $ExpectError + ghelmert.ndarray( true, 4, out, null, 1, 0 ); // $ExpectError + ghelmert.ndarray( true, 4, out, undefined, 1, 0 ); // $ExpectError + ghelmert.ndarray( true, 4, out, [], 1, 0 ); // $ExpectError + ghelmert.ndarray( true, 4, out, {}, 1, 0 ); // $ExpectError + ghelmert.ndarray( true, 4, out, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a number... +{ + const out = new Float64Array( 16 ); + + ghelmert.ndarray( true, 4, out, 4, '10', 0 ); // $ExpectError + ghelmert.ndarray( true, 4, out, 4, true, 0 ); // $ExpectError + ghelmert.ndarray( true, 4, out, 4, false, 0 ); // $ExpectError + ghelmert.ndarray( true, 4, out, 4, null, 0 ); // $ExpectError + ghelmert.ndarray( true, 4, out, 4, undefined, 0 ); // $ExpectError + ghelmert.ndarray( true, 4, out, 4, [], 0 ); // $ExpectError + ghelmert.ndarray( true, 4, out, 4, {}, 0 ); // $ExpectError + ghelmert.ndarray( true, 4, out, 4, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a sixth argument which is not a number... +{ + const out = new Float64Array( 16 ); + + ghelmert.ndarray( true, 4, out, 4, 1, '10' ); // $ExpectError + ghelmert.ndarray( true, 4, out, 4, 1, true ); // $ExpectError + ghelmert.ndarray( true, 4, out, 4, 1, false ); // $ExpectError + ghelmert.ndarray( true, 4, out, 4, 1, null ); // $ExpectError + ghelmert.ndarray( true, 4, out, 4, 1, undefined ); // $ExpectError + ghelmert.ndarray( true, 4, out, 4, 1, [] ); // $ExpectError + ghelmert.ndarray( true, 4, out, 4, 1, {} ); // $ExpectError + ghelmert.ndarray( true, 4, out, 4, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const out = new Float64Array( 16 ); + + ghelmert.ndarray(); // $ExpectError + ghelmert.ndarray( true ); // $ExpectError + ghelmert.ndarray( true, 4 ); // $ExpectError + ghelmert.ndarray( true, 4, out ); // $ExpectError + ghelmert.ndarray( true, 4, out, 4 ); // $ExpectError + ghelmert.ndarray( true, 4, out, 4, 1 ); // $ExpectError + ghelmert.ndarray( true, 4, out, 4, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ghelmert/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/ghelmert/examples/index.js new file mode 100644 index 000000000000..e2e2656ef598 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ghelmert/examples/index.js @@ -0,0 +1,34 @@ +/** +* @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 ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var zeros = require( '@stdlib/array/zeros' ); +var ghelmert = require( './../lib' ); + +var N = 4; +var order = 'row-major'; +var shape = [ N, N ]; +var strides = shape2strides( shape, order ); + +var out = zeros( N*N, 'generic' ); + +ghelmert( order, true, N, out, N ); +console.log( ndarray2array( out, shape, strides, 0, order ) ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ghelmert/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/ghelmert/lib/accessors.js new file mode 100644 index 000000000000..3797f1f6fd23 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ghelmert/lib/accessors.js @@ -0,0 +1,88 @@ +/** +* @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 sqrt = require( '@stdlib/math/base/special/sqrt' ); + + +// MAIN // + +/** +* Generates a Helmert matrix using accessor arrays. +* +* @private +* @param {boolean} full - boolean indicating whether to include the first row +* @param {NonNegativeInteger} N - order of the Helmert matrix +* @param {Object} out - output array object +* @param {integer} strideOut1 - stride length for the first dimension of `out` +* @param {integer} strideOut2 - stride length for the second dimension of `out` +* @param {NonNegativeInteger} offsetOut - starting index for `out` +* @returns {Object} output array object +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +* +* var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* ghelmert( true, 3, arraylike2object( toAccessorArray( out ) ), 3, 1, 0 ); +* // out => [ ~0.577, ~0.577, ~0.577, ~0.707, ~-0.707, 0.0, ~0.408, ~0.408, ~-0.816 ] +*/ +function ghelmert( full, N, out, strideOut1, strideOut2, offsetOut ) { + var obuf; + var oset; + var io; + var v; + var i; + var j; + + obuf = out.data; + oset = out.accessors[ 1 ]; + + io = offsetOut; + + // If full, write the first row with all elements equal to 1/sqrt(N)... + if ( full ) { + v = 1.0 / sqrt( N ); + for ( j = 0; j < N; j++ ) { + oset( obuf, io + (j*strideOut2), v ); + } + io += strideOut1; + } + // For the remaining rows, compute the sub-diagonal Helmert rows... + for ( i = 1; i < N; i++ ) { + v = 1.0 / sqrt( i * (i+1) ); + for ( j = 0; j < i; j++ ) { + oset( obuf, io + (j*strideOut2), v ); + } + oset( obuf, io + (i*strideOut2), -i * v ); + for ( j = i + 1; j < N; j++ ) { + oset( obuf, io + (j*strideOut2), 0.0 ); + } + io += strideOut1; + } + return out; +} + + +// EXPORTS // + +module.exports = ghelmert; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ghelmert/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/ghelmert/lib/index.js new file mode 100644 index 000000000000..1f59cbdcfdf4 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ghelmert/lib/index.js @@ -0,0 +1,73 @@ +/** +* @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'; + +/** +* Generate a Helmert matrix. +* +* @module @stdlib/blas/ext/base/ghelmert +* +* @example +* var ghelmert = require( '@stdlib/blas/ext/base/ghelmert' ); +* +* var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* ghelmert( 'row-major', true, 3, out, 3 ); +* // out => [ ~0.577, ~0.577, ~0.577, ~0.707, ~-0.707, 0.0, ~0.408, ~0.408, ~-0.816 ] +* +* @example +* var ghelmert = require( '@stdlib/blas/ext/base/ghelmert' ); +* +* var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* ghelmert( 'row-major', false, 3, out, 3 ); +* // out => [ ~0.707, ~-0.707, 0.0, ~0.408, ~0.408, ~-0.816 ] +* +* @example +* var ghelmert = require( '@stdlib/blas/ext/base/ghelmert' ); +* +* var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* ghelmert.ndarray( true, 3, out, 3, 1, 0 ); +* // out => [ ~0.577, ~0.577, ~0.577, ~0.707, ~-0.707, 0.0, ~0.408, ~0.408, ~-0.816 ] +* +* @example +* var ghelmert = require( '@stdlib/blas/ext/base/ghelmert' ); +* +* var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* ghelmert.ndarray( false, 3, out, 3, 1, 0 ); +* // out => [ ~0.707, ~-0.707, 0.0, ~0.408, ~0.408, ~-0.816 ] +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( main, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ghelmert/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/ghelmert/lib/main.js new file mode 100644 index 000000000000..3b2b5451f555 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ghelmert/lib/main.js @@ -0,0 +1,91 @@ +/** +* @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 isColumnMajor = require( '@stdlib/ndarray/base/assert/is-column-major-string' ); +var resolveLayout = require( '@stdlib/blas/base/layout-resolve-str' ); +var max = require( '@stdlib/math/base/special/fast/max' ); +var format = require( '@stdlib/string/format' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +/** +* Generates a Helmert matrix. +* +* @param {(integer|string)} order - storage layout +* @param {boolean} full - boolean indicating whether to include the first row +* @param {NonNegativeInteger} N - order of the Helmert matrix +* @param {Collection} out - output array +* @param {PositiveInteger} ldo - stride between successive contiguous vectors of the matrix `out` (a.k.a., leading dimension of the matrix `out`) +* @throws {TypeError} first argument must be a valid order +* @throws {RangeError} fifth argument must be a valid stride +* @returns {Collection} output matrix +* +* @example +* var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* ghelmert( 'row-major', true, 3, out, 3 ); +* // out => [ ~0.577, ~0.577, ~0.577, ~0.707, ~-0.707, 0.0, ~0.408, ~0.408, ~-0.816 ] +* +* @example +* var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* ghelmert( 'row-major', false, 3, out, 3 ); +* // out => [ ~0.707, ~-0.707, 0.0, ~0.408, ~0.408, ~-0.816 ] +*/ +function ghelmert( order, full, N, out, ldo ) { + var iscm; + var sa1; + var sa2; + var M; + var l; + + l = resolveLayout( order ); + if ( l === null ) { + throw new TypeError( format( 'invalid argument. First argument must be a valid order. Value: `%s`.', order ) ); + } + M = ( full ) ? N : N - 1; + iscm = isColumnMajor( l ); + if ( iscm ) { + if ( ldo < max( 1, M ) ) { + throw new RangeError( format( 'invalid argument. Fifth argument must be greater than or equal to max(1,%d). Value: `%d`.', M, ldo ) ); + } + sa1 = 1; + sa2 = ldo; + } else { // order === 'row-major' + if ( ldo < max( 1, N ) ) { + throw new RangeError( format( 'invalid argument. Fifth argument must be greater than or equal to max(1,%d). Value: `%d`.', N, ldo ) ); + } + sa1 = ldo; + sa2 = 1; + } + if ( M <= 0 ) { + return out; + } + return ndarray( full, N, out, sa1, sa2, 0 ); +} + + +// EXPORTS // + +module.exports = ghelmert; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ghelmert/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/ghelmert/lib/ndarray.js new file mode 100644 index 000000000000..31d151d1e1bc --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ghelmert/lib/ndarray.js @@ -0,0 +1,98 @@ +/** +* @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 arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +var sqrt = require( '@stdlib/math/base/special/sqrt' ); +var accessors = require( './accessors.js' ); + + +// MAIN // + +/** +* Generates a Helmert matrix using alternative indexing semantics. +* +* @param {boolean} full - boolean indicating whether to include the first row +* @param {NonNegativeInteger} N - order of the Helmert matrix +* @param {Collection} out - output array +* @param {integer} strideOut1 - stride length for the first dimension of `out` +* @param {integer} strideOut2 - stride length for the second dimension of `out` +* @param {NonNegativeInteger} offsetOut - starting index for `out` +* @returns {Collection} output matrix +* +* @example +* var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* ghelmert( true, 3, out, 3, 1, 0 ); +* // out => [ ~0.577, ~0.577, ~0.577, ~0.707, ~-0.707, 0.0, ~0.408, ~0.408, ~-0.816 ] +* +* @example +* var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* ghelmert( false, 3, out, 3, 1, 0 ); +* // out => [ ~0.707, ~-0.707, 0.0, ~0.408, ~0.408, ~-0.816 ] +*/ +function ghelmert( full, N, out, strideOut1, strideOut2, offsetOut ) { + var oo; + var io; + var v; + var M; + var i; + var j; + + M = ( full ) ? N : N - 1; + if ( M <= 0 ) { + return out; + } + oo = arraylike2object( out ); + if ( oo.accessorProtocol ) { + accessors( full, N, oo, strideOut1, strideOut2, offsetOut ); + return out; + } + io = offsetOut; + + // If full, write the first row with all elements equal to 1/sqrt(N)... + if ( full ) { + v = 1.0 / sqrt( N ); + for ( j = 0; j < N; j++ ) { + out[ io + (j*strideOut2) ] = v; + } + io += strideOut1; + } + // For the remaining rows, compute the sub-diagonal Helmert rows... + for ( i = 1; i < N; i++ ) { + v = 1.0 / sqrt( i * (i+1) ); + for ( j = 0; j < i; j++ ) { + out[ io + (j*strideOut2) ] = v; + } + out[ io + (i*strideOut2) ] = -i * v; + for ( j = i + 1; j < N; j++ ) { + out[ io + (j*strideOut2) ] = 0.0; + } + io += strideOut1; + } + return out; +} + + +// EXPORTS // + +module.exports = ghelmert; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ghelmert/package.json b/lib/node_modules/@stdlib/blas/ext/base/ghelmert/package.json new file mode 100644 index 000000000000..2585a5f5dd0b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ghelmert/package.json @@ -0,0 +1,70 @@ +{ + "name": "@stdlib/blas/ext/base/ghelmert", + "version": "0.0.0", + "description": "Generate a Helmert matrix.", + "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", + "stdmath", + "mathematics", + "math", + "blas", + "extended", + "helmert", + "matrix", + "strided", + "strided array", + "typed", + "array", + "ndarray", + "vector", + "ghelmert", + "orthogonal" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ghelmert/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/ghelmert/test/test.js new file mode 100644 index 000000000000..bd940dc10f51 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ghelmert/test/test.js @@ -0,0 +1,38 @@ +/** +* @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 ghelmert = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ghelmert, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is a method providing an ndarray interface', function test( t ) { + t.strictEqual( typeof ghelmert.ndarray, 'function', 'method is a function' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ghelmert/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/ghelmert/test/test.main.js new file mode 100644 index 000000000000..8eba85a56d63 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ghelmert/test/test.main.js @@ -0,0 +1,843 @@ +/** +* @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 toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var Float64Array = require( '@stdlib/array/float64' ); +var sqrt = require( '@stdlib/math/base/special/sqrt' ); +var ghelmert = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ghelmert, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 5', function test( t ) { + t.strictEqual( ghelmert.length, 5, 'has expected arity' ); + t.end(); +}); + +tape( 'the function throws an error if provided an invalid first argument', function test( t ) { + var values; + var i; + + values = [ + 'foo', + 'bar', + 'beep', + 'boop' + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + ghelmert( value, true, 2, [ 0.0, 0.0, 0.0, 0.0 ], 2 ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid first argument (accessors)', function test( t ) { + var values; + var i; + + values = [ + 'foo', + 'bar', + 'beep', + 'boop' + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + ghelmert( value, true, 2, toAccessorArray( [ 0.0, 0.0, 0.0, 0.0 ] ), 2 ); // eslint-disable-line max-len + }; + } +}); + +tape( 'the function throws an error if provided an invalid fifth argument (row-major)', function test( t ) { + var values; + var i; + + values = [ + -2, + -1, + 0, + 1 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + ghelmert( 'row-major', true, 2, [ 0.0, 0.0, 0.0, 0.0 ], value ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid fifth argument (row-major, accessors)', function test( t ) { + var values; + var i; + + values = [ + -2, + -1, + 0, + 1 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + ghelmert( 'row-major', true, 2, toAccessorArray( [ 0.0, 0.0, 0.0, 0.0 ] ), value ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid fifth argument (column-major)', function test( t ) { + var values; + var i; + + values = [ + -2, + -1, + 0, + 1 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + ghelmert( 'column-major', true, 2, [ 0.0, 0.0, 0.0, 0.0 ], value ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid fifth argument (column-major, accessors)', function test( t ) { + var values; + var i; + + values = [ + -2, + -1, + 0, + 1 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + ghelmert( 'column-major', true, 2, toAccessorArray( [ 0.0, 0.0, 0.0, 0.0 ] ), value ); + }; + } +}); + +tape( 'if the number of output rows is less than or equal to `0`, the function returns the output array unchanged (full=true)', function test( t ) { + var expected; + var out; + + out = [ 0.0, 0.0, 0.0, 0.0 ]; + + ghelmert( 'row-major', true, 0, out, 1 ); + + expected = [ 0.0, 0.0, 0.0, 0.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'if the number of output rows is less than or equal to `0`, the function returns the output array unchanged (full=true, accessors)', function test( t ) { + var expected; + var out; + + out = [ 0.0, 0.0, 0.0, 0.0 ]; + + ghelmert( 'row-major', true, 0, toAccessorArray( out ), 1 ); + + expected = [ 0.0, 0.0, 0.0, 0.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'if the number of output rows is less than or equal to `0`, the function returns the output array unchanged (full=false)', function test( t ) { + var expected; + var out; + + out = [ 0.0, 0.0, 0.0, 0.0 ]; + + ghelmert( 'row-major', false, 1, out, 1 ); + + expected = [ 0.0, 0.0, 0.0, 0.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'if the number of output rows is less than or equal to `0`, the function returns the output array unchanged (full=false, accessors)', function test( t ) { + var expected; + var out; + + out = [ 0.0, 0.0, 0.0, 0.0 ]; + + ghelmert( 'row-major', false, 1, toAccessorArray( out ), 1 ); + + expected = [ 0.0, 0.0, 0.0, 0.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the output matrix', function test( t ) { + var out; + var v; + + out = [ 0.0, 0.0, 0.0, 0.0 ]; + + v = ghelmert( 'row-major', true, 2, out, 2 ); + + t.strictEqual( v, out, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the output matrix (accessors)', function test( t ) { + var out; + var v; + + out = toAccessorArray( [ 0.0, 0.0, 0.0, 0.0 ] ); + + v = ghelmert( 'row-major', true, 2, out, 2 ); + + t.strictEqual( v, out, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a Helmert matrix (row-major, full=true)', function test( t ) { + var expected; + var out; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + ghelmert( 'row-major', true, 4, out, 4 ); + + expected = [ + 1.0 / sqrt( 4 ), + 1.0 / sqrt( 4 ), + 1.0 / sqrt( 4 ), + 1.0 / sqrt( 4 ), + 1.0 / sqrt( 2 ), + -1.0 / sqrt( 2 ), + 0.0, + 0.0, + 1.0 / sqrt( 6 ), + 1.0 / sqrt( 6 ), + -2.0 / sqrt( 6 ), + 0.0, + 1.0 / sqrt( 12 ), + 1.0 / sqrt( 12 ), + 1.0 / sqrt( 12 ), + -3.0 * ( 1.0 / sqrt( 12 ) ) + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a Helmert matrix (row-major, full=true, accessors)', function test( t ) { + var expected; + var out; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + ghelmert( 'row-major', true, 4, toAccessorArray( out ), 4 ); + + expected = [ + 1.0 / sqrt( 4 ), + 1.0 / sqrt( 4 ), + 1.0 / sqrt( 4 ), + 1.0 / sqrt( 4 ), + 1.0 / sqrt( 2 ), + -1.0 / sqrt( 2 ), + 0.0, + 0.0, + 1.0 / sqrt( 6 ), + 1.0 / sqrt( 6 ), + -2.0 / sqrt( 6 ), + 0.0, + 1.0 / sqrt( 12 ), + 1.0 / sqrt( 12 ), + 1.0 / sqrt( 12 ), + -3.0 * ( 1.0 / sqrt( 12 ) ) + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a Helmert matrix (row-major, full=false)', function test( t ) { + var expected; + var out; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + ghelmert( 'row-major', false, 4, out, 4 ); + + expected = [ + 1.0 / sqrt( 2 ), + -1.0 / sqrt( 2 ), + 0.0, + 0.0, + 1.0 / sqrt( 6 ), + 1.0 / sqrt( 6 ), + -2.0 / sqrt( 6 ), + 0.0, + 1.0 / sqrt( 12 ), + 1.0 / sqrt( 12 ), + 1.0 / sqrt( 12 ), + -3.0 * ( 1.0 / sqrt( 12 ) ) + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a Helmert matrix (row-major, full=false, accessors)', function test( t ) { + var expected; + var out; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + ghelmert( 'row-major', false, 4, toAccessorArray( out ), 4 ); + + expected = [ + 1.0 / sqrt( 2 ), + -1.0 / sqrt( 2 ), + 0.0, + 0.0, + 1.0 / sqrt( 6 ), + 1.0 / sqrt( 6 ), + -2.0 / sqrt( 6 ), + 0.0, + 1.0 / sqrt( 12 ), + 1.0 / sqrt( 12 ), + 1.0 / sqrt( 12 ), + -3.0 * ( 1.0 / sqrt( 12 ) ) + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a Helmert matrix (column-major, full=true)', function test( t ) { + var expected; + var out; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + ghelmert( 'column-major', true, 4, out, 4 ); + + expected = [ + 1.0 / sqrt( 4 ), + 1.0 / sqrt( 2 ), + 1.0 / sqrt( 6 ), + 1.0 / sqrt( 12 ), + 1.0 / sqrt( 4 ), + -1.0 / sqrt( 2 ), + 1.0 / sqrt( 6 ), + 1.0 / sqrt( 12 ), + 1.0 / sqrt( 4 ), + 0.0, + -2.0 / sqrt( 6 ), + 1.0 / sqrt( 12 ), + 1.0 / sqrt( 4 ), + 0.0, + 0.0, + -3.0 * ( 1.0 / sqrt( 12 ) ) + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a Helmert matrix (column-major, full=true, accessors)', function test( t ) { + var expected; + var out; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + ghelmert( 'column-major', true, 4, toAccessorArray( out ), 4 ); + + expected = [ + 1.0 / sqrt( 4 ), + 1.0 / sqrt( 2 ), + 1.0 / sqrt( 6 ), + 1.0 / sqrt( 12 ), + 1.0 / sqrt( 4 ), + -1.0 / sqrt( 2 ), + 1.0 / sqrt( 6 ), + 1.0 / sqrt( 12 ), + 1.0 / sqrt( 4 ), + 0.0, + -2.0 / sqrt( 6 ), + 1.0 / sqrt( 12 ), + 1.0 / sqrt( 4 ), + 0.0, + 0.0, + -3.0 * ( 1.0 / sqrt( 12 ) ) + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a Helmert matrix (column-major, full=false)', function test( t ) { + var expected; + var out; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + ghelmert( 'column-major', false, 4, out, 3 ); + + expected = [ + 1.0 / sqrt( 2 ), + 1.0 / sqrt( 6 ), + 1.0 / sqrt( 12 ), + -1.0 / sqrt( 2 ), + 1.0 / sqrt( 6 ), + 1.0 / sqrt( 12 ), + 0.0, + -2.0 / sqrt( 6 ), + 1.0 / sqrt( 12 ), + 0.0, + 0.0, + -3.0 * ( 1.0 / sqrt( 12 ) ) + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a Helmert matrix (column-major, full=false, accessors)', function test( t ) { + var expected; + var out; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + ghelmert( 'column-major', false, 4, toAccessorArray( out ), 3 ); + + expected = [ + 1.0 / sqrt( 2 ), + 1.0 / sqrt( 6 ), + 1.0 / sqrt( 12 ), + -1.0 / sqrt( 2 ), + 1.0 / sqrt( 6 ), + 1.0 / sqrt( 12 ), + 0.0, + -2.0 / sqrt( 6 ), + 1.0 / sqrt( 12 ), + 0.0, + 0.0, + -3.0 * ( 1.0 / sqrt( 12 ) ) + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a leading dimension for the output matrix (row-major, full=true)', function test( t ) { + var expected; + var out; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + ghelmert( 'row-major', true, 2, out, 3 ); + + expected = [ + 1.0 / sqrt( 2 ), + 1.0 / sqrt( 2 ), + 0.0, + 1.0 / sqrt( 2 ), + -1.0 / sqrt( 2 ), + 0.0 + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a leading dimension for the output matrix (row-major, full=true, accessors)', function test( t ) { + var expected; + var out; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + ghelmert( 'row-major', true, 2, toAccessorArray( out ), 3 ); + + expected = [ + 1.0 / sqrt( 2 ), + 1.0 / sqrt( 2 ), + 0.0, + 1.0 / sqrt( 2 ), + -1.0 / sqrt( 2 ), + 0.0 + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a leading dimension for the output matrix (column-major, full=true)', function test( t ) { + var expected; + var out; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + ghelmert( 'column-major', true, 2, out, 3 ); + + expected = [ + 1.0 / sqrt( 2 ), + 1.0 / sqrt( 2 ), + 0.0, + 1.0 / sqrt( 2 ), + -1.0 / sqrt( 2 ), + 0.0 + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a leading dimension for the output matrix (column-major, full=true, accessors)', function test( t ) { + var expected; + var out; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + ghelmert( 'column-major', true, 2, toAccessorArray( out ), 3 ); + + expected = [ + 1.0 / sqrt( 2 ), + 1.0 / sqrt( 2 ), + 0.0, + 1.0 / sqrt( 2 ), + -1.0 / sqrt( 2 ), + 0.0 + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a leading dimension for the output matrix (row-major, full=false)', function test( t ) { + var expected; + var out; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + ghelmert( 'row-major', false, 3, out, 5 ); + + expected = [ + 1.0 / sqrt( 2 ), + -1.0 / sqrt( 2 ), + 0.0, + 0.0, + 0.0, + 1.0 / sqrt( 6 ), + 1.0 / sqrt( 6 ), + -2.0 / sqrt( 6 ), + 0.0, + 0.0 + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a leading dimension for the output matrix (column-major, full=false)', function test( t ) { + var expected; + var out; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + ghelmert( 'column-major', false, 3, out, 4 ); + + expected = [ + 1.0 / sqrt( 2 ), + 1.0 / sqrt( 6 ), + 0.0, + 0.0, + -1.0 / sqrt( 2 ), + 1.0 / sqrt( 6 ), + 0.0, + 0.0, + 0.0, + -2.0 / sqrt( 6 ), + 0.0, + 0.0 + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports view offsets (full=true)', function test( t ) { + var expected; + var out0; + var out1; + + out0 = new Float64Array( 5 ); + out1 = new Float64Array( out0.buffer, out0.BYTES_PER_ELEMENT*1 ); + + ghelmert( 'row-major', true, 2, out1, 2 ); + + expected = new Float64Array([ + 1.0 / sqrt( 2 ), + 1.0 / sqrt( 2 ), + 1.0 / sqrt( 2 ), + -1.0 / sqrt( 2 ) + ]); + + t.deepEqual( out1, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports view offsets (full=false)', function test( t ) { + var expected; + var out0; + var out1; + + out0 = new Float64Array( 7 ); + out1 = new Float64Array( out0.buffer, out0.BYTES_PER_ELEMENT*1 ); + + ghelmert( 'row-major', false, 3, out1, 3 ); + + expected = new Float64Array([ + 1.0 / sqrt( 2 ), + -1.0 / sqrt( 2 ), + 0.0, + 1.0 / sqrt( 6 ), + 1.0 / sqrt( 6 ), + -2.0 / sqrt( 6 ) + ]); + + t.deepEqual( out1, expected, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ghelmert/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/ghelmert/test/test.ndarray.js new file mode 100644 index 000000000000..996f591a9068 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ghelmert/test/test.ndarray.js @@ -0,0 +1,888 @@ +/** +* @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 toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var sqrt = require( '@stdlib/math/base/special/sqrt' ); +var ghelmert = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ghelmert, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 6', function test( t ) { + t.strictEqual( ghelmert.length, 6, 'has expected arity' ); + t.end(); +}); + +tape( 'the function generates a Helmert matrix (row-major, full=true)', function test( t ) { + var expected; + var out; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + ghelmert( true, 4, out, 4, 1, 0 ); + + expected = [ + 1.0 / sqrt( 4 ), + 1.0 / sqrt( 4 ), + 1.0 / sqrt( 4 ), + 1.0 / sqrt( 4 ), + 1.0 / sqrt( 2 ), + -1.0 / sqrt( 2 ), + 0.0, + 0.0, + 1.0 / sqrt( 6 ), + 1.0 / sqrt( 6 ), + -2.0 / sqrt( 6 ), + 0.0, + 1.0 / sqrt( 12 ), + 1.0 / sqrt( 12 ), + 1.0 / sqrt( 12 ), + -3.0 * ( 1.0 / sqrt( 12 ) ) + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a Helmert matrix (row-major, full=true, accessors)', function test( t ) { + var expected; + var out; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + ghelmert( true, 4, toAccessorArray( out ), 4, 1, 0 ); + + expected = [ + 1.0 / sqrt( 4 ), + 1.0 / sqrt( 4 ), + 1.0 / sqrt( 4 ), + 1.0 / sqrt( 4 ), + 1.0 / sqrt( 2 ), + -1.0 / sqrt( 2 ), + 0.0, + 0.0, + 1.0 / sqrt( 6 ), + 1.0 / sqrt( 6 ), + -2.0 / sqrt( 6 ), + 0.0, + 1.0 / sqrt( 12 ), + 1.0 / sqrt( 12 ), + 1.0 / sqrt( 12 ), + -3.0 * ( 1.0 / sqrt( 12 ) ) + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a Helmert matrix (row-major, full=false)', function test( t ) { + var expected; + var out; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + ghelmert( false, 4, out, 4, 1, 0 ); + + expected = [ + 1.0 / sqrt( 2 ), + -1.0 / sqrt( 2 ), + 0.0, + 0.0, + 1.0 / sqrt( 6 ), + 1.0 / sqrt( 6 ), + -2.0 / sqrt( 6 ), + 0.0, + 1.0 / sqrt( 12 ), + 1.0 / sqrt( 12 ), + 1.0 / sqrt( 12 ), + -3.0 * ( 1.0 / sqrt( 12 ) ) + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a Helmert matrix (row-major, full=false, accessors)', function test( t ) { + var expected; + var out; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + ghelmert( false, 4, toAccessorArray( out ), 4, 1, 0 ); + + expected = [ + 1.0 / sqrt( 2 ), + -1.0 / sqrt( 2 ), + 0.0, + 0.0, + 1.0 / sqrt( 6 ), + 1.0 / sqrt( 6 ), + -2.0 / sqrt( 6 ), + 0.0, + 1.0 / sqrt( 12 ), + 1.0 / sqrt( 12 ), + 1.0 / sqrt( 12 ), + -3.0 * ( 1.0 / sqrt( 12 ) ) + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a Helmert matrix (column-major, full=true)', function test( t ) { + var expected; + var out; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + ghelmert( true, 4, out, 1, 4, 0 ); + + expected = [ + 1.0 / sqrt( 4 ), + 1.0 / sqrt( 2 ), + 1.0 / sqrt( 6 ), + 1.0 / sqrt( 12 ), + 1.0 / sqrt( 4 ), + -1.0 / sqrt( 2 ), + 1.0 / sqrt( 6 ), + 1.0 / sqrt( 12 ), + 1.0 / sqrt( 4 ), + 0.0, + -2.0 / sqrt( 6 ), + 1.0 / sqrt( 12 ), + 1.0 / sqrt( 4 ), + 0.0, + 0.0, + -3.0 * ( 1.0 / sqrt( 12 ) ) + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a Helmert matrix (column-major, full=true, accessors)', function test( t ) { + var expected; + var out; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + ghelmert( true, 4, toAccessorArray( out ), 1, 4, 0 ); + + expected = [ + 1.0 / sqrt( 4 ), + 1.0 / sqrt( 2 ), + 1.0 / sqrt( 6 ), + 1.0 / sqrt( 12 ), + 1.0 / sqrt( 4 ), + -1.0 / sqrt( 2 ), + 1.0 / sqrt( 6 ), + 1.0 / sqrt( 12 ), + 1.0 / sqrt( 4 ), + 0.0, + -2.0 / sqrt( 6 ), + 1.0 / sqrt( 12 ), + 1.0 / sqrt( 4 ), + 0.0, + 0.0, + -3.0 * ( 1.0 / sqrt( 12 ) ) + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a Helmert matrix (column-major, full=false)', function test( t ) { + var expected; + var out; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + ghelmert( false, 4, out, 1, 3, 0 ); + + expected = [ + 1.0 / sqrt( 2 ), + 1.0 / sqrt( 6 ), + 1.0 / sqrt( 12 ), + -1.0 / sqrt( 2 ), + 1.0 / sqrt( 6 ), + 1.0 / sqrt( 12 ), + 0.0, + -2.0 / sqrt( 6 ), + 1.0 / sqrt( 12 ), + 0.0, + 0.0, + -3.0 * ( 1.0 / sqrt( 12 ) ) + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a Helmert matrix (column-major, full=false, accessors)', function test( t ) { + var expected; + var out; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + ghelmert( false, 4, toAccessorArray( out ), 1, 3, 0 ); + + expected = [ + 1.0 / sqrt( 2 ), + 1.0 / sqrt( 6 ), + 1.0 / sqrt( 12 ), + -1.0 / sqrt( 2 ), + 1.0 / sqrt( 6 ), + 1.0 / sqrt( 12 ), + 0.0, + -2.0 / sqrt( 6 ), + 1.0 / sqrt( 12 ), + 0.0, + 0.0, + -3.0 * ( 1.0 / sqrt( 12 ) ) + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'if the number of output rows is less than or equal to `0`, the function returns the output array unchanged (full=true)', function test( t ) { + var expected; + var out; + + out = [ 0.0, 0.0, 0.0, 0.0 ]; + + ghelmert( true, 0, out, 0, 1, 0 ); + + expected = [ 0.0, 0.0, 0.0, 0.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'if the number of output rows is less than or equal to `0`, the function returns the output array unchanged (full=true, accessors)', function test( t ) { + var expected; + var out; + + out = [ 0.0, 0.0, 0.0, 0.0 ]; + + ghelmert( true, 0, toAccessorArray( out ), 0, 1, 0 ); + + expected = [ 0.0, 0.0, 0.0, 0.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'if the number of output rows is less than or equal to `0`, the function returns the output array unchanged (full=false)', function test( t ) { + var expected; + var out; + + out = [ 0.0, 0.0, 0.0, 0.0 ]; + + ghelmert( false, 1, out, 0, 1, 0 ); + + expected = [ 0.0, 0.0, 0.0, 0.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'if the number of output rows is less than or equal to `0`, the function returns the output array unchanged (full=false, accessors)', function test( t ) { + var expected; + var out; + + out = [ 0.0, 0.0, 0.0, 0.0 ]; + + ghelmert( false, 1, toAccessorArray( out ), 0, 1, 0 ); + + expected = [ 0.0, 0.0, 0.0, 0.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the output matrix', function test( t ) { + var out; + var v; + + out = [ 0.0, 0.0, 0.0, 0.0 ]; + + v = ghelmert( true, 2, out, 2, 1, 0 ); + + t.strictEqual( v, out, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the output matrix (accessors)', function test( t ) { + var out; + var v; + + out = toAccessorArray( [ 0.0, 0.0, 0.0, 0.0 ] ); + + v = ghelmert( true, 2, out, 2, 1, 0 ); + + t.strictEqual( v, out, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying output strides (row-major, full=true)', function test( t ) { + var expected; + var out; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + ghelmert( true, 2, out, 5, 1, 0 ); + + expected = [ + 1.0 / sqrt( 2 ), + 1.0 / sqrt( 2 ), + 0.0, + 0.0, + 0.0, + 1.0 / sqrt( 2 ), + -1.0 / sqrt( 2 ), + 0.0, + 0.0, + 0.0 + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying output strides (row-major, full=true, accessors)', function test( t ) { + var expected; + var out; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + ghelmert( true, 2, toAccessorArray( out ), 5, 1, 0 ); + + expected = [ + 1.0 / sqrt( 2 ), + 1.0 / sqrt( 2 ), + 0.0, + 0.0, + 0.0, + 1.0 / sqrt( 2 ), + -1.0 / sqrt( 2 ), + 0.0, + 0.0, + 0.0 + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying output strides (column-major, full=true)', function test( t ) { + var expected; + var out; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + ghelmert( true, 2, out, 1, 5, 0 ); + + expected = [ + 1.0 / sqrt( 2 ), + 1.0 / sqrt( 2 ), + 0.0, + 0.0, + 0.0, + 1.0 / sqrt( 2 ), + -1.0 / sqrt( 2 ), + 0.0, + 0.0, + 0.0 + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying output strides (column-major, full=true, accessors)', function test( t ) { + var expected; + var out; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + ghelmert( true, 2, toAccessorArray( out ), 1, 5, 0 ); + + expected = [ + 1.0 / sqrt( 2 ), + 1.0 / sqrt( 2 ), + 0.0, + 0.0, + 0.0, + 1.0 / sqrt( 2 ), + -1.0 / sqrt( 2 ), + 0.0, + 0.0, + 0.0 + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying output strides (row-major, full=false)', function test( t ) { + var expected; + var out; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + ghelmert( false, 3, out, 5, 1, 0 ); + + expected = [ + 1.0 / sqrt( 2 ), + -1.0 / sqrt( 2 ), + 0.0, + 0.0, + 0.0, + 1.0 / sqrt( 6 ), + 1.0 / sqrt( 6 ), + -2.0 / sqrt( 6 ), + 0.0, + 0.0 + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying output strides (column-major, full=false)', function test( t ) { + var expected; + var out; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + ghelmert( false, 3, out, 1, 5, 0 ); + + expected = [ + 1.0 / sqrt( 2 ), + 1.0 / sqrt( 6 ), + 0.0, + 0.0, + 0.0, + -1.0 / sqrt( 2 ), + 1.0 / sqrt( 6 ), + 0.0, + 0.0, + 0.0, + 0.0, + -2.0 / sqrt( 6 ), + 0.0, + 0.0, + 0.0 + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying an offset for `out` (full=false)', function test( t ) { + var expected; + var out; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + ghelmert( false, 3, out, 3, 1, 1 ); + + expected = [ + 0.0, + 1.0 / sqrt( 2 ), + -1.0 / sqrt( 2 ), + 0.0, + 1.0 / sqrt( 6 ), + 1.0 / sqrt( 6 ), + -2.0 / sqrt( 6 ) + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying negative output strides (row-major, full=true)', function test( t ) { + var expected; + var out; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + ghelmert( true, 2, out, -2, -1, 3 ); + + expected = [ + -1.0 / sqrt( 2 ), + 1.0 / sqrt( 2 ), + 1.0 / sqrt( 2 ), + 1.0 / sqrt( 2 ) + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying negative output strides (row-major, full=true, accessors)', function test( t ) { + var expected; + var out; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + ghelmert( true, 2, toAccessorArray( out ), -2, -1, 3 ); + + expected = [ + -1.0 / sqrt( 2 ), + 1.0 / sqrt( 2 ), + 1.0 / sqrt( 2 ), + 1.0 / sqrt( 2 ) + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying an offset for `out`', function test( t ) { + var expected; + var out; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + ghelmert( true, 2, out, 2, 1, 1 ); + + expected = [ + 0.0, + 1.0 / sqrt( 2 ), + 1.0 / sqrt( 2 ), + 1.0 / sqrt( 2 ), + -1.0 / sqrt( 2 ) + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying an offset for `out` (accessors)', function test( t ) { + var expected; + var out; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + ghelmert( true, 2, toAccessorArray( out ), 2, 1, 1 ); + + expected = [ + 0.0, + 1.0 / sqrt( 2 ), + 1.0 / sqrt( 2 ), + 1.0 / sqrt( 2 ), + -1.0 / sqrt( 2 ) + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports complex access patterns', function test( t ) { + var expected; + var out; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + ghelmert( true, 2, out, 3, 1, 1 ); + + expected = [ + 0.0, + 1.0 / sqrt( 2 ), + 1.0 / sqrt( 2 ), + 0.0, + 1.0 / sqrt( 2 ), + -1.0 / sqrt( 2 ), + 0.0 + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports complex access patterns (accessors)', function test( t ) { + var expected; + var out; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + ghelmert( true, 2, toAccessorArray( out ), 3, 1, 1 ); + + expected = [ + 0.0, + 1.0 / sqrt( 2 ), + 1.0 / sqrt( 2 ), + 0.0, + 1.0 / sqrt( 2 ), + -1.0 / sqrt( 2 ), + 0.0 + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); From f1298644a5b2aa659f5a873e2b7923f6dacdd7ca Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sat, 17 Oct 2026 15:25:44 +0500 Subject: [PATCH 2/4] fix: lint err --- .../@stdlib/blas/ext/base/ghelmert/docs/repl.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ghelmert/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ghelmert/docs/repl.txt index e6b538bfb8ab..cd0c070711ed 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ghelmert/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/ghelmert/docs/repl.txt @@ -34,14 +34,14 @@ Examples -------- // Standard usage: - > var out = new {{alias:@stdlib/array/float64}}( 9 ); + > var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; > {{alias}}( 'row-major', true, 3, out, 3 ) - [ ~0.577, ~0.577, ~0.577, ~0.707, ~-0.707, 0.0, ~0.408, ~0.408, ~-0.816 ] + [ ~0.577, ~0.577, ~0.577, ~0.707, ~-0.707, 0.0, ~0.408, ~0.408, ~-0.816 ] // Excluding the first row: - > out = new {{alias:@stdlib/array/float64}}( 6 ); + > out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; > {{alias}}( 'row-major', false, 3, out, 3 ) - [ ~0.707, ~-0.707, 0.0, ~0.408, ~0.408, ~-0.816 ] + [ ~0.707, ~-0.707, 0.0, ~0.408, ~0.408, ~-0.816 ] {{alias}}.ndarray( full, N, out, so1, so2, oo ) From 2e0d983c6342ff21b931e5904471b8b7f4da2fe4 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sat, 17 Oct 2026 15:33:59 +0500 Subject: [PATCH 3/4] fix: lint err --- .../@stdlib/blas/ext/base/ghelmert/docs/repl.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ghelmert/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ghelmert/docs/repl.txt index cd0c070711ed..9acabe021492 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ghelmert/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/ghelmert/docs/repl.txt @@ -88,9 +88,9 @@ [ ~0.577, ~0.577, ~0.577, ~0.707, ~-0.707, 0.0, ~0.408, ~0.408, ~-0.816 ] // Using an index offset: - > out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; - > {{alias}}.ndarray( true, 3, out, 3, 1, 1 ) - [ 0.0, ~0.577, ~0.577, ~0.577, ~0.707, ~-0.707, 0.0, ~0.408, ~0.408, ~-0.816 ] + > out = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + > {{alias}}.ndarray( true, 2, out, 2, 1, 1 ) + [ 0.0, ~0.707, ~0.707, ~0.707, ~-0.707 ] See Also -------- From 71af9ea9f7d3c4829aef7393b27229f0a8649aea Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sun, 18 Oct 2026 18:13:47 +0500 Subject: [PATCH 4/4] refactor: implementation --- .../blas/ext/base/ghelmert/lib/accessors.js | 18 ++++++++++----- .../blas/ext/base/ghelmert/lib/ndarray.js | 22 +++++++++++-------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ghelmert/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/ghelmert/lib/accessors.js index 3797f1f6fd23..fc8e5e3725d0 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ghelmert/lib/accessors.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ghelmert/lib/accessors.js @@ -49,6 +49,7 @@ var sqrt = require( '@stdlib/math/base/special/sqrt' ); function ghelmert( full, N, out, strideOut1, strideOut2, offsetOut ) { var obuf; var oset; + var do1; var io; var v; var i; @@ -57,27 +58,32 @@ function ghelmert( full, N, out, strideOut1, strideOut2, offsetOut ) { obuf = out.data; oset = out.accessors[ 1 ]; + do1 = strideOut1 - ( N*strideOut2 ); io = offsetOut; // If full, write the first row with all elements equal to 1/sqrt(N)... if ( full ) { v = 1.0 / sqrt( N ); for ( j = 0; j < N; j++ ) { - oset( obuf, io + (j*strideOut2), v ); + oset( obuf, io, v ); + io += strideOut2; } - io += strideOut1; + io += do1; } // For the remaining rows, compute the sub-diagonal Helmert rows... for ( i = 1; i < N; i++ ) { v = 1.0 / sqrt( i * (i+1) ); for ( j = 0; j < i; j++ ) { - oset( obuf, io + (j*strideOut2), v ); + oset( obuf, io, v ); + io += strideOut2; } - oset( obuf, io + (i*strideOut2), -i * v ); + oset( obuf, io, -i * v ); + io += strideOut2; for ( j = i + 1; j < N; j++ ) { - oset( obuf, io + (j*strideOut2), 0.0 ); + oset( obuf, io, 0.0 ); + io += strideOut2; } - io += strideOut1; + io += do1; } return out; } diff --git a/lib/node_modules/@stdlib/blas/ext/base/ghelmert/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/ghelmert/lib/ndarray.js index 31d151d1e1bc..0cc78474f3ba 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ghelmert/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ghelmert/lib/ndarray.js @@ -51,15 +51,14 @@ var accessors = require( './accessors.js' ); * // out => [ ~0.707, ~-0.707, 0.0, ~0.408, ~0.408, ~-0.816 ] */ function ghelmert( full, N, out, strideOut1, strideOut2, offsetOut ) { + var do1; var oo; var io; var v; - var M; var i; var j; - M = ( full ) ? N : N - 1; - if ( M <= 0 ) { + if ( N <= 0 || ( !full && N <= 1 ) ) { return out; } oo = arraylike2object( out ); @@ -67,27 +66,32 @@ function ghelmert( full, N, out, strideOut1, strideOut2, offsetOut ) { accessors( full, N, oo, strideOut1, strideOut2, offsetOut ); return out; } + do1 = strideOut1 - ( N*strideOut2 ); io = offsetOut; // If full, write the first row with all elements equal to 1/sqrt(N)... if ( full ) { v = 1.0 / sqrt( N ); for ( j = 0; j < N; j++ ) { - out[ io + (j*strideOut2) ] = v; + out[ io ] = v; + io += strideOut2; } - io += strideOut1; + io += do1; } // For the remaining rows, compute the sub-diagonal Helmert rows... for ( i = 1; i < N; i++ ) { v = 1.0 / sqrt( i * (i+1) ); for ( j = 0; j < i; j++ ) { - out[ io + (j*strideOut2) ] = v; + out[ io ] = v; + io += strideOut2; } - out[ io + (i*strideOut2) ] = -i * v; + out[ io ] = -i * v; + io += strideOut2; for ( j = i + 1; j < N; j++ ) { - out[ io + (j*strideOut2) ] = 0.0; + out[ io ] = 0.0; + io += strideOut2; } - io += strideOut1; + io += do1; } return out; }