From a631c1b91ce52117dd5da777908aa7eeb246b3a3 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Mon, 31 Aug 2026 17:43:54 +0500 Subject: [PATCH] feat: add blas/ext/base/gcauchy-matrix --- .../blas/ext/base/gcauchy-matrix/README.md | 204 +++++ .../gcauchy-matrix/benchmark/benchmark.js | 110 +++ .../benchmark/benchmark.ndarray.js | 110 +++ .../ext/base/gcauchy-matrix/docs/repl.txt | 145 ++++ .../base/gcauchy-matrix/docs/types/index.d.ts | 127 ++++ .../base/gcauchy-matrix/docs/types/test.ts | 408 ++++++++++ .../ext/base/gcauchy-matrix/examples/index.js | 39 + .../ext/base/gcauchy-matrix/lib/accessors.js | 105 +++ .../blas/ext/base/gcauchy-matrix/lib/index.js | 61 ++ .../blas/ext/base/gcauchy-matrix/lib/main.js | 95 +++ .../ext/base/gcauchy-matrix/lib/ndarray.js | 98 +++ .../blas/ext/base/gcauchy-matrix/package.json | 69 ++ .../blas/ext/base/gcauchy-matrix/test/test.js | 38 + .../ext/base/gcauchy-matrix/test/test.main.js | 707 ++++++++++++++++++ .../base/gcauchy-matrix/test/test.ndarray.js | 522 +++++++++++++ 15 files changed, 2838 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/README.md create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/lib/accessors.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/lib/ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/package.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/test/test.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/test/test.main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/test/test.ndarray.js diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/README.md b/lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/README.md new file mode 100644 index 000000000000..158c2d7bdfe2 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/README.md @@ -0,0 +1,204 @@ + + +# gcauchyMatrix + +> Generate a Cauchy matrix. + +
+ +## Usage + +```javascript +var gcauchyMatrix = require( '@stdlib/blas/ext/base/gcauchy-matrix' ); +``` + +#### gcauchyMatrix( order, M, N, x, strideX, y, strideY, out, LDO ) + +Generates a Cauchy matrix. + +```javascript +var x = [ 3.0, 5.0 ]; +var y = [ 1.0, 4.0 ]; +var out = [ 0.0, 0.0, 0.0, 0.0 ]; + +gcauchyMatrix( 'row-major', x.length, y.length, x, 1, y, 1, out, 2 ); +// out => [ 0.5, -1.0, 0.25, 1.0 ] +``` + +The function has the following parameters: + +- **order**: storage layout. Must be either `'row-major'` or `'column-major'`. +- **M**: number of indexed elements in `x`. +- **N**: number of indexed elements in `y`. +- **x**: first input [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. +- **strideX**: stride length for `x`. +- **y**: second input [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. +- **strideY**: stride length for `y`. +- **out**: output [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. +- **LDO**: stride length between successive contiguous vectors of the matrix `out` (a.k.a., leading dimension of `out`). + +The `M`, `N`, and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to generate a Cauchy matrix using every other element: + +```javascript +var x = [ 3.0, 0.0, 5.0, 0.0 ]; +var y = [ 1.0, 0.0, 4.0, 0.0 ]; +var out = [ 0.0, 0.0, 0.0, 0.0 ]; + +gcauchyMatrix( 'row-major', 2, 2, x, 2, y, 2, out, 2 ); +// out => [ 0.5, -1.0, 0.25, 1.0 ] +``` + +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 arrays: +var x0 = new Float64Array( [ 0.0, 3.0, 5.0 ] ); +var y0 = new Float64Array( [ 0.0, 1.0, 4.0 ] ); + +// Create offset views: +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element +var y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +// Output array: +var out = new Float64Array( 4 ); + +gcauchyMatrix( 'row-major', 2, 2, x1, 1, y1, 1, out, 2 ); +// out => [ 0.5, -1.0, 0.25, 1.0 ] +``` + + + +#### gcauchyMatrix.ndarray( M, N, x, strideX, offsetX, y, strideY, offsetY, out, strideOut1, strideOut2, offsetOut ) + + + +Generates a Cauchy matrix using alternative indexing semantics. + +```javascript +var x = [ 3.0, 5.0 ]; +var y = [ 1.0, 4.0 ]; +var out = [ 0.0, 0.0, 0.0, 0.0 ]; + +gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, 1, 0, out, 2, 1, 0 ); +// out => [ 0.5, -1.0, 0.25, 1.0 ] +``` + +The function has the following parameters: + +- **M**: number of indexed elements in `x`. +- **N**: number of indexed elements in `y`. +- **x**: first input [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. +- **strideX**: stride length for `x`. +- **offsetX**: starting index for `x`. +- **y**: second input [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. +- **strideY**: stride length for `y`. +- **offsetY**: starting index for `y`. +- **out**: output [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. +- **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 parameters support indexing semantics based on starting indices. For example, to access only the last two elements of `x`: + +```javascript +var x = [ 0.0, 3.0, 5.0 ]; +var y = [ 1.0, 4.0 ]; +var out = [ 0.0, 0.0, 0.0, 0.0 ]; + +gcauchyMatrix.ndarray( 2, y.length, x, 1, 1, y, 1, 0, out, 2, 1, 0 ); +// out => [ 0.5, -1.0, 0.25, 1.0 ] +``` + +
+ + + +
+ +## Notes + +- If `M <= 0` or `N <= 0`, both functions return `out` unchanged. +- A Cauchy matrix is an `M` by `N` matrix in which element `(i,j)` equals `1/(x_i-y_j)`. +- For a valid Cauchy matrix, `x_i - y_j` must not equal zero for all `(i,j)`. +- Both `x` and `y` should contain distinct elements (i.e., injective sequences). +- For input arrays of lengths `M` and `N`, the output array must contain at least `M * N` indexed elements. +- For row-major order, the `LDO` parameter must be greater than or equal to `max(1,N)`. For column-major order, the `LDO` parameter must be greater than or equal to `max(1,M)`. +- 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 uniform = require( '@stdlib/random/array/uniform' ); +var zeros = require( '@stdlib/array/zeros' ); +var gcauchyMatrix = require( '@stdlib/blas/ext/base/gcauchy-matrix' ); + +var M = 3; +var N = 2; +var x = uniform( M, 10.0, 20.0, { + 'dtype': 'generic' +}); +console.log( x ); + +var y = uniform( N, -10.0, -1.0, { + 'dtype': 'generic' +}); +console.log( y ); + +var out = zeros( M * N, 'generic' ); +gcauchyMatrix( 'row-major', M, N, x, 1, y, 1, out, N ); +console.log( out ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/benchmark/benchmark.js new file mode 100644 index 000000000000..856f9d2f5449 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/benchmark/benchmark.js @@ -0,0 +1,110 @@ +/** +* @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 uniform = require( '@stdlib/random/array/uniform' ); +var zeros = require( '@stdlib/array/zeros' ); +var isArray = require( '@stdlib/assert/is-array' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var gcauchyMatrix = 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; + var x; + var y; + + x = uniform( len, 10.0, 20.0, options ); + y = uniform( len, -10.0, -1.0, options ); + 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 = gcauchyMatrix( 'row-major', x.length, y.length, x, 1, y, 1, out, len ); + if ( !isArray( v ) ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( !isArray( v ) ) { + b.fail( 'should return an array' ); + } + 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/gcauchy-matrix/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..22161e078549 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/benchmark/benchmark.ndarray.js @@ -0,0 +1,110 @@ +/** +* @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 uniform = require( '@stdlib/random/array/uniform' ); +var zeros = require( '@stdlib/array/zeros' ); +var isArray = require( '@stdlib/assert/is-array' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var gcauchyMatrix = 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; + var x; + var y; + + x = uniform( len, 10.0, 20.0, options ); + y = uniform( len, -10.0, -1.0, options ); + 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 = gcauchyMatrix( x.length, y.length, x, 1, 0, y, 1, 0, out, len, 1, 0 ); + if ( !isArray( v ) ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( !isArray( v ) ) { + b.fail( 'should return an array' ); + } + 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/gcauchy-matrix/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/docs/repl.txt new file mode 100644 index 000000000000..9dfcb31dcdae --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/docs/repl.txt @@ -0,0 +1,145 @@ + +{{alias}}( order, M, N, x, strideX, y, strideY, out, LDO ) + Generates a Cauchy matrix. + + A Cauchy matrix is an M by N matrix in which element (i,j) equals + 1/(x_i-y_j). + + For a valid Cauchy matrix, x_i - y_j must not equal zero for all (i,j). + + Both x and y should contain distinct elements (i.e., injective sequences). + + The `M`, `N`, and stride parameters determine which elements in the strided + arrays are accessed at runtime. + + If `M <= 0` or `N <= 0`, the function returns `out` unchanged. + + Parameters + ---------- + order: string + Storage layout. + + M: integer + Number of indexed elements in `x`. + + N: integer + Number of indexed elements in `y`. + + x: ArrayLikeObject + First input array. + + strideX: integer + Stride length for `x`. + + y: ArrayLikeObject + Second input array. + + strideY: integer + Stride length for `y`. + + out: ArrayLikeObject + Output array. + + LDO: integer + Stride length between successive contiguous vectors of the matrix + `out` (a.k.a., leading dimension of `out`). For row-major order, + must be greater than or equal to `max(1,N)`. For column-major + order, must be greater than or equal to `max(1,M)`. + + Returns + ------- + out: ArrayLikeObject + Output array. + + Examples + -------- + // Standard Usage: + > var x = [ 3.0, 5.0 ]; + > var y = [ 1.0, 4.0 ]; + > var out = [ 0.0, 0.0, 0.0, 0.0 ]; + > {{alias}}( 'row-major', x.length, y.length, x, 1, y, 1, out, 2 ) + [ 0.5, -1.0, 0.25, 1.0 ] + + // Using `M`, `N`, and stride parameters: + > x = [ 3.0, 0.0, 5.0, 0.0 ]; + > y = [ 1.0, 4.0 ]; + > out = [ 0.0, 0.0, 0.0, 0.0 ]; + > {{alias}}( 'row-major', 2, y.length, x, 2, y, 1, out, 2 ) + [ 0.5, -1.0, 0.25, 1.0 ] + + +{{alias}}.ndarray( M, N, x, sx, ox, y, sy, oy, out, so1, so2, oo ) + Generates a Cauchy matrix using alternative indexing semantics. + + A Cauchy matrix is an M by N matrix in which element (i,j) equals + 1/(x_i-y_j). + + For a valid Cauchy matrix, x_i - y_j must not equal zero for all (i,j). + + Both x and y should contain distinct elements (i.e., injective sequences). + + While typed array views mandate a view offset based on the underlying + buffer, the offset parameters support indexing semantics based on + starting indices. + + Parameters + ---------- + M: integer + Number of indexed elements in `x`. + + N: integer + Number of indexed elements in `y`. + + x: ArrayLikeObject + First input array. + + sx: integer + Stride length for `x`. + + ox: integer + Starting index for `x`. + + y: ArrayLikeObject + Second input array. + + sy: integer + Stride length for `y`. + + oy: integer + Starting index for `y`. + + 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 x = [ 3.0, 5.0 ]; + > var y = [ 1.0, 4.0 ]; + > var out = [ 0.0, 0.0, 0.0, 0.0 ]; + > {{alias}}.ndarray( x.length, y.length, x, 1, 0, y, 1, 0, out, 2, 1, 0 ) + [ 0.5, -1.0, 0.25, 1.0 ] + + // Using an index offset: + > x = [ 0.0, 3.0, 5.0 ]; + > y = [ 1.0, 4.0 ]; + > out = [ 0.0, 0.0, 0.0, 0.0 ]; + > {{alias}}.ndarray( 2, y.length, x, 1, 1, y, 1, 0, out, 2, 1, 0 ) + [ 0.5, -1.0, 0.25, 1.0 ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/docs/types/index.d.ts new file mode 100644 index 000000000000..0329b6f1eb2c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/docs/types/index.d.ts @@ -0,0 +1,127 @@ +/* +* @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, NumericArray } from '@stdlib/types/array'; +import { Layout } from '@stdlib/types/blas'; + +/** +* Input array. +*/ +type InputArray = NumericArray | Collection | AccessorArrayLike; + +/** +* Output array. +*/ +type OutputArray = NumericArray | Collection | AccessorArrayLike; + +/** +* Interface describing `gcauchyMatrix`. +*/ +interface Routine { + /** + * Generates a Cauchy matrix. + * + * @param order - storage layout + * @param M - number of indexed elements in `x` + * @param N - number of indexed elements in `y` + * @param x - first input array + * @param strideX - stride length for `x` + * @param y - second input array + * @param strideY - stride length for `y` + * @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 x = [ 3.0, 5.0 ]; + * var y = [ 1.0, 4.0 ]; + * var out = [ 0.0, 0.0, 0.0, 0.0 ]; + * + * gcauchyMatrix( 'row-major', x.length, y.length, x, 1, y, 1, out, 2 ); + * // out => [ 0.5, -1.0, 0.25, 1.0 ] + */ + ( order: Layout, M: number, N: number, x: InputArray, strideX: number, y: InputArray, strideY: number, out: T, LDO: number ): T; + + /** + * Generates a Cauchy matrix using alternative indexing semantics. + * + * @param M - number of indexed elements in `x` + * @param N - number of indexed elements in `y` + * @param x - first input array + * @param strideX - stride length for `x` + * @param offsetX - starting index for `x` + * @param y - second input array + * @param strideY - stride length for `y` + * @param offsetY - starting index for `y` + * @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 x = [ 3.0, 5.0 ]; + * var y = [ 1.0, 4.0 ]; + * var out = [ 0.0, 0.0, 0.0, 0.0 ]; + * + * gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, 1, 0, out, 2, 1, 0 ); + * // out => [ 0.5, -1.0, 0.25, 1.0 ] + */ + ndarray( M: number, N: number, x: InputArray, strideX: number, offsetX: number, y: InputArray, strideY: number, offsetY: number, out: T, strideOut1: number, strideOut2: number, offsetOut: number ): T; +} + +/** +* Generates a Cauchy matrix. +* +* @param order - storage layout +* @param M - number of indexed elements in `x` +* @param N - number of indexed elements in `y` +* @param x - first input array +* @param strideX - stride length for `x` +* @param y - second input array +* @param strideY - stride length for `y` +* @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 x = [ 3.0, 5.0 ]; +* var y = [ 1.0, 4.0 ]; +* var out = [ 0.0, 0.0, 0.0, 0.0 ]; +* +* gcauchyMatrix( 'row-major', x.length, y.length, x, 1, y, 1, out, 2 ); +* // out => [ 0.5, -1.0, 0.25, 1.0 ] +* +* @example +* var x = [ 3.0, 5.0 ]; +* var y = [ 1.0, 4.0 ]; +* var out = [ 0.0, 0.0, 0.0, 0.0 ]; +* +* gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, 1, 0, out, 2, 1, 0 ); +* // out => [ 0.5, -1.0, 0.25, 1.0 ] +*/ +declare var gcauchyMatrix: Routine; + + +// EXPORTS // + +export = gcauchyMatrix; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/docs/types/test.ts new file mode 100644 index 000000000000..b8cddee47c33 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/docs/types/test.ts @@ -0,0 +1,408 @@ +/* +* @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 gcauchyMatrix = require( './index' ); + + +// TESTS // + +// The function returns a collection... +{ + const x = new Float64Array( 2 ); + const y = new Float64Array( 2 ); + const out = new Float64Array( 4 ); + + gcauchyMatrix( 'row-major', x.length, y.length, x, 1, y, 1, out, 2 ); // $ExpectType Float64Array + gcauchyMatrix( 'row-major', x.length, y.length, new AccessorArray( x ), 1, new AccessorArray( y ), 1, new AccessorArray( out ), 2 ); // $ExpectType AccessorArray +} + +// The compiler throws an error if the function is provided a first argument which is not a valid order... +{ + const x = new Float64Array( 2 ); + const y = new Float64Array( 2 ); + const out = new Float64Array( 4 ); + + gcauchyMatrix( 10, x.length, y.length, x, 1, y, 1, out, 2 ); // $ExpectError + gcauchyMatrix( true, x.length, y.length, x, 1, y, 1, out, 2 ); // $ExpectError + gcauchyMatrix( false, x.length, y.length, x, 1, y, 1, out, 2 ); // $ExpectError + gcauchyMatrix( null, x.length, y.length, x, 1, y, 1, out, 2 ); // $ExpectError + gcauchyMatrix( undefined, x.length, y.length, x, 1, y, 1, out, 2 ); // $ExpectError + gcauchyMatrix( [], x.length, y.length, x, 1, y, 1, out, 2 ); // $ExpectError + gcauchyMatrix( {}, x.length, y.length, x, 1, y, 1, out, 2 ); // $ExpectError + gcauchyMatrix( ( x: number ): number => x, x.length, y.length, x, 1, y, 1, out, 2 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a number... +{ + const x = new Float64Array( 2 ); + const y = new Float64Array( 2 ); + const out = new Float64Array( 4 ); + + gcauchyMatrix( 'row-major', '10', y.length, x, 1, y, 1, out, 2 ); // $ExpectError + gcauchyMatrix( 'row-major', true, y.length, x, 1, y, 1, out, 2 ); // $ExpectError + gcauchyMatrix( 'row-major', false, y.length, x, 1, y, 1, out, 2 ); // $ExpectError + gcauchyMatrix( 'row-major', null, y.length, x, 1, y, 1, out, 2 ); // $ExpectError + gcauchyMatrix( 'row-major', undefined, y.length, x, 1, y, 1, out, 2 ); // $ExpectError + gcauchyMatrix( 'row-major', [], y.length, x, 1, y, 1, out, 2 ); // $ExpectError + gcauchyMatrix( 'row-major', {}, y.length, x, 1, y, 1, out, 2 ); // $ExpectError + gcauchyMatrix( 'row-major', ( x: number ): number => x, y.length, x, 1, y, 1, out, 2 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a number... +{ + const x = new Float64Array( 2 ); + const y = new Float64Array( 2 ); + const out = new Float64Array( 4 ); + + gcauchyMatrix( 'row-major', x.length, '10', x, 1, y, 1, out, 2 ); // $ExpectError + gcauchyMatrix( 'row-major', x.length, true, x, 1, y, 1, out, 2 ); // $ExpectError + gcauchyMatrix( 'row-major', x.length, false, x, 1, y, 1, out, 2 ); // $ExpectError + gcauchyMatrix( 'row-major', x.length, null, x, 1, y, 1, out, 2 ); // $ExpectError + gcauchyMatrix( 'row-major', x.length, undefined, x, 1, y, 1, out, 2 ); // $ExpectError + gcauchyMatrix( 'row-major', x.length, [], x, 1, y, 1, out, 2 ); // $ExpectError + gcauchyMatrix( 'row-major', x.length, {}, x, 1, y, 1, out, 2 ); // $ExpectError + gcauchyMatrix( 'row-major', x.length, ( x: number ): number => x, x, 1, y, 1, out, 2 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a collection... +{ + const y = new Float64Array( 2 ); + const out = new Float64Array( 4 ); + + gcauchyMatrix( 'row-major', 2, y.length, 10, 1, y, 1, out, 2 ); // $ExpectError + gcauchyMatrix( 'row-major', 2, y.length, true, 1, y, 1, out, 2 ); // $ExpectError + gcauchyMatrix( 'row-major', 2, y.length, false, 1, y, 1, out, 2 ); // $ExpectError + gcauchyMatrix( 'row-major', 2, y.length, null, 1, y, 1, out, 2 ); // $ExpectError + gcauchyMatrix( 'row-major', 2, y.length, undefined, 1, y, 1, out, 2 ); // $ExpectError + gcauchyMatrix( 'row-major', 2, y.length, {}, 1, y, 1, out, 2 ); // $ExpectError + gcauchyMatrix( 'row-major', 2, y.length, ( x: number ): number => x, 1, y, 1, out, 2 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not a number... +{ + const x = new Float64Array( 2 ); + const y = new Float64Array( 2 ); + const out = new Float64Array( 4 ); + + gcauchyMatrix( 'row-major', x.length, y.length, x, '10', y, 1, out, 2 ); // $ExpectError + gcauchyMatrix( 'row-major', x.length, y.length, x, true, y, 1, out, 2 ); // $ExpectError + gcauchyMatrix( 'row-major', x.length, y.length, x, false, y, 1, out, 2 ); // $ExpectError + gcauchyMatrix( 'row-major', x.length, y.length, x, null, y, 1, out, 2 ); // $ExpectError + gcauchyMatrix( 'row-major', x.length, y.length, x, undefined, y, 1, out, 2 ); // $ExpectError + gcauchyMatrix( 'row-major', x.length, y.length, x, [], y, 1, out, 2 ); // $ExpectError + gcauchyMatrix( 'row-major', x.length, y.length, x, {}, y, 1, out, 2 ); // $ExpectError + gcauchyMatrix( 'row-major', x.length, y.length, x, ( x: number ): number => x, y, 1, out, 2 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a sixth argument which is not a collection... +{ + const x = new Float64Array( 2 ); + const out = new Float64Array( 4 ); + + gcauchyMatrix( 'row-major', x.length, 2, x, 1, 10, 1, out, 2 ); // $ExpectError + gcauchyMatrix( 'row-major', x.length, 2, x, 1, true, 1, out, 2 ); // $ExpectError + gcauchyMatrix( 'row-major', x.length, 2, x, 1, false, 1, out, 2 ); // $ExpectError + gcauchyMatrix( 'row-major', x.length, 2, x, 1, null, 1, out, 2 ); // $ExpectError + gcauchyMatrix( 'row-major', x.length, 2, x, 1, undefined, 1, out, 2 ); // $ExpectError + gcauchyMatrix( 'row-major', x.length, 2, x, 1, {}, 1, out, 2 ); // $ExpectError + gcauchyMatrix( 'row-major', x.length, 2, x, 1, ( x: number ): number => x, 1, out, 2 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a seventh argument which is not a number... +{ + const x = new Float64Array( 2 ); + const y = new Float64Array( 2 ); + const out = new Float64Array( 4 ); + + gcauchyMatrix( 'row-major', x.length, y.length, x, 1, y, '10', out, 2 ); // $ExpectError + gcauchyMatrix( 'row-major', x.length, y.length, x, 1, y, true, out, 2 ); // $ExpectError + gcauchyMatrix( 'row-major', x.length, y.length, x, 1, y, false, out, 2 ); // $ExpectError + gcauchyMatrix( 'row-major', x.length, y.length, x, 1, y, null, out, 2 ); // $ExpectError + gcauchyMatrix( 'row-major', x.length, y.length, x, 1, y, undefined, out, 2 ); // $ExpectError + gcauchyMatrix( 'row-major', x.length, y.length, x, 1, y, [], out, 2 ); // $ExpectError + gcauchyMatrix( 'row-major', x.length, y.length, x, 1, y, {}, out, 2 ); // $ExpectError + gcauchyMatrix( 'row-major', x.length, y.length, x, 1, y, ( x: number ): number => x, out, 2 ); // $ExpectError +} + +// The compiler throws an error if the function is provided an eighth argument which is not a collection... +{ + const x = new Float64Array( 2 ); + const y = new Float64Array( 2 ); + + gcauchyMatrix( 'row-major', x.length, y.length, x, 1, y, 1, 10, 2 ); // $ExpectError + gcauchyMatrix( 'row-major', x.length, y.length, x, 1, y, 1, true, 2 ); // $ExpectError + gcauchyMatrix( 'row-major', x.length, y.length, x, 1, y, 1, false, 2 ); // $ExpectError + gcauchyMatrix( 'row-major', x.length, y.length, x, 1, y, 1, null, 2 ); // $ExpectError + gcauchyMatrix( 'row-major', x.length, y.length, x, 1, y, 1, undefined, 2 ); // $ExpectError + gcauchyMatrix( 'row-major', x.length, y.length, x, 1, y, 1, {}, 2 ); // $ExpectError + gcauchyMatrix( 'row-major', x.length, y.length, x, 1, y, 1, ( x: number ): number => x, 2 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a ninth argument which is not a number... +{ + const x = new Float64Array( 2 ); + const y = new Float64Array( 2 ); + const out = new Float64Array( 4 ); + + gcauchyMatrix( 'row-major', x.length, y.length, x, 1, y, 1, out, '10' ); // $ExpectError + gcauchyMatrix( 'row-major', x.length, y.length, x, 1, y, 1, out, true ); // $ExpectError + gcauchyMatrix( 'row-major', x.length, y.length, x, 1, y, 1, out, false ); // $ExpectError + gcauchyMatrix( 'row-major', x.length, y.length, x, 1, y, 1, out, null ); // $ExpectError + gcauchyMatrix( 'row-major', x.length, y.length, x, 1, y, 1, out, undefined ); // $ExpectError + gcauchyMatrix( 'row-major', x.length, y.length, x, 1, y, 1, out, [] ); // $ExpectError + gcauchyMatrix( 'row-major', x.length, y.length, x, 1, y, 1, out, {} ); // $ExpectError + gcauchyMatrix( 'row-major', x.length, y.length, x, 1, y, 1, out, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = new Float64Array( 2 ); + const y = new Float64Array( 2 ); + const out = new Float64Array( 4 ); + + gcauchyMatrix(); // $ExpectError + gcauchyMatrix( 'row-major' ); // $ExpectError + gcauchyMatrix( 'row-major', x.length ); // $ExpectError + gcauchyMatrix( 'row-major', x.length, y.length ); // $ExpectError + gcauchyMatrix( 'row-major', x.length, y.length, x ); // $ExpectError + gcauchyMatrix( 'row-major', x.length, y.length, x, 1 ); // $ExpectError + gcauchyMatrix( 'row-major', x.length, y.length, x, 1, y ); // $ExpectError + gcauchyMatrix( 'row-major', x.length, y.length, x, 1, y, 1 ); // $ExpectError + gcauchyMatrix( 'row-major', x.length, y.length, x, 1, y, 1, out ); // $ExpectError + gcauchyMatrix( 'row-major', x.length, y.length, x, 1, y, 1, out, 2, 10 ); // $ExpectError +} + +// Attached to the main export is an `ndarray` method which returns a collection... +{ + const x = new Float64Array( 2 ); + const y = new Float64Array( 2 ); + const out = new Float64Array( 4 ); + + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, 1, 0, out, 2, 1, 0 ); // $ExpectType Float64Array + gcauchyMatrix.ndarray( x.length, y.length, new AccessorArray( x ), 1, 0, new AccessorArray( y ), 1, 0, new AccessorArray( out ), 2, 1, 0 ); // $ExpectType AccessorArray +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const x = new Float64Array( 2 ); + const y = new Float64Array( 2 ); + const out = new Float64Array( 4 ); + + gcauchyMatrix.ndarray( '10', y.length, x, 1, 0, y, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( true, y.length, x, 1, 0, y, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( false, y.length, x, 1, 0, y, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( null, y.length, x, 1, 0, y, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( undefined, y.length, x, 1, 0, y, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( [], y.length, x, 1, 0, y, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( {}, y.length, x, 1, 0, y, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( ( x: number ): number => x, y.length, x, 1, 0, y, 1, 0, out, 2, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a number... +{ + const x = new Float64Array( 2 ); + const y = new Float64Array( 2 ); + const out = new Float64Array( 4 ); + + gcauchyMatrix.ndarray( x.length, '10', x, 1, 0, y, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, true, x, 1, 0, y, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, false, x, 1, 0, y, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, null, x, 1, 0, y, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, undefined, x, 1, 0, y, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, [], x, 1, 0, y, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, {}, x, 1, 0, y, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, ( x: number ): number => x, x, 1, 0, y, 1, 0, out, 2, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a collection... +{ + const y = new Float64Array( 2 ); + const out = new Float64Array( 4 ); + + gcauchyMatrix.ndarray( 2, y.length, 10, 1, 0, y, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( 2, y.length, true, 1, 0, y, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( 2, y.length, false, 1, 0, y, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( 2, y.length, null, 1, 0, y, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( 2, y.length, undefined, 1, 0, y, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( 2, y.length, {}, 1, 0, y, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( 2, y.length, ( x: number ): number => x, 1, 0, y, 1, 0, out, 2, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... +{ + const x = new Float64Array( 2 ); + const y = new Float64Array( 2 ); + const out = new Float64Array( 4 ); + + gcauchyMatrix.ndarray( x.length, y.length, x, '10', 0, y, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, true, 0, y, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, false, 0, y, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, null, 0, y, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, undefined, 0, y, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, [], 0, y, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, {}, 0, y, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, ( x: number ): number => x, 0, y, 1, 0, out, 2, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a number... +{ + const x = new Float64Array( 2 ); + const y = new Float64Array( 2 ); + const out = new Float64Array( 4 ); + + gcauchyMatrix.ndarray( x.length, y.length, x, 1, '10', y, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, true, y, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, false, y, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, null, y, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, undefined, y, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, [], y, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, {}, y, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, ( x: number ): number => x, y, 1, 0, out, 2, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a sixth argument which is not a collection... +{ + const x = new Float64Array( 2 ); + const out = new Float64Array( 4 ); + + gcauchyMatrix.ndarray( x.length, 2, x, 1, 0, 10, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, 2, x, 1, 0, true, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, 2, x, 1, 0, false, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, 2, x, 1, 0, null, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, 2, x, 1, 0, undefined, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, 2, x, 1, 0, {}, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, 2, x, 1, 0, ( x: number ): number => x, 1, 0, out, 2, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a seventh argument which is not a number... +{ + const x = new Float64Array( 2 ); + const y = new Float64Array( 2 ); + const out = new Float64Array( 4 ); + + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, '10', 0, out, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, true, 0, out, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, false, 0, out, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, null, 0, out, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, undefined, 0, out, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, [], 0, out, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, {}, 0, out, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, ( x: number ): number => x, 0, out, 2, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an eighth argument which is not a number... +{ + const x = new Float64Array( 2 ); + const y = new Float64Array( 2 ); + const out = new Float64Array( 4 ); + + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, 1, '10', out, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, 1, true, out, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, 1, false, out, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, 1, null, out, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, 1, undefined, out, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, 1, [], out, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, 1, {}, out, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, 1, ( x: number ): number => x, out, 2, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a ninth argument which is not a collection... +{ + const x = new Float64Array( 2 ); + const y = new Float64Array( 2 ); + + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, 1, 0, 10, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, 1, 0, true, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, 1, 0, false, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, 1, 0, null, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, 1, 0, undefined, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, 1, 0, {}, 2, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, 1, 0, ( x: number ): number => x, 2, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a tenth argument which is not a number... +{ + const x = new Float64Array( 2 ); + const y = new Float64Array( 2 ); + const out = new Float64Array( 4 ); + + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, 1, 0, out, '10', 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, 1, 0, out, true, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, 1, 0, out, false, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, 1, 0, out, null, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, 1, 0, out, undefined, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, 1, 0, out, [], 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, 1, 0, out, {}, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, 1, 0, out, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an eleventh argument which is not a number... +{ + const x = new Float64Array( 2 ); + const y = new Float64Array( 2 ); + const out = new Float64Array( 4 ); + + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, 1, 0, out, 2, '10', 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, 1, 0, out, 2, true, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, 1, 0, out, 2, false, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, 1, 0, out, 2, null, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, 1, 0, out, 2, undefined, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, 1, 0, out, 2, [], 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, 1, 0, out, 2, {}, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, 1, 0, out, 2, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a twelfth argument which is not a number... +{ + const x = new Float64Array( 2 ); + const y = new Float64Array( 2 ); + const out = new Float64Array( 4 ); + + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, 1, 0, out, 2, 1, '10' ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, 1, 0, out, 2, 1, true ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, 1, 0, out, 2, 1, false ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, 1, 0, out, 2, 1, null ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, 1, 0, out, 2, 1, undefined ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, 1, 0, out, 2, 1, [] ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, 1, 0, out, 2, 1, {} ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, 1, 0, out, 2, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const x = new Float64Array( 2 ); + const y = new Float64Array( 2 ); + const out = new Float64Array( 4 ); + + gcauchyMatrix.ndarray(); // $ExpectError + gcauchyMatrix.ndarray( x.length ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, 1 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, 1, 0 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, 1, 0, out ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, 1, 0, out, 2 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, 1, 0, out, 2, 1 ); // $ExpectError + gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, 1, 0, out, 2, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/examples/index.js new file mode 100644 index 000000000000..095bbf9c0204 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/examples/index.js @@ -0,0 +1,39 @@ +/** +* @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 uniform = require( '@stdlib/random/array/uniform' ); +var zeros = require( '@stdlib/array/zeros' ); +var gcauchyMatrix = require( './../lib' ); + +var M = 3; +var N = 2; +var x = uniform( M, 10.0, 20.0, { + 'dtype': 'generic' +}); +console.log( x ); + +var y = uniform( N, -10.0, -1.0, { + 'dtype': 'generic' +}); +console.log( y ); + +var out = zeros( M * N, 'generic' ); +gcauchyMatrix( 'row-major', M, N, x, 1, y, 1, out, N ); +console.log( out ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/lib/accessors.js new file mode 100644 index 000000000000..19422af0a4bb --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/lib/accessors.js @@ -0,0 +1,105 @@ +/** +* @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 max-params */ + +'use strict'; + +// MAIN // + +/** +* Generates a Cauchy matrix. +* +* @private +* @param {NonNegativeInteger} M - number of indexed elements in `x` +* @param {NonNegativeInteger} N - number of indexed elements in `y` +* @param {Object} x - input array object +* @param {Collection} x.data - input array data +* @param {Array} x.accessors - array element accessors +* @param {integer} strideX - stride length for `x` +* @param {NonNegativeInteger} offsetX - starting index for `x` +* @param {Object} y - input array object +* @param {Collection} y.data - input array data +* @param {Array} y.accessors - array element accessors +* @param {integer} strideY - stride length for `y` +* @param {NonNegativeInteger} offsetY - starting index for `y` +* @param {Object} out - output array object +* @param {Collection} out.data - output array data +* @param {Array} out.accessors - array element accessors +* @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 x = [ 3.0, 5.0 ]; +* var y = [ 1.0, 4.0 ]; +* var out = [ 0.0, 0.0, 0.0, 0.0 ]; +* +* gcauchyMatrix( 2, 2, arraylike2object( toAccessorArray( x ) ), 1, 0, arraylike2object( toAccessorArray( y ) ), 1, 0, arraylike2object( toAccessorArray( out ) ), 2, 1, 0 ); +* // out => [ 0.5, -1.0, 0.25, 1.0 ] +*/ +function gcauchyMatrix( M, N, x, strideX, offsetX, y, strideY, offsetY, out, strideOut1, strideOut2, offsetOut ) { // eslint-disable-line max-len + var xbuf; + var ybuf; + var obuf; + var getX; + var getY; + var oset; + var ix; + var iy; + var io; + var ij; + var v; + var i; + var j; + + // Cache references to array data: + xbuf = x.data; + ybuf = y.data; + obuf = out.data; + + // Cache references to element accessors: + getX = x.accessors[ 0 ]; + getY = y.accessors[ 0 ]; + oset = out.accessors[ 1 ]; + + ix = offsetX; + io = offsetOut; + for ( i = 0; i < M; i++ ) { + v = getX( xbuf, ix ); + iy = offsetY; + ij = io; + for ( j = 0; j < N; j++ ) { + oset( obuf, ij, 1.0 / ( v - getY( ybuf, iy ) ) ); + iy += strideY; + ij += strideOut2; + } + ix += strideX; + io += strideOut1; + } + return out; +} + + +// EXPORTS // + +module.exports = gcauchyMatrix; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/lib/index.js new file mode 100644 index 000000000000..0f81be8b84b8 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/lib/index.js @@ -0,0 +1,61 @@ +/** +* @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 Cauchy matrix. +* +* @module @stdlib/blas/ext/base/gcauchy-matrix +* +* @example +* var gcauchyMatrix = require( '@stdlib/blas/ext/base/gcauchy-matrix' ); +* +* var x = [ 3.0, 5.0 ]; +* var y = [ 1.0, 4.0 ]; +* var out = [ 0.0, 0.0, 0.0, 0.0 ]; +* +* gcauchyMatrix( 'row-major', x.length, y.length, x, 1, y, 1, out, 2 ); +* // out => [ 0.5, -1.0, 0.25, 1.0 ] +* +* @example +* var gcauchyMatrix = require( '@stdlib/blas/ext/base/gcauchy-matrix' ); +* +* var x = [ 3.0, 5.0 ]; +* var y = [ 1.0, 4.0 ]; +* var out = [ 0.0, 0.0, 0.0, 0.0 ]; +* +* gcauchyMatrix.ndarray( x.length, y.length, x, 1, 0, y, 1, 0, out, 2, 1, 0 ); +* // out => [ 0.5, -1.0, 0.25, 1.0 ] +*/ + +// 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/gcauchy-matrix/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/lib/main.js new file mode 100644 index 000000000000..9e2e87bca8e1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/lib/main.js @@ -0,0 +1,95 @@ +/** +* @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 isLayout = require( '@stdlib/blas/base/assert/is-layout' ); +var isColumnMajor = require( '@stdlib/ndarray/base/assert/is-column-major-string' ); +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var max = require( '@stdlib/math/base/special/fast/max' ); +var format = require( '@stdlib/string/format' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +/** +* Generates a Cauchy matrix. +* +* @param {string} order - storage layout +* @param {NonNegativeInteger} M - number of indexed elements in `x` +* @param {NonNegativeInteger} N - number of indexed elements in `y` +* @param {Collection} x - first input array +* @param {integer} strideX - stride length for `x` +* @param {Collection} y - second input array +* @param {integer} strideY - stride length for `y` +* @param {Collection} out - output array +* @param {integer} LDO - stride length between successive contiguous vectors of the matrix `out` (a.k.a., leading dimension of `out`) +* @throws {TypeError} first argument must be a valid order +* @throws {RangeError} ninth argument must be a valid stride length +* @returns {Collection} output array +* +* @example +* var x = [ 3.0, 5.0 ]; +* var y = [ 1.0, 4.0 ]; +* var out = [ 0.0, 0.0, 0.0, 0.0 ]; +* +* gcauchyMatrix( 'row-major', x.length, y.length, x, 1, y, 1, out, 2 ); +* // out => [ 0.5, -1.0, 0.25, 1.0 ] +*/ +function gcauchyMatrix( order, M, N, x, strideX, y, strideY, out, LDO ) { + var iscm; + var sa1; + var sa2; + var ox; + var oy; + var k; + + if ( !isLayout( order ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a valid order. Value: `%s`.', order ) ); + } + iscm = isColumnMajor( order ); + if ( iscm ) { + k = M; + } else { + k = N; + } + if ( LDO < max( 1, k ) ) { + throw new RangeError( format( 'invalid argument. Ninth argument must be greater than or equal to max(1,%d). Value: `%d`.', k, LDO ) ); + } + if ( M === 0 || N === 0 ) { + return out; + } + ox = stride2offset( M, strideX ); + oy = stride2offset( N, strideY ); + if ( iscm ) { + sa1 = 1; + sa2 = LDO; + } else { // order === 'row-major' + sa1 = LDO; + sa2 = 1; + } + return ndarray( M, N, x, strideX, ox, y, strideY, oy, out, sa1, sa2, 0 ); +} + + +// EXPORTS // + +module.exports = gcauchyMatrix; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/lib/ndarray.js new file mode 100644 index 000000000000..0b06f615c9ee --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/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. +*/ + +/* eslint-disable max-params */ + +'use strict'; + +// MODULES // + +var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +var accessors = require( './accessors.js' ); + + +// MAIN // + +/** +* Generates a Cauchy matrix using alternative indexing semantics. +* +* @param {NonNegativeInteger} M - number of indexed elements in `x` +* @param {NonNegativeInteger} N - number of indexed elements in `y` +* @param {Collection} x - first input array +* @param {integer} strideX - stride length for `x` +* @param {NonNegativeInteger} offsetX - starting index for `x` +* @param {Collection} y - second input array +* @param {integer} strideY - stride length for `y` +* @param {NonNegativeInteger} offsetY - starting index for `y` +* @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 array +* +* @example +* var x = [ 3.0, 5.0 ]; +* var y = [ 1.0, 4.0 ]; +* var out = [ 0.0, 0.0, 0.0, 0.0 ]; +* +* gcauchyMatrix( x.length, y.length, x, 1, 0, y, 1, 0, out, 2, 1, 0 ); +* // out => [ 0.5, -1.0, 0.25, 1.0 ] +*/ +function gcauchyMatrix( M, N, x, strideX, offsetX, y, strideY, offsetY, out, strideOut1, strideOut2, offsetOut ) { // eslint-disable-line max-len + var ox; + var oy; + var oo; + var ix; + var iy; + var io; + var ij; + var v; + var i; + var j; + + if ( M <= 0 || N <= 0 ) { + return out; + } + ox = arraylike2object( x ); + oy = arraylike2object( y ); + oo = arraylike2object( out ); + if ( ox.accessorProtocol || oy.accessorProtocol || oo.accessorProtocol ) { + accessors( M, N, ox, strideX, offsetX, oy, strideY, offsetY, oo, strideOut1, strideOut2, offsetOut ); // eslint-disable-line max-len + return out; + } + ix = offsetX; + io = offsetOut; + for ( i = 0; i < M; i++ ) { + v = x[ ix ]; + iy = offsetY; + ij = io; + for ( j = 0; j < N; j++ ) { + out[ ij ] = 1.0 / ( v - y[ iy ] ); + iy += strideY; + ij += strideOut2; + } + ix += strideX; + io += strideOut1; + } + return out; +} + + +// EXPORTS // + +module.exports = gcauchyMatrix; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/package.json b/lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/package.json new file mode 100644 index 000000000000..b7ead7ff6850 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/package.json @@ -0,0 +1,69 @@ +{ + "name": "@stdlib/blas/ext/base/gcauchy-matrix", + "version": "0.0.0", + "description": "Generate a Cauchy 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", + "cauchy", + "matrix", + "strided", + "strided array", + "typed", + "array", + "ndarray", + "vector", + "gcauchy-matrix" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/test/test.js new file mode 100644 index 000000000000..442a468ba076 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/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 gcauchyMatrix = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gcauchyMatrix, '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 gcauchyMatrix.ndarray, 'function', 'method is a function' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/test/test.main.js new file mode 100644 index 000000000000..07d6bf797433 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/test/test.main.js @@ -0,0 +1,707 @@ +/** +* @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 gcauchyMatrix = require( './../lib/main.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gcauchyMatrix, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 9', function test( t ) { + t.strictEqual( gcauchyMatrix.length, 9, 'has expected arity' ); + t.end(); +}); + +tape( 'the function throws if the first argument is not a valid order', function test( t ) { + var values; + var i; + + values = [ + 'foo', + 'bar', + 1, + 0, + null, + true, + false, + void 0, + [], + {} + ]; + 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() { + var out = [ 0.0, 0.0, 0.0, 0.0 ]; + var x = [ 3.0, 5.0 ]; + var y = [ 1.0, 4.0 ]; + gcauchyMatrix( value, x.length, y.length, x, 1, y, 1, out, 2 ); + }; + } +}); + +tape( 'the function throws if the ninth argument is less than max(1,N) (row-major)', function test( t ) { + t.throws( badValue, RangeError, 'throws a range error' ); + t.end(); + + function badValue() { + var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + var x = [ 3.0, 5.0 ]; + var y = [ 1.0, 4.0, 6.0 ]; + gcauchyMatrix( 'row-major', x.length, y.length, x, 1, y, 1, out, 2 ); + } +}); + +tape( 'the function throws if the ninth argument is less than max(1,M) (column-major)', function test( t ) { + t.throws( badValue, RangeError, 'throws a range error' ); + t.end(); + + function badValue() { + var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + var x = [ 3.0, 5.0, 7.0 ]; + var y = [ 1.0, 4.0 ]; + gcauchyMatrix( 'column-major', x.length, y.length, x, 1, y, 1, out, 2 ); + } +}); + +tape( 'the function generates a Cauchy matrix (row-major)', function test( t ) { + var expected; + var out; + var x; + var y; + + x = [ 3.0, 5.0 ]; + y = [ 1.0, 4.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 0.5, -1.0, 0.25, 1.0 ]; + + gcauchyMatrix( 'row-major', x.length, y.length, x, 1, y, 1, out, 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + x = [ 2.0, 3.0, 4.0 ]; + y = [ 1.0, 0.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 1.0, 0.5, 0.5, 1.0/3.0, 1.0/3.0, 0.25 ]; + + gcauchyMatrix( 'row-major', x.length, y.length, x, 1, y, 1, out, 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + x = [ 5.0 ]; + y = [ 3.0 ]; + out = [ 0.0 ]; + expected = [ 0.5 ]; + + gcauchyMatrix( 'row-major', 1, 1, x, 1, y, 1, out, 1 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function generates a Cauchy matrix (column-major)', function test( t ) { + var expected; + var out; + var x; + var y; + + x = [ 3.0, 5.0 ]; + y = [ 1.0, 4.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 0.5, 0.25, -1.0, 1.0 ]; + + gcauchyMatrix( 'column-major', x.length, y.length, x, 1, y, 1, out, 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + x = [ 5.0 ]; + y = [ 3.0 ]; + out = [ 0.0 ]; + expected = [ 0.5 ]; + + gcauchyMatrix( 'column-major', 1, 1, x, 1, y, 1, out, 1 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function generates a Cauchy matrix (row-major, accessors)', function test( t ) { + var expected; + var out; + var x; + var y; + + x = [ 3.0, 5.0 ]; + y = [ 1.0, 4.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 0.5, -1.0, 0.25, 1.0 ]; + + gcauchyMatrix( 'row-major', 2, 2, toAccessorArray( x ), 1, toAccessorArray( y ), 1, toAccessorArray( out ), 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function generates a Cauchy matrix (column-major, accessors)', function test( t ) { + var expected; + var out; + var x; + var y; + + x = [ 3.0, 5.0 ]; + y = [ 1.0, 4.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 0.5, 0.25, -1.0, 1.0 ]; + + gcauchyMatrix( 'column-major', 2, 2, toAccessorArray( x ), 1, toAccessorArray( y ), 1, toAccessorArray( out ), 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a reference to the output array (row-major)', function test( t ) { + var out; + var x; + var y; + var z; + + x = [ 3.0, 5.0 ]; + y = [ 1.0, 4.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0 ]; + z = gcauchyMatrix( 'row-major', x.length, y.length, x, 1, y, 1, out, 2 ); + + t.strictEqual( z, out, 'same reference' ); + t.end(); +}); + +tape( 'the function returns a reference to the output array (column-major)', function test( t ) { + var out; + var x; + var y; + var z; + + x = [ 3.0, 5.0 ]; + y = [ 1.0, 4.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0 ]; + z = gcauchyMatrix( 'column-major', x.length, y.length, x, 1, y, 1, out, 2 ); + + t.strictEqual( z, out, 'same reference' ); + t.end(); +}); + +tape( 'if provided an `M` or `N` parameter equal to `0`, the function returns the output array unchanged (row-major)', function test( t ) { + var expected; + var out; + var x; + var y; + + x = [ 3.0, 5.0 ]; + y = [ 1.0, 4.0 ]; + out = [ 5.0, 6.0, 7.0, 8.0 ]; + expected = [ 5.0, 6.0, 7.0, 8.0 ]; + + gcauchyMatrix( 'row-major', 0, y.length, x, 1, y, 1, out, 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + gcauchyMatrix( 'row-major', x.length, 0, x, 1, y, 1, out, 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `M` or `N` parameter equal to `0`, the function returns the output array unchanged (column-major)', function test( t ) { + var expected; + var out; + var x; + var y; + + x = [ 3.0, 5.0 ]; + y = [ 1.0, 4.0 ]; + out = [ 5.0, 6.0, 7.0, 8.0 ]; + expected = [ 5.0, 6.0, 7.0, 8.0 ]; + + gcauchyMatrix( 'column-major', 0, y.length, x, 1, y, 1, out, 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + gcauchyMatrix( 'column-major', x.length, 0, x, 1, y, 1, out, 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a stride for `x` (row-major)', function test( t ) { + var expected; + var out; + var x; + var y; + + x = [ + 3.0, // 0 + 0.0, + 5.0, // 1 + 0.0 + ]; + y = [ 1.0, 4.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 0.5, -1.0, 0.25, 1.0 ]; + + gcauchyMatrix( 'row-major', 2, y.length, x, 2, y, 1, out, 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a stride for `x` (column-major)', function test( t ) { + var expected; + var out; + var x; + var y; + + x = [ + 3.0, // 0 + 0.0, + 5.0, // 1 + 0.0 + ]; + y = [ 1.0, 4.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 0.5, 0.25, -1.0, 1.0 ]; + + gcauchyMatrix( 'column-major', 2, y.length, x, 2, y, 1, out, 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a stride for `x` (row-major, accessors)', function test( t ) { + var expected; + var out; + var x; + var y; + + x = [ + 3.0, // 0 + 0.0, + 5.0, // 1 + 0.0 + ]; + y = [ 1.0, 4.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 0.5, -1.0, 0.25, 1.0 ]; + + gcauchyMatrix( 'row-major', 2, y.length, toAccessorArray( x ), 2, toAccessorArray( y ), 1, toAccessorArray( out ), 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a stride for `x` (column-major, accessors)', function test( t ) { + var expected; + var out; + var x; + var y; + + x = [ + 3.0, // 0 + 0.0, + 5.0, // 1 + 0.0 + ]; + y = [ 1.0, 4.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 0.5, 0.25, -1.0, 1.0 ]; + + gcauchyMatrix( 'column-major', 2, y.length, toAccessorArray( x ), 2, toAccessorArray( y ), 1, toAccessorArray( out ), 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative stride for `x` (row-major)', function test( t ) { + var expected; + var out; + var x; + var y; + + x = [ + 5.0, // 1 + 3.0 // 0 + ]; + y = [ 1.0, 4.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 0.5, -1.0, 0.25, 1.0 ]; + + gcauchyMatrix( 'row-major', 2, y.length, x, -1, y, 1, out, 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative stride for `x` (column-major)', function test( t ) { + var expected; + var out; + var x; + var y; + + x = [ + 5.0, // 1 + 3.0 // 0 + ]; + y = [ 1.0, 4.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 0.5, 0.25, -1.0, 1.0 ]; + + gcauchyMatrix( 'column-major', 2, y.length, x, -1, y, 1, out, 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative stride for `x` (row-major, accessors)', function test( t ) { + var expected; + var out; + var x; + var y; + + x = [ + 5.0, // 1 + 3.0 // 0 + ]; + y = [ 1.0, 4.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 0.5, -1.0, 0.25, 1.0 ]; + + gcauchyMatrix( 'row-major', 2, y.length, toAccessorArray( x ), -1, toAccessorArray( y ), 1, toAccessorArray( out ), 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative stride for `x` (column-major, accessors)', function test( t ) { + var expected; + var out; + var x; + var y; + + x = [ + 5.0, // 1 + 3.0 // 0 + ]; + y = [ 1.0, 4.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 0.5, 0.25, -1.0, 1.0 ]; + + gcauchyMatrix( 'column-major', 2, y.length, toAccessorArray( x ), -1, toAccessorArray( y ), 1, toAccessorArray( out ), 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a stride for `y` (row-major)', function test( t ) { + var expected; + var out; + var x; + var y; + + x = [ 3.0, 5.0 ]; + y = [ + 1.0, // 0 + 0.0, + 4.0, // 1 + 0.0 + ]; + out = [ 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 0.5, -1.0, 0.25, 1.0 ]; + + gcauchyMatrix( 'row-major', x.length, 2, x, 1, y, 2, out, 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a stride for `y` (column-major)', function test( t ) { + var expected; + var out; + var x; + var y; + + x = [ 3.0, 5.0 ]; + y = [ + 1.0, // 0 + 0.0, + 4.0, // 1 + 0.0 + ]; + out = [ 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 0.5, 0.25, -1.0, 1.0 ]; + + gcauchyMatrix( 'column-major', x.length, 2, x, 1, y, 2, out, 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a stride for `y` (row-major, accessors)', function test( t ) { + var expected; + var out; + var x; + var y; + + x = [ 3.0, 5.0 ]; + y = [ + 1.0, // 0 + 0.0, + 4.0, // 1 + 0.0 + ]; + out = [ 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 0.5, -1.0, 0.25, 1.0 ]; + + gcauchyMatrix( 'row-major', x.length, 2, toAccessorArray( x ), 1, toAccessorArray( y ), 2, toAccessorArray( out ), 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a stride for `y` (column-major, accessors)', function test( t ) { + var expected; + var out; + var x; + var y; + + x = [ 3.0, 5.0 ]; + y = [ + 1.0, // 0 + 0.0, + 4.0, // 1 + 0.0 + ]; + out = [ 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 0.5, 0.25, -1.0, 1.0 ]; + + gcauchyMatrix( 'column-major', x.length, 2, toAccessorArray( x ), 1, toAccessorArray( y ), 2, toAccessorArray( out ), 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative stride for `y` (row-major)', function test( t ) { + var expected; + var out; + var x; + var y; + + x = [ 3.0, 5.0 ]; + y = [ + 4.0, // 1 + 1.0 // 0 + ]; + out = [ 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 0.5, -1.0, 0.25, 1.0 ]; + + gcauchyMatrix( 'row-major', x.length, 2, x, 1, y, -1, out, 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative stride for `y` (column-major)', function test( t ) { + var expected; + var out; + var x; + var y; + + x = [ 3.0, 5.0 ]; + y = [ + 4.0, // 1 + 1.0 // 0 + ]; + out = [ 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 0.5, 0.25, -1.0, 1.0 ]; + + gcauchyMatrix( 'column-major', x.length, 2, x, 1, y, -1, out, 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative stride for `y` (row-major, accessors)', function test( t ) { + var expected; + var out; + var x; + var y; + + x = [ 3.0, 5.0 ]; + y = [ + 4.0, // 1 + 1.0 // 0 + ]; + out = [ 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 0.5, -1.0, 0.25, 1.0 ]; + + gcauchyMatrix( 'row-major', x.length, 2, toAccessorArray( x ), 1, toAccessorArray( y ), -1, toAccessorArray( out ), 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative stride for `y` (column-major, accessors)', function test( t ) { + var expected; + var out; + var x; + var y; + + x = [ 3.0, 5.0 ]; + y = [ + 4.0, // 1 + 1.0 // 0 + ]; + out = [ 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 0.5, 0.25, -1.0, 1.0 ]; + + gcauchyMatrix( 'column-major', x.length, 2, toAccessorArray( x ), 1, toAccessorArray( y ), -1, toAccessorArray( out ), 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a leading dimension stride for the output array (row-major)', function test( t ) { + var expected; + var out; + var x; + var y; + + x = [ 3.0, 5.0 ]; + y = [ 1.0, 4.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 0.5, -1.0, 0.0, 0.0, 0.25, 1.0, 0.0, 0.0 ]; + + gcauchyMatrix( 'row-major', x.length, y.length, x, 1, y, 1, out, 4 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a leading dimension stride for the output array (column-major)', function test( t ) { + var expected; + var out; + var x; + var y; + + x = [ 3.0, 5.0 ]; + y = [ 1.0, 4.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 0.5, 0.25, 0.0, 0.0, -1.0, 1.0, 0.0, 0.0 ]; + + gcauchyMatrix( 'column-major', x.length, y.length, x, 1, y, 1, out, 4 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a leading dimension stride for the output array (row-major, accessors)', function test( t ) { + var expected; + var out; + var x; + var y; + + x = [ 3.0, 5.0 ]; + y = [ 1.0, 4.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 0.5, -1.0, 0.0, 0.0, 0.25, 1.0, 0.0, 0.0 ]; + + gcauchyMatrix( 'row-major', x.length, y.length, toAccessorArray( x ), 1, toAccessorArray( y ), 1, toAccessorArray( out ), 4 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a leading dimension stride for the output array (column-major, accessors)', function test( t ) { + var expected; + var out; + var x; + var y; + + x = [ 3.0, 5.0 ]; + y = [ 1.0, 4.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 0.5, 0.25, 0.0, 0.0, -1.0, 1.0, 0.0, 0.0 ]; + + gcauchyMatrix( 'column-major', x.length, y.length, toAccessorArray( x ), 1, toAccessorArray( y ), 1, toAccessorArray( out ), 4 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports view offsets (row-major)', function test( t ) { + var expected; + var out; + var x0; + var x1; + var y0; + var y1; + + x0 = new Float64Array( [ 0.0, 3.0, 5.0 ] ); + x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + + y0 = new Float64Array( [ 0.0, 1.0, 4.0 ] ); + y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*1 ); + + out = new Float64Array( 4 ); + expected = new Float64Array( [ 0.5, -1.0, 0.25, 1.0 ] ); + + gcauchyMatrix( 'row-major', 2, 2, x1, 1, y1, 1, out, 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports view offsets (column-major)', function test( t ) { + var expected; + var out; + var x0; + var x1; + var y0; + var y1; + + x0 = new Float64Array( [ 0.0, 3.0, 5.0 ] ); + x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + + y0 = new Float64Array( [ 0.0, 1.0, 4.0 ] ); + y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*1 ); + + out = new Float64Array( 4 ); + expected = new Float64Array( [ 0.5, 0.25, -1.0, 1.0 ] ); + + gcauchyMatrix( 'column-major', 2, 2, x1, 1, y1, 1, out, 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/test/test.ndarray.js new file mode 100644 index 000000000000..2e50c75fc1bb --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcauchy-matrix/test/test.ndarray.js @@ -0,0 +1,522 @@ +/** +* @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 gcauchyMatrix = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gcauchyMatrix, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 12', function test( t ) { + t.strictEqual( gcauchyMatrix.length, 12, 'has expected arity' ); + t.end(); +}); + +tape( 'the function generates a Cauchy matrix (row-major)', function test( t ) { + var expected; + var out; + var x; + var y; + + x = [ 3.0, 5.0 ]; + y = [ 1.0, 4.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 0.5, -1.0, 0.25, 1.0 ]; + + gcauchyMatrix( x.length, y.length, x, 1, 0, y, 1, 0, out, 2, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + x = [ 2.0, 3.0, 4.0 ]; + y = [ 1.0, 0.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 1.0, 0.5, 0.5, 1.0/3.0, 1.0/3.0, 0.25 ]; + + gcauchyMatrix( x.length, y.length, x, 1, 0, y, 1, 0, out, 2, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function generates a Cauchy matrix (column-major)', function test( t ) { + var expected; + var out; + var x; + var y; + + x = [ 3.0, 5.0 ]; + y = [ 1.0, 4.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 0.5, 0.25, -1.0, 1.0 ]; + + gcauchyMatrix( x.length, y.length, x, 1, 0, y, 1, 0, out, 1, 2, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function generates a Cauchy matrix (row-major, accessors)', function test( t ) { + var expected; + var out; + var x; + var y; + + x = [ 3.0, 5.0 ]; + y = [ 1.0, 4.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 0.5, -1.0, 0.25, 1.0 ]; + + gcauchyMatrix( 2, 2, toAccessorArray( x ), 1, 0, toAccessorArray( y ), 1, 0, toAccessorArray( out ), 2, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function generates a Cauchy matrix (column-major, accessors)', function test( t ) { + var expected; + var out; + var x; + var y; + + x = [ 3.0, 5.0 ]; + y = [ 1.0, 4.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 0.5, 0.25, -1.0, 1.0 ]; + + gcauchyMatrix( 2, 2, toAccessorArray( x ), 1, 0, toAccessorArray( y ), 1, 0, toAccessorArray( out ), 1, 2, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a reference to the output array', function test( t ) { + var out; + var x; + var y; + var z; + + x = [ 3.0, 5.0 ]; + y = [ 1.0, 4.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0 ]; + z = gcauchyMatrix( x.length, y.length, x, 1, 0, y, 1, 0, out, 2, 1, 0 ); + + t.strictEqual( z, out, 'same reference' ); + t.end(); +}); + +tape( 'if provided an `M` or `N` parameter equal to `0`, the function returns the output array unchanged', function test( t ) { + var expected; + var out; + var x; + var y; + + x = [ 3.0, 5.0 ]; + y = [ 1.0, 4.0 ]; + out = [ 5.0, 6.0, 7.0, 8.0 ]; + expected = [ 5.0, 6.0, 7.0, 8.0 ]; + + gcauchyMatrix( 0, y.length, x, 1, 0, y, 1, 0, out, 2, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + gcauchyMatrix( x.length, 0, x, 1, 0, y, 1, 0, out, 2, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a stride for `x` (row-major)', function test( t ) { + var expected; + var out; + var x; + var y; + + x = [ + 3.0, // 0 + 0.0, + 5.0, // 1 + 0.0 + ]; + y = [ 1.0, 4.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 0.5, -1.0, 0.25, 1.0 ]; + + gcauchyMatrix( 2, y.length, x, 2, 0, y, 1, 0, out, 2, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a stride for `x` (row-major, accessors)', function test( t ) { + var expected; + var out; + var x; + var y; + + x = [ + 3.0, // 0 + 0.0, + 5.0, // 1 + 0.0 + ]; + y = [ 1.0, 4.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 0.5, -1.0, 0.25, 1.0 ]; + + gcauchyMatrix( 2, y.length, toAccessorArray( x ), 2, 0, toAccessorArray( y ), 1, 0, toAccessorArray( out ), 2, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative stride for `x` (row-major)', function test( t ) { + var expected; + var out; + var x; + var y; + + x = [ + 5.0, // 1 + 3.0 // 0 + ]; + y = [ 1.0, 4.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 0.5, -1.0, 0.25, 1.0 ]; + + gcauchyMatrix( 2, y.length, x, -1, 1, y, 1, 0, out, 2, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative stride for `x` (row-major, accessors)', function test( t ) { + var expected; + var out; + var x; + var y; + + x = [ + 5.0, // 1 + 3.0 // 0 + ]; + y = [ 1.0, 4.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 0.5, -1.0, 0.25, 1.0 ]; + + gcauchyMatrix( 2, y.length, toAccessorArray( x ), -1, 1, toAccessorArray( y ), 1, 0, toAccessorArray( out ), 2, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a stride for `y` (row-major)', function test( t ) { + var expected; + var out; + var x; + var y; + + x = [ 3.0, 5.0 ]; + y = [ + 1.0, // 0 + 0.0, + 4.0, // 1 + 0.0 + ]; + out = [ 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 0.5, -1.0, 0.25, 1.0 ]; + + gcauchyMatrix( x.length, 2, x, 1, 0, y, 2, 0, out, 2, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a stride for `y` (row-major, accessors)', function test( t ) { + var expected; + var out; + var x; + var y; + + x = [ 3.0, 5.0 ]; + y = [ + 1.0, // 0 + 0.0, + 4.0, // 1 + 0.0 + ]; + out = [ 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 0.5, -1.0, 0.25, 1.0 ]; + + gcauchyMatrix( x.length, 2, toAccessorArray( x ), 1, 0, toAccessorArray( y ), 2, 0, toAccessorArray( out ), 2, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative stride for `y` (row-major)', function test( t ) { + var expected; + var out; + var x; + var y; + + x = [ 3.0, 5.0 ]; + y = [ + 4.0, // 1 + 1.0 // 0 + ]; + out = [ 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 0.5, -1.0, 0.25, 1.0 ]; + + gcauchyMatrix( x.length, 2, x, 1, 0, y, -1, 1, out, 2, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative stride for `y` (row-major, accessors)', function test( t ) { + var expected; + var out; + var x; + var y; + + x = [ 3.0, 5.0 ]; + y = [ + 4.0, // 1 + 1.0 // 0 + ]; + out = [ 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 0.5, -1.0, 0.25, 1.0 ]; + + gcauchyMatrix( x.length, 2, toAccessorArray( x ), 1, 0, toAccessorArray( y ), -1, 1, toAccessorArray( out ), 2, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a stride for the output rows (row-major)', function test( t ) { + var expected; + var out; + var x; + var y; + + x = [ 3.0, 5.0 ]; + y = [ 1.0, 4.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 0.5, -1.0, 0.0, 0.0, 0.25, 1.0, 0.0, 0.0 ]; + + gcauchyMatrix( x.length, y.length, x, 1, 0, y, 1, 0, out, 4, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a stride for the output rows (row-major, accessors)', function test( t ) { + var expected; + var out; + var x; + var y; + + x = [ 3.0, 5.0 ]; + y = [ 1.0, 4.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 0.5, -1.0, 0.0, 0.0, 0.25, 1.0, 0.0, 0.0 ]; + + gcauchyMatrix( x.length, y.length, toAccessorArray( x ), 1, 0, toAccessorArray( y ), 1, 0, toAccessorArray( out ), 4, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative stride for the output rows (row-major)', function test( t ) { + var expected; + var out; + var x; + var y; + + x = [ 3.0, 5.0 ]; + y = [ 1.0, 4.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 0.25, 1.0, 0.5, -1.0 ]; + + gcauchyMatrix( x.length, y.length, x, 1, 0, y, 1, 0, out, -2, 1, 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative stride for the output rows (row-major, accessors)', function test( t ) { + var expected; + var out; + var x; + var y; + + x = [ 3.0, 5.0 ]; + y = [ 1.0, 4.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 0.25, 1.0, 0.5, -1.0 ]; + + gcauchyMatrix( x.length, y.length, toAccessorArray( x ), 1, 0, toAccessorArray( y ), 1, 0, toAccessorArray( out ), -2, 1, 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative stride for the output columns (row-major)', function test( t ) { + var expected; + var out; + var x; + var y; + + x = [ 3.0, 5.0 ]; + y = [ 1.0, 4.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0 ]; + expected = [ -1.0, 0.5, 1.0, 0.25 ]; + + gcauchyMatrix( x.length, y.length, x, 1, 0, y, 1, 0, out, 2, -1, 1 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative stride for the output columns (row-major, accessors)', function test( t ) { + var expected; + var out; + var x; + var y; + + x = [ 3.0, 5.0 ]; + y = [ 1.0, 4.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0 ]; + expected = [ -1.0, 0.5, 1.0, 0.25 ]; + + gcauchyMatrix( x.length, y.length, toAccessorArray( x ), 1, 0, toAccessorArray( y ), 1, 0, toAccessorArray( out ), 2, -1, 1 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `offsetX` parameter', function test( t ) { + var expected; + var out; + var x; + var y; + + x = [ 0.0, 3.0, 5.0 ]; + y = [ 1.0, 4.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 0.5, -1.0, 0.25, 1.0 ]; + + gcauchyMatrix( 2, y.length, x, 1, 1, y, 1, 0, out, 2, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `offsetX` parameter (accessors)', function test( t ) { + var expected; + var out; + var x; + var y; + + x = [ 0.0, 3.0, 5.0 ]; + y = [ 1.0, 4.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 0.5, -1.0, 0.25, 1.0 ]; + + gcauchyMatrix( 2, y.length, toAccessorArray( x ), 1, 1, toAccessorArray( y ), 1, 0, toAccessorArray( out ), 2, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `offsetY` parameter', function test( t ) { + var expected; + var out; + var x; + var y; + + x = [ 3.0, 5.0 ]; + y = [ 0.0, 1.0, 4.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 0.5, -1.0, 0.25, 1.0 ]; + + gcauchyMatrix( x.length, 2, x, 1, 0, y, 1, 1, out, 2, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `offsetY` parameter (accessors)', function test( t ) { + var expected; + var out; + var x; + var y; + + x = [ 3.0, 5.0 ]; + y = [ 0.0, 1.0, 4.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 0.5, -1.0, 0.25, 1.0 ]; + + gcauchyMatrix( x.length, 2, toAccessorArray( x ), 1, 0, toAccessorArray( y ), 1, 1, toAccessorArray( out ), 2, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `offsetOut` parameter', function test( t ) { + var expected; + var out; + var x; + var y; + + x = [ 3.0, 5.0 ]; + y = [ 1.0, 4.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 0.0, 0.0, 0.5, -1.0, 0.25, 1.0 ]; + + gcauchyMatrix( x.length, y.length, x, 1, 0, y, 1, 0, out, 2, 1, 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `offsetOut` parameter (accessors)', function test( t ) { + var expected; + var out; + var x; + var y; + + x = [ 3.0, 5.0 ]; + y = [ 1.0, 4.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 0.0, 0.0, 0.5, -1.0, 0.25, 1.0 ]; + + gcauchyMatrix( x.length, y.length, toAccessorArray( x ), 1, 0, toAccessorArray( y ), 1, 0, toAccessorArray( out ), 2, 1, 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +});