diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcompanion/README.md b/lib/node_modules/@stdlib/blas/ext/base/gcompanion/README.md new file mode 100644 index 000000000000..aa00770be5a8 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcompanion/README.md @@ -0,0 +1,191 @@ + + +# gcompanion + +> Generate a companion matrix. + +
+ +
+ + + +
+ +## Usage + +```javascript +var gcompanion = require( '@stdlib/blas/ext/base/gcompanion' ); +``` + +#### gcompanion( order, N, x, strideX, out, ldo ) + +Generates a companion matrix. + +```javascript +var x = [ 1.0, 2.0, 3.0 ]; +var out = [ 0.0, 0.0, 0.0, 0.0 ]; + +gcompanion( 'row-major', 3, x, 1, out, 2 ); +// out => [ -2.0, -3.0, 1.0, 0.0 ] +``` + +The function has the following parameters: + +- **order**: row-major (C-style) or column-major (Fortran-style) order. +- **N**: number of indexed elements in `x`. +- **x**: input [`Array`][mdn-array] or [`typed array`][mdn-typed-array] containing polynomial coefficients in order of decreasing degree, with the first indexed element being the leading coefficient. The leading coefficient must not be zero. +- **strideX**: stride length for `x`. +- **out**: output matrix. +- **ldo**: stride between successive contiguous vectors of the matrix `out` (a.k.a., leading dimension of the matrix `out`). Must be greater than or equal to `max(1,N-1)`. + +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( [ 999.0, 1.0, 2.0, 3.0 ] ); +var out0 = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + +// Create offset views: +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element +var out1 = new Float64Array( out0.buffer, out0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +gcompanion( 'row-major', 3, x1, 1, out1, 2 ); +// out0 => [ 0.0, -2.0, -3.0, 1.0, 0.0 ] +``` + + + +#### gcompanion.ndarray( N, x, strideX, offsetX, out, strideOut1, strideOut2, offsetOut ) + + + +Generates a companion matrix using alternative indexing semantics. + +```javascript +var x = [ 1.0, 2.0, 3.0 ]; +var out = [ 0.0, 0.0, 0.0, 0.0 ]; + +gcompanion.ndarray( 3, x, 1, 0, out, 2, 1, 0 ); +// out => [ -2.0, -3.0, 1.0, 0.0 ] +``` + +The function has the following additional parameters: + +- **offsetX**: starting index for `x`. +- **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 start writing matrix elements from the second element of the output array: + +```javascript +var x = [ 1.0, 2.0, 3.0 ]; +var out = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + +gcompanion.ndarray( 3, x, 1, 0, out, 2, 1, 1 ); +// out => [ 0.0, -2.0, -3.0, 1.0, 0.0 ] +``` + +
+ + + +
+ +## Notes + +- If `N <= 1`, both functions return `out` unchanged. +- Given `N` polynomial coefficients, both functions generate an `(N-1)`-by-`(N-1)` matrix in which the first row contains the remaining coefficients negated and divided by the leading coefficient and ones are placed along the first subdiagonal. +- Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]). + +
+ + + +
+ +## Examples + + + +```javascript +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var zeros = require( '@stdlib/array/zeros' ); +var gcompanion = require( '@stdlib/blas/ext/base/gcompanion' ); + +var N = 5; +var order = 'row-major'; +var shape = [ N-1, N-1 ]; +var strides = shape2strides( shape, order ); + +var x = discreteUniform( N, 1, 10, { + 'dtype': 'generic' +}); +console.log( x ); + +var out = zeros( ( N-1 )*( N-1 ), 'generic' ); + +gcompanion( order, N, x, 1, out, N-1 ); +console.log( ndarray2array( out, shape, strides, 0, order ) ); +``` + +
+ + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcompanion/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/gcompanion/benchmark/benchmark.js new file mode 100644 index 000000000000..f1b624fa52ec --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcompanion/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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var zeros = require( '@stdlib/array/zeros' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var gcompanion = 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; + + x = uniform( len, 1.0, 10.0, options ); + out = zeros( ( len-1 ) * ( len-1 ), 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++ ) { + x[ 0 ] += 0.1; + v = gcompanion( 'row-major', len, x, 1, out, len-1 ); + if ( isnan( v[ i%v.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v[ i%v.length ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 3; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcompanion/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gcompanion/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..d3b62cce3aff --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcompanion/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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var zeros = require( '@stdlib/array/zeros' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var gcompanion = 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; + + x = uniform( len, 1.0, 10.0, options ); + out = zeros( ( len-1 ) * ( len-1 ), 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++ ) { + x[ 0 ] += 0.1; + v = gcompanion( len, x, 1, 0, out, len-1, 1, 0 ); + if ( isnan( v[ i%v.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v[ i%v.length ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 3; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:ndarray:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcompanion/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/gcompanion/docs/repl.txt new file mode 100644 index 000000000000..f05efed9e108 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcompanion/docs/repl.txt @@ -0,0 +1,112 @@ + +{{alias}}( order, N, x, strideX, out, ldo ) + Generates a companion matrix. + + Given `N` polynomial coefficients, the function generates an + `(N-1)`-by-`(N-1)` matrix in which the first row contains the remaining + coefficients negated and divided by the leading coefficient and ones are + placed along the first subdiagonal. + + The `N` and stride parameters determine which elements in the strided array + are accessed at runtime. + + If `N` is less than or equal to `1`, the function returns `out` unchanged. + + Parameters + ---------- + order: string + Storage layout. + + N: integer + Number of indexed elements in `x`. + + x: ArrayLikeObject + Input array containing polynomial coefficients in order of decreasing + degree, with the first indexed element being the leading coefficient. + The leading coefficient must not be zero. + + strideX: integer + Stride length for `x`. + + out: ArrayLikeObject + Output array. + + ldo: integer + Stride length between successive contiguous vectors of the matrix + `out` (a.k.a., leading dimension of `out`). Must be greater than or + equal to `max(1,N-1)`. + + Returns + ------- + out: ArrayLikeObject + Output array. + + Examples + -------- + // Standard Usage: + > var x = [ 1.0, 2.0, 3.0 ]; + > var out = [ 0.0, 0.0, 0.0, 0.0 ]; + > {{alias}}( 'row-major', 3, x, 1, out, 2 ) + [ -2.0, -3.0, 1.0, 0.0 ] + + // Using a leading dimension greater than `N-1`: + > out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + > {{alias}}( 'row-major', 3, x, 1, out, 3 ) + [ -2.0, -3.0, 0.0, 1.0, 0.0, 0.0 ] + + +{{alias}}.ndarray( N, x, sx, ox, out, so1, so2, oo ) + Generates a companion matrix using alternative indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the offset parameters support indexing semantics based on starting + indices. + + Parameters + ---------- + N: integer + Number of indexed elements in `x`. + + x: ArrayLikeObject + Input array containing polynomial coefficients in order of decreasing + degree, with the first indexed element being the leading coefficient. + The leading coefficient must not be zero. + + sx: integer + Stride length for `x`. + + ox: integer + Starting index for `x`. + + 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 = [ 1.0, 2.0, 3.0 ]; + > var out = [ 0.0, 0.0, 0.0, 0.0 ]; + > {{alias}}.ndarray( 3, x, 1, 0, out, 2, 1, 0 ) + [ -2.0, -3.0, 1.0, 0.0 ] + + // Using an index offset: + > out = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + > {{alias}}.ndarray( 3, x, 1, 0, out, 2, 1, 1 ) + [ 0.0, -2.0, -3.0, 1.0, 0.0 ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcompanion/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/gcompanion/docs/types/index.d.ts new file mode 100644 index 000000000000..e4c177dbaee1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcompanion/docs/types/index.d.ts @@ -0,0 +1,113 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +import { Collection, AccessorArrayLike } from '@stdlib/types/array'; +import { Layout } from '@stdlib/types/blas'; + +/** +* Input array. +*/ +type InputArray = Collection | AccessorArrayLike; + +/** +* Output array. +*/ +type OutputArray = Collection | AccessorArrayLike; + +/** +* Interface describing `gcompanion`. +*/ +interface Routine { + /** + * Generates a companion matrix. + * + * @param order - storage layout + * @param N - number of indexed elements in `x` + * @param x - input array containing polynomial coefficients + * @param strideX - stride length for `x` + * @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 = [ 1.0, 2.0, 3.0 ]; + * var out = [ 0.0, 0.0, 0.0, 0.0 ]; + * + * gcompanion( 'row-major', 3, x, 1, out, 2 ); + * // out => [ -2.0, -3.0, 1.0, 0.0 ] + */ + = OutputArray>( order: Layout, N: number, x: InputArray, strideX: number, out: V, ldo: number ): V; + + /** + * Generates a companion matrix using alternative indexing semantics. + * + * @param N - number of indexed elements in `x` + * @param x - input array containing polynomial coefficients + * @param strideX - stride length for `x` + * @param offsetX - starting index for `x` + * @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 = [ 1.0, 2.0, 3.0 ]; + * var out = [ 0.0, 0.0, 0.0, 0.0 ]; + * + * gcompanion.ndarray( 3, x, 1, 0, out, 2, 1, 0 ); + * // out => [ -2.0, -3.0, 1.0, 0.0 ] + */ + ndarray = OutputArray>( N: number, x: InputArray, strideX: number, offsetX: number, out: V, strideOut1: number, strideOut2: number, offsetOut: number ): V; +} + +/** +* Generates a companion matrix. +* +* @param order - storage layout +* @param N - number of indexed elements in `x` +* @param x - input array containing polynomial coefficients +* @param strideX - stride length for `x` +* @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 = [ 1.0, 2.0, 3.0 ]; +* var out = [ 0.0, 0.0, 0.0, 0.0 ]; +* +* gcompanion( 'row-major', 3, x, 1, out, 2 ); +* // out => [ -2.0, -3.0, 1.0, 0.0 ] +* +* @example +* var x = [ 1.0, 2.0, 3.0 ]; +* var out = [ 0.0, 0.0, 0.0, 0.0 ]; +* +* gcompanion.ndarray( 3, x, 1, 0, out, 2, 1, 0 ); +* // out => [ -2.0, -3.0, 1.0, 0.0 ] +*/ +declare var gcompanion: Routine; + + +// EXPORTS // + +export = gcompanion; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcompanion/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/gcompanion/docs/types/test.ts new file mode 100644 index 000000000000..2e77c1c88c76 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcompanion/docs/types/test.ts @@ -0,0 +1,275 @@ +/* +* @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 gcompanion = require( './index' ); + + +// TESTS // + +// The function returns a collection... +{ + const x = new Float64Array( 4 ); + const out = new Float64Array( 9 ); + + gcompanion( 'row-major', 4, x, 1, out, 3 ); // $ExpectType Float64Array + gcompanion( 'row-major', 4, x, 1, new AccessorArray( out ), 3 ); // $ExpectType AccessorArray +} + +// The compiler throws an error if the function is provided a first argument which is not a valid order... +{ + const x = new Float64Array( 4 ); + const out = new Float64Array( 9 ); + + gcompanion( 10, 4, x, 1, out, 3 ); // $ExpectError + gcompanion( true, 4, x, 1, out, 3 ); // $ExpectError + gcompanion( false, 4, x, 1, out, 3 ); // $ExpectError + gcompanion( null, 4, x, 1, out, 3 ); // $ExpectError + gcompanion( undefined, 4, x, 1, out, 3 ); // $ExpectError + gcompanion( [], 4, x, 1, out, 3 ); // $ExpectError + gcompanion( {}, 4, x, 1, out, 3 ); // $ExpectError + gcompanion( ( x: number ): number => x, 4, x, 1, out, 3 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a number... +{ + const x = new Float64Array( 4 ); + const out = new Float64Array( 9 ); + + gcompanion( 'row-major', '10', x, 1, out, 3 ); // $ExpectError + gcompanion( 'row-major', true, x, 1, out, 3 ); // $ExpectError + gcompanion( 'row-major', false, x, 1, out, 3 ); // $ExpectError + gcompanion( 'row-major', null, x, 1, out, 3 ); // $ExpectError + gcompanion( 'row-major', undefined, x, 1, out, 3 ); // $ExpectError + gcompanion( 'row-major', [], x, 1, out, 3 ); // $ExpectError + gcompanion( 'row-major', {}, x, 1, out, 3 ); // $ExpectError + gcompanion( 'row-major', ( x: number ): number => x, x, 1, out, 3 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a collection... +{ + const out = new Float64Array( 9 ); + + gcompanion( 'row-major', 4, 10, 1, out, 3 ); // $ExpectError + gcompanion( 'row-major', 4, true, 1, out, 3 ); // $ExpectError + gcompanion( 'row-major', 4, false, 1, out, 3 ); // $ExpectError + gcompanion( 'row-major', 4, null, 1, out, 3 ); // $ExpectError + gcompanion( 'row-major', 4, undefined, 1, out, 3 ); // $ExpectError + gcompanion( 'row-major', 4, {}, 1, out, 3 ); // $ExpectError + gcompanion( 'row-major', 4, ( x: number ): number => x, 1, out, 3 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a number... +{ + const x = new Float64Array( 4 ); + const out = new Float64Array( 9 ); + + gcompanion( 'row-major', 4, x, '10', out, 3 ); // $ExpectError + gcompanion( 'row-major', 4, x, true, out, 3 ); // $ExpectError + gcompanion( 'row-major', 4, x, false, out, 3 ); // $ExpectError + gcompanion( 'row-major', 4, x, null, out, 3 ); // $ExpectError + gcompanion( 'row-major', 4, x, undefined, out, 3 ); // $ExpectError + gcompanion( 'row-major', 4, x, [], out, 3 ); // $ExpectError + gcompanion( 'row-major', 4, x, {}, out, 3 ); // $ExpectError + gcompanion( 'row-major', 4, x, ( x: number ): number => x, out, 3 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not a collection... +{ + const x = new Float64Array( 4 ); + + gcompanion( 'row-major', 4, x, 1, 10, 3 ); // $ExpectError + gcompanion( 'row-major', 4, x, 1, true, 3 ); // $ExpectError + gcompanion( 'row-major', 4, x, 1, false, 3 ); // $ExpectError + gcompanion( 'row-major', 4, x, 1, null, 3 ); // $ExpectError + gcompanion( 'row-major', 4, x, 1, undefined, 3 ); // $ExpectError + gcompanion( 'row-major', 4, x, 1, {}, 3 ); // $ExpectError + gcompanion( 'row-major', 4, x, 1, ( x: number ): number => x, 3 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a sixth argument which is not a number... +{ + const x = new Float64Array( 4 ); + const out = new Float64Array( 9 ); + + gcompanion( 'row-major', 4, x, 1, out, '10' ); // $ExpectError + gcompanion( 'row-major', 4, x, 1, out, true ); // $ExpectError + gcompanion( 'row-major', 4, x, 1, out, false ); // $ExpectError + gcompanion( 'row-major', 4, x, 1, out, null ); // $ExpectError + gcompanion( 'row-major', 4, x, 1, out, undefined ); // $ExpectError + gcompanion( 'row-major', 4, x, 1, out, [] ); // $ExpectError + gcompanion( 'row-major', 4, x, 1, out, {} ); // $ExpectError + gcompanion( 'row-major', 4, x, 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( 4 ); + const out = new Float64Array( 9 ); + + gcompanion(); // $ExpectError + gcompanion( 'row-major' ); // $ExpectError + gcompanion( 'row-major', 4 ); // $ExpectError + gcompanion( 'row-major', 4, x ); // $ExpectError + gcompanion( 'row-major', 4, x, 1 ); // $ExpectError + gcompanion( 'row-major', 4, x, 1, out ); // $ExpectError + gcompanion( 'row-major', 4, x, 1, out, 3, 10 ); // $ExpectError +} + +// Attached to the main export is an `ndarray` method which returns a collection... +{ + const x = new Float64Array( 4 ); + const out = new Float64Array( 9 ); + + gcompanion.ndarray( 4, x, 1, 0, out, 3, 1, 0 ); // $ExpectType Float64Array + gcompanion.ndarray( 4, x, 1, 0, new AccessorArray( out ), 3, 1, 0 ); // $ExpectType AccessorArray +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const x = new Float64Array( 4 ); + const out = new Float64Array( 9 ); + + gcompanion.ndarray( '10', x, 1, 0, out, 3, 1, 0 ); // $ExpectError + gcompanion.ndarray( true, x, 1, 0, out, 3, 1, 0 ); // $ExpectError + gcompanion.ndarray( false, x, 1, 0, out, 3, 1, 0 ); // $ExpectError + gcompanion.ndarray( null, x, 1, 0, out, 3, 1, 0 ); // $ExpectError + gcompanion.ndarray( undefined, x, 1, 0, out, 3, 1, 0 ); // $ExpectError + gcompanion.ndarray( [], x, 1, 0, out, 3, 1, 0 ); // $ExpectError + gcompanion.ndarray( {}, x, 1, 0, out, 3, 1, 0 ); // $ExpectError + gcompanion.ndarray( ( x: number ): number => x, x, 1, 0, out, 3, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a collection... +{ + const out = new Float64Array( 9 ); + + gcompanion.ndarray( 4, 10, 1, 0, out, 3, 1, 0 ); // $ExpectError + gcompanion.ndarray( 4, true, 1, 0, out, 3, 1, 0 ); // $ExpectError + gcompanion.ndarray( 4, false, 1, 0, out, 3, 1, 0 ); // $ExpectError + gcompanion.ndarray( 4, null, 1, 0, out, 3, 1, 0 ); // $ExpectError + gcompanion.ndarray( 4, undefined, 1, 0, out, 3, 1, 0 ); // $ExpectError + gcompanion.ndarray( 4, {}, 1, 0, out, 3, 1, 0 ); // $ExpectError + gcompanion.ndarray( 4, ( x: number ): number => x, 1, 0, out, 3, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a number... +{ + const x = new Float64Array( 4 ); + const out = new Float64Array( 9 ); + + gcompanion.ndarray( 4, x, '10', 0, out, 3, 1, 0 ); // $ExpectError + gcompanion.ndarray( 4, x, true, 0, out, 3, 1, 0 ); // $ExpectError + gcompanion.ndarray( 4, x, false, 0, out, 3, 1, 0 ); // $ExpectError + gcompanion.ndarray( 4, x, null, 0, out, 3, 1, 0 ); // $ExpectError + gcompanion.ndarray( 4, x, undefined, 0, out, 3, 1, 0 ); // $ExpectError + gcompanion.ndarray( 4, x, [], 0, out, 3, 1, 0 ); // $ExpectError + gcompanion.ndarray( 4, x, {}, 0, out, 3, 1, 0 ); // $ExpectError + gcompanion.ndarray( 4, x, ( x: number ): number => x, 0, out, 3, 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( 4 ); + const out = new Float64Array( 9 ); + + gcompanion.ndarray( 4, x, 1, '10', out, 3, 1, 0 ); // $ExpectError + gcompanion.ndarray( 4, x, 1, true, out, 3, 1, 0 ); // $ExpectError + gcompanion.ndarray( 4, x, 1, false, out, 3, 1, 0 ); // $ExpectError + gcompanion.ndarray( 4, x, 1, null, out, 3, 1, 0 ); // $ExpectError + gcompanion.ndarray( 4, x, 1, undefined, out, 3, 1, 0 ); // $ExpectError + gcompanion.ndarray( 4, x, 1, [], out, 3, 1, 0 ); // $ExpectError + gcompanion.ndarray( 4, x, 1, {}, out, 3, 1, 0 ); // $ExpectError + gcompanion.ndarray( 4, x, 1, ( x: number ): number => x, out, 3, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a collection... +{ + const x = new Float64Array( 4 ); + + gcompanion.ndarray( 4, x, 1, 0, 10, 3, 1, 0 ); // $ExpectError + gcompanion.ndarray( 4, x, 1, 0, true, 3, 1, 0 ); // $ExpectError + gcompanion.ndarray( 4, x, 1, 0, false, 3, 1, 0 ); // $ExpectError + gcompanion.ndarray( 4, x, 1, 0, null, 3, 1, 0 ); // $ExpectError + gcompanion.ndarray( 4, x, 1, 0, undefined, 3, 1, 0 ); // $ExpectError + gcompanion.ndarray( 4, x, 1, 0, {}, 3, 1, 0 ); // $ExpectError + gcompanion.ndarray( 4, x, 1, 0, ( x: number ): number => x, 3, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a sixth argument which is not a number... +{ + const x = new Float64Array( 4 ); + const out = new Float64Array( 9 ); + + gcompanion.ndarray( 4, x, 1, 0, out, '10', 1, 0 ); // $ExpectError + gcompanion.ndarray( 4, x, 1, 0, out, true, 1, 0 ); // $ExpectError + gcompanion.ndarray( 4, x, 1, 0, out, false, 1, 0 ); // $ExpectError + gcompanion.ndarray( 4, x, 1, 0, out, null, 1, 0 ); // $ExpectError + gcompanion.ndarray( 4, x, 1, 0, out, undefined, 1, 0 ); // $ExpectError + gcompanion.ndarray( 4, x, 1, 0, out, [], 1, 0 ); // $ExpectError + gcompanion.ndarray( 4, x, 1, 0, out, {}, 1, 0 ); // $ExpectError + gcompanion.ndarray( 4, x, 1, 0, out, ( x: number ): number => x, 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( 4 ); + const out = new Float64Array( 9 ); + + gcompanion.ndarray( 4, x, 1, 0, out, 3, '10', 0 ); // $ExpectError + gcompanion.ndarray( 4, x, 1, 0, out, 3, true, 0 ); // $ExpectError + gcompanion.ndarray( 4, x, 1, 0, out, 3, false, 0 ); // $ExpectError + gcompanion.ndarray( 4, x, 1, 0, out, 3, null, 0 ); // $ExpectError + gcompanion.ndarray( 4, x, 1, 0, out, 3, undefined, 0 ); // $ExpectError + gcompanion.ndarray( 4, x, 1, 0, out, 3, [], 0 ); // $ExpectError + gcompanion.ndarray( 4, x, 1, 0, out, 3, {}, 0 ); // $ExpectError + gcompanion.ndarray( 4, x, 1, 0, out, 3, ( x: number ): number => x, 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( 4 ); + const out = new Float64Array( 9 ); + + gcompanion.ndarray( 4, x, 1, 0, out, 3, 1, '10' ); // $ExpectError + gcompanion.ndarray( 4, x, 1, 0, out, 3, 1, true ); // $ExpectError + gcompanion.ndarray( 4, x, 1, 0, out, 3, 1, false ); // $ExpectError + gcompanion.ndarray( 4, x, 1, 0, out, 3, 1, null ); // $ExpectError + gcompanion.ndarray( 4, x, 1, 0, out, 3, 1, undefined ); // $ExpectError + gcompanion.ndarray( 4, x, 1, 0, out, 3, 1, [] ); // $ExpectError + gcompanion.ndarray( 4, x, 1, 0, out, 3, 1, {} ); // $ExpectError + gcompanion.ndarray( 4, x, 1, 0, out, 3, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const x = new Float64Array( 4 ); + const out = new Float64Array( 9 ); + + gcompanion.ndarray(); // $ExpectError + gcompanion.ndarray( 4 ); // $ExpectError + gcompanion.ndarray( 4, x ); // $ExpectError + gcompanion.ndarray( 4, x, 1 ); // $ExpectError + gcompanion.ndarray( 4, x, 1, 0 ); // $ExpectError + gcompanion.ndarray( 4, x, 1, 0, out ); // $ExpectError + gcompanion.ndarray( 4, x, 1, 0, out, 3 ); // $ExpectError + gcompanion.ndarray( 4, x, 1, 0, out, 3, 1 ); // $ExpectError + gcompanion.ndarray( 4, x, 1, 0, out, 3, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcompanion/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/gcompanion/examples/index.js new file mode 100644 index 000000000000..df0325985340 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcompanion/examples/index.js @@ -0,0 +1,40 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var zeros = require( '@stdlib/array/zeros' ); +var gcompanion = require( './../lib' ); + +var N = 5; +var order = 'row-major'; +var shape = [ N-1, N-1 ]; +var strides = shape2strides( shape, order ); + +var x = discreteUniform( N, 1, 10, { + 'dtype': 'generic' +}); +console.log( x ); + +var out = zeros( ( N-1 )*( N-1 ), 'generic' ); + +gcompanion( order, N, x, 1, out, N-1 ); +console.log( ndarray2array( out, shape, strides, 0, order ) ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcompanion/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/gcompanion/lib/accessors.js new file mode 100644 index 000000000000..057aa965bb42 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcompanion/lib/accessors.js @@ -0,0 +1,128 @@ +/** +* @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 isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major' ); + + +// MAIN // + +/** +* Generates a companion matrix using accessor arrays. +* +* @private +* @param {NonNegativeInteger} N - number of indexed elements in `x` +* @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} 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 = [ 1.0, 2.0, 3.0 ]; +* var out = [ 0.0, 0.0, 0.0, 0.0 ]; +* +* gcompanion( 3, arraylike2object( toAccessorArray( x ) ), 1, 0, arraylike2object( toAccessorArray( out ) ), 2, 1, 0 ); +* // out => [ -2.0, -3.0, 1.0, 0.0 ] +*/ +function gcompanion( N, x, strideX, offsetX, out, strideOut1, strideOut2, offsetOut ) { // eslint-disable-line max-len + var xbuf; + var obuf; + var getX; + var oset; + var ix; + var io; + var ij; + var M; + var v; + var i; + var j; + + // Cache references to array data: + xbuf = x.data; + obuf = out.data; + + // Cache references to element accessors: + getX = x.accessors[ 0 ]; + oset = out.accessors[ 1 ]; + + M = N - 1; + + // Cache the leading coefficient: + v = getX( xbuf, offsetX ); + + ix = offsetX + strideX; + io = offsetOut; + if ( isRowMajor( [ strideOut1, strideOut2 ] ) ) { + // Fill the first row with the remaining coefficients negated and normalized by the leading coefficient... + ij = io; + for ( j = 0; j < M; j++ ) { + oset( obuf, ij, -getX( xbuf, ix ) / v ); + ix += strideX; + ij += strideOut2; + } + // Fill the remaining rows with ones along the first subdiagonal and zeros elsewhere... + for ( i = 1; i < M; i++ ) { + io += strideOut1; + ij = io; + for ( j = 0; j < M; j++ ) { + if ( j === i-1 ) { + oset( obuf, ij, 1.0 ); + } else { + oset( obuf, ij, 0.0 ); + } + ij += strideOut2; + } + } + return out; + } + // Column-major: fill each column with a normalized coefficient negated in the first row, a one along the first subdiagonal, and zeros elsewhere... + for ( j = 0; j < M; j++ ) { + ij = io; + oset( obuf, ij, -getX( xbuf, ix ) / v ); + for ( i = 1; i < M; i++ ) { + ij += strideOut1; + if ( i === j+1 ) { + oset( obuf, ij, 1.0 ); + } else { + oset( obuf, ij, 0.0 ); + } + } + ix += strideX; + io += strideOut2; + } + return out; +} + + +// EXPORTS // + +module.exports = gcompanion; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcompanion/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/gcompanion/lib/index.js new file mode 100644 index 000000000000..926065d194c1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcompanion/lib/index.js @@ -0,0 +1,59 @@ +/** +* @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 companion matrix. +* +* @module @stdlib/blas/ext/base/gcompanion +* +* @example +* var gcompanion = require( '@stdlib/blas/ext/base/gcompanion' ); +* +* var x = [ 1.0, 2.0, 3.0 ]; +* var out = [ 0.0, 0.0, 0.0, 0.0 ]; +* +* gcompanion( 'row-major', 3, x, 1, out, 2 ); +* // out => [ -2.0, -3.0, 1.0, 0.0 ] +* +* @example +* var gcompanion = require( '@stdlib/blas/ext/base/gcompanion' ); +* +* var x = [ 1.0, 2.0, 3.0 ]; +* var out = [ 0.0, 0.0, 0.0, 0.0 ]; +* +* gcompanion.ndarray( 3, x, 1, 0, out, 2, 1, 0 ); +* // out => [ -2.0, -3.0, 1.0, 0.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/gcompanion/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/gcompanion/lib/main.js new file mode 100644 index 000000000000..327dfeacef6f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcompanion/lib/main.js @@ -0,0 +1,87 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isColumnMajor = require( '@stdlib/ndarray/base/assert/is-column-major-string' ); +var resolveLayout = require( '@stdlib/blas/base/layout-resolve-str' ); +var 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 companion matrix. +* +* @param {(integer|string)} order - storage layout +* @param {NonNegativeInteger} N - number of indexed elements in `x` +* @param {Collection} x - input array containing polynomial coefficients +* @param {integer} strideX - stride length for `x` +* @param {Collection} out - output array +* @param {PositiveInteger} ldo - stride between successive contiguous vectors of the matrix `out` (a.k.a., leading dimension of the matrix `out`) +* @throws {TypeError} first argument must be a valid order +* @throws {RangeError} sixth argument must be a valid stride +* @returns {Collection} output matrix +* +* @example +* var x = [ 1.0, 2.0, 3.0 ]; +* var out = [ 0.0, 0.0, 0.0, 0.0 ]; +* +* gcompanion( 'row-major', 3, x, 1, out, 2 ); +* // out => [ -2.0, -3.0, 1.0, 0.0 ] +*/ +function gcompanion( order, N, x, strideX, out, ldo ) { + var iscm; + var sa1; + var sa2; + var ox; + var l; + var m; + + l = resolveLayout( order ); + if ( l === null ) { + throw new TypeError( format( 'invalid argument. First argument must be a valid order. Value: `%s`.', order ) ); + } + m = N - 1; + if ( ldo < max( 1, m ) ) { + throw new RangeError( format( 'invalid argument. Sixth argument must be greater than or equal to max(1,%d). Value: `%d`.', m, ldo ) ); + } + if ( N <= 1 ) { + return out; + } + ox = stride2offset( N, strideX ); + iscm = isColumnMajor( l ); + if ( iscm ) { + sa1 = 1; + sa2 = ldo; + } else { // order === 'row-major' + sa1 = ldo; + sa2 = 1; + } + return ndarray( N, x, strideX, ox, out, sa1, sa2, 0 ); +} + + +// EXPORTS // + +module.exports = gcompanion; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcompanion/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gcompanion/lib/ndarray.js new file mode 100644 index 000000000000..2fffcbbf2859 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcompanion/lib/ndarray.js @@ -0,0 +1,121 @@ +/** +* @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 isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major' ); +var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +var accessors = require( './accessors.js' ); + + +// MAIN // + +/** +* Generates a companion matrix using alternative indexing semantics. +* +* @param {NonNegativeInteger} N - number of indexed elements in `x` +* @param {Collection} x - input array containing polynomial coefficients +* @param {integer} strideX - stride length for `x` +* @param {NonNegativeInteger} offsetX - starting index for `x` +* @param {Collection} out - output array +* @param {integer} strideOut1 - stride length for the first dimension of `out` +* @param {integer} strideOut2 - stride length for the second dimension of `out` +* @param {NonNegativeInteger} offsetOut - starting index for `out` +* @returns {Collection} output matrix +* +* @example +* var x = [ 1.0, 2.0, 3.0 ]; +* var out = [ 0.0, 0.0, 0.0, 0.0 ]; +* +* gcompanion( 3, x, 1, 0, out, 2, 1, 0 ); +* // out => [ -2.0, -3.0, 1.0, 0.0 ] +*/ +function gcompanion( N, x, strideX, offsetX, out, strideOut1, strideOut2, offsetOut ) { // eslint-disable-line max-len + var ox; + var oo; + var ix; + var io; + var ij; + var M; + var v; + var i; + var j; + + if ( N <= 1 ) { + return out; + } + ox = arraylike2object( x ); + oo = arraylike2object( out ); + if ( ox.accessorProtocol || oo.accessorProtocol ) { + accessors( N, ox, strideX, offsetX, oo, strideOut1, strideOut2, offsetOut ); // eslint-disable-line max-len + return out; + } + M = N - 1; + + // Cache the leading coefficient: + v = x[ offsetX ]; + + ix = offsetX + strideX; + io = offsetOut; + if ( isRowMajor( [ strideOut1, strideOut2 ] ) ) { + // Fill the first row with the remaining coefficients negated and normalized by the leading coefficient... + ij = io; + for ( j = 0; j < M; j++ ) { + out[ ij ] = -x[ ix ] / v; + ix += strideX; + ij += strideOut2; + } + // Fill the remaining rows with ones along the first subdiagonal and zeros elsewhere... + for ( i = 1; i < M; i++ ) { + io += strideOut1; + ij = io; + for ( j = 0; j < M; j++ ) { + if ( j === i-1 ) { + out[ ij ] = 1.0; + } else { + out[ ij ] = 0.0; + } + ij += strideOut2; + } + } + return out; + } + // Column-major: fill each column with a normalized coefficient negated in the first row, a one along the first subdiagonal, and zeros elsewhere... + for ( j = 0; j < M; j++ ) { + ij = io; + out[ ij ] = -x[ ix ] / v; + for ( i = 1; i < M; i++ ) { + ij += strideOut1; + if ( i === j+1 ) { + out[ ij ] = 1.0; + } else { + out[ ij ] = 0.0; + } + } + ix += strideX; + io += strideOut2; + } + return out; +} + + +// EXPORTS // + +module.exports = gcompanion; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcompanion/package.json b/lib/node_modules/@stdlib/blas/ext/base/gcompanion/package.json new file mode 100644 index 000000000000..780cc7326a1f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcompanion/package.json @@ -0,0 +1,70 @@ +{ + "name": "@stdlib/blas/ext/base/gcompanion", + "version": "0.0.0", + "description": "Generate a companion 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", + "companion", + "polynomial", + "matrix", + "strided", + "strided array", + "typed", + "array", + "ndarray", + "vector", + "gcompanion" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcompanion/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/gcompanion/test/test.js new file mode 100644 index 000000000000..2e4f3e97de3b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcompanion/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 gcompanion = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gcompanion, '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 gcompanion.ndarray, 'function', 'method is a function' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcompanion/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/gcompanion/test/test.main.js new file mode 100644 index 000000000000..3632962419cf --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcompanion/test/test.main.js @@ -0,0 +1,837 @@ +/** +* @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 gcompanion = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gcompanion, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 6', function test( t ) { + t.strictEqual( gcompanion.length, 6, 'has expected arity' ); + t.end(); +}); + +tape( 'the function throws an error if provided an invalid first argument', function test( t ) { + var values; + var i; + + values = [ + 'foo', + 'bar', + 'beep', + 'boop' + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + gcompanion( value, 3, [ 1.0, 2.0, 3.0 ], 1, [ 0.0, 0.0, 0.0, 0.0 ], 2 ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid first argument (accessors)', function test( t ) { + var values; + var i; + + values = [ + 'foo', + 'bar', + 'beep', + 'boop' + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + gcompanion( value, 3, toAccessorArray( [ 1.0, 2.0, 3.0 ] ), 1, toAccessorArray( [ 0.0, 0.0, 0.0, 0.0 ] ), 2 ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid sixth argument', function test( t ) { + var values; + var i; + + values = [ + -2, + -1, + 0, + 1 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + gcompanion( 'row-major', 3, [ 1.0, 2.0, 3.0 ], 1, [ 0.0, 0.0, 0.0, 0.0 ], value ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid sixth argument (accessors)', function test( t ) { + var values; + var i; + + values = [ + -2, + -1, + 0, + 1 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + gcompanion( 'row-major', 3, toAccessorArray( [ 1.0, 2.0, 3.0 ] ), 1, toAccessorArray( [ 0.0, 0.0, 0.0, 0.0 ] ), value ); + }; + } +}); + +tape( 'if provided an `N` less than or equal to `1`, the function returns the output array unchanged', function test( t ) { + var expected; + var out; + + out = [ 0.0, 0.0, 0.0, 0.0 ]; + + expected = [ 0.0, 0.0, 0.0, 0.0 ]; + + gcompanion( 'row-major', 0, [], 1, out, 1 ); + t.deepEqual( out, expected, 'returns expected value' ); + + gcompanion( 'row-major', 1, [ 1.0 ], 1, out, 1 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` less than or equal to `1`, the function returns the output array unchanged (accessors)', function test( t ) { + var expected; + var out; + + out = [ 0.0, 0.0, 0.0, 0.0 ]; + + expected = [ 0.0, 0.0, 0.0, 0.0 ]; + + gcompanion( 'row-major', 0, toAccessorArray( [] ), 1, toAccessorArray( out ), 1 ); + t.deepEqual( out, expected, 'returns expected value' ); + + gcompanion( 'row-major', 1, toAccessorArray( [ 1.0 ] ), 1, toAccessorArray( out ), 1 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the output matrix', function test( t ) { + var out; + var v; + + out = [ 0.0, 0.0, 0.0, 0.0 ]; + + v = gcompanion( 'row-major', 3, [ 1.0, 2.0, 3.0 ], 1, out, 2 ); + + t.strictEqual( v, out, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the output matrix (accessors)', function test( t ) { + var out; + var v; + + out = toAccessorArray( [ 0.0, 0.0, 0.0, 0.0 ] ); + + v = gcompanion( 'row-major', 3, toAccessorArray( [ 1.0, 2.0, 3.0 ] ), 1, out, 2 ); + + t.strictEqual( v, out, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a companion matrix (row-major)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, -10.0, 31.0, -30.0 ]; + + out = [ + 9.0, + 9.0, + 9.0, + 9.0, + 9.0, + 9.0, + 9.0, + 9.0, + 9.0 + ]; + + gcompanion( 'row-major', 4, x, 1, out, 3 ); + + expected = [ + 10.0, + -31.0, + 30.0, + 1.0, + 0.0, + 0.0, + 0.0, + 1.0, + 0.0 + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a companion matrix (row-major, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, -10.0, 31.0, -30.0 ]; + + out = [ + 9.0, + 9.0, + 9.0, + 9.0, + 9.0, + 9.0, + 9.0, + 9.0, + 9.0 + ]; + + gcompanion( 'row-major', 4, toAccessorArray( x ), 1, toAccessorArray( out ), 3 ); + + expected = [ + 10.0, + -31.0, + 30.0, + 1.0, + 0.0, + 0.0, + 0.0, + 1.0, + 0.0 + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a companion matrix (column-major)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, -10.0, 31.0, -30.0 ]; + + out = [ + 9.0, + 9.0, + 9.0, + 9.0, + 9.0, + 9.0, + 9.0, + 9.0, + 9.0 + ]; + + gcompanion( 'column-major', 4, x, 1, out, 3 ); + + expected = [ + 10.0, + 1.0, + 0.0, + -31.0, + 0.0, + 1.0, + 30.0, + 0.0, + 0.0 + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a companion matrix (column-major, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, -10.0, 31.0, -30.0 ]; + + out = [ + 9.0, + 9.0, + 9.0, + 9.0, + 9.0, + 9.0, + 9.0, + 9.0, + 9.0 + ]; + + gcompanion( 'column-major', 4, toAccessorArray( x ), 1, toAccessorArray( out ), 3 ); + + expected = [ + 10.0, + 1.0, + 0.0, + -31.0, + 0.0, + 1.0, + 30.0, + 0.0, + 0.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; + + x = [ 1.0, 0.0, -10.0, 0.0, 31.0, 0.0, -30.0 ]; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + gcompanion( 'row-major', 4, x, 2, out, 3 ); + + expected = [ + 10.0, + -31.0, + 30.0, + 1.0, + 0.0, + 0.0, + 0.0, + 1.0, + 0.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; + + x = [ 1.0, 0.0, -10.0, 0.0, 31.0, 0.0, -30.0 ]; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + gcompanion( 'row-major', 4, toAccessorArray( x ), 2, toAccessorArray( out ), 3 ); + + expected = [ + 10.0, + -31.0, + 30.0, + 1.0, + 0.0, + 0.0, + 0.0, + 1.0, + 0.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; + + x = [ -30.0, 31.0, -10.0, 1.0 ]; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + gcompanion( 'row-major', 4, x, -1, out, 3 ); + + expected = [ + 10.0, + -31.0, + 30.0, + 1.0, + 0.0, + 0.0, + 0.0, + 1.0, + 0.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; + + x = [ -30.0, 31.0, -10.0, 1.0 ]; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + gcompanion( 'row-major', 4, toAccessorArray( x ), -1, toAccessorArray( out ), 3 ); + + expected = [ + 10.0, + -31.0, + 30.0, + 1.0, + 0.0, + 0.0, + 0.0, + 1.0, + 0.0 + ]; + + 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; + + x = [ 1.0, 0.0, -10.0, 0.0, 31.0, 0.0, -30.0 ]; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + gcompanion( 'column-major', 4, x, 2, out, 3 ); + + expected = [ + 10.0, + 1.0, + 0.0, + -31.0, + 0.0, + 1.0, + 30.0, + 0.0, + 0.0 + ]; + + 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; + + x = [ 1.0, 0.0, -10.0, 0.0, 31.0, 0.0, -30.0 ]; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + gcompanion( 'column-major', 4, toAccessorArray( x ), 2, toAccessorArray( out ), 3 ); + + expected = [ + 10.0, + 1.0, + 0.0, + -31.0, + 0.0, + 1.0, + 30.0, + 0.0, + 0.0 + ]; + + 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; + + x = [ -30.0, 31.0, -10.0, 1.0 ]; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + gcompanion( 'column-major', 4, x, -1, out, 3 ); + + expected = [ + 10.0, + 1.0, + 0.0, + -31.0, + 0.0, + 1.0, + 30.0, + 0.0, + 0.0 + ]; + + 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; + + x = [ -30.0, 31.0, -10.0, 1.0 ]; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + gcompanion( 'column-major', 4, toAccessorArray( x ), -1, toAccessorArray( out ), 3 ); + + expected = [ + 10.0, + 1.0, + 0.0, + -31.0, + 0.0, + 1.0, + 30.0, + 0.0, + 0.0 + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a leading dimension for the output matrix (row-major)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, -10.0, 31.0, -30.0 ]; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + gcompanion( 'row-major', 4, x, 1, out, 4 ); + + expected = [ + 10.0, + -31.0, + 30.0, + 0.0, + 1.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 0.0, + 0.0 + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a leading dimension for the output matrix (row-major, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, -10.0, 31.0, -30.0 ]; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + gcompanion( 'row-major', 4, toAccessorArray( x ), 1, toAccessorArray( out ), 4 ); + + expected = [ + 10.0, + -31.0, + 30.0, + 0.0, + 1.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 0.0, + 0.0 + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a leading dimension for the output matrix (column-major)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, -10.0, 31.0, -30.0 ]; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + gcompanion( 'column-major', 4, x, 1, out, 4 ); + + expected = [ + 10.0, + 1.0, + 0.0, + 0.0, + -31.0, + 0.0, + 1.0, + 0.0, + 30.0, + 0.0, + 0.0, + 0.0 + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a leading dimension for the output matrix (column-major, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, -10.0, 31.0, -30.0 ]; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + gcompanion( 'column-major', 4, toAccessorArray( x ), 1, toAccessorArray( out ), 4 ); + + expected = [ + 10.0, + 1.0, + 0.0, + 0.0, + -31.0, + 0.0, + 1.0, + 0.0, + 30.0, + 0.0, + 0.0, + 0.0 + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports view offsets', function test( t ) { + var expected; + var out0; + var out1; + var x0; + var x1; + + x0 = new Float64Array( [ 999.0, 1.0, -10.0, 31.0, -30.0 ] ); + x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + + out0 = new Float64Array( 10 ); + out1 = new Float64Array( out0.buffer, out0.BYTES_PER_ELEMENT*1 ); + + gcompanion( 'row-major', 4, x1, 1, out1, 3 ); + + expected = new Float64Array([ + 10.0, + -31.0, + 30.0, + 1.0, + 0.0, + 0.0, + 0.0, + 1.0, + 0.0 + ]); + + t.deepEqual( out1, expected, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcompanion/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gcompanion/test/test.ndarray.js new file mode 100644 index 000000000000..6853441900dd --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcompanion/test/test.ndarray.js @@ -0,0 +1,1033 @@ +/** +* @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 gcompanion = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gcompanion, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 8', function test( t ) { + t.strictEqual( gcompanion.length, 8, 'has expected arity' ); + t.end(); +}); + +tape( 'if provided an `N` less than or equal to `1`, the function returns the output array unchanged', function test( t ) { + var expected; + var out; + + out = [ 0.0, 0.0, 0.0, 0.0 ]; + + expected = [ 0.0, 0.0, 0.0, 0.0 ]; + + gcompanion( 0, [], 1, 0, out, 1, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + gcompanion( 1, [ 1.0 ], 1, 0, out, 1, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` less than or equal to `1`, the function returns the output array unchanged (accessors)', function test( t ) { + var expected; + var out; + + out = [ 0.0, 0.0, 0.0, 0.0 ]; + + expected = [ 0.0, 0.0, 0.0, 0.0 ]; + + gcompanion( 0, toAccessorArray( [] ), 1, 0, toAccessorArray( out ), 1, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + gcompanion( 1, toAccessorArray( [ 1.0 ] ), 1, 0, toAccessorArray( out ), 1, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the output matrix', function test( t ) { + var out; + var v; + + out = [ 0.0, 0.0, 0.0, 0.0 ]; + + v = gcompanion( 3, [ 1.0, 2.0, 3.0 ], 1, 0, out, 2, 1, 0 ); + + t.strictEqual( v, out, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the output matrix (accessors)', function test( t ) { + var out; + var v; + + out = toAccessorArray( [ 0.0, 0.0, 0.0, 0.0 ] ); + + v = gcompanion( 3, toAccessorArray( [ 1.0, 2.0, 3.0 ] ), 1, 0, out, 2, 1, 0 ); + + t.strictEqual( v, out, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a companion matrix (row-major)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, -10.0, 31.0, -30.0 ]; + + out = [ + 9.0, + 9.0, + 9.0, + 9.0, + 9.0, + 9.0, + 9.0, + 9.0, + 9.0 + ]; + + gcompanion( 4, x, 1, 0, out, 3, 1, 0 ); + + expected = [ + 10.0, + -31.0, + 30.0, + 1.0, + 0.0, + 0.0, + 0.0, + 1.0, + 0.0 + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a companion matrix (row-major, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, -10.0, 31.0, -30.0 ]; + + out = [ + 9.0, + 9.0, + 9.0, + 9.0, + 9.0, + 9.0, + 9.0, + 9.0, + 9.0 + ]; + + gcompanion( 4, toAccessorArray( x ), 1, 0, toAccessorArray( out ), 3, 1, 0 ); + + expected = [ + 10.0, + -31.0, + 30.0, + 1.0, + 0.0, + 0.0, + 0.0, + 1.0, + 0.0 + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a companion matrix (column-major)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, -10.0, 31.0, -30.0 ]; + + out = [ + 9.0, + 9.0, + 9.0, + 9.0, + 9.0, + 9.0, + 9.0, + 9.0, + 9.0 + ]; + + gcompanion( 4, x, 1, 0, out, 1, 3, 0 ); + + expected = [ + 10.0, + 1.0, + 0.0, + -31.0, + 0.0, + 1.0, + 30.0, + 0.0, + 0.0 + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a companion matrix (column-major, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, -10.0, 31.0, -30.0 ]; + + out = [ + 9.0, + 9.0, + 9.0, + 9.0, + 9.0, + 9.0, + 9.0, + 9.0, + 9.0 + ]; + + gcompanion( 4, toAccessorArray( x ), 1, 0, toAccessorArray( out ), 1, 3, 0 ); + + expected = [ + 10.0, + 1.0, + 0.0, + -31.0, + 0.0, + 1.0, + 30.0, + 0.0, + 0.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; + + x = [ 1.0, 0.0, -10.0, 0.0, 31.0, 0.0, -30.0 ]; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + gcompanion( 4, x, 2, 0, out, 3, 1, 0 ); + + expected = [ + 10.0, + -31.0, + 30.0, + 1.0, + 0.0, + 0.0, + 0.0, + 1.0, + 0.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; + + x = [ 1.0, 0.0, -10.0, 0.0, 31.0, 0.0, -30.0 ]; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + gcompanion( 4, toAccessorArray( x ), 2, 0, toAccessorArray( out ), 3, 1, 0 ); + + expected = [ + 10.0, + -31.0, + 30.0, + 1.0, + 0.0, + 0.0, + 0.0, + 1.0, + 0.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; + + x = [ -30.0, 31.0, -10.0, 1.0 ]; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + gcompanion( 4, x, -1, 3, out, 3, 1, 0 ); + + expected = [ + 10.0, + -31.0, + 30.0, + 1.0, + 0.0, + 0.0, + 0.0, + 1.0, + 0.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; + + x = [ -30.0, 31.0, -10.0, 1.0 ]; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + gcompanion( 4, toAccessorArray( x ), -1, 3, toAccessorArray( out ), 3, 1, 0 ); + + expected = [ + 10.0, + -31.0, + 30.0, + 1.0, + 0.0, + 0.0, + 0.0, + 1.0, + 0.0 + ]; + + 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; + + x = [ 1.0, 0.0, -10.0, 0.0, 31.0, 0.0, -30.0 ]; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + gcompanion( 4, x, 2, 0, out, 1, 3, 0 ); + + expected = [ + 10.0, + 1.0, + 0.0, + -31.0, + 0.0, + 1.0, + 30.0, + 0.0, + 0.0 + ]; + + 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; + + x = [ 1.0, 0.0, -10.0, 0.0, 31.0, 0.0, -30.0 ]; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + gcompanion( 4, toAccessorArray( x ), 2, 0, toAccessorArray( out ), 1, 3, 0 ); + + expected = [ + 10.0, + 1.0, + 0.0, + -31.0, + 0.0, + 1.0, + 30.0, + 0.0, + 0.0 + ]; + + 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; + + x = [ -30.0, 31.0, -10.0, 1.0 ]; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + gcompanion( 4, x, -1, 3, out, 1, 3, 0 ); + + expected = [ + 10.0, + 1.0, + 0.0, + -31.0, + 0.0, + 1.0, + 30.0, + 0.0, + 0.0 + ]; + + 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; + + x = [ -30.0, 31.0, -10.0, 1.0 ]; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + gcompanion( 4, toAccessorArray( x ), -1, 3, toAccessorArray( out ), 1, 3, 0 ); + + expected = [ + 10.0, + 1.0, + 0.0, + -31.0, + 0.0, + 1.0, + 30.0, + 0.0, + 0.0 + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an `x` offset', function test( t ) { + var expected; + var out; + var x; + + x = [ 999.0, 1.0, -10.0, 31.0, -30.0 ]; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + gcompanion( 4, x, 1, 1, out, 3, 1, 0 ); + + expected = [ + 10.0, + -31.0, + 30.0, + 1.0, + 0.0, + 0.0, + 0.0, + 1.0, + 0.0 + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an `x` offset (accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 999.0, 1.0, -10.0, 31.0, -30.0 ]; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + gcompanion( 4, toAccessorArray( x ), 1, 1, toAccessorArray( out ), 3, 1, 0 ); + + expected = [ + 10.0, + -31.0, + 30.0, + 1.0, + 0.0, + 0.0, + 0.0, + 1.0, + 0.0 + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an output offset', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, -10.0, 31.0, -30.0 ]; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + gcompanion( 4, x, 1, 0, out, 3, 1, 2 ); + + expected = [ + 0.0, + 0.0, + 10.0, + -31.0, + 30.0, + 1.0, + 0.0, + 0.0, + 0.0, + 1.0, + 0.0 + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an output offset (accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, -10.0, 31.0, -30.0 ]; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + gcompanion( 4, toAccessorArray( x ), 1, 0, toAccessorArray( out ), 3, 1, 2 ); + + expected = [ + 0.0, + 0.0, + 10.0, + -31.0, + 30.0, + 1.0, + 0.0, + 0.0, + 0.0, + 1.0, + 0.0 + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports output stride with padding (row-major)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, -10.0, 31.0, -30.0 ]; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + gcompanion( 4, x, 1, 0, out, 4, 1, 0 ); + + expected = [ + 10.0, + -31.0, + 30.0, + 0.0, + 1.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 0.0, + 0.0 + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports output stride with padding (row-major, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, -10.0, 31.0, -30.0 ]; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + gcompanion( 4, toAccessorArray( x ), 1, 0, toAccessorArray( out ), 4, 1, 0 ); + + expected = [ + 10.0, + -31.0, + 30.0, + 0.0, + 1.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 0.0, + 0.0 + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports output stride with padding (column-major)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, -10.0, 31.0, -30.0 ]; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + gcompanion( 4, x, 1, 0, out, 1, 4, 0 ); + + expected = [ + 10.0, + 1.0, + 0.0, + 0.0, + -31.0, + 0.0, + 1.0, + 0.0, + 30.0, + 0.0, + 0.0, + 0.0 + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports output stride with padding (column-major, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, -10.0, 31.0, -30.0 ]; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + gcompanion( 4, toAccessorArray( x ), 1, 0, toAccessorArray( out ), 1, 4, 0 ); + + expected = [ + 10.0, + 1.0, + 0.0, + 0.0, + -31.0, + 0.0, + 1.0, + 0.0, + 30.0, + 0.0, + 0.0, + 0.0 + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying negative output strides (row-major)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, -10.0, 31.0, -30.0 ]; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + gcompanion( 4, x, 1, 0, out, -3, -1, 8 ); + + expected = [ + 0.0, + 1.0, + 0.0, + 0.0, + 0.0, + 1.0, + 30.0, + -31.0, + 10.0 + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying negative output strides (row-major, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, -10.0, 31.0, -30.0 ]; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + gcompanion( 4, toAccessorArray( x ), 1, 0, toAccessorArray( out ), -3, -1, 8 ); + + expected = [ + 0.0, + 1.0, + 0.0, + 0.0, + 0.0, + 1.0, + 30.0, + -31.0, + 10.0 + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports complex access patterns', function test( t ) { + var expected; + var out; + var x; + + x = [ 999.0, 1.0, 0.0, -10.0, 0.0, 31.0, 0.0, -30.0 ]; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + gcompanion( 4, x, 2, 1, out, 1, 4, 1 ); + + expected = [ + 0.0, + 10.0, + 1.0, + 0.0, + 0.0, + -31.0, + 0.0, + 1.0, + 0.0, + 30.0, + 0.0, + 0.0, + 0.0 + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports complex access patterns (accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 999.0, 1.0, 0.0, -10.0, 0.0, 31.0, 0.0, -30.0 ]; + + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + gcompanion( 4, toAccessorArray( x ), 2, 1, toAccessorArray( out ), 1, 4, 1 ); + + expected = [ + 0.0, + 10.0, + 1.0, + 0.0, + 0.0, + -31.0, + 0.0, + 1.0, + 0.0, + 30.0, + 0.0, + 0.0, + 0.0 + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +});