diff --git a/lib/node_modules/@stdlib/blas/ext/base/gconvolution-matrix/README.md b/lib/node_modules/@stdlib/blas/ext/base/gconvolution-matrix/README.md new file mode 100644 index 000000000000..9e419a786a0b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gconvolution-matrix/README.md @@ -0,0 +1,201 @@ + + +# gconvolutionMatrix + +> Generate a convolution matrix. + +
+ +
+ + + +
+ +## Usage + +```javascript +var gconvolutionMatrix = require( '@stdlib/blas/ext/base/gconvolution-matrix' ); +``` + +#### gconvolutionMatrix( order, mode, m, N, x, strideX, out, ldo ) + +Generates a convolution matrix. + +```javascript +var x = [ 1.0, 2.0 ]; +var 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 ]; + +gconvolutionMatrix( 'row-major', 'full', 2, 3, x, 1, out, 3 ); +// out => [ 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 0.0, 2.0 ] +``` + +The function has the following parameters: + +- **order**: row-major (C-style) or column-major (Fortran-style) order. +- **mode**: convolution mode. Must be one of `'full'`, `'same'`, or `'valid'`. +- **m**: number of indexed elements in `x`. +- **N**: number of columns in the output matrix. +- **x**: input array ([`Array`][mdn-array] or [`typed array`][mdn-typed-array]). +- **strideX**: stride length for `x`. +- **out**: output matrix. +- **ldo**: stride length between successive contiguous vectors of the matrix `out` (a.k.a., leading dimension of `out`). + +The number of rows `k` in the output matrix is determined by the convolution `mode`: + +- `'full'`: `k = m + N - 1` +- `'same'`: `k = max( m, N )` +- `'valid'`: `k = abs( m - 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 ] ); +var out0 = new Float64Array( [ 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 ] ); + +// Create offset views: +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); +var out1 = new Float64Array( out0.buffer, out0.BYTES_PER_ELEMENT*1 ); + +gconvolutionMatrix( 'row-major', 'full', 2, 3, x1, 1, out1, 3 ); +// out0 => [ 0.0, 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 0.0, 2.0 ] +``` + + + +#### gconvolutionMatrix.ndarray( mode, m, N, x, strideX, offsetX, out, strideOut1, strideOut2, offsetOut ) + + + +Generates a convolution matrix using alternative indexing semantics. + +```javascript +var x = [ 1.0, 2.0 ]; +var 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 ]; + +gconvolutionMatrix.ndarray( 'full', 2, 3, x, 1, 0, out, 3, 1, 0 ); +// out => [ 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 0.0, 2.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, offset parameters support indexing semantics based on starting indices. For example, to use every other element from the input array starting from the second element: + +```javascript +var x = [ 0.0, 1.0, 0.0, 2.0 ]; +var 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 ]; + +gconvolutionMatrix.ndarray( 'full', 2, 3, x, 2, 1, out, 3, 1, 0 ); +// out => [ 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 0.0, 2.0 ] +``` + +
+ + + +
+ +## Notes + +- If `m <= 0` or `N <= 0`, both functions return `out` unchanged. +- Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]). + +
+ + + +
+ +## Examples + + + +```javascript +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var zeros = require( '@stdlib/array/zeros' ); +var gconvolutionMatrix = require( '@stdlib/blas/ext/base/gconvolution-matrix' ); + +var m = 3; +var N = 4; +var mode = 'full'; +var order = 'row-major'; +var k = m + N - 1; +var shape = [ k, N ]; +var strides = shape2strides( shape, order ); + +var x = discreteUniform( m, 0, 10, { + 'dtype': 'generic' +}); +console.log( 'x:', x ); + +var out = zeros( k*N, 'generic' ); + +gconvolutionMatrix( order, mode, m, N, x, 1, out, N ); +console.log( ndarray2array( out, shape, strides, 0, order ) ); +``` + +
+ + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/gconvolution-matrix/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/gconvolution-matrix/benchmark/benchmark.js new file mode 100644 index 000000000000..c2f044804f70 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gconvolution-matrix/benchmark/benchmark.js @@ -0,0 +1,111 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var zeros = require( '@stdlib/array/zeros' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var gconvolutionMatrix = 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 k; + var x; + + x = uniform( len, -10.0, 10.0, options ); + k = len + len - 1; + out = zeros( k * 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++ ) { + x[ 0 ] += 0.1; + v = gconvolutionMatrix( 'row-major', 'full', len, len, x, 1, out, len ); + if ( isnan( v[ i%v.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v[ i%v.length ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 3; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gconvolution-matrix/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gconvolution-matrix/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..1ad836f5f225 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gconvolution-matrix/benchmark/benchmark.ndarray.js @@ -0,0 +1,111 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var zeros = require( '@stdlib/array/zeros' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var gconvolutionMatrix = 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 k; + var x; + + x = uniform( len, -10.0, 10.0, options ); + k = len + len - 1; + out = zeros( k * 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++ ) { + x[ 0 ] += 0.1; + v = gconvolutionMatrix( 'full', len, len, x, 1, 0, out, len, 1, 0 ); + if ( isnan( v[ i%v.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v[ i%v.length ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 3; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:ndarray:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gconvolution-matrix/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/gconvolution-matrix/docs/repl.txt new file mode 100644 index 000000000000..7a8db9ba1e46 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gconvolution-matrix/docs/repl.txt @@ -0,0 +1,134 @@ + +{{alias}}( order, mode, m, N, x, strideX, out, ldo ) + Generates a convolution matrix. + + The number of rows `k` in the output matrix is determined by the convolution + `mode`: + + - 'full': k = m + N - 1 + - 'same': k = max( m, N ) + - 'valid': k = abs( m - N ) + 1 + + The `m`, `N`, and stride parameters determine which elements in the strided + arrays are accessed at runtime. + + If `m` or `N` is less than or equal to `0`, the function returns `out` + unchanged. + + Parameters + ---------- + order: string + Storage layout. + + mode: string + Convolution mode. Must be one of 'full', 'same', or 'valid'. + + m: integer + Number of indexed elements in `x`. + + N: integer + Number of columns in the output matrix. + + x: ArrayLikeObject + Input array. + + 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`). + + Returns + ------- + out: ArrayLikeObject + Output array. + + Examples + -------- + // Standard Usage: + > var x = [ 1.0, 2.0 ]; + > var 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 ]; + > {{alias}}( 'row-major', 'full', 2, 3, x, 1, out, 3 ) + [ 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 0.0, 2.0 ] + + // Using `m`, `N`, and stride parameters: + > x = [ 1.0, 0.0, 2.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 ]; + > {{alias}}( 'row-major', 'full', 2, 3, x, 2, out, 3 ) + [ 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 0.0, 2.0 ] + + +{{alias}}.ndarray( mode, m, N, x, sx, ox, out, so1, so2, oo ) + Generates a convolution matrix using alternative indexing semantics. + + The number of rows `k` in the output matrix is determined by the convolution + `mode`: + + - 'full': k = m + N - 1 + - 'same': k = max( m, N ) + - 'valid': k = abs( m - N ) + 1 + + While typed array views mandate a view offset based on the underlying + buffer, the offset parameters support indexing semantics based on starting + indices. + + If `m` or `N` is less than or equal to `0`, the function returns `out` + unchanged. + + Parameters + ---------- + mode: string + Convolution mode. Must be one of 'full', 'same', or 'valid'. + + m: integer + Number of indexed elements in `x`. + + N: integer + Number of columns in the output matrix. + + x: ArrayLikeObject + Input array. + + 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 ]; + > var 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 ]; + > {{alias}}.ndarray( 'full', 2, 3, x, 1, 0, out, 3, 1, 0 ) + [ 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 0.0, 2.0 ] + + // Using an index offset: + > x = [ 0.0, 1.0, 2.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 ]; + > {{alias}}.ndarray( 'full', 2, 3, x, 1, 1, out, 3, 1, 0 ) + [ 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 0.0, 2.0 ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/blas/ext/base/gconvolution-matrix/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/gconvolution-matrix/docs/types/index.d.ts new file mode 100644 index 000000000000..b16e32f049e0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gconvolution-matrix/docs/types/index.d.ts @@ -0,0 +1,124 @@ +/* +* @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; + +/** +* Convolution mode. +*/ +type Mode = 'full' | 'same' | 'valid'; + +/** +* Interface describing `gconvolutionMatrix`. +*/ +interface Routine { + /** + * Generates a convolution matrix. + * + * @param order - storage layout + * @param mode - convolution mode + * @param m - number of indexed elements in `x` + * @param N - number of columns in the output matrix + * @param x - input array + * @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 ]; + * var 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 ]; + * + * gconvolutionMatrix( 'row-major', 'full', 2, 3, x, 1, out, 3 ); + * // out => [ 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 0.0, 2.0 ] + */ + = OutputArray>( order: Layout, mode: Mode, m: number, N: number, x: InputArray, strideX: number, out: V, ldo: number ): V; + + /** + * Generates a convolution matrix using alternative indexing semantics. + * + * @param mode - convolution mode + * @param m - number of indexed elements in `x` + * @param N - number of columns in the output matrix + * @param x - input array + * @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 ]; + * var 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 ]; + * + * gconvolutionMatrix.ndarray( 'full', 2, 3, x, 1, 0, out, 3, 1, 0 ); + * // out => [ 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 0.0, 2.0 ] + */ + ndarray = OutputArray>( mode: Mode, m: number, N: number, x: InputArray, strideX: number, offsetX: number, out: V, strideOut1: number, strideOut2: number, offsetOut: number ): V; +} + +/** +* Generates a convolution matrix. +* +* @param order - storage layout +* @param mode - convolution mode +* @param m - number of indexed elements in `x` +* @param N - number of columns in the output matrix +* @param x - input array +* @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 ]; +* var 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 ]; +* +* gconvolutionMatrix( 'row-major', 'full', 2, 3, x, 1, out, 3 ); +* // out => [ 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 0.0, 2.0 ] +* +* @example +* var x = [ 1.0, 2.0 ]; +* var 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 ]; +* +* gconvolutionMatrix.ndarray( 'full', 2, 3, x, 1, 0, out, 3, 1, 0 ); +* // out => [ 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 0.0, 2.0 ] +*/ +declare var gconvolutionMatrix: Routine; + + +// EXPORTS // + +export = gconvolutionMatrix; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gconvolution-matrix/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/gconvolution-matrix/docs/types/test.ts new file mode 100644 index 000000000000..9f4889a983a9 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gconvolution-matrix/docs/types/test.ts @@ -0,0 +1,339 @@ +/* +* @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 gconvolutionMatrix = require( './index' ); + + +// TESTS // + +// The function returns a collection... +{ + const x = new Float64Array( 2 ); + const out = new Float64Array( 12 ); + + gconvolutionMatrix( 'row-major', 'full', 2, 3, x, 1, out, 3 ); // $ExpectType Float64Array + gconvolutionMatrix( 'row-major', 'full', 2, 3, new AccessorArray( 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( 2 ); + const out = new Float64Array( 12 ); + + gconvolutionMatrix( 10, 'full', 2, 3, x, 1, out, 3 ); // $ExpectError + gconvolutionMatrix( true, 'full', 2, 3, x, 1, out, 3 ); // $ExpectError + gconvolutionMatrix( false, 'full', 2, 3, x, 1, out, 3 ); // $ExpectError + gconvolutionMatrix( null, 'full', 2, 3, x, 1, out, 3 ); // $ExpectError + gconvolutionMatrix( undefined, 'full', 2, 3, x, 1, out, 3 ); // $ExpectError + gconvolutionMatrix( [], 'full', 2, 3, x, 1, out, 3 ); // $ExpectError + gconvolutionMatrix( {}, 'full', 2, 3, x, 1, out, 3 ); // $ExpectError + gconvolutionMatrix( ( x: number ): number => x, 'full', 2, 3, x, 1, out, 3 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a valid mode... +{ + const x = new Float64Array( 2 ); + const out = new Float64Array( 12 ); + + gconvolutionMatrix( 'row-major', 10, 2, 3, x, 1, out, 3 ); // $ExpectError + gconvolutionMatrix( 'row-major', true, 2, 3, x, 1, out, 3 ); // $ExpectError + gconvolutionMatrix( 'row-major', false, 2, 3, x, 1, out, 3 ); // $ExpectError + gconvolutionMatrix( 'row-major', null, 2, 3, x, 1, out, 3 ); // $ExpectError + gconvolutionMatrix( 'row-major', undefined, 2, 3, x, 1, out, 3 ); // $ExpectError + gconvolutionMatrix( 'row-major', [], 2, 3, x, 1, out, 3 ); // $ExpectError + gconvolutionMatrix( 'row-major', {}, 2, 3, x, 1, out, 3 ); // $ExpectError + gconvolutionMatrix( 'row-major', ( x: number ): number => x, 2, 3, x, 1, out, 3 ); // $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 out = new Float64Array( 12 ); + + gconvolutionMatrix( 'row-major', 'full', '10', 3, x, 1, out, 3 ); // $ExpectError + gconvolutionMatrix( 'row-major', 'full', true, 3, x, 1, out, 3 ); // $ExpectError + gconvolutionMatrix( 'row-major', 'full', false, 3, x, 1, out, 3 ); // $ExpectError + gconvolutionMatrix( 'row-major', 'full', null, 3, x, 1, out, 3 ); // $ExpectError + gconvolutionMatrix( 'row-major', 'full', undefined, 3, x, 1, out, 3 ); // $ExpectError + gconvolutionMatrix( 'row-major', 'full', [], 3, x, 1, out, 3 ); // $ExpectError + gconvolutionMatrix( 'row-major', 'full', {}, 3, x, 1, out, 3 ); // $ExpectError + gconvolutionMatrix( 'row-major', 'full', ( x: number ): number => x, 3, 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( 2 ); + const out = new Float64Array( 12 ); + + gconvolutionMatrix( 'row-major', 'full', 2, '10', x, 1, out, 3 ); // $ExpectError + gconvolutionMatrix( 'row-major', 'full', 2, true, x, 1, out, 3 ); // $ExpectError + gconvolutionMatrix( 'row-major', 'full', 2, false, x, 1, out, 3 ); // $ExpectError + gconvolutionMatrix( 'row-major', 'full', 2, null, x, 1, out, 3 ); // $ExpectError + gconvolutionMatrix( 'row-major', 'full', 2, undefined, x, 1, out, 3 ); // $ExpectError + gconvolutionMatrix( 'row-major', 'full', 2, [], x, 1, out, 3 ); // $ExpectError + gconvolutionMatrix( 'row-major', 'full', 2, {}, x, 1, out, 3 ); // $ExpectError + gconvolutionMatrix( 'row-major', 'full', 2, ( x: number ): number => x, x, 1, out, 3 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not a collection... +{ + const out = new Float64Array( 12 ); + + gconvolutionMatrix( 'row-major', 'full', 2, 3, 10, 1, out, 3 ); // $ExpectError + gconvolutionMatrix( 'row-major', 'full', 2, 3, true, 1, out, 3 ); // $ExpectError + gconvolutionMatrix( 'row-major', 'full', 2, 3, false, 1, out, 3 ); // $ExpectError + gconvolutionMatrix( 'row-major', 'full', 2, 3, null, 1, out, 3 ); // $ExpectError + gconvolutionMatrix( 'row-major', 'full', 2, 3, undefined, 1, out, 3 ); // $ExpectError + gconvolutionMatrix( 'row-major', 'full', 2, 3, {}, 1, out, 3 ); // $ExpectError + gconvolutionMatrix( 'row-major', 'full', 2, 3, ( x: number ): number => x, 1, out, 3 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a sixth argument which is not a number... +{ + const x = new Float64Array( 2 ); + const out = new Float64Array( 12 ); + + gconvolutionMatrix( 'row-major', 'full', 2, 3, x, '10', out, 3 ); // $ExpectError + gconvolutionMatrix( 'row-major', 'full', 2, 3, x, true, out, 3 ); // $ExpectError + gconvolutionMatrix( 'row-major', 'full', 2, 3, x, false, out, 3 ); // $ExpectError + gconvolutionMatrix( 'row-major', 'full', 2, 3, x, null, out, 3 ); // $ExpectError + gconvolutionMatrix( 'row-major', 'full', 2, 3, x, undefined, out, 3 ); // $ExpectError + gconvolutionMatrix( 'row-major', 'full', 2, 3, x, [], out, 3 ); // $ExpectError + gconvolutionMatrix( 'row-major', 'full', 2, 3, x, {}, out, 3 ); // $ExpectError + gconvolutionMatrix( 'row-major', 'full', 2, 3, x, ( x: number ): number => x, out, 3 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a seventh argument which is not a collection... +{ + const x = new Float64Array( 2 ); + + gconvolutionMatrix( 'row-major', 'full', 2, 3, x, 1, 10, 3 ); // $ExpectError + gconvolutionMatrix( 'row-major', 'full', 2, 3, x, 1, true, 3 ); // $ExpectError + gconvolutionMatrix( 'row-major', 'full', 2, 3, x, 1, false, 3 ); // $ExpectError + gconvolutionMatrix( 'row-major', 'full', 2, 3, x, 1, null, 3 ); // $ExpectError + gconvolutionMatrix( 'row-major', 'full', 2, 3, x, 1, undefined, 3 ); // $ExpectError + gconvolutionMatrix( 'row-major', 'full', 2, 3, x, 1, {}, 3 ); // $ExpectError + gconvolutionMatrix( 'row-major', 'full', 2, 3, x, 1, ( x: number ): number => x, 3 ); // $ExpectError +} + +// The compiler throws an error if the function is provided an eighth argument which is not a number... +{ + const x = new Float64Array( 2 ); + const out = new Float64Array( 12 ); + + gconvolutionMatrix( 'row-major', 'full', 2, 3, x, 1, out, '10' ); // $ExpectError + gconvolutionMatrix( 'row-major', 'full', 2, 3, x, 1, out, true ); // $ExpectError + gconvolutionMatrix( 'row-major', 'full', 2, 3, x, 1, out, false ); // $ExpectError + gconvolutionMatrix( 'row-major', 'full', 2, 3, x, 1, out, null ); // $ExpectError + gconvolutionMatrix( 'row-major', 'full', 2, 3, x, 1, out, undefined ); // $ExpectError + gconvolutionMatrix( 'row-major', 'full', 2, 3, x, 1, out, [] ); // $ExpectError + gconvolutionMatrix( 'row-major', 'full', 2, 3, x, 1, out, {} ); // $ExpectError + gconvolutionMatrix( 'row-major', 'full', 2, 3, 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( 2 ); + const out = new Float64Array( 12 ); + + gconvolutionMatrix(); // $ExpectError + gconvolutionMatrix( 'row-major' ); // $ExpectError + gconvolutionMatrix( 'row-major', 'full' ); // $ExpectError + gconvolutionMatrix( 'row-major', 'full', 2 ); // $ExpectError + gconvolutionMatrix( 'row-major', 'full', 2, 3 ); // $ExpectError + gconvolutionMatrix( 'row-major', 'full', 2, 3, x ); // $ExpectError + gconvolutionMatrix( 'row-major', 'full', 2, 3, x, 1 ); // $ExpectError + gconvolutionMatrix( 'row-major', 'full', 2, 3, x, 1, out ); // $ExpectError + gconvolutionMatrix( 'row-major', 'full', 2, 3, x, 1, out, 3, 10 ); // $ExpectError +} + +// Attached to the main export is an `ndarray` method which returns a collection... +{ + const x = new Float64Array( 2 ); + const out = new Float64Array( 12 ); + + gconvolutionMatrix.ndarray( 'full', 2, 3, x, 1, 0, out, 3, 1, 0 ); // $ExpectType Float64Array + gconvolutionMatrix.ndarray( 'full', 2, 3, new AccessorArray( 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 valid mode... +{ + const x = new Float64Array( 2 ); + const out = new Float64Array( 12 ); + + gconvolutionMatrix.ndarray( 10, 2, 3, x, 1, 0, out, 3, 1, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( true, 2, 3, x, 1, 0, out, 3, 1, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( false, 2, 3, x, 1, 0, out, 3, 1, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( null, 2, 3, x, 1, 0, out, 3, 1, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( undefined, 2, 3, x, 1, 0, out, 3, 1, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( [], 2, 3, x, 1, 0, out, 3, 1, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( {}, 2, 3, x, 1, 0, out, 3, 1, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( ( x: number ): number => x, 2, 3, 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 number... +{ + const x = new Float64Array( 2 ); + const out = new Float64Array( 12 ); + + gconvolutionMatrix.ndarray( 'full', '10', 3, x, 1, 0, out, 3, 1, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', true, 3, x, 1, 0, out, 3, 1, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', false, 3, x, 1, 0, out, 3, 1, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', null, 3, x, 1, 0, out, 3, 1, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', undefined, 3, x, 1, 0, out, 3, 1, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', [], 3, x, 1, 0, out, 3, 1, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', {}, 3, x, 1, 0, out, 3, 1, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', ( x: number ): number => x, 3, 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( 2 ); + const out = new Float64Array( 12 ); + + gconvolutionMatrix.ndarray( 'full', 2, '10', x, 1, 0, out, 3, 1, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, true, x, 1, 0, out, 3, 1, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, false, x, 1, 0, out, 3, 1, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, null, x, 1, 0, out, 3, 1, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, undefined, x, 1, 0, out, 3, 1, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, [], x, 1, 0, out, 3, 1, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, {}, x, 1, 0, out, 3, 1, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, ( x: number ): number => x, x, 1, 0, out, 3, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a collection... +{ + const out = new Float64Array( 12 ); + + gconvolutionMatrix.ndarray( 'full', 2, 3, 10, 1, 0, out, 3, 1, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, 3, true, 1, 0, out, 3, 1, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, 3, false, 1, 0, out, 3, 1, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, 3, null, 1, 0, out, 3, 1, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, 3, undefined, 1, 0, out, 3, 1, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, 3, {}, 1, 0, out, 3, 1, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, 3, ( x: number ): number => x, 1, 0, out, 3, 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 out = new Float64Array( 12 ); + + gconvolutionMatrix.ndarray( 'full', 2, 3, x, '10', 0, out, 3, 1, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, 3, x, true, 0, out, 3, 1, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, 3, x, false, 0, out, 3, 1, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, 3, x, null, 0, out, 3, 1, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, 3, x, undefined, 0, out, 3, 1, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, 3, x, [], 0, out, 3, 1, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, 3, x, {}, 0, out, 3, 1, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, 3, x, ( x: number ): number => x, 0, out, 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( 2 ); + const out = new Float64Array( 12 ); + + gconvolutionMatrix.ndarray( 'full', 2, 3, x, 1, '10', out, 3, 1, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, 3, x, 1, true, out, 3, 1, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, 3, x, 1, false, out, 3, 1, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, 3, x, 1, null, out, 3, 1, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, 3, x, 1, undefined, out, 3, 1, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, 3, x, 1, [], out, 3, 1, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, 3, x, 1, {}, out, 3, 1, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, 3, x, 1, ( x: number ): number => x, out, 3, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a seventh argument which is not a collection... +{ + const x = new Float64Array( 2 ); + + gconvolutionMatrix.ndarray( 'full', 2, 3, x, 1, 0, 10, 3, 1, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, 3, x, 1, 0, true, 3, 1, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, 3, x, 1, 0, false, 3, 1, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, 3, x, 1, 0, null, 3, 1, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, 3, x, 1, 0, undefined, 3, 1, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, 3, x, 1, 0, {}, 3, 1, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, 3, x, 1, 0, ( x: number ): number => x, 3, 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 out = new Float64Array( 12 ); + + gconvolutionMatrix.ndarray( 'full', 2, 3, x, 1, 0, out, '10', 1, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, 3, x, 1, 0, out, true, 1, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, 3, x, 1, 0, out, false, 1, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, 3, x, 1, 0, out, null, 1, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, 3, x, 1, 0, out, undefined, 1, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, 3, x, 1, 0, out, [], 1, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, 3, x, 1, 0, out, {}, 1, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, 3, x, 1, 0, out, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a ninth argument which is not a number... +{ + const x = new Float64Array( 2 ); + const out = new Float64Array( 12 ); + + gconvolutionMatrix.ndarray( 'full', 2, 3, x, 1, 0, out, 3, '10', 0 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, 3, x, 1, 0, out, 3, true, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, 3, x, 1, 0, out, 3, false, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, 3, x, 1, 0, out, 3, null, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, 3, x, 1, 0, out, 3, undefined, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, 3, x, 1, 0, out, 3, [], 0 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, 3, x, 1, 0, out, 3, {}, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, 3, x, 1, 0, out, 3, ( x: number ): number => x, 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 out = new Float64Array( 12 ); + + gconvolutionMatrix.ndarray( 'full', 2, 3, x, 1, 0, out, 3, 1, '10' ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, 3, x, 1, 0, out, 3, 1, true ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, 3, x, 1, 0, out, 3, 1, false ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, 3, x, 1, 0, out, 3, 1, null ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, 3, x, 1, 0, out, 3, 1, undefined ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, 3, x, 1, 0, out, 3, 1, [] ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, 3, x, 1, 0, out, 3, 1, {} ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, 3, 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( 2 ); + const out = new Float64Array( 12 ); + + gconvolutionMatrix.ndarray(); // $ExpectError + gconvolutionMatrix.ndarray( 'full' ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, 3 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, 3, x ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, 3, x, 1 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, 3, x, 1, 0 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, 3, x, 1, 0, out ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, 3, x, 1, 0, out, 3 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, 3, x, 1, 0, out, 3, 1 ); // $ExpectError + gconvolutionMatrix.ndarray( 'full', 2, 3, x, 1, 0, out, 3, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gconvolution-matrix/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/gconvolution-matrix/examples/index.js new file mode 100644 index 000000000000..cda432c078b9 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gconvolution-matrix/examples/index.js @@ -0,0 +1,43 @@ +/** +* @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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var zeros = require( '@stdlib/array/zeros' ); +var gconvolutionMatrix = require( './../lib' ); + +var m = 3; +var N = 4; +var mode = 'full'; +var order = 'row-major'; +var k = m + N - 1; +var shape = [ k, N ]; +var strides = shape2strides( shape, order ); + +var x = discreteUniform( m, 0, 10, { + 'dtype': 'generic' +}); +console.log( 'x:', x ); + +var out = zeros( k*N, 'generic' ); + +gconvolutionMatrix( order, mode, m, N, x, 1, out, N ); +console.log( ndarray2array( out, shape, strides, 0, order ) ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gconvolution-matrix/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/gconvolution-matrix/lib/accessors.js new file mode 100644 index 000000000000..31f2e0141dd5 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gconvolution-matrix/lib/accessors.js @@ -0,0 +1,157 @@ +/** +* @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, max-len */ + +'use strict'; + +// MODULES // + +var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major' ); + + +// MAIN // + +/** +* Generates a convolution matrix using accessor arrays. +* +* @private +* @param {PositiveInteger} k - number of rows in the output matrix +* @param {NonNegativeInteger} startRow - starting row offset +* @param {NonNegativeInteger} m - number of indexed elements in `x` +* @param {NonNegativeInteger} N - number of columns in the output matrix +* @param {Object} x - input array object +* @param {integer} strideX - stride length for `x` +* @param {NonNegativeInteger} offsetX - starting index for `x` +* @param {Object} out - output array object +* @param {integer} strideOut1 - stride length for the first dimension of `out` +* @param {integer} strideOut2 - stride length for the second dimension of `out` +* @param {NonNegativeInteger} offsetOut - starting index for `out` +* @returns {Object} output array object +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +* +* var x = [ 1.0, 2.0, 3.0 ]; +* var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* gconvolutionMatrix( 5, 0, 3, 3, arraylike2object( toAccessorArray( x ) ), 1, 0, arraylike2object( toAccessorArray( out ) ), 3, 1, 0 ); +* // out => [ 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 3.0, 2.0, 1.0, 0.0, 3.0, 2.0, 0.0, 0.0, 3.0 ] +*/ +function gconvolutionMatrix( k, startRow, m, N, x, strideX, offsetX, out, strideOut1, strideOut2, offsetOut ) { + var jstart; + var istart; + var jend; + var iend; + var xbuf; + var obuf; + var getX; + var oset; + var do0; + var do1; + var tmp; + var io; + var ix; + var i; + var j; + + xbuf = x.data; + obuf = out.data; + getX = x.accessors[ 0 ]; + oset = out.accessors[ 1 ]; + + // Note on variable naming convention: S#, do#, io, i# where # corresponds to the loop number, with `0` being the innermost loop... + if ( isRowMajor( [ strideOut1, strideOut2 ] ) ) { + // Row-first iteration (inner loop walks columns): + do0 = strideOut2; + do1 = strideOut1 - ( N * strideOut2 ); + io = offsetOut; + for ( i = 0; i < k; i++ ) { + tmp = i + startRow; + + // Compute the valid column range: + jstart = tmp - m + 1; + if ( jstart < 0 ) { + jstart = 0; + } + jend = tmp; + if ( jend > N - 1 ) { + jend = N - 1; + } + // Leading zeros: + for ( j = 0; j < jstart; j++ ) { + oset( obuf, io, 0.0 ); + io += do0; + } + // Values from `x` (index decreases as column increases): + ix = offsetX + ( ( tmp - jstart ) * strideX ); + for ( j = jstart; j <= jend; j++ ) { + oset( obuf, io, getX( xbuf, ix ) ); + ix -= strideX; + io += do0; + } + // Trailing zeros: + for ( j = jend + 1; j < N; j++ ) { + oset( obuf, io, 0.0 ); + io += do0; + } + io += do1; + } + } else { + // Column-first iteration (inner loop walks rows): + do0 = strideOut1; + do1 = strideOut2 - ( k * strideOut1 ); + io = offsetOut; + for ( j = 0; j < N; j++ ) { + // Compute the valid row range: + istart = j - startRow; + if ( istart < 0 ) { + istart = 0; + } + iend = j - startRow + m - 1; + if ( iend > k - 1 ) { + iend = k - 1; + } + // Leading zeros: + for ( i = 0; i < istart; i++ ) { + oset( obuf, io, 0.0 ); + io += do0; + } + // Values from `x` (index increases as row increases): + ix = offsetX + ( ( istart + startRow - j ) * strideX ); + for ( i = istart; i <= iend; i++ ) { + oset( obuf, io, getX( xbuf, ix ) ); + ix += strideX; + io += do0; + } + // Trailing zeros: + for ( i = iend + 1; i < k; i++ ) { + oset( obuf, io, 0.0 ); + io += do0; + } + io += do1; + } + } + return out; +} + + +// EXPORTS // + +module.exports = gconvolutionMatrix; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gconvolution-matrix/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/gconvolution-matrix/lib/index.js new file mode 100644 index 000000000000..a18471923773 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gconvolution-matrix/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 convolution matrix. +* +* @module @stdlib/blas/ext/base/gconvolution-matrix +* +* @example +* var gconvolutionMatrix = require( '@stdlib/blas/ext/base/gconvolution-matrix' ); +* +* var x = [ 1.0, 2.0, 3.0 ]; +* var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* gconvolutionMatrix( 'row-major', 'full', 3, 3, x, 1, out, 3 ); +* // out => [ 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 3.0, 2.0, 1.0, 0.0, 3.0, 2.0, 0.0, 0.0, 3.0 ] +* +* @example +* var gconvolutionMatrix = require( '@stdlib/blas/ext/base/gconvolution-matrix' ); +* +* var x = [ 1.0, 2.0, 3.0 ]; +* var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* gconvolutionMatrix.ndarray( 'full', 3, 3, x, 1, 0, out, 3, 1, 0 ); +* // out => [ 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 3.0, 2.0, 1.0, 0.0, 3.0, 2.0, 0.0, 0.0, 3.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/gconvolution-matrix/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/gconvolution-matrix/lib/main.js new file mode 100644 index 000000000000..23cd504594c1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gconvolution-matrix/lib/main.js @@ -0,0 +1,99 @@ +/** +* @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 resolveMode = require( './mode.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +/** +* Generates a convolution matrix. +* +* @param {(integer|string)} order - storage layout +* @param {string} mode - convolution mode +* @param {NonNegativeInteger} m - number of indexed elements in `x` +* @param {NonNegativeInteger} N - number of columns in the output matrix +* @param {Collection} x - input array +* @param {integer} strideX - stride length for `x` +* @param {Collection} out - output array +* @param {PositiveInteger} 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 {TypeError} second argument must be a valid mode +* @throws {RangeError} eighth 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, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* gconvolutionMatrix( 'row-major', 'full', 3, 3, x, 1, out, 3 ); +* // out => [ 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 3.0, 2.0, 1.0, 0.0, 3.0, 2.0, 0.0, 0.0, 3.0 ] +*/ +function gconvolutionMatrix( order, mode, m, N, x, strideX, out, ldo ) { + var iscm; + var tmp; + var sa1; + var sa2; + var ox; + var k; + var l; + + l = resolveLayout( order ); + if ( l === null ) { + throw new TypeError( format( 'invalid argument. First argument must be a valid order. Value: `%s`.', order ) ); + } + if ( mode !== 'full' && mode !== 'same' && mode !== 'valid' ) { + throw new TypeError( format( 'invalid argument. Second argument must be a valid mode. Value: `%s`.', mode ) ); + } + if ( m <= 0 || N <= 0 ) { + return out; + } + tmp = resolveMode( mode, m, N, [ 0, 0 ] ); + k = tmp[ 0 ]; + iscm = isColumnMajor( l ); + if ( iscm ) { + if ( ldo < max( 1, k ) ) { + throw new RangeError( format( 'invalid argument. Eighth argument must be greater than or equal to max(1,%d). Value: `%d`.', k, ldo ) ); + } + sa1 = 1; + sa2 = ldo; + } else { // order === 'row-major' + if ( ldo < max( 1, N ) ) { + throw new RangeError( format( 'invalid argument. Eighth argument must be greater than or equal to max(1,%d). Value: `%d`.', N, ldo ) ); + } + sa1 = ldo; + sa2 = 1; + } + ox = stride2offset( m, strideX ); + return ndarray( mode, m, N, x, strideX, ox, out, sa1, sa2, 0 ); +} + + +// EXPORTS // + +module.exports = gconvolutionMatrix; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gconvolution-matrix/lib/mode.js b/lib/node_modules/@stdlib/blas/ext/base/gconvolution-matrix/lib/mode.js new file mode 100644 index 000000000000..8a98ba9b1d15 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gconvolution-matrix/lib/mode.js @@ -0,0 +1,69 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MAIN // + +/** +* Resolves the number of output rows and the starting row offset for a convolution matrix. +* +* @private +* @param {string} mode - convolution mode +* @param {NonNegativeInteger} m - number of indexed elements in `x` +* @param {NonNegativeInteger} N - number of columns in the output matrix +* @param {Array} out - output array for storing the result +* @returns {Array} output array where `out[0]` is the number of rows and `out[1]` is the starting row offset +* +* @example +* var out = [ 0, 0 ]; +* resolveMode( 'full', 3, 3, out ); +* // out => [ 5, 0 ] +* +* @example +* var out = [ 0, 0 ]; +* resolveMode( 'same', 3, 3, out ); +* // out => [ 3, 1 ] +* +* @example +* var out = [ 0, 0 ]; +* resolveMode( 'valid', 3, 5, out ); +* // out => [ 3, 2 ] +*/ +function resolveMode( mode, m, N, out ) { + var d; + if ( mode === 'full' ) { + out[ 0 ] = m + N - 1; + out[ 1 ] = 0; + } else if ( mode === 'same' ) { + out[ 0 ] = ( m >= N ) ? m : N; + d = ( m < N ) ? m : N; + out[ 1 ] = ( ( d - 1 ) / 2 ) | 0; + } else { // mode === 'valid' + d = m - N; + out[ 0 ] = ( ( d < 0 ) ? -d : d ) + 1; + d = ( m < N ) ? m : N; + out[ 1 ] = d - 1; + } + return out; +} + + +// EXPORTS // + +module.exports = resolveMode; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gconvolution-matrix/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gconvolution-matrix/lib/ndarray.js new file mode 100644 index 000000000000..fcd30d963055 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gconvolution-matrix/lib/ndarray.js @@ -0,0 +1,161 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major' ); +var resolveMode = require( './mode.js' ); +var accessors = require( './accessors.js' ); + + +// MAIN // + +/** +* Generates a convolution matrix using alternative indexing semantics. +* +* @param {string} mode - convolution mode +* @param {NonNegativeInteger} m - number of indexed elements in `x` +* @param {NonNegativeInteger} N - number of columns in the output matrix +* @param {Collection} x - input array +* @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, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* gconvolutionMatrix( 'full', 3, 3, x, 1, 0, out, 3, 1, 0 ); +* // out => [ 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 3.0, 2.0, 1.0, 0.0, 3.0, 2.0, 0.0, 0.0, 3.0 ] +*/ +function gconvolutionMatrix( mode, m, N, x, strideX, offsetX, out, strideOut1, strideOut2, offsetOut ) { // eslint-disable-line max-len + var startRow; + var jstart; + var istart; + var jend; + var iend; + var do0; + var do1; + var tmp; + var ox; + var oo; + var io; + var ix; + var k; + var i; + var j; + + if ( m <= 0 || N <= 0 ) { + return out; + } + tmp = resolveMode( mode, m, N, [ 0, 0 ] ); + k = tmp[ 0 ]; + startRow = tmp[ 1 ]; + + ox = arraylike2object( x ); + oo = arraylike2object( out ); + if ( ox.accessorProtocol || oo.accessorProtocol ) { + accessors( k, startRow, m, N, ox, strideX, offsetX, oo, strideOut1, strideOut2, offsetOut ); // eslint-disable-line max-len + return out; + } + // Note on variable naming convention: S#, do#, io, i# where # corresponds to the loop number, with `0` being the innermost loop... + if ( isRowMajor( [ strideOut1, strideOut2 ] ) ) { + // Row-first iteration (inner loop walks columns): + do0 = strideOut2; + do1 = strideOut1 - ( N * strideOut2 ); + io = offsetOut; + for ( i = 0; i < k; i++ ) { + tmp = i + startRow; + + // Compute the valid column range: + jstart = tmp - m + 1; + if ( jstart < 0 ) { + jstart = 0; + } + jend = tmp; + if ( jend > N - 1 ) { + jend = N - 1; + } + // Leading zeros: + for ( j = 0; j < jstart; j++ ) { + out[ io ] = 0.0; + io += do0; + } + // Values from `x` (index decreases as column increases): + ix = offsetX + ( ( tmp - jstart ) * strideX ); + for ( j = jstart; j <= jend; j++ ) { + out[ io ] = x[ ix ]; + ix -= strideX; + io += do0; + } + // Trailing zeros: + for ( j = jend + 1; j < N; j++ ) { + out[ io ] = 0.0; + io += do0; + } + io += do1; + } + } else { + // Column-first iteration (inner loop walks rows): + do0 = strideOut1; + do1 = strideOut2 - ( k * strideOut1 ); + io = offsetOut; + for ( j = 0; j < N; j++ ) { + // Compute the valid row range: + istart = j - startRow; + if ( istart < 0 ) { + istart = 0; + } + iend = j - startRow + m - 1; + if ( iend > k - 1 ) { + iend = k - 1; + } + // Leading zeros: + for ( i = 0; i < istart; i++ ) { + out[ io ] = 0.0; + io += do0; + } + // Values from `x` (index increases as row increases): + ix = offsetX + ( ( istart + startRow - j ) * strideX ); + for ( i = istart; i <= iend; i++ ) { + out[ io ] = x[ ix ]; + ix += strideX; + io += do0; + } + // Trailing zeros: + for ( i = iend + 1; i < k; i++ ) { + out[ io ] = 0.0; + io += do0; + } + io += do1; + } + } + return out; +} + + +// EXPORTS // + +module.exports = gconvolutionMatrix; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gconvolution-matrix/package.json b/lib/node_modules/@stdlib/blas/ext/base/gconvolution-matrix/package.json new file mode 100644 index 000000000000..dd35001e297e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gconvolution-matrix/package.json @@ -0,0 +1,69 @@ +{ + "name": "@stdlib/blas/ext/base/gconvolution-matrix", + "version": "0.0.0", + "description": "Generate a convolution 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", + "convolution", + "matrix", + "strided", + "strided array", + "typed", + "array", + "ndarray", + "vector", + "gconvolution-matrix" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gconvolution-matrix/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/gconvolution-matrix/test/test.js new file mode 100644 index 000000000000..92127c4f397d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gconvolution-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 gconvolutionMatrix = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gconvolutionMatrix, '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 gconvolutionMatrix.ndarray, 'function', 'method is a function' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gconvolution-matrix/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/gconvolution-matrix/test/test.main.js new file mode 100644 index 000000000000..80cde82ef519 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gconvolution-matrix/test/test.main.js @@ -0,0 +1,897 @@ +/** +* @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 zeros = require( '@stdlib/array/zeros' ); +var gconvolutionMatrix = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gconvolutionMatrix, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 8', function test( t ) { + t.strictEqual( gconvolutionMatrix.length, 8, '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() { + gconvolutionMatrix( value, 'full', 3, 3, [ 1.0, 2.0, 3.0 ], 1, zeros( 15, 'generic' ), 3 ); + }; + } +}); + +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() { + gconvolutionMatrix( value, 'full', 3, 3, toAccessorArray( [ 1.0, 2.0, 3.0 ] ), 1, toAccessorArray( zeros( 15, 'generic' ) ), 3 ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid second argument', function test( t ) { + var values; + var i; + + values = [ + 'foo', + 'bar', + 'partial' + ]; + + 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() { + gconvolutionMatrix( 'row-major', value, 3, 3, [ 1.0, 2.0, 3.0 ], 1, zeros( 15, 'generic' ), 3 ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid second argument (accessors)', function test( t ) { + var values; + var i; + + values = [ + 'foo', + 'bar', + 'partial' + ]; + + 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() { + gconvolutionMatrix( 'row-major', value, 3, 3, toAccessorArray( [ 1.0, 2.0, 3.0 ] ), 1, toAccessorArray( zeros( 15, 'generic' ) ), 3 ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid eighth argument (row-major)', function test( t ) { + var values; + var i; + + values = [ + -3, + -2, + -1, + 0, + 1, + 2 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + gconvolutionMatrix( 'row-major', 'full', 3, 3, [ 1.0, 2.0, 3.0 ], 1, zeros( 15, 'generic' ), value ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid eighth argument (row-major, accessors)', function test( t ) { + var values; + var i; + + values = [ + -3, + -2, + -1, + 0, + 1, + 2 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + gconvolutionMatrix( 'row-major', 'full', 3, 3, toAccessorArray( [ 1.0, 2.0, 3.0 ] ), 1, toAccessorArray( zeros( 15, 'generic' ) ), value ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid eighth argument (column-major)', function test( t ) { + var values; + var i; + + values = [ + -3, + -2, + -1, + 0, + 1, + 2, + 3, + 4 + ]; + + 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() { + gconvolutionMatrix( 'column-major', 'full', 3, 3, [ 1.0, 2.0, 3.0 ], 1, zeros( 15, 'generic' ), value ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid eighth argument (column-major, accessors)', function test( t ) { + var values; + var i; + + values = [ + -3, + -2, + -1, + 0, + 1, + 2, + 3, + 4 + ]; + + 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() { + gconvolutionMatrix( 'column-major', 'full', 3, 3, toAccessorArray( [ 1.0, 2.0, 3.0 ] ), 1, toAccessorArray( zeros( 15, 'generic' ) ), value ); + }; + } +}); + +tape( 'if provided `m` less than or equal to `0`, the function returns the output array unchanged', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0 ]; + out = [ 0.0, 0.0, 0.0 ]; + + gconvolutionMatrix( 'row-major', 'full', 0, 3, x, 1, out, 3 ); + + expected = [ 0.0, 0.0, 0.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + + out = [ 0.0, 0.0, 0.0 ]; + gconvolutionMatrix( 'row-major', 'full', -1, 3, x, 1, out, 3 ); + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided `m` less than or equal to `0`, the function returns the output array unchanged (accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0 ]; + out = [ 0.0, 0.0, 0.0 ]; + + gconvolutionMatrix( 'row-major', 'full', 0, 3, toAccessorArray( x ), 1, toAccessorArray( out ), 3 ); + + expected = [ 0.0, 0.0, 0.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided `N` less than or equal to `0`, the function returns the output array unchanged', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0 ]; + out = [ 0.0, 0.0, 0.0 ]; + + gconvolutionMatrix( 'row-major', 'full', 3, 0, x, 1, out, 1 ); + + expected = [ 0.0, 0.0, 0.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + + out = [ 0.0, 0.0, 0.0 ]; + gconvolutionMatrix( 'row-major', 'full', 3, -1, x, 1, out, 1 ); + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided `N` less than or equal to `0`, the function returns the output array unchanged (accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0 ]; + out = [ 0.0, 0.0, 0.0 ]; + + gconvolutionMatrix( 'row-major', 'full', 3, 0, toAccessorArray( x ), 1, toAccessorArray( out ), 1 ); + + expected = [ 0.0, 0.0, 0.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the output array', function test( t ) { + var out; + var v; + var x; + + x = [ 1.0, 2.0, 3.0 ]; + out = zeros( 15, 'generic' ); + + v = gconvolutionMatrix( 'row-major', 'full', 3, 3, x, 1, out, 3 ); + + t.strictEqual( v, out, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the output array (accessors)', function test( t ) { + var out; + var v; + var x; + + x = toAccessorArray( [ 1.0, 2.0, 3.0 ] ); + out = toAccessorArray( zeros( 15, 'generic' ) ); + + v = gconvolutionMatrix( 'row-major', 'full', 3, 3, x, 1, out, 3 ); + + t.strictEqual( v, out, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a convolution matrix (full, row-major)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0 ]; + out = zeros( 15, 'generic' ); + + gconvolutionMatrix( 'row-major', 'full', 3, 3, x, 1, out, 3 ); + + expected = [ 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 3.0, 2.0, 1.0, 0.0, 3.0, 2.0, 0.0, 0.0, 3.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a convolution matrix (full, row-major, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0 ]; + out = zeros( 15, 'generic' ); + + gconvolutionMatrix( 'row-major', 'full', 3, 3, toAccessorArray( x ), 1, toAccessorArray( out ), 3 ); + + expected = [ 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 3.0, 2.0, 1.0, 0.0, 3.0, 2.0, 0.0, 0.0, 3.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a convolution matrix (full, column-major)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0 ]; + out = zeros( 15, 'generic' ); + + gconvolutionMatrix( 'column-major', 'full', 3, 3, x, 1, out, 5 ); + + expected = [ 1.0, 2.0, 3.0, 0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 0.0, 0.0, 0.0, 1.0, 2.0, 3.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a convolution matrix (full, column-major, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0 ]; + out = zeros( 15, 'generic' ); + + gconvolutionMatrix( 'column-major', 'full', 3, 3, toAccessorArray( x ), 1, toAccessorArray( out ), 5 ); + + expected = [ 1.0, 2.0, 3.0, 0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 0.0, 0.0, 0.0, 1.0, 2.0, 3.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a convolution matrix (same, row-major)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0 ]; + out = zeros( 9, 'generic' ); + + gconvolutionMatrix( 'row-major', 'same', 3, 3, x, 1, out, 3 ); + + expected = [ 2.0, 1.0, 0.0, 3.0, 2.0, 1.0, 0.0, 3.0, 2.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a convolution matrix (same, row-major, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0 ]; + out = zeros( 9, 'generic' ); + + gconvolutionMatrix( 'row-major', 'same', 3, 3, toAccessorArray( x ), 1, toAccessorArray( out ), 3 ); + + expected = [ 2.0, 1.0, 0.0, 3.0, 2.0, 1.0, 0.0, 3.0, 2.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a convolution matrix (same, column-major)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0 ]; + out = zeros( 9, 'generic' ); + + gconvolutionMatrix( 'column-major', 'same', 3, 3, x, 1, out, 3 ); + + expected = [ 2.0, 3.0, 0.0, 1.0, 2.0, 3.0, 0.0, 1.0, 2.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a convolution matrix (same, column-major, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0 ]; + out = zeros( 9, 'generic' ); + + gconvolutionMatrix( 'column-major', 'same', 3, 3, toAccessorArray( x ), 1, toAccessorArray( out ), 3 ); + + expected = [ 2.0, 3.0, 0.0, 1.0, 2.0, 3.0, 0.0, 1.0, 2.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a convolution matrix (valid, row-major)', function test( t ) { + var expected; + var out; + var x; + + x = [ -1.0, 4.0, -2.0 ]; + out = zeros( 15, 'generic' ); + + gconvolutionMatrix( 'row-major', 'valid', 3, 5, x, 1, out, 5 ); + + expected = [ -2.0, 4.0, -1.0, 0.0, 0.0, 0.0, -2.0, 4.0, -1.0, 0.0, 0.0, 0.0, -2.0, 4.0, -1.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a convolution matrix (valid, row-major, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ -1.0, 4.0, -2.0 ]; + out = zeros( 15, 'generic' ); + + gconvolutionMatrix( 'row-major', 'valid', 3, 5, toAccessorArray( x ), 1, toAccessorArray( out ), 5 ); + + expected = [ -2.0, 4.0, -1.0, 0.0, 0.0, 0.0, -2.0, 4.0, -1.0, 0.0, 0.0, 0.0, -2.0, 4.0, -1.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a convolution matrix (valid, column-major)', function test( t ) { + var expected; + var out; + var x; + + x = [ -1.0, 4.0, -2.0 ]; + out = zeros( 15, 'generic' ); + + gconvolutionMatrix( 'column-major', 'valid', 3, 5, x, 1, out, 3 ); + + expected = [ -2.0, 0.0, 0.0, 4.0, -2.0, 0.0, -1.0, 4.0, -2.0, 0.0, -1.0, 4.0, 0.0, 0.0, -1.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a convolution matrix (valid, column-major, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ -1.0, 4.0, -2.0 ]; + out = zeros( 15, 'generic' ); + + gconvolutionMatrix( 'column-major', 'valid', 3, 5, toAccessorArray( x ), 1, toAccessorArray( out ), 3 ); + + expected = [ -2.0, 0.0, 0.0, 4.0, -2.0, 0.0, -1.0, 4.0, -2.0, 0.0, -1.0, 4.0, 0.0, 0.0, -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; + + x = [ 1.0, 0.0, 2.0, 0.0, 3.0 ]; + out = zeros( 15, 'generic' ); + + gconvolutionMatrix( 'row-major', 'full', 3, 3, x, 2, out, 3 ); + + expected = [ 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 3.0, 2.0, 1.0, 0.0, 3.0, 2.0, 0.0, 0.0, 3.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, 2.0, 0.0, 3.0 ]; + out = zeros( 15, 'generic' ); + + gconvolutionMatrix( 'row-major', 'full', 3, 3, toAccessorArray( x ), 2, toAccessorArray( out ), 3 ); + + expected = [ 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 3.0, 2.0, 1.0, 0.0, 3.0, 2.0, 0.0, 0.0, 3.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 = [ 3.0, 0.0, 2.0, 0.0, 1.0 ]; + out = zeros( 15, 'generic' ); + + gconvolutionMatrix( 'row-major', 'full', 3, 3, x, -2, out, 3 ); + + expected = [ 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 3.0, 2.0, 1.0, 0.0, 3.0, 2.0, 0.0, 0.0, 3.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 = [ 3.0, 0.0, 2.0, 0.0, 1.0 ]; + out = zeros( 15, 'generic' ); + + gconvolutionMatrix( 'row-major', 'full', 3, 3, toAccessorArray( x ), -2, toAccessorArray( out ), 3 ); + + expected = [ 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 3.0, 2.0, 1.0, 0.0, 3.0, 2.0, 0.0, 0.0, 3.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, 2.0, 0.0, 3.0 ]; + out = zeros( 15, 'generic' ); + + gconvolutionMatrix( 'column-major', 'full', 3, 3, x, 2, out, 5 ); + + expected = [ 1.0, 2.0, 3.0, 0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 0.0, 0.0, 0.0, 1.0, 2.0, 3.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, 2.0, 0.0, 3.0 ]; + out = zeros( 15, 'generic' ); + + gconvolutionMatrix( 'column-major', 'full', 3, 3, toAccessorArray( x ), 2, toAccessorArray( out ), 5 ); + + expected = [ 1.0, 2.0, 3.0, 0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 0.0, 0.0, 0.0, 1.0, 2.0, 3.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 = [ 3.0, 0.0, 2.0, 0.0, 1.0 ]; + out = zeros( 15, 'generic' ); + + gconvolutionMatrix( 'column-major', 'full', 3, 3, x, -2, out, 5 ); + + expected = [ 1.0, 2.0, 3.0, 0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 0.0, 0.0, 0.0, 1.0, 2.0, 3.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 = [ 3.0, 0.0, 2.0, 0.0, 1.0 ]; + out = zeros( 15, 'generic' ); + + gconvolutionMatrix( 'column-major', 'full', 3, 3, toAccessorArray( x ), -2, toAccessorArray( out ), 5 ); + + expected = [ 1.0, 2.0, 3.0, 0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 0.0, 0.0, 0.0, 1.0, 2.0, 3.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a convolution matrix (same, row-major, m < N)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0 ]; + out = zeros( 9, 'generic' ); + + gconvolutionMatrix( 'row-major', 'same', 2, 3, x, 1, out, 3 ); + + expected = [ 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 0.0, 2.0, 1.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a convolution matrix (same, row-major, m > N)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0, 4.0 ]; + out = zeros( 8, 'generic' ); + + gconvolutionMatrix( 'row-major', 'same', 4, 2, x, 1, out, 2 ); + + expected = [ 1.0, 0.0, 2.0, 1.0, 3.0, 2.0, 4.0, 3.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a convolution matrix (same, row-major, m < N, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0 ]; + out = zeros( 9, 'generic' ); + + gconvolutionMatrix( 'row-major', 'same', 2, 3, toAccessorArray( x ), 1, toAccessorArray( out ), 3 ); + + expected = [ 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 0.0, 2.0, 1.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a convolution matrix (same, row-major, m > N, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0, 4.0 ]; + out = zeros( 8, 'generic' ); + + gconvolutionMatrix( 'row-major', 'same', 4, 2, toAccessorArray( x ), 1, toAccessorArray( out ), 2 ); + + expected = [ 1.0, 0.0, 2.0, 1.0, 3.0, 2.0, 4.0, 3.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a convolution matrix (valid, row-major, m > N)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + out = zeros( 9, 'generic' ); + + gconvolutionMatrix( 'row-major', 'valid', 5, 3, x, 1, out, 3 ); + + expected = [ 3.0, 2.0, 1.0, 4.0, 3.0, 2.0, 5.0, 4.0, 3.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a convolution matrix (valid, row-major, m > N, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + out = zeros( 9, 'generic' ); + + gconvolutionMatrix( 'row-major', 'valid', 5, 3, toAccessorArray( x ), 1, toAccessorArray( out ), 3 ); + + expected = [ 3.0, 2.0, 1.0, 4.0, 3.0, 2.0, 5.0, 4.0, 3.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an `ldo` larger than `N` (row-major)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.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 ]; + + gconvolutionMatrix( 'row-major', 'full', 2, 2, x, 1, out, 4 ); + + expected = [ + 1.0, + 0.0, + 0.0, + 0.0, + 2.0, + 1.0, + 0.0, + 0.0, + 0.0, + 2.0, + 0.0, + 0.0 + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an `ldo` larger than `N` (row-major, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.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 ]; + + gconvolutionMatrix( 'row-major', 'full', 2, 2, toAccessorArray( x ), 1, toAccessorArray( out ), 4 ); + + expected = [ + 1.0, + 0.0, + 0.0, + 0.0, + 2.0, + 1.0, + 0.0, + 0.0, + 0.0, + 2.0, + 0.0, + 0.0 + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an `ldo` larger than `N` (column-major)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gconvolutionMatrix( 'column-major', 'full', 2, 2, x, 1, out, 4 ); + + expected = [ + 1.0, + 2.0, + 0.0, + 0.0, + 0.0, + 1.0, + 2.0, + 0.0 + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an `ldo` larger than `N` (column-major, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gconvolutionMatrix( 'column-major', 'full', 2, 2, toAccessorArray( x ), 1, toAccessorArray( out ), 4 ); + + expected = [ + 1.0, + 2.0, + 0.0, + 0.0, + 0.0, + 1.0, + 2.0, + 0.0 + ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports view offsets', function test( t ) { + var expected; + var out; + var x0; + var x1; + + x0 = new Float64Array( [ 0.0, 1.0, 2.0, 3.0 ] ); + + x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + + out = new Float64Array( 15 ); + + gconvolutionMatrix( 'row-major', 'full', 3, 3, x1, 1, out, 3 ); + + expected = new Float64Array([ + 1.0, + 0.0, + 0.0, + 2.0, + 1.0, + 0.0, + 3.0, + 2.0, + 1.0, + 0.0, + 3.0, + 2.0, + 0.0, + 0.0, + 3.0 + ]); + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gconvolution-matrix/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gconvolution-matrix/test/test.ndarray.js new file mode 100644 index 000000000000..6fd72f14c1e5 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gconvolution-matrix/test/test.ndarray.js @@ -0,0 +1,866 @@ +/** +* @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 zeros = require( '@stdlib/array/zeros' ); +var gconvolutionMatrix = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gconvolutionMatrix, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 10', function test( t ) { + t.strictEqual( gconvolutionMatrix.length, 10, 'has expected arity' ); + t.end(); +}); + +tape( 'the function returns the output array', function test( t ) { + var out; + var v; + var x; + + x = [ 1.0, 2.0, 3.0 ]; + out = zeros( 15, 'generic' ); + + v = gconvolutionMatrix( 'full', 3, 3, x, 1, 0, out, 3, 1, 0 ); + + t.strictEqual( v, out, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the output array (accessors)', function test( t ) { + var out; + var v; + var x; + + x = toAccessorArray( [ 1.0, 2.0, 3.0 ] ); + out = toAccessorArray( zeros( 15, 'generic' ) ); + + v = gconvolutionMatrix( 'full', 3, 3, x, 1, 0, out, 3, 1, 0 ); + + t.strictEqual( v, out, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a convolution matrix (full, row-major)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0 ]; + out = zeros( 15, 'generic' ); + + gconvolutionMatrix( 'full', 3, 3, x, 1, 0, out, 3, 1, 0 ); + + expected = [ 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 3.0, 2.0, 1.0, 0.0, 3.0, 2.0, 0.0, 0.0, 3.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a convolution matrix (full, row-major, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0 ]; + out = zeros( 15, 'generic' ); + + gconvolutionMatrix( 'full', 3, 3, toAccessorArray( x ), 1, 0, toAccessorArray( out ), 3, 1, 0 ); + + expected = [ 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 3.0, 2.0, 1.0, 0.0, 3.0, 2.0, 0.0, 0.0, 3.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a convolution matrix (full, column-major)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0 ]; + out = zeros( 15, 'generic' ); + + gconvolutionMatrix( 'full', 3, 3, x, 1, 0, out, 1, 5, 0 ); + + expected = [ 1.0, 2.0, 3.0, 0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 0.0, 0.0, 0.0, 1.0, 2.0, 3.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a convolution matrix (full, column-major, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0 ]; + out = zeros( 15, 'generic' ); + + gconvolutionMatrix( 'full', 3, 3, toAccessorArray( x ), 1, 0, toAccessorArray( out ), 1, 5, 0 ); + + expected = [ 1.0, 2.0, 3.0, 0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 0.0, 0.0, 0.0, 1.0, 2.0, 3.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a convolution matrix (same, row-major)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0 ]; + out = zeros( 9, 'generic' ); + + gconvolutionMatrix( 'same', 3, 3, x, 1, 0, out, 3, 1, 0 ); + + expected = [ 2.0, 1.0, 0.0, 3.0, 2.0, 1.0, 0.0, 3.0, 2.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a convolution matrix (same, row-major, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0 ]; + out = zeros( 9, 'generic' ); + + gconvolutionMatrix( 'same', 3, 3, toAccessorArray( x ), 1, 0, toAccessorArray( out ), 3, 1, 0 ); + + expected = [ 2.0, 1.0, 0.0, 3.0, 2.0, 1.0, 0.0, 3.0, 2.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a convolution matrix (same, column-major)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0 ]; + out = zeros( 9, 'generic' ); + + gconvolutionMatrix( 'same', 3, 3, x, 1, 0, out, 1, 3, 0 ); + + expected = [ 2.0, 3.0, 0.0, 1.0, 2.0, 3.0, 0.0, 1.0, 2.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a convolution matrix (same, column-major, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0 ]; + out = zeros( 9, 'generic' ); + + gconvolutionMatrix( 'same', 3, 3, toAccessorArray( x ), 1, 0, toAccessorArray( out ), 1, 3, 0 ); + + expected = [ 2.0, 3.0, 0.0, 1.0, 2.0, 3.0, 0.0, 1.0, 2.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a convolution matrix (valid, row-major)', function test( t ) { + var expected; + var out; + var x; + + x = [ -1.0, 4.0, -2.0 ]; + out = zeros( 15, 'generic' ); + + gconvolutionMatrix( 'valid', 3, 5, x, 1, 0, out, 5, 1, 0 ); + + expected = [ -2.0, 4.0, -1.0, 0.0, 0.0, 0.0, -2.0, 4.0, -1.0, 0.0, 0.0, 0.0, -2.0, 4.0, -1.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a convolution matrix (valid, row-major, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ -1.0, 4.0, -2.0 ]; + out = zeros( 15, 'generic' ); + + gconvolutionMatrix( 'valid', 3, 5, toAccessorArray( x ), 1, 0, toAccessorArray( out ), 5, 1, 0 ); + + expected = [ -2.0, 4.0, -1.0, 0.0, 0.0, 0.0, -2.0, 4.0, -1.0, 0.0, 0.0, 0.0, -2.0, 4.0, -1.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a convolution matrix (valid, column-major)', function test( t ) { + var expected; + var out; + var x; + + x = [ -1.0, 4.0, -2.0 ]; + out = zeros( 15, 'generic' ); + + gconvolutionMatrix( 'valid', 3, 5, x, 1, 0, out, 1, 3, 0 ); + + expected = [ -2.0, 0.0, 0.0, 4.0, -2.0, 0.0, -1.0, 4.0, -2.0, 0.0, -1.0, 4.0, 0.0, 0.0, -1.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a convolution matrix (valid, column-major, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ -1.0, 4.0, -2.0 ]; + out = zeros( 15, 'generic' ); + + gconvolutionMatrix( 'valid', 3, 5, toAccessorArray( x ), 1, 0, toAccessorArray( out ), 1, 3, 0 ); + + expected = [ -2.0, 0.0, 0.0, 4.0, -2.0, 0.0, -1.0, 4.0, -2.0, 0.0, -1.0, 4.0, 0.0, 0.0, -1.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a convolution matrix (same, row-major, m < N)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0 ]; + out = zeros( 9, 'generic' ); + + gconvolutionMatrix( 'same', 2, 3, x, 1, 0, out, 3, 1, 0 ); + + expected = [ 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 0.0, 2.0, 1.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a convolution matrix (same, row-major, m < N, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0 ]; + out = zeros( 9, 'generic' ); + + gconvolutionMatrix( 'same', 2, 3, toAccessorArray( x ), 1, 0, toAccessorArray( out ), 3, 1, 0 ); + + expected = [ 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 0.0, 2.0, 1.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a convolution matrix (same, row-major, m > N)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0, 4.0 ]; + out = zeros( 8, 'generic' ); + + gconvolutionMatrix( 'same', 4, 2, x, 1, 0, out, 2, 1, 0 ); + + expected = [ 1.0, 0.0, 2.0, 1.0, 3.0, 2.0, 4.0, 3.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a convolution matrix (same, row-major, m > N, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0, 4.0 ]; + out = zeros( 8, 'generic' ); + + gconvolutionMatrix( 'same', 4, 2, toAccessorArray( x ), 1, 0, toAccessorArray( out ), 2, 1, 0 ); + + expected = [ 1.0, 0.0, 2.0, 1.0, 3.0, 2.0, 4.0, 3.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a convolution matrix (valid, row-major, m > N)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + out = zeros( 9, 'generic' ); + + gconvolutionMatrix( 'valid', 5, 3, x, 1, 0, out, 3, 1, 0 ); + + expected = [ 3.0, 2.0, 1.0, 4.0, 3.0, 2.0, 5.0, 4.0, 3.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a convolution matrix (valid, row-major, m > N, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + out = zeros( 9, 'generic' ); + + gconvolutionMatrix( 'valid', 5, 3, toAccessorArray( x ), 1, 0, toAccessorArray( out ), 3, 1, 0 ); + + expected = [ 3.0, 2.0, 1.0, 4.0, 3.0, 2.0, 5.0, 4.0, 3.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a convolution matrix (same, row-major, m < N)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0 ]; + out = zeros( 9, 'generic' ); + + gconvolutionMatrix( 'same', 2, 3, x, 1, 0, out, 3, 1, 0 ); + + expected = [ 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 0.0, 2.0, 1.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a convolution matrix (same, row-major, m < N, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0 ]; + out = zeros( 9, 'generic' ); + + gconvolutionMatrix( 'same', 2, 3, toAccessorArray( x ), 1, 0, toAccessorArray( out ), 3, 1, 0 ); + + expected = [ 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 0.0, 2.0, 1.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a convolution matrix (same, column-major, m < N)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0 ]; + out = zeros( 9, 'generic' ); + + gconvolutionMatrix( 'same', 2, 3, x, 1, 0, out, 1, 3, 0 ); + + expected = [ 1.0, 2.0, 0.0, 0.0, 1.0, 2.0, 0.0, 0.0, 1.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a convolution matrix (same, column-major, m < N, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0 ]; + out = zeros( 9, 'generic' ); + + gconvolutionMatrix( 'same', 2, 3, toAccessorArray( x ), 1, 0, toAccessorArray( out ), 1, 3, 0 ); + + expected = [ 1.0, 2.0, 0.0, 0.0, 1.0, 2.0, 0.0, 0.0, 1.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a convolution matrix (same, row-major, m > N)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0, 4.0 ]; + out = zeros( 8, 'generic' ); + + gconvolutionMatrix( 'same', 4, 2, x, 1, 0, out, 2, 1, 0 ); + + expected = [ 1.0, 0.0, 2.0, 1.0, 3.0, 2.0, 4.0, 3.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a convolution matrix (same, row-major, m > N, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0, 4.0 ]; + out = zeros( 8, 'generic' ); + + gconvolutionMatrix( 'same', 4, 2, toAccessorArray( x ), 1, 0, toAccessorArray( out ), 2, 1, 0 ); + + expected = [ 1.0, 0.0, 2.0, 1.0, 3.0, 2.0, 4.0, 3.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a convolution matrix (same, column-major, m > N)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0, 4.0 ]; + out = zeros( 8, 'generic' ); + + gconvolutionMatrix( 'same', 4, 2, x, 1, 0, out, 1, 4, 0 ); + + expected = [ 1.0, 2.0, 3.0, 4.0, 0.0, 1.0, 2.0, 3.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a convolution matrix (same, column-major, m > N, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0, 4.0 ]; + out = zeros( 8, 'generic' ); + + gconvolutionMatrix( 'same', 4, 2, toAccessorArray( x ), 1, 0, toAccessorArray( out ), 1, 4, 0 ); + + expected = [ 1.0, 2.0, 3.0, 4.0, 0.0, 1.0, 2.0, 3.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a convolution matrix (valid, row-major, m > N)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + out = zeros( 9, 'generic' ); + + gconvolutionMatrix( 'valid', 5, 3, x, 1, 0, out, 3, 1, 0 ); + + expected = [ 3.0, 2.0, 1.0, 4.0, 3.0, 2.0, 5.0, 4.0, 3.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a convolution matrix (valid, row-major, m > N, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + out = zeros( 9, 'generic' ); + + gconvolutionMatrix( 'valid', 5, 3, toAccessorArray( x ), 1, 0, toAccessorArray( out ), 3, 1, 0 ); + + expected = [ 3.0, 2.0, 1.0, 4.0, 3.0, 2.0, 5.0, 4.0, 3.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a convolution matrix (valid, column-major, m > N)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + out = zeros( 9, 'generic' ); + + gconvolutionMatrix( 'valid', 5, 3, x, 1, 0, out, 1, 3, 0 ); + + expected = [ 3.0, 4.0, 5.0, 2.0, 3.0, 4.0, 1.0, 2.0, 3.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a convolution matrix (valid, column-major, m > N, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + out = zeros( 9, 'generic' ); + + gconvolutionMatrix( 'valid', 5, 3, toAccessorArray( x ), 1, 0, toAccessorArray( out ), 1, 3, 0 ); + + expected = [ 3.0, 4.0, 5.0, 2.0, 3.0, 4.0, 1.0, 2.0, 3.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided `m` less than or equal to `0`, the function returns the output array unchanged', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0 ]; + out = [ 0.0, 0.0, 0.0 ]; + + gconvolutionMatrix( 'full', 0, 3, x, 1, 0, out, 3, 1, 0 ); + + expected = [ 0.0, 0.0, 0.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + + out = [ 0.0, 0.0, 0.0 ]; + gconvolutionMatrix( 'full', -1, 3, x, 1, 0, out, 3, 1, 0 ); + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided `m` less than or equal to `0`, the function returns the output array unchanged (accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0 ]; + out = [ 0.0, 0.0, 0.0 ]; + + gconvolutionMatrix( 'full', 0, 3, toAccessorArray( x ), 1, 0, toAccessorArray( out ), 3, 1, 0 ); + + expected = [ 0.0, 0.0, 0.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided `N` less than or equal to `0`, the function returns the output array unchanged', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0 ]; + out = [ 0.0, 0.0, 0.0 ]; + + gconvolutionMatrix( 'full', 3, 0, x, 1, 0, out, 0, 1, 0 ); + + expected = [ 0.0, 0.0, 0.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + + out = [ 0.0, 0.0, 0.0 ]; + gconvolutionMatrix( 'full', 3, -1, x, 1, 0, out, 0, 1, 0 ); + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided `N` less than or equal to `0`, the function returns the output array unchanged (accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0, 3.0 ]; + out = [ 0.0, 0.0, 0.0 ]; + + gconvolutionMatrix( 'full', 3, 0, toAccessorArray( x ), 1, 0, toAccessorArray( out ), 0, 1, 0 ); + + expected = [ 0.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, 2.0, 0.0, 3.0 ]; + out = zeros( 15, 'generic' ); + + gconvolutionMatrix( 'full', 3, 3, x, 2, 0, out, 3, 1, 0 ); + + expected = [ 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 3.0, 2.0, 1.0, 0.0, 3.0, 2.0, 0.0, 0.0, 3.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, 2.0, 0.0, 3.0 ]; + out = zeros( 15, 'generic' ); + + gconvolutionMatrix( 'full', 3, 3, toAccessorArray( x ), 2, 0, toAccessorArray( out ), 3, 1, 0 ); + + expected = [ 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 3.0, 2.0, 1.0, 0.0, 3.0, 2.0, 0.0, 0.0, 3.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 = [ 3.0, 0.0, 2.0, 0.0, 1.0 ]; + out = zeros( 15, 'generic' ); + + gconvolutionMatrix( 'full', 3, 3, x, -2, 4, out, 3, 1, 0 ); + + expected = [ 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 3.0, 2.0, 1.0, 0.0, 3.0, 2.0, 0.0, 0.0, 3.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 = [ 3.0, 0.0, 2.0, 0.0, 1.0 ]; + out = zeros( 15, 'generic' ); + + gconvolutionMatrix( 'full', 3, 3, toAccessorArray( x ), -2, 4, toAccessorArray( out ), 3, 1, 0 ); + + expected = [ 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 3.0, 2.0, 1.0, 0.0, 3.0, 2.0, 0.0, 0.0, 3.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, 2.0, 0.0, 3.0 ]; + out = zeros( 15, 'generic' ); + + gconvolutionMatrix( 'full', 3, 3, x, 2, 0, out, 1, 5, 0 ); + + expected = [ 1.0, 2.0, 3.0, 0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 0.0, 0.0, 0.0, 1.0, 2.0, 3.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, 2.0, 0.0, 3.0 ]; + out = zeros( 15, 'generic' ); + + gconvolutionMatrix( 'full', 3, 3, toAccessorArray( x ), 2, 0, toAccessorArray( out ), 1, 5, 0 ); + + expected = [ 1.0, 2.0, 3.0, 0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 0.0, 0.0, 0.0, 1.0, 2.0, 3.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 = [ 3.0, 0.0, 2.0, 0.0, 1.0 ]; + out = zeros( 15, 'generic' ); + + gconvolutionMatrix( 'full', 3, 3, x, -2, 4, out, 1, 5, 0 ); + + expected = [ 1.0, 2.0, 3.0, 0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 0.0, 0.0, 0.0, 1.0, 2.0, 3.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 = [ 3.0, 0.0, 2.0, 0.0, 1.0 ]; + out = zeros( 15, 'generic' ); + + gconvolutionMatrix( 'full', 3, 3, toAccessorArray( x ), -2, 4, toAccessorArray( out ), 1, 5, 0 ); + + expected = [ 1.0, 2.0, 3.0, 0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 0.0, 0.0, 0.0, 1.0, 2.0, 3.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 = [ + 0.0, + 1.0, // 0 + 2.0, // 1 + 3.0 // 2 + ]; + out = zeros( 15, 'generic' ); + + gconvolutionMatrix( 'full', 3, 3, x, 1, 1, out, 3, 1, 0 ); + + expected = [ 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 3.0, 2.0, 1.0, 0.0, 3.0, 2.0, 0.0, 0.0, 3.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 = [ + 0.0, + 1.0, // 0 + 2.0, // 1 + 3.0 // 2 + ]; + out = zeros( 15, 'generic' ); + + gconvolutionMatrix( 'full', 3, 3, toAccessorArray( x ), 1, 1, toAccessorArray( out ), 3, 1, 0 ); + + expected = [ 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 3.0, 2.0, 1.0, 0.0, 3.0, 2.0, 0.0, 0.0, 3.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, 2.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gconvolutionMatrix( 'full', 2, 2, x, 1, 0, out, 2, 1, 2 ); + + expected = [ 0.0, 0.0, 1.0, 0.0, 2.0, 1.0, 0.0, 2.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, 2.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gconvolutionMatrix( 'full', 2, 2, toAccessorArray( x ), 1, 0, toAccessorArray( out ), 2, 1, 2 ); + + expected = [ 0.0, 0.0, 1.0, 0.0, 2.0, 1.0, 0.0, 2.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 = [ + 0.0, + 1.0, // 0 + 0.0, + 2.0 // 1 + ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gconvolutionMatrix( 'full', 2, 2, x, 2, 1, out, 2, -1, 1 ); + + expected = [ 0.0, 1.0, 1.0, 2.0, 2.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 = [ + 0.0, + 1.0, // 0 + 0.0, + 2.0 // 1 + ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gconvolutionMatrix( 'full', 2, 2, toAccessorArray( x ), 2, 1, toAccessorArray( out ), 2, -1, 1 ); + + expected = [ 0.0, 1.0, 1.0, 2.0, 2.0, 0.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +});