From 4954a9ed4dbe1a28a5a2ae87f707634d8441b5c8 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Fri, 16 Oct 2026 23:10:02 +0500 Subject: [PATCH] feat: add blas/ext/base/ghilbert --- .../@stdlib/blas/ext/base/ghilbert/README.md | 171 +++++++++ .../ext/base/ghilbert/benchmark/benchmark.js | 103 ++++++ .../ghilbert/benchmark/benchmark.ndarray.js | 103 ++++++ .../blas/ext/base/ghilbert/docs/repl.txt | 83 +++++ .../ext/base/ghilbert/docs/types/index.d.ts | 97 ++++++ .../blas/ext/base/ghilbert/docs/types/test.ts | 184 ++++++++++ .../blas/ext/base/ghilbert/examples/index.js | 34 ++ .../blas/ext/base/ghilbert/lib/accessors.js | 69 ++++ .../blas/ext/base/ghilbert/lib/index.js | 57 +++ .../blas/ext/base/ghilbert/lib/main.js | 79 +++++ .../blas/ext/base/ghilbert/lib/ndarray.js | 75 ++++ .../blas/ext/base/ghilbert/package.json | 69 ++++ .../blas/ext/base/ghilbert/test/test.js | 38 ++ .../blas/ext/base/ghilbert/test/test.main.js | 326 ++++++++++++++++++ .../ext/base/ghilbert/test/test.ndarray.js | 287 +++++++++++++++ 15 files changed, 1775 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ghilbert/README.md create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ghilbert/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ghilbert/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ghilbert/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ghilbert/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ghilbert/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ghilbert/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ghilbert/lib/accessors.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ghilbert/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ghilbert/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ghilbert/lib/ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ghilbert/package.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ghilbert/test/test.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ghilbert/test/test.main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ghilbert/test/test.ndarray.js diff --git a/lib/node_modules/@stdlib/blas/ext/base/ghilbert/README.md b/lib/node_modules/@stdlib/blas/ext/base/ghilbert/README.md new file mode 100644 index 000000000000..3ab3190f1269 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ghilbert/README.md @@ -0,0 +1,171 @@ + + +# ghilbert + +> Generate a Hilbert matrix. + +
+ +
+ + + +
+ +## Usage + +```javascript +var ghilbert = require( '@stdlib/blas/ext/base/ghilbert' ); +``` + +#### ghilbert( order, N, out, ldo ) + +Generates a Hilbert matrix. + +```javascript +var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + +ghilbert( 'row-major', 3, out, 3 ); +// out => [ 1.0, 0.5, ~0.3333, 0.5, ~0.3333, 0.25, ~0.3333, 0.25, 0.2 ] +``` + +The function has the following parameters: + +- **order**: row-major (C-style) or column-major (Fortran-style) order. +- **N**: number of rows and columns of the output matrix. +- **out**: output matrix. +- **ldo**: stride between successive contiguous vectors of the matrix `out` (a.k.a., leading dimension of the matrix `out`). Must be greater than or equal to `max(1,N)`. + +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, 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 ); + +ghilbert( 'row-major', 3, out1, 3 ); +// out0 => [ 0.0, 1.0, 0.5, ~0.3333, 0.5, ~0.3333, 0.25, ~0.3333, 0.25, 0.2 ] +``` + +#### ghilbert.ndarray( N, out, strideOut1, strideOut2, offsetOut ) + +Generates a Hilbert 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 ]; + +ghilbert.ndarray( 3, out, 3, 1, 0 ); +// out => [ 1.0, 0.5, ~0.3333, 0.5, ~0.3333, 0.25, ~0.3333, 0.25, 0.2 ] +``` + +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, 0.0, 0.0, 0.0 ]; + +ghilbert.ndarray( 3, out, 3, 1, 1 ); +// out => [ 0.0, 1.0, 0.5, ~0.3333, 0.5, ~0.3333, 0.25, ~0.3333, 0.25, 0.2 ] +``` + +
+ + + +
+ +## Notes + +- If `N <= 0`, both functions return `out` unchanged. +- Each element of the output matrix is equal to `1/(i+j+1)`, where `i` and `j` denote the (zero-based) row and column indices, respectively. +- 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 ghilbert = require( '@stdlib/blas/ext/base/ghilbert' ); + +var N = 4; +var order = 'row-major'; +var shape = [ N, N ]; +var strides = shape2strides( shape, order ); + +var out = zeros( N*N, 'generic' ); + +ghilbert( order, N, out, N ); +console.log( ndarray2array( out, shape, strides, 0, order ) ); +``` + +
+ + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/ghilbert/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/ghilbert/benchmark/benchmark.js new file mode 100644 index 000000000000..bbab28aa5e9d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ghilbert/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 ghilbert = 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 = ghilbert( 'row-major', 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 = 1; // 10^min + max = 3; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ghilbert/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/ghilbert/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..82cd65b99d6a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ghilbert/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 ghilbert = 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 = ghilbert( 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 = 1; // 10^min + max = 3; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:ndarray:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ghilbert/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ghilbert/docs/repl.txt new file mode 100644 index 000000000000..bd7bce19c1ab --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ghilbert/docs/repl.txt @@ -0,0 +1,83 @@ + +{{alias}}( order, N, out, ldo ) + Generates a Hilbert matrix. + + If `N` is less than or equal to `0`, the function returns `out` unchanged. + + Parameters + ---------- + order: string + Storage layout. + + N: integer + Number of rows and columns of the output matrix. + + out: ArrayLikeObject + Output array. + + ldo: integer + Stride length between successive contiguous vectors of the matrix + `out` (a.k.a., leading dimension of `out`). Must be greater than or + equal to `max(1,N)`. + + 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}}( 'row-major', 3, out, 3 ) + [ 1.0, 0.5, ~0.3333, 0.5, ~0.3333, 0.25, ~0.3333, 0.25, 0.2 ] + + // Using a leading dimension greater than `N`: + > out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + > {{alias}}( 'row-major', 2, out, 3 ) + [ 1.0, 0.5, 0.0, 0.5, ~0.3333, 0.0 ] + + +{{alias}}.ndarray( N, out, so1, so2, oo ) + Generates a Hilbert matrix using alternative indexing semantics. + + 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 + ---------- + N: integer + Number of rows and columns of the output 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( 3, out, 3, 1, 0 ) + [ 1.0, 0.5, ~0.3333, 0.5, ~0.3333, 0.25, ~0.3333, 0.25, 0.2 ] + + // Using an index offset: + > out = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + > {{alias}}.ndarray( 2, out, 2, 1, 1 ) + [ 0.0, 1.0, 0.5, 0.5, ~0.3333 ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/blas/ext/base/ghilbert/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ghilbert/docs/types/index.d.ts new file mode 100644 index 000000000000..f914f6d822e3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ghilbert/docs/types/index.d.ts @@ -0,0 +1,97 @@ +/* +* @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 `ghilbert`. +*/ +interface Routine { + /** + * Generates a Hilbert matrix. + * + * @param order - storage layout + * @param N - number of rows and columns of the output 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 ]; + * + * ghilbert( 'row-major', 3, out, 3 ); + * // out => [ 1.0, 0.5, ~0.3333, 0.5, ~0.3333, 0.25, ~0.3333, 0.25, 0.2 ] + */ + = OutputArray>( order: Layout, N: number, out: V, ldo: number ): V; + + /** + * Generates a Hilbert matrix using alternative indexing semantics. + * + * @param N - number of rows and columns of the output 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 ]; + * + * ghilbert.ndarray( 3, out, 3, 1, 0 ); + * // out => [ 1.0, 0.5, ~0.3333, 0.5, ~0.3333, 0.25, ~0.3333, 0.25, 0.2 ] + */ + ndarray = OutputArray>( N: number, out: V, strideOut1: number, strideOut2: number, offsetOut: number ): V; +} + +/** +* Generates a Hilbert matrix. +* +* @param order - storage layout +* @param N - number of rows and columns of the output 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 ]; +* +* ghilbert( 'row-major', 3, out, 3 ); +* // out => [ 1.0, 0.5, ~0.3333, 0.5, ~0.3333, 0.25, ~0.3333, 0.25, 0.2 ] +* +* @example +* var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* ghilbert.ndarray( 3, out, 3, 1, 0 ); +* // out => [ 1.0, 0.5, ~0.3333, 0.5, ~0.3333, 0.25, ~0.3333, 0.25, 0.2 ] +*/ +declare var ghilbert: Routine; + + +// EXPORTS // + +export = ghilbert; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ghilbert/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/ghilbert/docs/types/test.ts new file mode 100644 index 000000000000..1b8f666aec61 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ghilbert/docs/types/test.ts @@ -0,0 +1,184 @@ +/* +* @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 ghilbert = require( './index' ); + + +// TESTS // + +// The function returns a collection... +{ + const out = new Float64Array( 9 ); + + ghilbert( 'row-major', 3, out, 3 ); // $ExpectType Float64Array + ghilbert( 'row-major', 3, new AccessorArray( out ), 3 ); // $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( 9 ); + + ghilbert( 10, 3, out, 3 ); // $ExpectError + ghilbert( true, 3, out, 3 ); // $ExpectError + ghilbert( false, 3, out, 3 ); // $ExpectError + ghilbert( null, 3, out, 3 ); // $ExpectError + ghilbert( undefined, 3, out, 3 ); // $ExpectError + ghilbert( [], 3, out, 3 ); // $ExpectError + ghilbert( {}, 3, out, 3 ); // $ExpectError + ghilbert( ( x: number ): number => x, 3, out, 3 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a number... +{ + const out = new Float64Array( 9 ); + + ghilbert( 'row-major', '10', out, 3 ); // $ExpectError + ghilbert( 'row-major', true, out, 3 ); // $ExpectError + ghilbert( 'row-major', false, out, 3 ); // $ExpectError + ghilbert( 'row-major', null, out, 3 ); // $ExpectError + ghilbert( 'row-major', undefined, out, 3 ); // $ExpectError + ghilbert( 'row-major', [], out, 3 ); // $ExpectError + ghilbert( 'row-major', {}, out, 3 ); // $ExpectError + ghilbert( 'row-major', ( x: number ): number => x, out, 3 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a collection... +{ + ghilbert( 'row-major', 3, 10, 3 ); // $ExpectError + ghilbert( 'row-major', 3, true, 3 ); // $ExpectError + ghilbert( 'row-major', 3, false, 3 ); // $ExpectError + ghilbert( 'row-major', 3, null, 3 ); // $ExpectError + ghilbert( 'row-major', 3, undefined, 3 ); // $ExpectError + ghilbert( 'row-major', 3, {}, 3 ); // $ExpectError + ghilbert( 'row-major', 3, ( x: number ): number => x, 3 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a number... +{ + const out = new Float64Array( 9 ); + + ghilbert( 'row-major', 3, out, '10' ); // $ExpectError + ghilbert( 'row-major', 3, out, true ); // $ExpectError + ghilbert( 'row-major', 3, out, false ); // $ExpectError + ghilbert( 'row-major', 3, out, null ); // $ExpectError + ghilbert( 'row-major', 3, out, undefined ); // $ExpectError + ghilbert( 'row-major', 3, out, [] ); // $ExpectError + ghilbert( 'row-major', 3, out, {} ); // $ExpectError + ghilbert( 'row-major', 3, 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( 9 ); + + ghilbert(); // $ExpectError + ghilbert( 'row-major' ); // $ExpectError + ghilbert( 'row-major', 3 ); // $ExpectError + ghilbert( 'row-major', 3, out ); // $ExpectError + ghilbert( 'row-major', 3, out, 3, 10 ); // $ExpectError +} + +// Attached to the main export is an `ndarray` method which returns a collection... +{ + const out = new Float64Array( 9 ); + + ghilbert.ndarray( 3, out, 3, 1, 0 ); // $ExpectType Float64Array + ghilbert.ndarray( 3, new AccessorArray( out ), 3, 1, 0 ); // $ExpectType AccessorArray +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const out = new Float64Array( 9 ); + + ghilbert.ndarray( '10', out, 3, 1, 0 ); // $ExpectError + ghilbert.ndarray( true, out, 3, 1, 0 ); // $ExpectError + ghilbert.ndarray( false, out, 3, 1, 0 ); // $ExpectError + ghilbert.ndarray( null, out, 3, 1, 0 ); // $ExpectError + ghilbert.ndarray( undefined, out, 3, 1, 0 ); // $ExpectError + ghilbert.ndarray( [], out, 3, 1, 0 ); // $ExpectError + ghilbert.ndarray( {}, out, 3, 1, 0 ); // $ExpectError + ghilbert.ndarray( ( x: number ): number => x, out, 3, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a collection... +{ + ghilbert.ndarray( 3, 10, 3, 1, 0 ); // $ExpectError + ghilbert.ndarray( 3, true, 3, 1, 0 ); // $ExpectError + ghilbert.ndarray( 3, false, 3, 1, 0 ); // $ExpectError + ghilbert.ndarray( 3, null, 3, 1, 0 ); // $ExpectError + ghilbert.ndarray( 3, undefined, 3, 1, 0 ); // $ExpectError + ghilbert.ndarray( 3, {}, 3, 1, 0 ); // $ExpectError + ghilbert.ndarray( 3, ( x: number ): number => x, 3, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a number... +{ + const out = new Float64Array( 9 ); + + ghilbert.ndarray( 3, out, '10', 1, 0 ); // $ExpectError + ghilbert.ndarray( 3, out, true, 1, 0 ); // $ExpectError + ghilbert.ndarray( 3, out, false, 1, 0 ); // $ExpectError + ghilbert.ndarray( 3, out, null, 1, 0 ); // $ExpectError + ghilbert.ndarray( 3, out, undefined, 1, 0 ); // $ExpectError + ghilbert.ndarray( 3, out, [], 1, 0 ); // $ExpectError + ghilbert.ndarray( 3, out, {}, 1, 0 ); // $ExpectError + ghilbert.ndarray( 3, out, ( x: number ): number => x, 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( 9 ); + + ghilbert.ndarray( 3, out, 3, '10', 0 ); // $ExpectError + ghilbert.ndarray( 3, out, 3, true, 0 ); // $ExpectError + ghilbert.ndarray( 3, out, 3, false, 0 ); // $ExpectError + ghilbert.ndarray( 3, out, 3, null, 0 ); // $ExpectError + ghilbert.ndarray( 3, out, 3, undefined, 0 ); // $ExpectError + ghilbert.ndarray( 3, out, 3, [], 0 ); // $ExpectError + ghilbert.ndarray( 3, out, 3, {}, 0 ); // $ExpectError + ghilbert.ndarray( 3, out, 3, ( x: number ): number => x, 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( 9 ); + + ghilbert.ndarray( 3, out, 3, 1, '10' ); // $ExpectError + ghilbert.ndarray( 3, out, 3, 1, true ); // $ExpectError + ghilbert.ndarray( 3, out, 3, 1, false ); // $ExpectError + ghilbert.ndarray( 3, out, 3, 1, null ); // $ExpectError + ghilbert.ndarray( 3, out, 3, 1, undefined ); // $ExpectError + ghilbert.ndarray( 3, out, 3, 1, [] ); // $ExpectError + ghilbert.ndarray( 3, out, 3, 1, {} ); // $ExpectError + ghilbert.ndarray( 3, out, 3, 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( 9 ); + + ghilbert.ndarray(); // $ExpectError + ghilbert.ndarray( 3 ); // $ExpectError + ghilbert.ndarray( 3, out ); // $ExpectError + ghilbert.ndarray( 3, out, 3 ); // $ExpectError + ghilbert.ndarray( 3, out, 3, 1 ); // $ExpectError + ghilbert.ndarray( 3, out, 3, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ghilbert/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/ghilbert/examples/index.js new file mode 100644 index 000000000000..bb951181289d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ghilbert/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 ghilbert = require( './../lib' ); + +var N = 4; +var order = 'row-major'; +var shape = [ N, N ]; +var strides = shape2strides( shape, order ); + +var out = zeros( N*N, 'generic' ); + +ghilbert( order, N, out, N ); +console.log( ndarray2array( out, shape, strides, 0, order ) ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ghilbert/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/ghilbert/lib/accessors.js new file mode 100644 index 000000000000..019e11e5512f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ghilbert/lib/accessors.js @@ -0,0 +1,69 @@ +/** +* @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'; + +// MAIN // + +/** +* Generates a Hilbert matrix using accessor arrays. +* +* @private +* @param {NonNegativeInteger} N - number of rows and columns of the output 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 ]; +* +* ghilbert( 3, arraylike2object( toAccessorArray( out ) ), 3, 1, 0 ); +* // out => [ 1.0, 0.5, ~0.3333, 0.5, ~0.3333, 0.25, ~0.3333, 0.25, 0.2 ] +*/ +function ghilbert( N, out, strideOut1, strideOut2, offsetOut ) { + var obuf; + var oset; + var io; + var ij; + var i; + var j; + + obuf = out.data; + oset = out.accessors[ 1 ]; + + io = offsetOut; + for ( i = 0; i < N; i++ ) { + ij = io; + for ( j = 0; j < N; j++ ) { + oset( obuf, ij, 1.0 / ( i + j + 1 ) ); + ij += strideOut2; + } + io += strideOut1; + } + return out; +} + + +// EXPORTS // + +module.exports = ghilbert; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ghilbert/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/ghilbert/lib/index.js new file mode 100644 index 000000000000..4822a18fb702 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ghilbert/lib/index.js @@ -0,0 +1,57 @@ +/** +* @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 Hilbert matrix. +* +* @module @stdlib/blas/ext/base/ghilbert +* +* @example +* var ghilbert = require( '@stdlib/blas/ext/base/ghilbert' ); +* +* var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* ghilbert( 'row-major', 3, out, 3 ); +* // out => [ 1.0, 0.5, ~0.3333, 0.5, ~0.3333, 0.25, ~0.3333, 0.25, 0.2 ] +* +* @example +* var ghilbert = require( '@stdlib/blas/ext/base/ghilbert' ); +* +* var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* ghilbert.ndarray( 3, out, 3, 1, 0 ); +* // out => [ 1.0, 0.5, ~0.3333, 0.5, ~0.3333, 0.25, ~0.3333, 0.25, 0.2 ] +*/ + +// 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/ghilbert/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/ghilbert/lib/main.js new file mode 100644 index 000000000000..9625bcf8e61c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ghilbert/lib/main.js @@ -0,0 +1,79 @@ +/** +* @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 Hilbert matrix. +* +* @param {(integer|string)} order - storage layout +* @param {NonNegativeInteger} N - number of rows and columns of the output 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} fourth 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 ]; +* +* ghilbert( 'row-major', 3, out, 3 ); +* // out => [ 1.0, 0.5, ~0.3333, 0.5, ~0.3333, 0.25, ~0.3333, 0.25, 0.2 ] +*/ +function ghilbert( order, N, out, ldo ) { + var iscm; + var sa1; + var sa2; + var l; + + l = resolveLayout( order ); + if ( l === null ) { + throw new TypeError( format( 'invalid argument. First argument must be a valid order. Value: `%s`.', order ) ); + } + if ( ldo < max( 1, N ) ) { + throw new RangeError( format( 'invalid argument. Fourth argument must be greater than or equal to max(1,%d). Value: `%d`.', N, ldo ) ); + } + if ( N <= 0 ) { + return out; + } + iscm = isColumnMajor( l ); + if ( iscm ) { + sa1 = 1; + sa2 = ldo; + } else { // order === 'row-major' + sa1 = ldo; + sa2 = 1; + } + return ndarray( N, out, sa1, sa2, 0 ); +} + + +// EXPORTS // + +module.exports = ghilbert; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ghilbert/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/ghilbert/lib/ndarray.js new file mode 100644 index 000000000000..561da3b6e5ec --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ghilbert/lib/ndarray.js @@ -0,0 +1,75 @@ +/** +* @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 accessors = require( './accessors.js' ); + + +// MAIN // + +/** +* Generates a Hilbert matrix using alternative indexing semantics. +* +* @param {NonNegativeInteger} N - number of rows and columns of the output 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 ]; +* +* ghilbert( 3, out, 3, 1, 0 ); +* // out => [ 1.0, 0.5, ~0.3333, 0.5, ~0.3333, 0.25, ~0.3333, 0.25, 0.2 ] +*/ +function ghilbert( N, out, strideOut1, strideOut2, offsetOut ) { + var oo; + var io; + var ij; + var i; + var j; + + if ( N <= 0 ) { + return out; + } + oo = arraylike2object( out ); + if ( oo.accessorProtocol ) { + accessors( N, oo, strideOut1, strideOut2, offsetOut ); + return out; + } + io = offsetOut; + for ( i = 0; i < N; i++ ) { + ij = io; + for ( j = 0; j < N; j++ ) { + out[ ij ] = 1.0 / ( i + j + 1 ); + ij += strideOut2; + } + io += strideOut1; + } + return out; +} + + +// EXPORTS // + +module.exports = ghilbert; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ghilbert/package.json b/lib/node_modules/@stdlib/blas/ext/base/ghilbert/package.json new file mode 100644 index 000000000000..d8d94ee26728 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ghilbert/package.json @@ -0,0 +1,69 @@ +{ + "name": "@stdlib/blas/ext/base/ghilbert", + "version": "0.0.0", + "description": "Generate a Hilbert 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", + "hilbert", + "matrix", + "strided", + "strided array", + "typed", + "array", + "ndarray", + "vector", + "ghilbert" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ghilbert/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/ghilbert/test/test.js new file mode 100644 index 000000000000..45562b480f4e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ghilbert/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 ghilbert = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ghilbert, '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 ghilbert.ndarray, 'function', 'method is a function' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ghilbert/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/ghilbert/test/test.main.js new file mode 100644 index 000000000000..5c1022335b22 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ghilbert/test/test.main.js @@ -0,0 +1,326 @@ +/** +* @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 ghilbert = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ghilbert, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 4', function test( t ) { + t.strictEqual( ghilbert.length, 4, '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() { + ghilbert( value, 3, [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 3 ); // eslint-disable-line max-len + }; + } +}); + +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() { + ghilbert( value, 3, toAccessorArray( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ), 3 ); // eslint-disable-line max-len + }; + } +}); + +tape( 'the function throws an error if provided an invalid fourth argument', function test( t ) { + var values; + var i; + + values = [ + -3, + -2, + -1, + 0, + 1, + 2 + ]; + + 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() { + ghilbert( 'row-major', 3, [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], value ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid fourth argument (accessors)', function test( t ) { + var values; + var i; + + values = [ + -3, + -2, + -1, + 0, + 1, + 2 + ]; + + 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() { + ghilbert( 'row-major', 3, toAccessorArray( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ), value ); + }; + } +}); + +tape( 'if provided an `N` less than or equal to `0`, the function returns the output array unchanged', 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 ]; + + ghilbert( 'row-major', 0, out, 1 ); + + expected = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided an `N` less than or equal to `0`, the function returns the output array unchanged (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 ]; + + ghilbert( 'row-major', 0, toAccessorArray( out ), 1 ); + + expected = [ 0.0, 0.0, 0.0, 0.0, 0.0, 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, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + v = ghilbert( 'row-major', 3, out, 3 ); + + 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, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + v = ghilbert( 'row-major', 3, out, 3 ); + + t.strictEqual( v, out, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a Hilbert matrix (row-major)', 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 ]; + + ghilbert( 'row-major', 3, out, 3 ); + + expected = [ 1.0, 0.5, 1.0/3.0, 0.5, 1.0/3.0, 0.25, 1.0/3.0, 0.25, 0.2 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a Hilbert matrix (row-major, 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 ]; + + ghilbert( 'row-major', 3, toAccessorArray( out ), 3 ); + + expected = [ 1.0, 0.5, 1.0/3.0, 0.5, 1.0/3.0, 0.25, 1.0/3.0, 0.25, 0.2 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a Hilbert matrix (column-major)', 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 ]; + + ghilbert( 'column-major', 3, out, 3 ); + + expected = [ 1.0, 0.5, 1.0/3.0, 0.5, 1.0/3.0, 0.25, 1.0/3.0, 0.25, 0.2 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a Hilbert matrix (column-major, 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 ]; + + ghilbert( 'column-major', 3, toAccessorArray( out ), 3 ); + + expected = [ 1.0, 0.5, 1.0/3.0, 0.5, 1.0/3.0, 0.25, 1.0/3.0, 0.25, 0.2 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a leading dimension for the output matrix (row-major)', 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 ]; + + ghilbert( 'row-major', 3, out, 4 ); + + expected = [ 1.0, 0.5, 1.0/3.0, 0.0, 0.5, 1.0/3.0, 0.25, 0.0, 1.0/3.0, 0.25, 0.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, 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 ]; + + ghilbert( 'row-major', 3, toAccessorArray( out ), 4 ); + + expected = [ 1.0, 0.5, 1.0/3.0, 0.0, 0.5, 1.0/3.0, 0.25, 0.0, 1.0/3.0, 0.25, 0.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)', 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 ]; + + ghilbert( 'column-major', 3, out, 4 ); + + expected = [ 1.0, 0.5, 1.0/3.0, 0.0, 0.5, 1.0/3.0, 0.25, 0.0, 1.0/3.0, 0.25, 0.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, 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 ]; + + ghilbert( 'column-major', 3, toAccessorArray( out ), 4 ); + + expected = [ 1.0, 0.5, 1.0/3.0, 0.0, 0.5, 1.0/3.0, 0.25, 0.0, 1.0/3.0, 0.25, 0.2, 0.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports view offsets', function test( t ) { + var expected; + var out0; + var out1; + + out0 = new Float64Array( 10 ); + out1 = new Float64Array( out0.buffer, out0.BYTES_PER_ELEMENT*1 ); + + ghilbert( 'row-major', 3, out1, 3 ); + + expected = new Float64Array([ + 1.0, + 0.5, + 1.0/3.0, + 0.5, + 1.0/3.0, + 0.25, + 1.0/3.0, + 0.25, + 0.2 + ]); + + t.deepEqual( out1, expected, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ghilbert/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/ghilbert/test/test.ndarray.js new file mode 100644 index 000000000000..e758e58c104e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ghilbert/test/test.ndarray.js @@ -0,0 +1,287 @@ +/** +* @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 ghilbert = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ghilbert, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 5', function test( t ) { + t.strictEqual( ghilbert.length, 5, 'has expected arity' ); + t.end(); +}); + +tape( 'the function generates a Hilbert matrix (row-major)', 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 ]; + + ghilbert( 3, out, 3, 1, 0 ); + + expected = [ 1.0, 0.5, 1.0/3.0, 0.5, 1.0/3.0, 0.25, 1.0/3.0, 0.25, 0.2 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a Hilbert matrix (row-major, 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 ]; + + ghilbert( 3, toAccessorArray( out ), 3, 1, 0 ); + + expected = [ 1.0, 0.5, 1.0/3.0, 0.5, 1.0/3.0, 0.25, 1.0/3.0, 0.25, 0.2 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a Hilbert matrix (column-major)', 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 ]; + + ghilbert( 3, out, 1, 3, 0 ); + + expected = [ 1.0, 0.5, 1.0/3.0, 0.5, 1.0/3.0, 0.25, 1.0/3.0, 0.25, 0.2 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a Hilbert matrix (column-major, 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 ]; + + ghilbert( 3, toAccessorArray( out ), 1, 3, 0 ); + + expected = [ 1.0, 0.5, 1.0/3.0, 0.5, 1.0/3.0, 0.25, 1.0/3.0, 0.25, 0.2 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided an `N` less than or equal to `0`, the function returns the output array unchanged', 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 ]; + + ghilbert( 0, out, 0, 1, 0 ); + + expected = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided an `N` less than or equal to `0`, the function returns the output array unchanged (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 ]; + + ghilbert( 0, toAccessorArray( out ), 0, 1, 0 ); + + expected = [ 0.0, 0.0, 0.0, 0.0, 0.0, 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, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + v = ghilbert( 3, out, 3, 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, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + v = ghilbert( 3, out, 3, 1, 0 ); + + t.strictEqual( v, out, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying output strides (row-major)', 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 ]; + + ghilbert( 3, out, 4, 1, 0 ); + + expected = [ 1.0, 0.5, 1.0/3.0, 0.0, 0.5, 1.0/3.0, 0.25, 0.0, 1.0/3.0, 0.25, 0.2, 0.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying output strides (row-major, 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 ]; + + ghilbert( 3, toAccessorArray( out ), 4, 1, 0 ); + + expected = [ 1.0, 0.5, 1.0/3.0, 0.0, 0.5, 1.0/3.0, 0.25, 0.0, 1.0/3.0, 0.25, 0.2, 0.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying output strides (column-major)', 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 ]; + + ghilbert( 3, out, 1, 4, 0 ); + + expected = [ 1.0, 0.5, 1.0/3.0, 0.0, 0.5, 1.0/3.0, 0.25, 0.0, 1.0/3.0, 0.25, 0.2, 0.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying output strides (column-major, 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 ]; + + ghilbert( 3, toAccessorArray( out ), 1, 4, 0 ); + + expected = [ 1.0, 0.5, 1.0/3.0, 0.0, 0.5, 1.0/3.0, 0.25, 0.0, 1.0/3.0, 0.25, 0.2, 0.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying negative output strides (row-major)', 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 ]; + + ghilbert( 3, out, -3, -1, 8 ); + + expected = [ 0.2, 0.25, 1.0/3.0, 0.25, 1.0/3.0, 0.5, 1.0/3.0, 0.5, 1.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying negative output strides (row-major, 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 ]; + + ghilbert( 3, toAccessorArray( out ), -3, -1, 8 ); + + expected = [ 0.2, 0.25, 1.0/3.0, 0.25, 1.0/3.0, 0.5, 1.0/3.0, 0.5, 1.0 ]; + + 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, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + ghilbert( 3, out, 3, 1, 1 ); + + expected = [ 0.0, 1.0, 0.5, 1.0/3.0, 0.5, 1.0/3.0, 0.25, 1.0/3.0, 0.25, 0.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, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + ghilbert( 3, toAccessorArray( out ), 3, 1, 1 ); + + expected = [ 0.0, 1.0, 0.5, 1.0/3.0, 0.5, 1.0/3.0, 0.25, 1.0/3.0, 0.25, 0.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, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + ghilbert( 3, out, 4, 1, 1 ); + + expected = [ 0.0, 1.0, 0.5, 1.0/3.0, 0.0, 0.5, 1.0/3.0, 0.25, 0.0, 1.0/3.0, 0.25, 0.2 ]; + + 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, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + ghilbert( 3, toAccessorArray( out ), 4, 1, 1 ); + + expected = [ 0.0, 1.0, 0.5, 1.0/3.0, 0.0, 0.5, 1.0/3.0, 0.25, 0.0, 1.0/3.0, 0.25, 0.2 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +});