diff --git a/lib/node_modules/@stdlib/blas/ext/base/gpermute-rows/README.md b/lib/node_modules/@stdlib/blas/ext/base/gpermute-rows/README.md new file mode 100644 index 000000000000..a2be282d800e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gpermute-rows/README.md @@ -0,0 +1,207 @@ + + +# gpermuteRows + +> Permute the rows of a matrix according to the specified strided permutation array. + +
+ +## Usage + +```javascript +var gpermuteRows = require( '@stdlib/blas/ext/base/gpermute-rows' ); +``` + +#### gpermuteRows( order, M, N, A, LDA, ip, strideIp, workspace, strideW ) + +Permutes the rows of a matrix according to the specified strided permutation array. + +```javascript +/* + A = [ + [ 1.0, 2.0 ], + [ 3.0, 4.0 ], + [ 5.0, 6.0 ] + ] +*/ +var A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +var ip = [ 2, 0, 1 ]; +var workspace = [ 0.0, 0.0 ]; + +gpermuteRows( 'row-major', 3, 2, A, 2, ip, 1, workspace, 1 ); +// A => [ 5.0, 6.0, 1.0, 2.0, 3.0, 4.0 ] +``` + +The function has the following parameters: + +- **order**: storage layout. +- **M**: number of rows in `A`. +- **N**: number of columns in `A`. +- **A**: input matrix as a linear array. +- **LDA**: stride length for the first dimension of `A` (a.k.a., leading dimension of the matrix `A`). +- **ip**: permutation index array. Must have at least `M` indexed elements. +- **strideIp**: stride length for `ip`. +- **workspace**: workspace array for storing a row during permutation. Must have at least `N` indexed elements. +- **strideW**: stride length for `workspace`. + +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 A0 = new Float64Array( [ 9999.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + +// Create offset views: +var A1 = new Float64Array( A0.buffer, A0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +var ip = [ 2, 0, 1 ]; +var workspace = [ 0.0, 0.0 ]; + +gpermuteRows( 'row-major', 3, 2, A1, 2, ip, 1, workspace, 1 ); +// A1 => [ 5.0, 6.0, 1.0, 2.0, 3.0, 4.0 ] +``` + + + +#### gpermuteRows.ndarray( M, N, A, strideA1, strideA2, offsetA, ip, strideIp, offsetIp, workspace, strideW, offsetW ) + +Permutes the rows of a matrix according to the specified strided permutation array using alternative indexing semantics. + +```javascript +/* + A = [ + [ 1.0, 2.0 ], + [ 3.0, 4.0 ], + [ 5.0, 6.0 ] + ] +*/ +var A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +var ip = [ 2, 0, 1 ]; +var workspace = [ 0.0, 0.0 ]; + +gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, ip, 1, 0, workspace, 1, 0 ); +// A => [ 5.0, 6.0, 1.0, 2.0, 3.0, 4.0 ] +``` + +The function has the following parameters: + +- **M**: number of rows in `A`. +- **N**: number of columns in `A`. +- **A**: input matrix as a linear array. +- **strideA1**: stride length for the first dimension of `A`. +- **strideA2**: stride length for the second dimension of `A`. +- **offsetA**: starting index for `A`. +- **ip**: permutation index array. Must have at least `M` indexed elements. +- **strideIp**: stride length for `ip`. +- **offsetIp**: starting index for `ip`. +- **workspace**: workspace array for storing a row during permutation. Must have at least `N` indexed elements. +- **strideW**: stride length for `workspace`. +- **offsetW**: starting index for `workspace`. + +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, + +```javascript +/* + A = [ + [ 1.0, 2.0 ], + [ 3.0, 4.0 ], + [ 5.0, 6.0 ] + ] +*/ +var A = [ 9999.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +var ip = [ 9999, 2, 0, 1 ]; +var workspace = [ 0.0, 0.0 ]; + +gpermuteRows.ndarray( 3, 2, A, 2, 1, 1, ip, 1, 1, workspace, 1, 0 ); +// A => [ 9999.0, 5.0, 6.0, 1.0, 2.0, 3.0, 4.0 ] +``` + +
+ + + +
+ +## Notes + +- The function permutes the rows of a matrix in-place using [cycle decomposition][cycle-decomposition]. +- Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]). + +
+ + + +
+ +## Examples + + + + + +```javascript +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var zeros = require( '@stdlib/array/zeros' ); +var gpermuteRows = require( '@stdlib/blas/ext/base/gpermute-rows' ); + +var shape = [ 4, 3 ]; +var order = 'row-major'; +var strides = shape2strides( shape, order ); + +var A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ]; +console.log( ndarray2array( A, shape, strides, 0, order ) ); + +var ip = [ 3, 0, 1, 2 ]; +var workspace = zeros( shape[ 1 ], 'generic' ); + +gpermuteRows( order, shape[ 0 ], shape[ 1 ], A, strides[ 0 ], ip, 1, workspace, 1 ); +console.log( ndarray2array( A, shape, strides, 0, order ) ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/gpermute-rows/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/gpermute-rows/benchmark/benchmark.js new file mode 100644 index 000000000000..fdbec0d9ff3f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gpermute-rows/benchmark/benchmark.js @@ -0,0 +1,125 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var zeros = require( '@stdlib/array/zeros' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var gpermuteRows = require( './../lib' ); + + +// VARIABLES // + +var LAYOUTS = [ + 'row-major', + 'column-major' +]; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {string} order - storage layout +* @param {PositiveInteger} N - number of elements along each dimension +* @returns {Function} benchmark function +*/ +function createBenchmark( order, N ) { + var workspace; + var ip; + var A; + var i; + + A = zeros( N*N, 'generic' ); + ip = zeros( N, 'generic' ); + workspace = zeros( N, 'generic' ); + for ( i = 0; i < N; i++ ) { + ip[ i ] = i; + } + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var k; + var z; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + k = ( i % ( N - 1 ) ) + 1; + ip[ 0 ] = k; + ip[ k ] = 0; + z = gpermuteRows( order, N, N, A, N, ip, 1, workspace, 1 ); + if ( isnan( z[ i%z.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( z[ i%z.length ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var min; + var max; + var ord; + var N; + var f; + var i; + var k; + + min = 1; // 10^min + max = 6; // 10^max + + for ( k = 0; k < LAYOUTS.length; k++ ) { + ord = LAYOUTS[ k ]; + for ( i = min; i <= max; i++ ) { + N = floor( pow( pow( 10, i ), 1.0/2.0 ) ); + f = createBenchmark( ord, N ); + bench( format( '%s::square_matrix:order=%s,size=%d', pkg, ord, N*N ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gpermute-rows/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gpermute-rows/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..17fa13d4420e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gpermute-rows/benchmark/benchmark.ndarray.js @@ -0,0 +1,135 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var zeros = require( '@stdlib/array/zeros' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var isColumnMajor = require( '@stdlib/ndarray/base/assert/is-column-major-string' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var gpermuteRows = require( './../lib/ndarray.js' ); + + +// VARIABLES // + +var LAYOUTS = [ + 'row-major', + 'column-major' +]; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {string} order - storage layout +* @param {PositiveInteger} N - number of elements along each dimension +* @returns {Function} benchmark function +*/ +function createBenchmark( order, N ) { + var workspace; + var sa1; + var sa2; + var ip; + var A; + var i; + + if ( isColumnMajor( order ) ) { + sa1 = 1; + sa2 = N; + } else { + sa1 = N; + sa2 = 1; + } + A = zeros( N*N, 'generic' ); + ip = zeros( N, 'generic' ); + workspace = zeros( N, 'generic' ); + for ( i = 0; i < N; i++ ) { + ip[ i ] = i; + } + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var k; + var z; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + k = ( i % ( N - 1 ) ) + 1; + ip[ 0 ] = k; + ip[ k ] = 0; + z = gpermuteRows( N, N, A, sa1, sa2, 0, ip, 1, 0, workspace, 1, 0 ); + if ( isnan( z[ i%z.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( z[ i%z.length ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var min; + var max; + var ord; + var N; + var f; + var i; + var k; + + min = 1; // 10^min + max = 6; // 10^max + + for ( k = 0; k < LAYOUTS.length; k++ ) { + ord = LAYOUTS[ k ]; + for ( i = min; i <= max; i++ ) { + N = floor( pow( pow( 10, i ), 1.0/2.0 ) ); + f = createBenchmark( ord, N ); + bench( format( '%s::square_matrix:ndarray:order=%s,size=%d', pkg, ord, N*N ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gpermute-rows/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/gpermute-rows/docs/repl.txt new file mode 100644 index 000000000000..43005d4a1631 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gpermute-rows/docs/repl.txt @@ -0,0 +1,120 @@ + +{{alias}}( order, M, N, A, LDA, ip, strideIp, workspace, strideW ) + Permutes the rows of a matrix according to the specified strided + permutation array. + + The permutation index array `ip` is modified during the operation + (each entry is set to its own index after processing). + + Indexing is relative to the first index. To introduce an offset, use + typed array views. + + Parameters + ---------- + order: string + Row-major (C-style) or column-major (Fortran-style) order. Must be + either 'row-major' or 'column-major'. + + M: integer + Number of rows in `A`. + + N: integer + Number of columns in `A`. + + A: Array|TypedArray + Input matrix. + + LDA: integer + Stride length for the first dimension of `A` (a.k.a., leading dimension + of the matrix `A`). + + ip: Array|TypedArray + Permutation index array. + + strideIp: integer + Stride length for `ip`. + + workspace: Array|TypedArray + Workspace array for storing a row during permutation. + + strideW: integer + Stride length for `workspace`. + + Returns + ------- + A: Array|TypedArray + Input matrix. + + Examples + -------- + > var A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + > var ip = [ 2, 0, 1 ]; + > var w = [ 0.0, 0.0 ]; + > {{alias}}( 'row-major', 3, 2, A, 2, ip, 1, w, 1 ) + [ 5.0, 6.0, 1.0, 2.0, 3.0, 4.0 ] + + +{{alias}}.ndarray( M, N, A, sa1, sa2, oa, ip, sip, oip, w, sw, ow ) + Permutes the rows of a matrix according to the specified strided + permutation array using alternative indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, offset parameters support indexing semantics based on starting + indices. + + The permutation index array `ip` is modified during the operation + (each entry is set to its own index after processing). + + Parameters + ---------- + M: integer + Number of rows in `A`. + + N: integer + Number of columns in `A`. + + A: Array|TypedArray + Input matrix. + + sa1: integer + Stride length for the first dimension of `A`. + + sa2: integer + Stride length for the second dimension of `A`. + + oa: integer + Starting index for `A`. + + ip: Array|TypedArray + Permutation index array. + + sip: integer + Stride length for `ip`. + + oip: integer + Starting index for `ip`. + + w: Array|TypedArray + Workspace array for storing a row during permutation. + + sw: integer + Stride length for `w`. + + ow: integer + Starting index for `w`. + + Returns + ------- + A: Array|TypedArray + Input matrix. + + Examples + -------- + > var A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + > var ip = [ 2, 0, 1 ]; + > var w = [ 0.0, 0.0 ]; + > {{alias}}.ndarray( 3, 2, A, 2, 1, 0, ip, 1, 0, w, 1, 0 ) + [ 5.0, 6.0, 1.0, 2.0, 3.0, 4.0 ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/blas/ext/base/gpermute-rows/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/gpermute-rows/docs/types/index.d.ts new file mode 100644 index 000000000000..b6ee4fabff41 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gpermute-rows/docs/types/index.d.ts @@ -0,0 +1,122 @@ +/* +* @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; + +/** +* Interface describing `gpermuteRows`. +*/ +interface Routine { + /** + * Permutes the rows of a matrix according to the specified strided permutation array. + * + * @param order - storage layout + * @param M - number of rows in `A` + * @param N - number of columns in `A` + * @param A - input matrix + * @param LDA - stride length for the first dimension of `A` (a.k.a., leading dimension of the matrix `A`) + * @param ip - permutation index array + * @param strideIp - stride length for `ip` + * @param workspace - workspace array for storing a row during permutation + * @param strideW - stride length for `workspace` + * @returns `A` + * + * @example + * var A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + * var ip = [ 2, 0, 1 ]; + * var workspace = [ 0.0, 0.0 ]; + * + * gpermuteRows( 'row-major', 3, 2, A, 2, ip, 1, workspace, 1 ); + * // A => [ 5.0, 6.0, 1.0, 2.0, 3.0, 4.0 ] + */ + = InputArray>( order: Layout, M: number, N: number, A: U, LDA: number, ip: InputArray, strideIp: number, workspace: InputArray, strideW: number ): U; + + /** + * Permutes the rows of a matrix according to the specified strided permutation array using alternative indexing semantics. + * + * @param M - number of rows in `A` + * @param N - number of columns in `A` + * @param A - input matrix + * @param strideA1 - stride length for the first dimension of `A` + * @param strideA2 - stride length for the second dimension of `A` + * @param offsetA - starting index for `A` + * @param ip - permutation index array + * @param strideIp - stride length for `ip` + * @param offsetIp - starting index for `ip` + * @param workspace - workspace array for storing a row during permutation + * @param strideW - stride length for `workspace` + * @param offsetW - starting index for `workspace` + * @returns `A` + * + * @example + * var A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + * var ip = [ 2, 0, 1 ]; + * var workspace = [ 0.0, 0.0 ]; + * + * gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, ip, 1, 0, workspace, 1, 0 ); + * // A => [ 5.0, 6.0, 1.0, 2.0, 3.0, 4.0 ] + */ + ndarray = InputArray>( M: number, N: number, A: U, strideA1: number, strideA2: number, offsetA: number, ip: InputArray, strideIp: number, offsetIp: number, workspace: InputArray, strideW: number, offsetW: number ): U; +} + +/** +* Permutes the rows of a matrix according to the specified strided permutation array. +* +* @param order - storage layout +* @param M - number of rows in `A` +* @param N - number of columns in `A` +* @param A - input matrix +* @param LDA - stride length for the first dimension of `A` (a.k.a., leading dimension of the matrix `A`) +* @param ip - permutation index array +* @param strideIp - stride length for `ip` +* @param workspace - workspace array for storing a row during permutation +* @param strideW - stride length for `workspace` +* @returns `A` +* +* @example +* var A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +* var ip = [ 2, 0, 1 ]; +* var workspace = [ 0.0, 0.0 ]; +* +* gpermuteRows( 'row-major', 3, 2, A, 2, ip, 1, workspace, 1 ); +* // A => [ 5.0, 6.0, 1.0, 2.0, 3.0, 4.0 ] +* +* @example +* var A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +* var ip = [ 2, 0, 1 ]; +* var workspace = [ 0.0, 0.0 ]; +* +* gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, ip, 1, 0, workspace, 1, 0 ); +* // A => [ 5.0, 6.0, 1.0, 2.0, 3.0, 4.0 ] +*/ +declare var gpermuteRows: Routine; + + +// EXPORTS // + +export = gpermuteRows; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gpermute-rows/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/gpermute-rows/docs/types/test.ts new file mode 100644 index 000000000000..fb2917cc0898 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gpermute-rows/docs/types/test.ts @@ -0,0 +1,403 @@ +/* +* @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. +*/ + +import gpermuteRows = require( './index' ); + + +// TESTS // + +// The function returns a collection... +{ + const A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + const ip = [ 2, 0, 1 ]; + const w = new Float64Array( [ 0.0, 0.0 ] ); + + gpermuteRows( 'row-major', 3, 2, A, 2, ip, 1, w, 1 ); // $ExpectType Float64Array +} + +// The compiler throws an error if the function is provided a first argument which is not a string... +{ + const A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + const ip = [ 2, 0, 1 ]; + const w = [ 0.0, 0.0 ]; + + gpermuteRows( 5, 3, 2, A, 2, ip, 1, w, 1 ); // $ExpectError + gpermuteRows( true, 3, 2, A, 2, ip, 1, w, 1 ); // $ExpectError + gpermuteRows( false, 3, 2, A, 2, ip, 1, w, 1 ); // $ExpectError + gpermuteRows( null, 3, 2, A, 2, ip, 1, w, 1 ); // $ExpectError + gpermuteRows( void 0, 3, 2, A, 2, ip, 1, w, 1 ); // $ExpectError + gpermuteRows( [], 3, 2, A, 2, ip, 1, w, 1 ); // $ExpectError + gpermuteRows( {}, 3, 2, A, 2, ip, 1, w, 1 ); // $ExpectError + gpermuteRows( ( x: number ): number => x, 3, 2, A, 2, ip, 1, w, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a number... +{ + const A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + const ip = [ 2, 0, 1 ]; + const w = [ 0.0, 0.0 ]; + + gpermuteRows( 'row-major', '5', 2, A, 2, ip, 1, w, 1 ); // $ExpectError + gpermuteRows( 'row-major', true, 2, A, 2, ip, 1, w, 1 ); // $ExpectError + gpermuteRows( 'row-major', false, 2, A, 2, ip, 1, w, 1 ); // $ExpectError + gpermuteRows( 'row-major', null, 2, A, 2, ip, 1, w, 1 ); // $ExpectError + gpermuteRows( 'row-major', void 0, 2, A, 2, ip, 1, w, 1 ); // $ExpectError + gpermuteRows( 'row-major', [], 2, A, 2, ip, 1, w, 1 ); // $ExpectError + gpermuteRows( 'row-major', {}, 2, A, 2, ip, 1, w, 1 ); // $ExpectError + gpermuteRows( 'row-major', ( x: number ): number => x, 2, A, 2, ip, 1, w, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a number... +{ + const A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + const ip = [ 2, 0, 1 ]; + const w = [ 0.0, 0.0 ]; + + gpermuteRows( 'row-major', 3, '5', A, 2, ip, 1, w, 1 ); // $ExpectError + gpermuteRows( 'row-major', 3, true, A, 2, ip, 1, w, 1 ); // $ExpectError + gpermuteRows( 'row-major', 3, false, A, 2, ip, 1, w, 1 ); // $ExpectError + gpermuteRows( 'row-major', 3, null, A, 2, ip, 1, w, 1 ); // $ExpectError + gpermuteRows( 'row-major', 3, void 0, A, 2, ip, 1, w, 1 ); // $ExpectError + gpermuteRows( 'row-major', 3, [], A, 2, ip, 1, w, 1 ); // $ExpectError + gpermuteRows( 'row-major', 3, {}, A, 2, ip, 1, w, 1 ); // $ExpectError + gpermuteRows( 'row-major', 3, ( x: number ): number => x, A, 2, ip, 1, w, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a collection... +{ + const ip = [ 2, 0, 1 ]; + const w = [ 0.0, 0.0 ]; + + gpermuteRows( 'row-major', 3, 2, 5, 2, ip, 1, w, 1 ); // $ExpectError + gpermuteRows( 'row-major', 3, 2, true, 2, ip, 1, w, 1 ); // $ExpectError + gpermuteRows( 'row-major', 3, 2, false, 2, ip, 1, w, 1 ); // $ExpectError + gpermuteRows( 'row-major', 3, 2, null, 2, ip, 1, w, 1 ); // $ExpectError + gpermuteRows( 'row-major', 3, 2, void 0, 2, ip, 1, w, 1 ); // $ExpectError + gpermuteRows( 'row-major', 3, 2, {}, 2, ip, 1, w, 1 ); // $ExpectError + gpermuteRows( 'row-major', 3, 2, ( x: number ): number => x, 2, ip, 1, w, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not a number... +{ + const A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + const ip = [ 2, 0, 1 ]; + const w = [ 0.0, 0.0 ]; + + gpermuteRows( 'row-major', 3, 2, A, '5', ip, 1, w, 1 ); // $ExpectError + gpermuteRows( 'row-major', 3, 2, A, true, ip, 1, w, 1 ); // $ExpectError + gpermuteRows( 'row-major', 3, 2, A, false, ip, 1, w, 1 ); // $ExpectError + gpermuteRows( 'row-major', 3, 2, A, null, ip, 1, w, 1 ); // $ExpectError + gpermuteRows( 'row-major', 3, 2, A, void 0, ip, 1, w, 1 ); // $ExpectError + gpermuteRows( 'row-major', 3, 2, A, [], ip, 1, w, 1 ); // $ExpectError + gpermuteRows( 'row-major', 3, 2, A, {}, ip, 1, w, 1 ); // $ExpectError + gpermuteRows( 'row-major', 3, 2, A, ( x: number ): number => x, ip, 1, w, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a sixth argument which is not a collection... +{ + const A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + const w = [ 0.0, 0.0 ]; + + gpermuteRows( 'row-major', 3, 2, A, 2, 5, 1, w, 1 ); // $ExpectError + gpermuteRows( 'row-major', 3, 2, A, 2, true, 1, w, 1 ); // $ExpectError + gpermuteRows( 'row-major', 3, 2, A, 2, false, 1, w, 1 ); // $ExpectError + gpermuteRows( 'row-major', 3, 2, A, 2, null, 1, w, 1 ); // $ExpectError + gpermuteRows( 'row-major', 3, 2, A, 2, void 0, 1, w, 1 ); // $ExpectError + gpermuteRows( 'row-major', 3, 2, A, 2, {}, 1, w, 1 ); // $ExpectError + gpermuteRows( 'row-major', 3, 2, A, 2, ( x: number ): number => x, 1, w, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a seventh argument which is not a number... +{ + const A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + const ip = [ 2, 0, 1 ]; + const w = [ 0.0, 0.0 ]; + + gpermuteRows( 'row-major', 3, 2, A, 2, ip, '5', w, 1 ); // $ExpectError + gpermuteRows( 'row-major', 3, 2, A, 2, ip, true, w, 1 ); // $ExpectError + gpermuteRows( 'row-major', 3, 2, A, 2, ip, false, w, 1 ); // $ExpectError + gpermuteRows( 'row-major', 3, 2, A, 2, ip, null, w, 1 ); // $ExpectError + gpermuteRows( 'row-major', 3, 2, A, 2, ip, void 0, w, 1 ); // $ExpectError + gpermuteRows( 'row-major', 3, 2, A, 2, ip, [], w, 1 ); // $ExpectError + gpermuteRows( 'row-major', 3, 2, A, 2, ip, {}, w, 1 ); // $ExpectError + gpermuteRows( 'row-major', 3, 2, A, 2, ip, ( x: number ): number => x, w, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided an eighth argument which is not a collection... +{ + const A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + const ip = [ 2, 0, 1 ]; + + gpermuteRows( 'row-major', 3, 2, A, 2, ip, 1, 5, 1 ); // $ExpectError + gpermuteRows( 'row-major', 3, 2, A, 2, ip, 1, true, 1 ); // $ExpectError + gpermuteRows( 'row-major', 3, 2, A, 2, ip, 1, false, 1 ); // $ExpectError + gpermuteRows( 'row-major', 3, 2, A, 2, ip, 1, null, 1 ); // $ExpectError + gpermuteRows( 'row-major', 3, 2, A, 2, ip, 1, void 0, 1 ); // $ExpectError + gpermuteRows( 'row-major', 3, 2, A, 2, ip, 1, {}, 1 ); // $ExpectError + gpermuteRows( 'row-major', 3, 2, A, 2, ip, 1, ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a ninth argument which is not a number... +{ + const A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + const ip = [ 2, 0, 1 ]; + const w = [ 0.0, 0.0 ]; + + gpermuteRows( 'row-major', 3, 2, A, 2, ip, 1, w, '5' ); // $ExpectError + gpermuteRows( 'row-major', 3, 2, A, 2, ip, 1, w, true ); // $ExpectError + gpermuteRows( 'row-major', 3, 2, A, 2, ip, 1, w, false ); // $ExpectError + gpermuteRows( 'row-major', 3, 2, A, 2, ip, 1, w, null ); // $ExpectError + gpermuteRows( 'row-major', 3, 2, A, 2, ip, 1, w, void 0 ); // $ExpectError + gpermuteRows( 'row-major', 3, 2, A, 2, ip, 1, w, [] ); // $ExpectError + gpermuteRows( 'row-major', 3, 2, A, 2, ip, 1, w, {} ); // $ExpectError + gpermuteRows( 'row-major', 3, 2, A, 2, ip, 1, w, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + const ip = [ 2, 0, 1 ]; + const w = [ 0.0, 0.0 ]; + + gpermuteRows(); // $ExpectError + gpermuteRows( 'row-major' ); // $ExpectError + gpermuteRows( 'row-major', 3 ); // $ExpectError + gpermuteRows( 'row-major', 3, 2 ); // $ExpectError + gpermuteRows( 'row-major', 3, 2, A ); // $ExpectError + gpermuteRows( 'row-major', 3, 2, A, 2 ); // $ExpectError + gpermuteRows( 'row-major', 3, 2, A, 2, ip ); // $ExpectError + gpermuteRows( 'row-major', 3, 2, A, 2, ip, 1 ); // $ExpectError + gpermuteRows( 'row-major', 3, 2, A, 2, ip, 1, w ); // $ExpectError + gpermuteRows( 'row-major', 3, 2, A, 2, ip, 1, w, 1, 0 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a collection... +{ + const A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + const ip = [ 2, 0, 1 ]; + const w = new Float64Array( [ 0.0, 0.0 ] ); + + gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, ip, 1, 0, w, 1, 0 ); // $ExpectType Float64Array +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + const ip = [ 2, 0, 1 ]; + const w = [ 0.0, 0.0 ]; + + gpermuteRows.ndarray( '5', 2, A, 2, 1, 0, ip, 1, 0, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( true, 2, A, 2, 1, 0, ip, 1, 0, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( false, 2, A, 2, 1, 0, ip, 1, 0, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( null, 2, A, 2, 1, 0, ip, 1, 0, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( void 0, 2, A, 2, 1, 0, ip, 1, 0, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( [], 2, A, 2, 1, 0, ip, 1, 0, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( {}, 2, A, 2, 1, 0, ip, 1, 0, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( ( x: number ): number => x, 2, A, 2, 1, 0, ip, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a number... +{ + const A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + const ip = [ 2, 0, 1 ]; + const w = [ 0.0, 0.0 ]; + + gpermuteRows.ndarray( 3, '5', A, 2, 1, 0, ip, 1, 0, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, true, A, 2, 1, 0, ip, 1, 0, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, false, A, 2, 1, 0, ip, 1, 0, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, null, A, 2, 1, 0, ip, 1, 0, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, void 0, A, 2, 1, 0, ip, 1, 0, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, [], A, 2, 1, 0, ip, 1, 0, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, {}, A, 2, 1, 0, ip, 1, 0, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, ( x: number ): number => x, A, 2, 1, 0, ip, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a collection... +{ + const ip = [ 2, 0, 1 ]; + const w = [ 0.0, 0.0 ]; + + gpermuteRows.ndarray( 3, 2, 5, 2, 1, 0, ip, 1, 0, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, true, 2, 1, 0, ip, 1, 0, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, false, 2, 1, 0, ip, 1, 0, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, null, 2, 1, 0, ip, 1, 0, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, void 0, 2, 1, 0, ip, 1, 0, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, {}, 2, 1, 0, ip, 1, 0, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, ( x: number ): number => x, 2, 1, 0, ip, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... +{ + const A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + const ip = [ 2, 0, 1 ]; + const w = [ 0.0, 0.0 ]; + + gpermuteRows.ndarray( 3, 2, A, '5', 1, 0, ip, 1, 0, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, true, 1, 0, ip, 1, 0, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, false, 1, 0, ip, 1, 0, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, null, 1, 0, ip, 1, 0, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, void 0, 1, 0, ip, 1, 0, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, [], 1, 0, ip, 1, 0, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, {}, 1, 0, ip, 1, 0, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, ( x: number ): number => x, 1, 0, ip, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a number... +{ + const A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + const ip = [ 2, 0, 1 ]; + const w = [ 0.0, 0.0 ]; + + gpermuteRows.ndarray( 3, 2, A, 2, '5', 0, ip, 1, 0, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, true, 0, ip, 1, 0, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, false, 0, ip, 1, 0, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, null, 0, ip, 1, 0, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, void 0, 0, ip, 1, 0, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, [], 0, ip, 1, 0, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, {}, 0, ip, 1, 0, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, ( x: number ): number => x, 0, ip, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a sixth argument which is not a number... +{ + const A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + const ip = [ 2, 0, 1 ]; + const w = [ 0.0, 0.0 ]; + + gpermuteRows.ndarray( 3, 2, A, 2, 1, '5', ip, 1, 0, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, 1, true, ip, 1, 0, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, 1, false, ip, 1, 0, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, 1, null, ip, 1, 0, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, 1, void 0, ip, 1, 0, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, 1, [], ip, 1, 0, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, 1, {}, ip, 1, 0, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, 1, ( x: number ): number => x, ip, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a seventh argument which is not a collection... +{ + const A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + const w = [ 0.0, 0.0 ]; + + gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, 5, 1, 0, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, true, 1, 0, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, false, 1, 0, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, null, 1, 0, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, void 0, 1, 0, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, {}, 1, 0, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, ( x: number ): number => x, 1, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an eighth argument which is not a number... +{ + const A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + const ip = [ 2, 0, 1 ]; + const w = [ 0.0, 0.0 ]; + + gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, ip, '5', 0, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, ip, true, 0, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, ip, false, 0, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, ip, null, 0, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, ip, void 0, 0, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, ip, [], 0, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, ip, {}, 0, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, ip, ( x: number ): number => x, 0, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a ninth argument which is not a number... +{ + const A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + const ip = [ 2, 0, 1 ]; + const w = [ 0.0, 0.0 ]; + + gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, ip, 1, '5', w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, ip, 1, true, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, ip, 1, false, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, ip, 1, null, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, ip, 1, void 0, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, ip, 1, [], w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, ip, 1, {}, w, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, ip, 1, ( x: number ): number => x, w, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a tenth argument which is not a collection... +{ + const A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + const ip = [ 2, 0, 1 ]; + + gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, ip, 1, 0, 5, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, ip, 1, 0, true, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, ip, 1, 0, false, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, ip, 1, 0, null, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, ip, 1, 0, void 0, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, ip, 1, 0, {}, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, ip, 1, 0, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an eleventh argument which is not a number... +{ + const A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + const ip = [ 2, 0, 1 ]; + const w = [ 0.0, 0.0 ]; + + gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, ip, 1, 0, w, '5', 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, ip, 1, 0, w, true, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, ip, 1, 0, w, false, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, ip, 1, 0, w, null, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, ip, 1, 0, w, void 0, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, ip, 1, 0, w, [], 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, ip, 1, 0, w, {}, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, ip, 1, 0, w, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a twelfth argument which is not a number... +{ + const A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + const ip = [ 2, 0, 1 ]; + const w = [ 0.0, 0.0 ]; + + gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, ip, 1, 0, w, 1, '5' ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, ip, 1, 0, w, 1, true ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, ip, 1, 0, w, 1, false ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, ip, 1, 0, w, 1, null ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, ip, 1, 0, w, 1, void 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, ip, 1, 0, w, 1, [] ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, ip, 1, 0, w, 1, {} ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, ip, 1, 0, w, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + const ip = [ 2, 0, 1 ]; + const w = [ 0.0, 0.0 ]; + + gpermuteRows.ndarray(); // $ExpectError + gpermuteRows.ndarray( 3 ); // $ExpectError + gpermuteRows.ndarray( 3, 2 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, 1 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, ip ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, ip, 1 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, ip, 1, 0 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, ip, 1, 0, w ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, ip, 1, 0, w, 1 ); // $ExpectError + gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, ip, 1, 0, w, 1, 0, 0 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gpermute-rows/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/gpermute-rows/examples/index.js new file mode 100644 index 000000000000..c047c1368673 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gpermute-rows/examples/index.js @@ -0,0 +1,39 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var zeros = require( '@stdlib/array/zeros' ); +var gpermuteRows = require( './../lib' ); + +var shape = [ 4, 3 ]; +var order = 'row-major'; +var strides = shape2strides( shape, order ); + +var A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ]; +console.log( ndarray2array( A, shape, strides, 0, order ) ); +// => [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ] + +var ip = [ 3, 0, 1, 2 ]; +var workspace = zeros( shape[ 1 ], 'generic' ); + +gpermuteRows( order, shape[ 0 ], shape[ 1 ], A, strides[ 0 ], ip, 1, workspace, 1 ); +console.log( ndarray2array( A, shape, strides, 0, order ) ); +// => [ [ 10, 11, 12 ], [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] diff --git a/lib/node_modules/@stdlib/blas/ext/base/gpermute-rows/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/gpermute-rows/lib/accessors.js new file mode 100644 index 000000000000..6ffac6206eeb --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gpermute-rows/lib/accessors.js @@ -0,0 +1,115 @@ +/** +* @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-len, max-params */ + +'use strict'; + +// MODULES // + +var gcopy = require( '@stdlib/blas/base/gcopy' ).ndarray; + + +// MAIN // + +/** +* Permutes the rows of a matrix according to the specified strided permutation array. +* +* @private +* @param {NonNegativeInteger} M - number of rows in matrix `A` +* @param {NonNegativeInteger} N - number of columns in matrix `A` +* @param {Object} A - input matrix object +* @param {Collection} A.data - input matrix data +* @param {Array} A.accessors - matrix element accessors +* @param {integer} strideA1 - stride length for the first dimension of `A` +* @param {integer} strideA2 - stride length for the second dimension of `A` +* @param {NonNegativeInteger} offsetA - starting index for `A` +* @param {Object} ip - permutation index array object +* @param {Collection} ip.data - permutation index array data +* @param {Array} ip.accessors - permutation index array element accessors +* @param {integer} strideIp - stride length for `ip` +* @param {NonNegativeInteger} offsetIp - starting index for `ip` +* @param {Object} workspace - workspace array object +* @param {Collection} workspace.data - workspace array data +* @param {Array} workspace.accessors - workspace array element accessors +* @param {integer} strideW - stride length for `workspace` +* @param {NonNegativeInteger} offsetW - starting index for `workspace` +* @returns {Object} `A` +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +* +* var A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +* var ip = [ 2, 0, 1 ]; +* var workspace = [ 0.0, 0.0 ]; +* +* gpermuteRows( 3, 2, arraylike2object( toAccessorArray( A ) ), 2, 1, 0, arraylike2object( toAccessorArray( ip ) ), 1, 0, arraylike2object( toAccessorArray( workspace ) ), 1, 0 ); +* // A => [ 5.0, 6.0, 1.0, 2.0, 3.0, 4.0 ] +*/ +function gpermuteRows( M, N, A, strideA1, strideA2, offsetA, ip, strideIp, offsetIp, workspace, strideW, offsetW ) { + var abuf; + var pbuf; + var wbuf; + var pget; + var pset; + var pp; + var i; + var j; + var k; + + // Cache references to array data: + abuf = A.data; + pbuf = ip.data; + wbuf = workspace.data; + + // Cache references to the element accessors: + pget = ip.accessors[ 0 ]; + pset = ip.accessors[ 1 ]; + + pp = offsetIp; + for ( i = 0; i < M; i++ ) { + if ( pget( pbuf, pp ) === i ) { + pp += strideIp; + continue; + } + // Save row `i` into the workspace... + gcopy( N, abuf, strideA2, offsetA+(i*strideA1), wbuf, strideW, offsetW ); + + // Follow the permutation cycle... + j = i; + k = pget( pbuf, offsetIp+(j*strideIp) ); + while ( k !== i ) { + // Copy row `k` into row `j`... + gcopy( N, abuf, strideA2, offsetA+(k*strideA1), abuf, strideA2, offsetA+(j*strideA1) ); + pset( pbuf, offsetIp+(j*strideIp), j ); + j = k; + k = pget( pbuf, offsetIp+(j*strideIp) ); + } + // Close the cycle by copying the workspace into row `j`... + gcopy( N, wbuf, strideW, offsetW, abuf, strideA2, offsetA+(j*strideA1) ); + pset( pbuf, offsetIp+(j*strideIp), j ); + pp += strideIp; + } + return A; +} + + +// EXPORTS // + +module.exports = gpermuteRows; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gpermute-rows/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/gpermute-rows/lib/index.js new file mode 100644 index 000000000000..d14f380c796a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gpermute-rows/lib/index.js @@ -0,0 +1,63 @@ +/** +* @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'; + +/** +* Permute the rows of a matrix according to the specified strided permutation array. +* +* @module @stdlib/blas/ext/base/gpermute-rows +* +* @example +* var gpermuteRows = require( '@stdlib/blas/ext/base/gpermute-rows' ); +* +* var A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +* var ip = [ 2, 0, 1 ]; +* var workspace = [ 0.0, 0.0 ]; +* +* gpermuteRows( 'row-major', 3, 2, A, 2, ip, 1, workspace, 1 ); +* // A => [ 5.0, 6.0, 1.0, 2.0, 3.0, 4.0 ] +* +* @example +* var gpermuteRows = require( '@stdlib/blas/ext/base/gpermute-rows' ); +* +* var A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +* var ip = [ 2, 0, 1 ]; +* var workspace = [ 0.0, 0.0 ]; +* +* gpermuteRows.ndarray( 3, 2, A, 2, 1, 0, ip, 1, 0, workspace, 1, 0 ); +* // A => [ 5.0, 6.0, 1.0, 2.0, 3.0, 4.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; + +// exports: { "ndarray": "main.ndarray" } diff --git a/lib/node_modules/@stdlib/blas/ext/base/gpermute-rows/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/gpermute-rows/lib/main.js new file mode 100644 index 000000000000..db7e062fb697 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gpermute-rows/lib/main.js @@ -0,0 +1,82 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isLayout = require( '@stdlib/blas/base/assert/is-layout' ); +var isColumnMajor = require( '@stdlib/ndarray/base/assert/is-column-major-string' ); +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var max = require( '@stdlib/math/base/special/fast/max' ); +var format = require( '@stdlib/string/format' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +/** +* Permutes the rows of a matrix according to the specified strided permutation array. +* +* @param {string} order - storage layout +* @param {NonNegativeInteger} M - number of rows in matrix `A` +* @param {NonNegativeInteger} N - number of columns in matrix `A` +* @param {Collection} A - input matrix +* @param {PositiveInteger} LDA - stride length for the first dimension of `A` (a.k.a., leading dimension of the matrix `A`) +* @param {Collection} ip - permutation index array +* @param {integer} strideIp - stride length for `ip` +* @param {Collection} workspace - workspace array for storing a row during permutation +* @param {integer} strideW - stride length for `workspace` +* @throws {TypeError} first argument must be a valid order +* @throws {RangeError} fifth argument must be a valid stride +* @returns {Collection} `A` +* +* @example +* var A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +* var ip = [ 2, 0, 1 ]; +* var workspace = [ 0.0, 0.0 ]; +* +* gpermuteRows( 'row-major', 3, 2, A, 2, ip, 1, workspace, 1 ); +* // A => [ 5.0, 6.0, 1.0, 2.0, 3.0, 4.0 ] +*/ +function gpermuteRows( order, M, N, A, LDA, ip, strideIp, workspace, strideW ) { + var sa1; + var sa2; + var s; + if ( !isLayout( order ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a valid order. Value: `%s`.', order ) ); + } + if ( isColumnMajor( order ) ) { + s = M; + sa1 = 1; + sa2 = LDA; + } else { // order === 'row-major' + s = N; + sa1 = LDA; + sa2 = 1; + } + if ( LDA < max( 1, s ) ) { + throw new RangeError( format( 'invalid argument. Fifth argument must be greater than or equal to max(1,%d). Value: `%d`.', s, LDA ) ); + } + return ndarray( M, N, A, sa1, sa2, 0, ip, strideIp, stride2offset( M, strideIp ), workspace, strideW, stride2offset( N, strideW ) ); // eslint-disable-line max-len +} + + +// EXPORTS // + +module.exports = gpermuteRows; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gpermute-rows/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gpermute-rows/lib/ndarray.js new file mode 100644 index 000000000000..a04e0b71c45c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gpermute-rows/lib/ndarray.js @@ -0,0 +1,106 @@ +/** +* @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-len, max-params */ + +'use strict'; + +// MODULES // + +var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +var gcopy = require( '@stdlib/blas/base/gcopy' ).ndarray; +var accessors = require( './accessors.js' ); + + +// MAIN // + +/** +* Permutes the rows of a matrix according to the specified strided permutation array using alternative indexing semantics. +* +* @param {NonNegativeInteger} M - number of rows in matrix `A` +* @param {NonNegativeInteger} N - number of columns in matrix `A` +* @param {Collection} A - input matrix +* @param {integer} strideA1 - stride length for the first dimension of `A` +* @param {integer} strideA2 - stride length for the second dimension of `A` +* @param {NonNegativeInteger} offsetA - starting index for `A` +* @param {Collection} ip - permutation index array +* @param {integer} strideIp - stride length for `ip` +* @param {NonNegativeInteger} offsetIp - starting index for `ip` +* @param {Collection} workspace - workspace array for storing a row during permutation +* @param {integer} strideW - stride length for `workspace` +* @param {NonNegativeInteger} offsetW - starting index for `workspace` +* @returns {Collection} `A` +* +* @example +* var A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +* var ip = [ 2, 0, 1 ]; +* var workspace = [ 0.0, 0.0 ]; +* +* gpermuteRows( 3, 2, A, 2, 1, 0, ip, 1, 0, workspace, 1, 0 ); +* // A => [ 5.0, 6.0, 1.0, 2.0, 3.0, 4.0 ] +*/ +function gpermuteRows( M, N, A, strideA1, strideA2, offsetA, ip, strideIp, offsetIp, workspace, strideW, offsetW ) { + var ow; + var op; + var pp; + var oa; + var i; + var j; + var k; + + if ( M <= 0 || N <= 0 ) { + return A; + } + oa = arraylike2object( A ); + op = arraylike2object( ip ); + ow = arraylike2object( workspace ); + if ( oa.accessorProtocol || op.accessorProtocol || ow.accessorProtocol ) { + accessors( M, N, oa, strideA1, strideA2, offsetA, op, strideIp, offsetIp, ow, strideW, offsetW ); + return A; + } + pp = offsetIp; + for ( i = 0; i < M; i++ ) { + if ( ip[pp] === i ) { + pp += strideIp; + continue; + } + // Save row `i` into the workspace... + gcopy( N, A, strideA2, offsetA+(i*strideA1), workspace, strideW, offsetW ); + + // Follow the permutation cycle... + j = i; + k = ip[offsetIp+(j*strideIp)]; + while ( k !== i ) { + // Copy row `k` into row `j`... + gcopy( N, A, strideA2, offsetA+(k*strideA1), A, strideA2, offsetA+(j*strideA1) ); + ip[offsetIp+(j*strideIp)] = j; + j = k; + k = ip[offsetIp+(j*strideIp)]; + } + // Close the cycle by copying the workspace into row `j`... + gcopy( N, workspace, strideW, offsetW, A, strideA2, offsetA+(j*strideA1) ); + ip[offsetIp+(j*strideIp)] = j; + pp += strideIp; + } + return A; +} + + +// EXPORTS // + +module.exports = gpermuteRows; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gpermute-rows/package.json b/lib/node_modules/@stdlib/blas/ext/base/gpermute-rows/package.json new file mode 100644 index 000000000000..a03bcdced306 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gpermute-rows/package.json @@ -0,0 +1,67 @@ +{ + "name": "@stdlib/blas/ext/base/gpermute-rows", + "version": "0.0.0", + "description": "Permute the rows of a matrix according to the specified strided permutation array.", + "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", + "blas", + "extended", + "ext", + "matrix", + "strided", + "array", + "ndarray", + "vector", + "row", + "permute", + "reorder", + "rearrange", + "sort" + ] +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gpermute-rows/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/gpermute-rows/test/test.js new file mode 100644 index 000000000000..933c53398c3f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gpermute-rows/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 gpermuteRows = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gpermuteRows, '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 gpermuteRows.ndarray, 'function', 'method is a function' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gpermute-rows/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/gpermute-rows/test/test.main.js new file mode 100644 index 000000000000..ad7ad9c30a66 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gpermute-rows/test/test.main.js @@ -0,0 +1,472 @@ +/** +* @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 gpermuteRows = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gpermuteRows, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 9', function test( t ) { + t.strictEqual( gpermuteRows.length, 9, 'returns expected value' ); + 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', + -5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + 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() { + gpermuteRows( value, 2, 2, [ 1.0, 2.0, 3.0, 4.0 ], 2, [ 0, 1 ], 1, [ 0.0, 0.0 ], 1 ); + }; + } +}); + +tape( 'the function throws an error if provided a fifth argument which is not a valid LDA value (row-major)', function test( t ) { + var values; + var i; + + values = [ 0, 1 ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + gpermuteRows( 'row-major', 2, 2, [ 1.0, 2.0, 3.0, 4.0 ], value, [ 0, 1 ], 1, [ 0.0, 0.0 ], 1 ); + }; + } +}); + +tape( 'the function throws an error if provided a fifth argument which is not a valid LDA value (column-major)', function test( t ) { + var values; + var i; + + values = [ 0, 1 ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + gpermuteRows( 'column-major', 2, 2, [ 1.0, 2.0, 3.0, 4.0 ], value, [ 0, 1 ], 1, [ 0.0, 0.0 ], 1 ); + }; + } +}); + +tape( 'the function returns a reference to the input matrix', function test( t ) { + var out; + var A; + + A = [ 1.0, 2.0, 3.0, 4.0 ]; + out = gpermuteRows( 'row-major', 2, 2, A, 2, [ 1, 0 ], 1, [ 0.0, 0.0 ], 1 ); + t.strictEqual( out, A, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided an `M` parameter equal to `0`, the function returns the input matrix unchanged', function test( t ) { + var expected; + var A; + + A = [ 1.0, 2.0, 3.0, 4.0 ]; + expected = [ 1.0, 2.0, 3.0, 4.0 ]; + gpermuteRows( 'row-major', 0, 2, A, 2, [], 1, [], 1 ); + t.deepEqual( A, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `0`, the function returns the input matrix unchanged', function test( t ) { + var expected; + var A; + + A = [ 1.0, 2.0, 3.0, 4.0 ]; + expected = [ 1.0, 2.0, 3.0, 4.0 ]; + gpermuteRows( 'row-major', 2, 0, A, 2, [ 0, 1 ], 1, [], 1 ); + t.deepEqual( A, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function permutes matrix rows according to an identity permutation (row-major)', function test( t ) { + var expected; + var out; + var A; + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + out = gpermuteRows( 'row-major', 3, 2, A, 2, [ 0, 1, 2 ], 1, [ 0.0, 0.0 ], 1 ); + t.strictEqual( out, A, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function permutes matrix rows according to an identity permutation (row-major, accessors)', function test( t ) { + var expected; + var ip; + var w; + var A; + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + ip = [ 0, 1, 2 ]; + w = [ 0.0, 0.0 ]; + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + gpermuteRows( 'row-major', 3, 2, toAccessorArray( A ), 2, toAccessorArray( ip ), 1, toAccessorArray( w ), 1 ); + t.deepEqual( A, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function permutes matrix rows according to an identity permutation (column-major)', function test( t ) { + var expected; + var out; + var A; + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + out = gpermuteRows( 'column-major', 3, 2, A, 3, [ 0, 1, 2 ], 1, [ 0.0, 0.0 ], 1 ); + t.strictEqual( out, A, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function permutes matrix rows according to an identity permutation (column-major, accessors)', function test( t ) { + var expected; + var ip; + var w; + var A; + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + ip = [ 0, 1, 2 ]; + w = [ 0.0, 0.0 ]; + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + gpermuteRows( 'column-major', 3, 2, toAccessorArray( A ), 3, toAccessorArray( ip ), 1, toAccessorArray( w ), 1 ); + t.deepEqual( A, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function permutes matrix rows according to a reverse permutation (row-major)', function test( t ) { + var expected; + var out; + var A; + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + expected = [ 5.0, 6.0, 3.0, 4.0, 1.0, 2.0 ]; + out = gpermuteRows( 'row-major', 3, 2, A, 2, [ 2, 1, 0 ], 1, [ 0.0, 0.0 ], 1 ); + t.strictEqual( out, A, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function permutes matrix rows according to a reverse permutation (row-major, accessors)', function test( t ) { + var expected; + var ip; + var w; + var A; + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + ip = [ 2, 1, 0 ]; + w = [ 0.0, 0.0 ]; + expected = [ 5.0, 6.0, 3.0, 4.0, 1.0, 2.0 ]; + gpermuteRows( 'row-major', 3, 2, toAccessorArray( A ), 2, toAccessorArray( ip ), 1, toAccessorArray( w ), 1 ); + t.deepEqual( A, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function permutes matrix rows according to a reverse permutation (column-major)', function test( t ) { + var expected; + var out; + var A; + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + expected = [ 3.0, 2.0, 1.0, 6.0, 5.0, 4.0 ]; + out = gpermuteRows( 'column-major', 3, 2, A, 3, [ 2, 1, 0 ], 1, [ 0.0, 0.0 ], 1 ); + t.strictEqual( out, A, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function permutes matrix rows according to a reverse permutation (column-major, accessors)', function test( t ) { + var expected; + var ip; + var w; + var A; + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + ip = [ 2, 1, 0 ]; + w = [ 0.0, 0.0 ]; + expected = [ 3.0, 2.0, 1.0, 6.0, 5.0, 4.0 ]; + gpermuteRows( 'column-major', 3, 2, toAccessorArray( A ), 3, toAccessorArray( ip ), 1, toAccessorArray( w ), 1 ); + t.deepEqual( A, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function permutes matrix rows according to a cyclic permutation (row-major)', function test( t ) { + var expected; + var out; + var A; + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + expected = [ 5.0, 6.0, 1.0, 2.0, 3.0, 4.0 ]; + out = gpermuteRows( 'row-major', 3, 2, A, 2, [ 2, 0, 1 ], 1, [ 0.0, 0.0 ], 1 ); + t.strictEqual( out, A, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function permutes matrix rows according to a cyclic permutation (row-major, accessors)', function test( t ) { + var expected; + var ip; + var w; + var A; + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + ip = [ 2, 0, 1 ]; + w = [ 0.0, 0.0 ]; + expected = [ 5.0, 6.0, 1.0, 2.0, 3.0, 4.0 ]; + gpermuteRows( 'row-major', 3, 2, toAccessorArray( A ), 2, toAccessorArray( ip ), 1, toAccessorArray( w ), 1 ); + t.deepEqual( A, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function permutes matrix rows according to a cyclic permutation (column-major)', function test( t ) { + var expected; + var out; + var A; + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + expected = [ 3.0, 1.0, 2.0, 6.0, 4.0, 5.0 ]; + out = gpermuteRows( 'column-major', 3, 2, A, 3, [ 2, 0, 1 ], 1, [ 0.0, 0.0 ], 1 ); + t.strictEqual( out, A, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function permutes matrix rows according to a cyclic permutation (column-major, accessors)', function test( t ) { + var expected; + var ip; + var w; + var A; + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + ip = [ 2, 0, 1 ]; + w = [ 0.0, 0.0 ]; + expected = [ 3.0, 1.0, 2.0, 6.0, 4.0, 5.0 ]; + gpermuteRows( 'column-major', 3, 2, toAccessorArray( A ), 3, toAccessorArray( ip ), 1, toAccessorArray( w ), 1 ); + t.deepEqual( A, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function handles multiple disjoint cycles (row-major)', function test( t ) { + var expected; + var out; + var A; + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + expected = [ 3.0, 4.0, 1.0, 2.0, 7.0, 8.0, 5.0, 6.0 ]; + out = gpermuteRows( 'row-major', 4, 2, A, 2, [ 1, 0, 3, 2 ], 1, [ 0.0, 0.0 ], 1 ); + t.strictEqual( out, A, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function handles multiple disjoint cycles (row-major, accessors)', function test( t ) { + var expected; + var ip; + var w; + var A; + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + ip = [ 1, 0, 3, 2 ]; + w = [ 0.0, 0.0 ]; + expected = [ 3.0, 4.0, 1.0, 2.0, 7.0, 8.0, 5.0, 6.0 ]; + gpermuteRows( 'row-major', 4, 2, toAccessorArray( A ), 2, toAccessorArray( ip ), 1, toAccessorArray( w ), 1 ); + t.deepEqual( A, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function handles multiple disjoint cycles (column-major)', function test( t ) { + var expected; + var out; + var A; + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + expected = [ 2.0, 1.0, 4.0, 3.0, 6.0, 5.0, 8.0, 7.0 ]; + out = gpermuteRows( 'column-major', 4, 2, A, 4, [ 1, 0, 3, 2 ], 1, [ 0.0, 0.0 ], 1 ); + t.strictEqual( out, A, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function handles multiple disjoint cycles (column-major, accessors)', function test( t ) { + var expected; + var ip; + var w; + var A; + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + ip = [ 1, 0, 3, 2 ]; + w = [ 0.0, 0.0 ]; + expected = [ 2.0, 1.0, 4.0, 3.0, 6.0, 5.0, 8.0, 7.0 ]; + gpermuteRows( 'column-major', 4, 2, toAccessorArray( A ), 4, toAccessorArray( ip ), 1, toAccessorArray( w ), 1 ); + t.deepEqual( A, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function permutes rows of a non-square matrix (row-major)', function test( t ) { + var expected; + var out; + var A; + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + expected = [ 5.0, 6.0, 7.0, 8.0, 1.0, 2.0, 3.0, 4.0 ]; + out = gpermuteRows( 'row-major', 2, 4, A, 4, [ 1, 0 ], 1, [ 0.0, 0.0, 0.0, 0.0 ], 1 ); + t.strictEqual( out, A, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function permutes rows of a non-square matrix (row-major, accessors)', function test( t ) { + var expected; + var ip; + var w; + var A; + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + ip = [ 1, 0 ]; + w = [ 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 5.0, 6.0, 7.0, 8.0, 1.0, 2.0, 3.0, 4.0 ]; + gpermuteRows( 'row-major', 2, 4, toAccessorArray( A ), 4, toAccessorArray( ip ), 1, toAccessorArray( w ), 1 ); + t.deepEqual( A, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function permutes rows of a non-square matrix (column-major)', function test( t ) { + var expected; + var out; + var A; + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + expected = [ 2.0, 1.0, 4.0, 3.0, 6.0, 5.0, 8.0, 7.0 ]; + out = gpermuteRows( 'column-major', 2, 4, A, 2, [ 1, 0 ], 1, [ 0.0, 0.0, 0.0, 0.0 ], 1 ); + t.strictEqual( out, A, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function permutes rows of a non-square matrix (column-major, accessors)', function test( t ) { + var expected; + var ip; + var w; + var A; + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + ip = [ 1, 0 ]; + w = [ 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 2.0, 1.0, 4.0, 3.0, 6.0, 5.0, 8.0, 7.0 ]; + gpermuteRows( 'column-major', 2, 4, toAccessorArray( A ), 2, toAccessorArray( ip ), 1, toAccessorArray( w ), 1 ); + t.deepEqual( A, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function permutes matrix rows with a single row (row-major)', function test( t ) { + var expected; + var out; + var A; + + A = [ 1.0, 2.0, 3.0 ]; + expected = [ 1.0, 2.0, 3.0 ]; + out = gpermuteRows( 'row-major', 1, 3, A, 3, [ 0 ], 1, [ 0.0, 0.0, 0.0 ], 1 ); + t.strictEqual( out, A, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function permutes matrix rows with a single row (row-major, accessors)', function test( t ) { + var expected; + var ip; + var w; + var A; + + A = [ 1.0, 2.0, 3.0 ]; + ip = [ 0 ]; + w = [ 0.0, 0.0, 0.0 ]; + expected = [ 1.0, 2.0, 3.0 ]; + gpermuteRows( 'row-major', 1, 3, toAccessorArray( A ), 3, toAccessorArray( ip ), 1, toAccessorArray( w ), 1 ); + t.deepEqual( A, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function permutes matrix rows with a single column (row-major)', function test( t ) { + var expected; + var out; + var A; + + A = [ 1.0, 2.0, 3.0 ]; + expected = [ 3.0, 1.0, 2.0 ]; + out = gpermuteRows( 'row-major', 3, 1, A, 1, [ 2, 0, 1 ], 1, [ 0.0 ], 1 ); + t.strictEqual( out, A, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function permutes matrix rows with a single column (row-major, accessors)', function test( t ) { + var expected; + var ip; + var w; + var A; + + A = [ 1.0, 2.0, 3.0 ]; + ip = [ 2, 0, 1 ]; + w = [ 0.0 ]; + expected = [ 3.0, 1.0, 2.0 ]; + gpermuteRows( 'row-major', 3, 1, toAccessorArray( A ), 1, toAccessorArray( ip ), 1, toAccessorArray( w ), 1 ); + t.deepEqual( A, expected, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gpermute-rows/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gpermute-rows/test/test.ndarray.js new file mode 100644 index 000000000000..2228fae81886 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gpermute-rows/test/test.ndarray.js @@ -0,0 +1,519 @@ +/** +* @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 gpermuteRows = require( './../lib' ).ndarray; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gpermuteRows, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 12', function test( t ) { + t.strictEqual( gpermuteRows.length, 12, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a reference to the input matrix', function test( t ) { + var out; + var A; + + A = [ 1.0, 2.0, 3.0, 4.0 ]; + out = gpermuteRows( 2, 2, A, 2, 1, 0, [ 1, 0 ], 1, 0, [ 0.0, 0.0 ], 1, 0 ); + t.strictEqual( out, A, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided an `M` parameter equal to `0`, the function returns the input matrix unchanged', function test( t ) { + var expected; + var A; + + A = [ 1.0, 2.0, 3.0, 4.0 ]; + expected = [ 1.0, 2.0, 3.0, 4.0 ]; + gpermuteRows( 0, 2, A, 2, 1, 0, [], 1, 0, [], 1, 0 ); + t.deepEqual( A, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `0`, the function returns the input matrix unchanged', function test( t ) { + var expected; + var A; + + A = [ 1.0, 2.0, 3.0, 4.0 ]; + expected = [ 1.0, 2.0, 3.0, 4.0 ]; + gpermuteRows( 2, 0, A, 2, 1, 0, [ 0, 1 ], 1, 0, [], 1, 0 ); + t.deepEqual( A, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function permutes matrix rows according to an identity permutation (row-major)', function test( t ) { + var expected; + var out; + var A; + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + out = gpermuteRows( 3, 2, A, 2, 1, 0, [ 0, 1, 2 ], 1, 0, [ 0.0, 0.0 ], 1, 0 ); + t.strictEqual( out, A, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function permutes matrix rows according to an identity permutation (row-major, accessors)', function test( t ) { + var expected; + var ip; + var w; + var A; + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + ip = [ 0, 1, 2 ]; + w = [ 0.0, 0.0 ]; + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + gpermuteRows( 3, 2, toAccessorArray( A ), 2, 1, 0, toAccessorArray( ip ), 1, 0, toAccessorArray( w ), 1, 0 ); + t.deepEqual( A, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function permutes matrix rows according to an identity permutation (column-major)', function test( t ) { + var expected; + var out; + var A; + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + out = gpermuteRows( 3, 2, A, 1, 3, 0, [ 0, 1, 2 ], 1, 0, [ 0.0, 0.0 ], 1, 0 ); + t.strictEqual( out, A, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function permutes matrix rows according to an identity permutation (column-major, accessors)', function test( t ) { + var expected; + var ip; + var w; + var A; + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + ip = [ 0, 1, 2 ]; + w = [ 0.0, 0.0 ]; + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + gpermuteRows( 3, 2, toAccessorArray( A ), 1, 3, 0, toAccessorArray( ip ), 1, 0, toAccessorArray( w ), 1, 0 ); + t.deepEqual( A, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function permutes matrix rows according to a cyclic permutation (row-major)', function test( t ) { + var expected; + var out; + var A; + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + expected = [ 5.0, 6.0, 1.0, 2.0, 3.0, 4.0 ]; + out = gpermuteRows( 3, 2, A, 2, 1, 0, [ 2, 0, 1 ], 1, 0, [ 0.0, 0.0 ], 1, 0 ); + t.strictEqual( out, A, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function permutes matrix rows according to a cyclic permutation (row-major, accessors)', function test( t ) { + var expected; + var ip; + var w; + var A; + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + ip = [ 2, 0, 1 ]; + w = [ 0.0, 0.0 ]; + expected = [ 5.0, 6.0, 1.0, 2.0, 3.0, 4.0 ]; + gpermuteRows( 3, 2, toAccessorArray( A ), 2, 1, 0, toAccessorArray( ip ), 1, 0, toAccessorArray( w ), 1, 0 ); + t.deepEqual( A, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function permutes matrix rows according to a cyclic permutation (column-major)', function test( t ) { + var expected; + var out; + var A; + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + expected = [ 3.0, 1.0, 2.0, 6.0, 4.0, 5.0 ]; + out = gpermuteRows( 3, 2, A, 1, 3, 0, [ 2, 0, 1 ], 1, 0, [ 0.0, 0.0 ], 1, 0 ); + t.strictEqual( out, A, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function permutes matrix rows according to a cyclic permutation (column-major, accessors)', function test( t ) { + var expected; + var ip; + var w; + var A; + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + ip = [ 2, 0, 1 ]; + w = [ 0.0, 0.0 ]; + expected = [ 3.0, 1.0, 2.0, 6.0, 4.0, 5.0 ]; + gpermuteRows( 3, 2, toAccessorArray( A ), 1, 3, 0, toAccessorArray( ip ), 1, 0, toAccessorArray( w ), 1, 0 ); + t.deepEqual( A, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function permutes matrix rows according to a reverse permutation (row-major)', function test( t ) { + var expected; + var out; + var A; + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + expected = [ 5.0, 6.0, 3.0, 4.0, 1.0, 2.0 ]; + out = gpermuteRows( 3, 2, A, 2, 1, 0, [ 2, 1, 0 ], 1, 0, [ 0.0, 0.0 ], 1, 0 ); + t.strictEqual( out, A, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function permutes matrix rows according to a reverse permutation (row-major, accessors)', function test( t ) { + var expected; + var ip; + var w; + var A; + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + ip = [ 2, 1, 0 ]; + w = [ 0.0, 0.0 ]; + expected = [ 5.0, 6.0, 3.0, 4.0, 1.0, 2.0 ]; + gpermuteRows( 3, 2, toAccessorArray( A ), 2, 1, 0, toAccessorArray( ip ), 1, 0, toAccessorArray( w ), 1, 0 ); + t.deepEqual( A, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function permutes matrix rows according to a reverse permutation (column-major)', function test( t ) { + var expected; + var out; + var A; + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + expected = [ 3.0, 2.0, 1.0, 6.0, 5.0, 4.0 ]; + out = gpermuteRows( 3, 2, A, 1, 3, 0, [ 2, 1, 0 ], 1, 0, [ 0.0, 0.0 ], 1, 0 ); + t.strictEqual( out, A, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function permutes matrix rows according to a reverse permutation (column-major, accessors)', function test( t ) { + var expected; + var ip; + var w; + var A; + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + ip = [ 2, 1, 0 ]; + w = [ 0.0, 0.0 ]; + expected = [ 3.0, 2.0, 1.0, 6.0, 5.0, 4.0 ]; + gpermuteRows( 3, 2, toAccessorArray( A ), 1, 3, 0, toAccessorArray( ip ), 1, 0, toAccessorArray( w ), 1, 0 ); + t.deepEqual( A, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function handles multiple disjoint cycles (row-major)', function test( t ) { + var expected; + var out; + var A; + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + expected = [ 3.0, 4.0, 1.0, 2.0, 7.0, 8.0, 5.0, 6.0 ]; + out = gpermuteRows( 4, 2, A, 2, 1, 0, [ 1, 0, 3, 2 ], 1, 0, [ 0.0, 0.0 ], 1, 0 ); + t.strictEqual( out, A, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function handles multiple disjoint cycles (row-major, accessors)', function test( t ) { + var expected; + var ip; + var w; + var A; + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + ip = [ 1, 0, 3, 2 ]; + w = [ 0.0, 0.0 ]; + expected = [ 3.0, 4.0, 1.0, 2.0, 7.0, 8.0, 5.0, 6.0 ]; + gpermuteRows( 4, 2, toAccessorArray( A ), 2, 1, 0, toAccessorArray( ip ), 1, 0, toAccessorArray( w ), 1, 0 ); + t.deepEqual( A, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function handles multiple disjoint cycles (column-major)', function test( t ) { + var expected; + var out; + var A; + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + expected = [ 2.0, 1.0, 4.0, 3.0, 6.0, 5.0, 8.0, 7.0 ]; + out = gpermuteRows( 4, 2, A, 1, 4, 0, [ 1, 0, 3, 2 ], 1, 0, [ 0.0, 0.0 ], 1, 0 ); + t.strictEqual( out, A, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function handles multiple disjoint cycles (column-major, accessors)', function test( t ) { + var expected; + var ip; + var w; + var A; + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + ip = [ 1, 0, 3, 2 ]; + w = [ 0.0, 0.0 ]; + expected = [ 2.0, 1.0, 4.0, 3.0, 6.0, 5.0, 8.0, 7.0 ]; + gpermuteRows( 4, 2, toAccessorArray( A ), 1, 4, 0, toAccessorArray( ip ), 1, 0, toAccessorArray( w ), 1, 0 ); + t.deepEqual( A, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function permutes rows of a non-square matrix (row-major)', function test( t ) { + var expected; + var out; + var A; + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + expected = [ 5.0, 6.0, 7.0, 8.0, 1.0, 2.0, 3.0, 4.0 ]; + out = gpermuteRows( 2, 4, A, 4, 1, 0, [ 1, 0 ], 1, 0, [ 0.0, 0.0, 0.0, 0.0 ], 1, 0 ); + t.strictEqual( out, A, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function permutes rows of a non-square matrix (row-major, accessors)', function test( t ) { + var expected; + var ip; + var w; + var A; + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + ip = [ 1, 0 ]; + w = [ 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 5.0, 6.0, 7.0, 8.0, 1.0, 2.0, 3.0, 4.0 ]; + gpermuteRows( 2, 4, toAccessorArray( A ), 4, 1, 0, toAccessorArray( ip ), 1, 0, toAccessorArray( w ), 1, 0 ); + t.deepEqual( A, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function permutes rows of a non-square matrix (column-major)', function test( t ) { + var expected; + var out; + var A; + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + expected = [ 2.0, 1.0, 4.0, 3.0, 6.0, 5.0, 8.0, 7.0 ]; + out = gpermuteRows( 2, 4, A, 1, 2, 0, [ 1, 0 ], 1, 0, [ 0.0, 0.0, 0.0, 0.0 ], 1, 0 ); + t.strictEqual( out, A, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function permutes rows of a non-square matrix (column-major, accessors)', function test( t ) { + var expected; + var ip; + var w; + var A; + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + ip = [ 1, 0 ]; + w = [ 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 2.0, 1.0, 4.0, 3.0, 6.0, 5.0, 8.0, 7.0 ]; + gpermuteRows( 2, 4, toAccessorArray( A ), 1, 2, 0, toAccessorArray( ip ), 1, 0, toAccessorArray( w ), 1, 0 ); + t.deepEqual( A, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function permutes matrix rows with a single row (row-major)', function test( t ) { + var expected; + var out; + var A; + + A = [ 1.0, 2.0, 3.0 ]; + expected = [ 1.0, 2.0, 3.0 ]; + out = gpermuteRows( 1, 3, A, 3, 1, 0, [ 0 ], 1, 0, [ 0.0, 0.0, 0.0 ], 1, 0 ); + t.strictEqual( out, A, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function permutes matrix rows with a single row (row-major, accessors)', function test( t ) { + var expected; + var ip; + var w; + var A; + + A = [ 1.0, 2.0, 3.0 ]; + ip = [ 0 ]; + w = [ 0.0, 0.0, 0.0 ]; + expected = [ 1.0, 2.0, 3.0 ]; + gpermuteRows( 1, 3, toAccessorArray( A ), 3, 1, 0, toAccessorArray( ip ), 1, 0, toAccessorArray( w ), 1, 0 ); + t.deepEqual( A, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function permutes matrix rows with a single column (row-major)', function test( t ) { + var expected; + var out; + var A; + + A = [ 1.0, 2.0, 3.0 ]; + expected = [ 3.0, 1.0, 2.0 ]; + out = gpermuteRows( 3, 1, A, 1, 1, 0, [ 2, 0, 1 ], 1, 0, [ 0.0 ], 1, 0 ); + t.strictEqual( out, A, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function permutes matrix rows with a single column (row-major, accessors)', function test( t ) { + var expected; + var ip; + var w; + var A; + + A = [ 1.0, 2.0, 3.0 ]; + ip = [ 2, 0, 1 ]; + w = [ 0.0 ]; + expected = [ 3.0, 1.0, 2.0 ]; + gpermuteRows( 3, 1, toAccessorArray( A ), 1, 1, 0, toAccessorArray( ip ), 1, 0, toAccessorArray( w ), 1, 0 ); + t.deepEqual( A, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying a negative stride for `A` (row-major)', function test( t ) { + var expected; + var out; + var A; + + A = [ 5.0, 6.0, 3.0, 4.0, 1.0, 2.0 ]; + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + out = gpermuteRows( 3, 2, A, -2, 1, 4, [ 2, 1, 0 ], 1, 0, [ 0.0, 0.0 ], 1, 0 ); + t.strictEqual( out, A, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying a negative stride for `A` (row-major, accessors)', function test( t ) { + var expected; + var ip; + var w; + var A; + + A = [ 5.0, 6.0, 3.0, 4.0, 1.0, 2.0 ]; + ip = [ 2, 1, 0 ]; + w = [ 0.0, 0.0 ]; + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + gpermuteRows( 3, 2, toAccessorArray( A ), -2, 1, 4, toAccessorArray( ip ), 1, 0, toAccessorArray( w ), 1, 0 ); + t.deepEqual( A, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an `A` offset parameter (row-major)', function test( t ) { + var expected; + var out; + var A; + + A = [ 9999.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + expected = [ 9999.0, 5.0, 6.0, 1.0, 2.0, 3.0, 4.0 ]; + out = gpermuteRows( 3, 2, A, 2, 1, 1, [ 2, 0, 1 ], 1, 0, [ 0.0, 0.0 ], 1, 0 ); + t.strictEqual( out, A, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an `A` offset parameter (row-major, accessors)', function test( t ) { + var expected; + var ip; + var w; + var A; + + A = [ 9999.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + ip = [ 2, 0, 1 ]; + w = [ 0.0, 0.0 ]; + expected = [ 9999.0, 5.0, 6.0, 1.0, 2.0, 3.0, 4.0 ]; + gpermuteRows( 3, 2, toAccessorArray( A ), 2, 1, 1, toAccessorArray( ip ), 1, 0, toAccessorArray( w ), 1, 0 ); + t.deepEqual( A, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an `ip` offset parameter', function test( t ) { + var expected; + var out; + var A; + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + expected = [ 5.0, 6.0, 1.0, 2.0, 3.0, 4.0 ]; + out = gpermuteRows( 3, 2, A, 2, 1, 0, [ 9999, 2, 0, 1 ], 1, 1, [ 0.0, 0.0 ], 1, 0 ); + t.strictEqual( out, A, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an `ip` offset parameter (accessors)', function test( t ) { + var expected; + var ip; + var w; + var A; + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + ip = [ 9999, 2, 0, 1 ]; + w = [ 0.0, 0.0 ]; + expected = [ 5.0, 6.0, 1.0, 2.0, 3.0, 4.0 ]; + gpermuteRows( 3, 2, toAccessorArray( A ), 2, 1, 0, toAccessorArray( ip ), 1, 1, toAccessorArray( w ), 1, 0 ); + t.deepEqual( A, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `workspace` offset parameter', function test( t ) { + var expected; + var out; + var A; + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + expected = [ 5.0, 6.0, 1.0, 2.0, 3.0, 4.0 ]; + out = gpermuteRows( 3, 2, A, 2, 1, 0, [ 2, 0, 1 ], 1, 0, [ 9999.0, 0.0, 0.0 ], 1, 1 ); + t.strictEqual( out, A, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `workspace` offset parameter (accessors)', function test( t ) { + var expected; + var ip; + var w; + var A; + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + ip = [ 2, 0, 1 ]; + w = [ 9999.0, 0.0, 0.0 ]; + expected = [ 5.0, 6.0, 1.0, 2.0, 3.0, 4.0 ]; + gpermuteRows( 3, 2, toAccessorArray( A ), 2, 1, 0, toAccessorArray( ip ), 1, 0, toAccessorArray( w ), 1, 1 ); + t.deepEqual( A, expected, 'returns expected value' ); + t.end(); +});