From 0bebedd7f000293b2a3c8b4b4512e62838f7e32e Mon Sep 17 00:00:00 2001 From: Pranav <85227306+Pranavchiku@users.noreply.github.com> Date: Wed, 14 Aug 2024 06:45:16 +0530 Subject: [PATCH] feat: add `lapack/base/sge-trans` PR-URL: https://github.com/stdlib-js/stdlib/pull/2786 Ref: https://github.com/stdlib-js/stdlib/issues/2464 Co-authored-by: Athan Reines Reviewed-by: Athan Reines --- .../@stdlib/lapack/base/dge-trans/README.md | 2 +- .../@stdlib/lapack/base/sge-trans/README.md | 296 ++++++++ .../base/sge-trans/benchmark/benchmark.js | 105 +++ .../sge-trans/benchmark/benchmark.ndarray.js | 105 +++ .../lapack/base/sge-trans/docs/repl.txt | 101 +++ .../base/sge-trans/docs/types/index.d.ts | 114 +++ .../lapack/base/sge-trans/docs/types/test.ts | 326 ++++++++ .../lapack/base/sge-trans/examples/index.js | 80 ++ .../@stdlib/lapack/base/sge-trans/lib/base.js | 106 +++ .../lapack/base/sge-trans/lib/index.js | 68 ++ .../@stdlib/lapack/base/sge-trans/lib/main.js | 35 + .../lapack/base/sge-trans/lib/ndarray.js | 61 ++ .../lapack/base/sge-trans/lib/sgetrans.js | 78 ++ .../lapack/base/sge-trans/package.json | 68 ++ .../lapack/base/sge-trans/test/test.js | 82 ++ .../base/sge-trans/test/test.ndarray.js | 713 ++++++++++++++++++ .../base/sge-trans/test/test.sgetrans.js | 419 ++++++++++ 17 files changed, 2758 insertions(+), 1 deletion(-) create mode 100644 lib/node_modules/@stdlib/lapack/base/sge-trans/README.md create mode 100644 lib/node_modules/@stdlib/lapack/base/sge-trans/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/lapack/base/sge-trans/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/lapack/base/sge-trans/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/lapack/base/sge-trans/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/lapack/base/sge-trans/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/lapack/base/sge-trans/examples/index.js create mode 100644 lib/node_modules/@stdlib/lapack/base/sge-trans/lib/base.js create mode 100644 lib/node_modules/@stdlib/lapack/base/sge-trans/lib/index.js create mode 100644 lib/node_modules/@stdlib/lapack/base/sge-trans/lib/main.js create mode 100644 lib/node_modules/@stdlib/lapack/base/sge-trans/lib/ndarray.js create mode 100644 lib/node_modules/@stdlib/lapack/base/sge-trans/lib/sgetrans.js create mode 100644 lib/node_modules/@stdlib/lapack/base/sge-trans/package.json create mode 100644 lib/node_modules/@stdlib/lapack/base/sge-trans/test/test.js create mode 100644 lib/node_modules/@stdlib/lapack/base/sge-trans/test/test.ndarray.js create mode 100644 lib/node_modules/@stdlib/lapack/base/sge-trans/test/test.sgetrans.js diff --git a/lib/node_modules/@stdlib/lapack/base/dge-trans/README.md b/lib/node_modules/@stdlib/lapack/base/dge-trans/README.md index 8d0e38df26f..6231771a3bd 100644 --- a/lib/node_modules/@stdlib/lapack/base/dge-trans/README.md +++ b/lib/node_modules/@stdlib/lapack/base/dge-trans/README.md @@ -18,7 +18,7 @@ limitations under the License. --> -# dge-trans +# dgetrans > Convert a matrix from row-major layout to column-major layout or vice versa. diff --git a/lib/node_modules/@stdlib/lapack/base/sge-trans/README.md b/lib/node_modules/@stdlib/lapack/base/sge-trans/README.md new file mode 100644 index 00000000000..b3451f62622 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/sge-trans/README.md @@ -0,0 +1,296 @@ + + +# sgetrans + +> Convert a matrix from row-major layout to column-major layout or vice versa. + +
+ +## Usage + +```javascript +var sgetrans = require( '@stdlib/lapack/base/sge-trans' ); +``` + +#### sgetrans( order, M, N, A, LDA, out, LDO ) + +Converts a matrix from row-major layout to column-major layout or vice versa. + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); + +var A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +var out = new Float32Array( 6 ); + +out = sgetrans( 'row-major', 2, 3, A, 3, out, 2 ); +// returns [ 1.0, 4.0, 2.0, 5.0, 3.0, 6.0 ] +``` + +The function has the following parameters: + +- **order**: storage layout. +- **M**: number of rows in `A`. +- **N**: number of columns in `A`. +- **A**: input [`Float32Array`][mdn-float32array]. +- **LDA**: stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`). +- **out**: output [`Float32Array`][mdn-float32array]. +- **LDO**: stride of the first dimension of `out` (a.k.a., leading dimension of the matrix `out`). + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + + + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); + +// Initial arrays... +var A0 = new Float32Array( [ 0.0, 1.0, 2.0, 3.0, 4.0 ] ); +var Out0 = new Float32Array( [ 0.0, 1.0, 2.0, 3.0, 4.0 ] ); + +// Create offset views... +var A1 = new Float32Array( A0.buffer, A0.BYTES_PER_ELEMENT*1 ); // start at 2nd element +var Out1 = new Float32Array( Out0.buffer, Out0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +sgetrans( 'row-major', 2, 2, A1, 2, Out1, 2 ); +// Out0 => [ 0.0, 1.0, 3.0, 2.0, 4.0 ] +``` + +#### sgetrans.ndarray( M, N, A, sa1, sa2, oa, out, so1, so2, oo ) + +Converts a matrix from row-major layout to column-major layout or vice versa using alternative indexing semantics. + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); + +var A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +var out = new Float32Array( 6 ); + +out = sgetrans.ndarray( 2, 3, A, 3, 1, 0, out, 2, 1, 0 ); +// returns [ 1.0, 4.0, 2.0, 5.0, 3.0, 6.0 ] +``` + +The function has the following parameters: + +- **M**: number of rows in `A`. +- **N**: number of columns in `A`. +- **A**: input [`Float32Array`][mdn-float32array]. +- **sa1**: stride of the first dimension of `A`. +- **sa2**: stride of the second dimension of `A`. +- **oa**: starting index for `A`. +- **out**: output [`Float32Array`][mdn-float32array]. +- **so1**: stride of the first dimension of `out`. +- **so2**: stride of the second dimension of `out`. +- **oo**: starting index for `out`. + +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on starting indices. For example, + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); + +var A = new Float32Array( [ 0.0, 1.0, 2.0, 3.0, 4.0 ] ); +var out = new Float32Array( [ 0.0, 0.0, 11.0, 312.0, 53.0, 412.0 ] ); + +sgetrans.ndarray( 2, 2, A, 2, 1, 1, out, 2, 1, 2 ); +// out => [ 0.0, 0.0, 1.0, 3.0, 2.0, 4.0 ] +``` + +
+ + + +
+ +## Notes + +- `sgetrans()` corresponds to the [LAPACK][lapack] utility routine [`sge_trans`][lapack-sge-trans]. + +
+ + + +
+ +## Examples + + + + + +```javascript +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var numel = require( '@stdlib/ndarray/base/numel' ); +var Float32Array = require( '@stdlib/array/float32' ); +var sgetrans = require( '@stdlib/lapack/base/sge-trans' ); + +var shapeA = [ 2, 3 ]; +var shapeOut = [ 3, 2 ]; + +// Row-major layout... +var order = 'row-major'; + +var stridesA = shape2strides( shapeA, order ); +var stridesOut = shape2strides( shapeOut, order ); + +var A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +console.log( ndarray2array( A, shapeA, stridesA, 0, order ) ); + +var out = new Float32Array( numel( shapeA ) ); + +out = sgetrans( order, shapeA[0], shapeA[1], A, stridesA[0], out, stridesOut[0] ); +console.log( ndarray2array( out, shapeOut, stridesOut, 0, order ) ); + +// Column-major layout... +order = 'column-major'; + +stridesA = shape2strides( shapeA, order ); +stridesOut = shape2strides( shapeOut, order ); + +A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +console.log( ndarray2array( A, shapeA, stridesA, 0, order ) ); + +out = new Float32Array( numel( shapeA ) ); + +out = sgetrans( order, shapeA[0], shapeA[1], A, stridesA[1], out, stridesOut[1] ); +console.log( ndarray2array( out, shapeOut, stridesOut, 0, order ) ); + +// Input and output arrays have different layouts... +stridesA = shape2strides( shapeA, 'row-major' ); +stridesOut = shape2strides( shapeOut, 'column-major' ); + +A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +console.log( ndarray2array( A, shapeA, stridesA, 0, 'row-major' ) ); + +out = new Float32Array( numel( shapeA ) ); + +out = sgetrans.ndarray( shapeA[0], shapeA[1], A, stridesA[0], stridesA[1], 0, out, stridesOut[0], stridesOut[1], 0 ); +console.log( ndarray2array( out, shapeOut, stridesOut, 0, 'column-major' ) ); + +// Input and output arrays have different layouts... +stridesA = shape2strides( shapeA, 'column-major' ); +stridesOut = shape2strides( shapeOut, 'row-major' ); + +A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +console.log( ndarray2array( A, shapeA, stridesA, 0, 'column-major' ) ); + +out = new Float32Array( numel( shapeA ) ); + +out = sgetrans.ndarray( shapeA[0], shapeA[1], A, stridesA[0], stridesA[1], 0, out, stridesOut[0], stridesOut[1], 0 ); +console.log( ndarray2array( out, shapeOut, stridesOut, 0, 'row-major' ) ); +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +TODO +``` + +#### TODO + +TODO. + +```c +TODO +``` + +TODO + +```c +TODO +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +TODO +``` + +
+ + + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/lapack/base/sge-trans/benchmark/benchmark.js b/lib/node_modules/@stdlib/lapack/base/sge-trans/benchmark/benchmark.js new file mode 100644 index 00000000000..57bf3b8c9d4 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/sge-trans/benchmark/benchmark.js @@ -0,0 +1,105 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var pkg = require( './../package.json' ).name; +var sgetrans = require( './../lib/sgetrans.js' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} N - number of elements along each dimension +* @returns {Function} benchmark function +*/ +function createBenchmark( N ) { + var opts; + var A; + var B; + + opts = { + 'dtype': 'float32' + }; + + A = uniform( N*N, -10.0, 10.0, opts ); + B = uniform( N*N, -10.0, 10.0, opts ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var z; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + z = sgetrans( 'column-major', N, N, A, N, B, N ); + if ( isnanf( z[ i%z.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( 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 N; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + N = floor( pow( pow( 10, i ), 1.0/2.0 ) ); + f = createBenchmark( N ); + bench( pkg+':order=column-major,size='+(N*N), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/lapack/base/sge-trans/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/lapack/base/sge-trans/benchmark/benchmark.ndarray.js new file mode 100644 index 00000000000..224f4cdced6 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/sge-trans/benchmark/benchmark.ndarray.js @@ -0,0 +1,105 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var pkg = require( './../package.json' ).name; +var sgetrans = require( './../lib/ndarray.js' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} N - number of elements along each dimension +* @returns {Function} benchmark function +*/ +function createBenchmark( N ) { + var opts; + var A; + var B; + + opts = { + 'dtype': 'float32' + }; + + A = uniform( N*N, -10.0, 10.0, opts ); + B = uniform( N*N, -10.0, 10.0, opts ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var z; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + z = sgetrans( N, N, A, 1, N, 0, B, 1, N, 0 ); + if ( isnanf( z[ i%z.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( 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 N; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + N = floor( pow( pow( 10, i ), 1.0/2.0 ) ); + f = createBenchmark( N ); + bench( pkg+':ndarray:order=column-major,size='+(N*N), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/lapack/base/sge-trans/docs/repl.txt b/lib/node_modules/@stdlib/lapack/base/sge-trans/docs/repl.txt new file mode 100644 index 00000000000..79f7780094b --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/sge-trans/docs/repl.txt @@ -0,0 +1,101 @@ + +{{alias}}( order, M, N, A, LDA, out, LDO ) + Converts a matrix from row-major layout to column-major layout or vice + versa. + + 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: Float32Array + Input matrix `A`. + + LDA: integer + Stride of the first dimension of `A` (a.k.a., leading dimension of the + matrix `A`). + + out: Float32Array + Output matrix `out`. + + LDO: integer + Stride of the first dimension of `out` (a.k.a., leading dimension of the + matrix `out`). + + Returns + ------- + out: Float32Array + Output matrix. + + Examples + -------- + > var out = new {{alias:@stdlib/array/float32}}( [ 5.0, 7.0, 0.0, 8.0 ] ); + > var A = new {{alias:@stdlib/array/float32}}( [ 1.0, 3.0, 0.0, 4.0 ] ); + > {{alias}}( 'row-major', 2, 2, A, 2, out, 2 ) + [ 1.0, 0.0, 3.0, 4.0 ] + + +{{alias}}.ndarray( M, N, A, sa1, sa2, oa, out, so1, so2, oo ) + Converts a matrix from row-major layout to column-major layout or vice versa + using alternative indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the offset parameters support indexing semantics based on starting + indices. + + Parameters + ---------- + M: integer + Number of rows in `A`. + + N: integer + Number of columns in `A`. + + A: Float32Array + Input matrix `A`. + + sa1: integer + Stride of the first dimension of `A`. + + sa2: integer + Stride of the second dimension of `A`. + + oa: integer + Starting index for `A`. + + out: Float32Array + Output matrix `out`. + + so1: integer + Stride of the first dimension of `out`. + + so2: integer + Stride of the second dimension of `out`. + + oo: integer + Starting index for `out`. + + Returns + ------- + out: Float32Array + Output matrix. + + Examples + -------- + > var A = new {{alias:@stdlib/array/float32}}( [ 0.0, 1.0, 3.0, 0.0, 4.0 ] ); + > var out = new {{alias:@stdlib/array/float32}}( [ 0.0, 0.0, 5.0, 7.0, 0.0, 8.0 ] ); + > {{alias}}.ndarray( 2, 2, A, 2, 1, 1, out, 2, 1, 2 ) + [ 0.0, 0.0, 1.0, 0.0, 3.0, 4.0 ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/lapack/base/sge-trans/docs/types/index.d.ts b/lib/node_modules/@stdlib/lapack/base/sge-trans/docs/types/index.d.ts new file mode 100644 index 00000000000..c331053df3c --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/sge-trans/docs/types/index.d.ts @@ -0,0 +1,114 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 { Layout } from '@stdlib/types/blas'; + +/** +* Interface describing `sgetrans`. +*/ +interface Routine { + /** + * Converts a matrix from row-major layout to column-major layout or vice versa. + * + * @param order - storage layout + * @param M - number of rows in matrix `A` + * @param N - number of columns in matrix `A` + * @param A - input matrix + * @param LDA - stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`) + * @param out - output matrix + * @param LDO - stride of the first dimension of `out` (a.k.a., leading dimension of the matrix `out`) + * @returns `out` + * + * @example + * var Float32Array = require( '@stdlib/array/float32' ); + * + * var A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + * var out = new Float32Array( 6 ); + * + * out = sgetrans( 'row-major', 2, 3, A, 3, out, 2 ); + * // returns [ 1.0, 4.0, 2.0, 5.0, 3.0, 6.0 ] + */ + ( order: Layout, M: number, N: number, A: Float32Array, LDA: number, out: Float32Array, LDO: number ): Float32Array; + + /** + * Converts a matrix from row-major layout to column-major layout or vice versa using alternative indexing semantics. + * + * @param M - number of rows in matrix `A` + * @param N - number of columns in matrix `A` + * @param A - input matrix + * @param strideA1 - stride of the first dimension of `A` + * @param strideA2 - stride of the second dimension of `A` + * @param offsetA - starting index for `A` + * @param out - output matrix + * @param strideO1 - stride of the first dimension of `out` + * @param strideO2 - stride of the second dimension of `out` + * @param offsetO - starting index for `out` + * @returns `out` + * + * @example + * var Float32Array = require( '@stdlib/array/float32' ); + * + * var A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + * var out = new Float32Array( 6 ); + * + * out = sgetrans.ndarray( 2, 3, A, 3, 1, 0, out, 2, 1, 0 ); + * // returns [ 1.0, 4.0, 2.0, 5.0, 3.0, 6.0 ] + */ + ndarray( M: number, N: number, A: Float32Array, strideA1: number, strideA2: number, offsetA: number, out: Float32Array, strideO1: number, strideO2: number, offsetO: number ): Float32Array; +} + +/** +* Converts a matrix from row-major layout to column-major layout or vice versa. +* +* @param order - storage layout +* @param M - number of rows in matrix `A` +* @param N - number of columns in matrix `A` +* @param A - input matrix +* @param LDA - stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`) +* @param out - output matrix +* @param LDO - stride of the first dimension of `out` (a.k.a., leading dimension of the matrix `out`) +* @returns `out` +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var out = new Float32Array( 6 ); +* +* out = sgetrans( 'row-major', 2, 3, A, 3, out, 2 ); +* // returns [ 1.0, 4.0, 2.0, 5.0, 3.0, 6.0 ] +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var out = new Float32Array( 6 ); +* +* out = sgetrans.ndarray( 2, 3, A, 3, 1, 0, out, 2, 1, 0 ); +* // returns [ 1.0, 4.0, 2.0, 5.0, 3.0, 6.0 ] +*/ +declare var sgetrans: Routine; + + +// EXPORTS // + +export = sgetrans; diff --git a/lib/node_modules/@stdlib/lapack/base/sge-trans/docs/types/test.ts b/lib/node_modules/@stdlib/lapack/base/sge-trans/docs/types/test.ts new file mode 100644 index 00000000000..9b2b236d7b3 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/sge-trans/docs/types/test.ts @@ -0,0 +1,326 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 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 sgetrans = require( './index' ); + + +// TESTS // + +// The function returns a Float32Array... +{ + const A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + const out = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + + sgetrans( 'row-major', 2, 2, A, 2, out, 2 ); // $ExpectType Float32Array +} + +// The compiler throws an error if the function is provided a first argument which is not a string... +{ + const A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + const out = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + + sgetrans( 5, 2, 2, A, 2, out, 2 ); // $ExpectError + sgetrans( true, 2, 2, A, 2, out, 2 ); // $ExpectError + sgetrans( false, 2, 2, A, 2, out, 2 ); // $ExpectError + sgetrans( null, 2, 2, A, 2, out, 2 ); // $ExpectError + sgetrans( void 0, 2, 2, A, 2, out, 2 ); // $ExpectError + sgetrans( [], 2, 2, A, 2, out, 2 ); // $ExpectError + sgetrans( {}, 2, 2, A, 2, out, 2 ); // $ExpectError + sgetrans( ( x: number ): number => x, 2, 2, A, 2, out, 2 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a number... +{ + const A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + const out = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + + sgetrans( 'row-major', '5', 2, A, 2, out, 2 ); // $ExpectError + sgetrans( 'row-major', true, 2, A, 2, out, 2 ); // $ExpectError + sgetrans( 'row-major', false, 2, A, 2, out, 2 ); // $ExpectError + sgetrans( 'row-major', null, 2, A, 2, out, 2 ); // $ExpectError + sgetrans( 'row-major', void 0, 2, A, 2, out, 2 ); // $ExpectError + sgetrans( 'row-major', [], 2, A, 2, out, 2 ); // $ExpectError + sgetrans( 'row-major', {}, 2, A, 2, out, 2 ); // $ExpectError + sgetrans( 'row-major', ( x: number ): number => x, 2, A, 2, out, 2 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a number... +{ + const A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + const out = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + + sgetrans( 'row-major', 2, '5', A, 2, out, 2 ); // $ExpectError + sgetrans( 'row-major', 2, true, A, 2, out, 2 ); // $ExpectError + sgetrans( 'row-major', 2, false, A, 2, out, 2 ); // $ExpectError + sgetrans( 'row-major', 2, null, A, 2, out, 2 ); // $ExpectError + sgetrans( 'row-major', 2, void 0, A, 2, out, 2 ); // $ExpectError + sgetrans( 'row-major', 2, [], A, 2, out, 2 ); // $ExpectError + sgetrans( 'row-major', 2, {}, A, 2, out, 2 ); // $ExpectError + sgetrans( 'row-major', 2, ( x: number ): number => x, A, 2, out, 2 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a Float32Array... +{ + const out = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + + sgetrans( 'row-major', 2, 2, '5', 2, out, 2 ); // $ExpectError + sgetrans( 'row-major', 2, 2, 5, 2, out, 2 ); // $ExpectError + sgetrans( 'row-major', 2, 2, true, 2, out, 2 ); // $ExpectError + sgetrans( 'row-major', 2, 2, false, 2, out, 2 ); // $ExpectError + sgetrans( 'row-major', 2, 2, null, 2, out, 2 ); // $ExpectError + sgetrans( 'row-major', 2, 2, void 0, 2, out, 2 ); // $ExpectError + sgetrans( 'row-major', 2, 2, [], 2, out, 2 ); // $ExpectError + sgetrans( 'row-major', 2, 2, {}, 2, out, 2 ); // $ExpectError + sgetrans( 'row-major', 2, 2, ( x: number ): number => x, 2, out, 2 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not a number... +{ + const A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + const out = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + + sgetrans( 'row-major', 2, 2, A, '5', out, 2 ); // $ExpectError + sgetrans( 'row-major', 2, 2, A, true, out, 2 ); // $ExpectError + sgetrans( 'row-major', 2, 2, A, false, out, 2 ); // $ExpectError + sgetrans( 'row-major', 2, 2, A, null, out, 2 ); // $ExpectError + sgetrans( 'row-major', 2, 2, A, void 0, out, 2 ); // $ExpectError + sgetrans( 'row-major', 2, 2, A, [], out, 2 ); // $ExpectError + sgetrans( 'row-major', 2, 2, A, {}, out, 2 ); // $ExpectError + sgetrans( 'row-major', 2, 2, A, ( x: number ): number => x, out, 2 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a sixth argument which is not a Float32Array... +{ + const A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + + sgetrans( 'row-major', 2, 2, A, 2, '5', 2 ); // $ExpectError + sgetrans( 'row-major', 2, 2, A, 2, 5, 2 ); // $ExpectError + sgetrans( 'row-major', 2, 2, A, 2, true, 2 ); // $ExpectError + sgetrans( 'row-major', 2, 2, A, 2, false, 2 ); // $ExpectError + sgetrans( 'row-major', 2, 2, A, 2, null, 2 ); // $ExpectError + sgetrans( 'row-major', 2, 2, A, 2, void 0, 2 ); // $ExpectError + sgetrans( 'row-major', 2, 2, A, 2, [], 2 ); // $ExpectError + sgetrans( 'row-major', 2, 2, A, 2, {}, 2 ); // $ExpectError + sgetrans( 'row-major', 2, 2, A, 2, ( x: number ): number => x, 2 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a seventh argument which is not a number... +{ + const A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + const out = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + + sgetrans( 'row-major', 2, 2, A, 2, out, '5' ); // $ExpectError + sgetrans( 'row-major', 2, 2, A, 2, out, true ); // $ExpectError + sgetrans( 'row-major', 2, 2, A, 2, out, false ); // $ExpectError + sgetrans( 'row-major', 2, 2, A, 2, out, null ); // $ExpectError + sgetrans( 'row-major', 2, 2, A, 2, out, void 0 ); // $ExpectError + sgetrans( 'row-major', 2, 2, A, 2, out, [] ); // $ExpectError + sgetrans( 'row-major', 2, 2, A, 2, out, {} ); // $ExpectError + sgetrans( 'row-major', 2, 2, A, 2, out, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + const out = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + + sgetrans(); // $ExpectError + sgetrans( 'row-major' ); // $ExpectError + sgetrans( 'row-major', 2 ); // $ExpectError + sgetrans( 'row-major', 2, 2 ); // $ExpectError + sgetrans( 'row-major', 2, 2, A ); // $ExpectError + sgetrans( 'row-major', 2, 2, A, 2 ); // $ExpectError + sgetrans( 'row-major', 2, 2, A, 2, out ); // $ExpectError + sgetrans( 'row-major', 2, 2, A, 2, out, 2, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a Float32Array... +{ + const A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + const out = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + + sgetrans.ndarray( 2, 2, A, 2, 1, 0, out, 2, 1, 0 ); // $ExpectType Float32Array +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + const A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + const out = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + + sgetrans.ndarray( '5', 2, A, 2, 1, 0, out, 2, 1, 0 ); // $ExpectError + sgetrans.ndarray( true, 2, A, 2, 1, 0, out, 2, 1, 0 ); // $ExpectError + sgetrans.ndarray( false, 2, A, 2, 1, 0, out, 2, 1, 0 ); // $ExpectError + sgetrans.ndarray( null, 2, A, 2, 1, 0, out, 2, 1, 0 ); // $ExpectError + sgetrans.ndarray( void 0, 2, A, 2, 1, 0, out, 2, 1, 0 ); // $ExpectError + sgetrans.ndarray( [], 2, A, 2, 1, 0, out, 2, 1, 0 ); // $ExpectError + sgetrans.ndarray( {}, 2, A, 2, 1, 0, out, 2, 1, 0 ); // $ExpectError + sgetrans.ndarray( ( x: number ): number => x, 2, A, 2, 1, 0, out, 2, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a number... +{ + const A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + const out = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + + sgetrans.ndarray( 2, '5', A, 2, 1, 0, out, 2, 1, 0 ); // $ExpectError + sgetrans.ndarray( 2, true, A, 2, 1, 0, out, 2, 1, 0 ); // $ExpectError + sgetrans.ndarray( 2, false, A, 2, 1, 0, out, 2, 1, 0 ); // $ExpectError + sgetrans.ndarray( 2, null, A, 2, 1, 0, out, 2, 1, 0 ); // $ExpectError + sgetrans.ndarray( 2, void 0, A, 2, 1, 0, out, 2, 1, 0 ); // $ExpectError + sgetrans.ndarray( 2, [], A, 2, 1, 0, out, 2, 1, 0 ); // $ExpectError + sgetrans.ndarray( 2, {}, A, 2, 1, 0, out, 2, 1, 0 ); // $ExpectError + sgetrans.ndarray( 2, ( x: number ): number => x, A, 2, 1, 0, out, 2, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a Float32Array... +{ + const out = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + + sgetrans.ndarray( 2, 2, '5', 2, 1, 0, out, 2, 1, 0 ); // $ExpectError + sgetrans.ndarray( 2, 2, 5, 2, 1, 0, out, 2, 1, 0 ); // $ExpectError + sgetrans.ndarray( 2, 2, true, 2, 1, 0, out, 2, 1, 0 ); // $ExpectError + sgetrans.ndarray( 2, 2, false, 2, 1, 0, out, 2, 1, 0 ); // $ExpectError + sgetrans.ndarray( 2, 2, null, 2, 1, 0, out, 2, 1, 0 ); // $ExpectError + sgetrans.ndarray( 2, 2, void 0, 2, 1, 0, out, 2, 1, 0 ); // $ExpectError + sgetrans.ndarray( 2, 2, [], 2, 1, 0, out, 2, 1, 0 ); // $ExpectError + sgetrans.ndarray( 2, 2, {}, 2, 1, 0, out, 2, 1, 0 ); // $ExpectError + sgetrans.ndarray( 2, 2, ( x: number ): number => x, 2, 1, 0, out, 2, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a number... +{ + const A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + const out = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + + sgetrans.ndarray( 2, 2, A, '5', 1, 0, out, 2, 1, 0 ); // $ExpectError + sgetrans.ndarray( 2, 2, A, true, 1, 0, out, 2, 1, 0 ); // $ExpectError + sgetrans.ndarray( 2, 2, A, false, 1, 0, out, 2, 1, 0 ); // $ExpectError + sgetrans.ndarray( 2, 2, A, null, 1, 0, out, 2, 1, 0 ); // $ExpectError + sgetrans.ndarray( 2, 2, A, void 0, 1, 0, out, 2, 1, 0 ); // $ExpectError + sgetrans.ndarray( 2, 2, A, [], 1, 0, out, 2, 1, 0 ); // $ExpectError + sgetrans.ndarray( 2, 2, A, {}, 1, 0, out, 2, 1, 0 ); // $ExpectError + sgetrans.ndarray( 2, 2, A, ( x: number ): number => x, 1, 0, out, 2, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not a number... +{ + const A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + const out = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + + sgetrans.ndarray( 2, 2, A, 2, '5', 0, out, 2, 1, 0 ); // $ExpectError + sgetrans.ndarray( 2, 2, A, 2, true, 0, out, 2, 1, 0 ); // $ExpectError + sgetrans.ndarray( 2, 2, A, 2, false, 0, out, 2, 1, 0 ); // $ExpectError + sgetrans.ndarray( 2, 2, A, 2, null, 0, out, 2, 1, 0 ); // $ExpectError + sgetrans.ndarray( 2, 2, A, 2, void 0, 0, out, 2, 1, 0 ); // $ExpectError + sgetrans.ndarray( 2, 2, A, 2, [], 0, out, 2, 1, 0 ); // $ExpectError + sgetrans.ndarray( 2, 2, A, 2, {}, 0, out, 2, 1, 0 ); // $ExpectError + sgetrans.ndarray( 2, 2, A, 2, ( x: number ): number => x, 0, out, 2, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a sixth argument which is not a number... +{ + const A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + const out = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + + sgetrans.ndarray( 2, 2, A, 2, 1, '5', out, 2, 1, 0 ); // $ExpectError + sgetrans.ndarray( 2, 2, A, 2, 1, true, out, 2, 1, 0 ); // $ExpectError + sgetrans.ndarray( 2, 2, A, 2, 1, false, out, 2, 1, 0 ); // $ExpectError + sgetrans.ndarray( 2, 2, A, 2, 1, null, out, 2, 1, 0 ); // $ExpectError + sgetrans.ndarray( 2, 2, A, 2, 1, void 0, out, 2, 1, 0 ); // $ExpectError + sgetrans.ndarray( 2, 2, A, 2, 1, [], out, 2, 1, 0 ); // $ExpectError + sgetrans.ndarray( 2, 2, A, 2, 1, {}, out, 2, 1, 0 ); // $ExpectError + sgetrans.ndarray( 2, 2, A, 2, 1, ( x: number ): number => x, out, 2, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a seventh argument which is not a Float32Array... +{ + const A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + + sgetrans.ndarray( 2, 2, A, 2, 1, 0, '5', 2, 1, 0 ); // $ExpectError + sgetrans.ndarray( 2, 2, A, 2, 1, 0, 5, 2, 1, 0 ); // $ExpectError + sgetrans.ndarray( 2, 2, A, 2, 1, 0, true, 2, 1, 0 ); // $ExpectError + sgetrans.ndarray( 2, 2, A, 2, 1, 0, false, 2, 1, 0 ); // $ExpectError + sgetrans.ndarray( 2, 2, A, 2, 1, 0, null, 2, 1, 0 ); // $ExpectError + sgetrans.ndarray( 2, 2, A, 2, 1, 0, void 0, 2, 1, 0 ); // $ExpectError + sgetrans.ndarray( 2, 2, A, 2, 1, 0, [], 2, 1, 0 ); // $ExpectError + sgetrans.ndarray( 2, 2, A, 2, 1, 0, {}, 2, 1, 0 ); // $ExpectError + sgetrans.ndarray( 2, 2, A, 2, 1, 0, ( x: number ): number => x, 2, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided an eighth argument which is not a number... +{ + const A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + const out = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + + sgetrans.ndarray( 2, 2, A, 2, 1, 0, out, '5', 1, 0 ); // $ExpectError + sgetrans.ndarray( 2, 2, A, 2, 1, 0, out, true, 1, 0 ); // $ExpectError + sgetrans.ndarray( 2, 2, A, 2, 1, 0, out, false, 1, 0 ); // $ExpectError + sgetrans.ndarray( 2, 2, A, 2, 1, 0, out, null, 1, 0 ); // $ExpectError + sgetrans.ndarray( 2, 2, A, 2, 1, 0, out, void 0, 1, 0 ); // $ExpectError + sgetrans.ndarray( 2, 2, A, 2, 1, 0, out, [], 1, 0 ); // $ExpectError + sgetrans.ndarray( 2, 2, A, 2, 1, 0, out, {}, 1, 0 ); // $ExpectError + sgetrans.ndarray( 2, 2, A, 2, 1, 0, out, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a ninth argument which is not a number... +{ + const A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + const out = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + + sgetrans.ndarray( 2, 2, A, 2, 1, 0, out, 2, '5', 0 ); // $ExpectError + sgetrans.ndarray( 2, 2, A, 2, 1, 0, out, 2, true, 0 ); // $ExpectError + sgetrans.ndarray( 2, 2, A, 2, 1, 0, out, 2, false, 0 ); // $ExpectError + sgetrans.ndarray( 2, 2, A, 2, 1, 0, out, 2, null, 0 ); // $ExpectError + sgetrans.ndarray( 2, 2, A, 2, 1, 0, out, 2, void 0, 0 ); // $ExpectError + sgetrans.ndarray( 2, 2, A, 2, 1, 0, out, 2, [], 0 ); // $ExpectError + sgetrans.ndarray( 2, 2, A, 2, 1, 0, out, 2, {}, 0 ); // $ExpectError + sgetrans.ndarray( 2, 2, A, 2, 1, 0, out, 2, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a tenth argument which is not a number... +{ + const A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + const out = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + + sgetrans.ndarray( 2, 2, A, 2, 1, 0, out, 2, 1, '5' ); // $ExpectError + sgetrans.ndarray( 2, 2, A, 2, 1, 0, out, 2, 1, true ); // $ExpectError + sgetrans.ndarray( 2, 2, A, 2, 1, 0, out, 2, 1, false ); // $ExpectError + sgetrans.ndarray( 2, 2, A, 2, 1, 0, out, 2, 1, null ); // $ExpectError + sgetrans.ndarray( 2, 2, A, 2, 1, 0, out, 2, 1, void 0 ); // $ExpectError + sgetrans.ndarray( 2, 2, A, 2, 1, 0, out, 2, 1, [] ); // $ExpectError + sgetrans.ndarray( 2, 2, A, 2, 1, 0, out, 2, 1, {} ); // $ExpectError + sgetrans.ndarray( 2, 2, A, 2, 1, 0, out, 2, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + const out = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + + sgetrans.ndarray(); // $ExpectError + sgetrans.ndarray( 2 ); // $ExpectError + sgetrans.ndarray( 2, 2 ); // $ExpectError + sgetrans.ndarray( 2, 2, A ); // $ExpectError + sgetrans.ndarray( 2, 2, A, 2 ); // $ExpectError + sgetrans.ndarray( 2, 2, A, 2, 1 ); // $ExpectError + sgetrans.ndarray( 2, 2, A, 2, 1, 0 ); // $ExpectError + sgetrans.ndarray( 2, 2, A, 2, 1, 0, out ); // $ExpectError + sgetrans.ndarray( 2, 2, A, 2, 1, 0, out, 2 ); // $ExpectError + sgetrans.ndarray( 2, 2, A, 2, 1, 0, out, 2, 1 ); // $ExpectError + sgetrans.ndarray( 2, 2, A, 2, 1, 0, out, 2, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/lapack/base/sge-trans/examples/index.js b/lib/node_modules/@stdlib/lapack/base/sge-trans/examples/index.js new file mode 100644 index 00000000000..9077f9e158a --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/sge-trans/examples/index.js @@ -0,0 +1,80 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 numel = require( '@stdlib/ndarray/base/numel' ); +var Float32Array = require( '@stdlib/array/float32' ); +var sgetrans = require( './../lib' ); + +var shapeA = [ 2, 3 ]; +var shapeOut = [ 3, 2 ]; + +// Row-major layout... +var order = 'row-major'; + +var stridesA = shape2strides( shapeA, order ); +var stridesOut = shape2strides( shapeOut, order ); + +var A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +console.log( ndarray2array( A, shapeA, stridesA, 0, order ) ); + +var out = new Float32Array( numel( shapeA ) ); + +out = sgetrans( order, shapeA[0], shapeA[1], A, stridesA[0], out, stridesOut[0] ); // eslint-disable-line max-len +console.log( ndarray2array( out, shapeOut, stridesOut, 0, order ) ); + +// Column-major layout... +order = 'column-major'; + +stridesA = shape2strides( shapeA, order ); +stridesOut = shape2strides( shapeOut, order ); + +A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +console.log( ndarray2array( A, shapeA, stridesA, 0, order ) ); + +out = new Float32Array( numel( shapeA ) ); + +out = sgetrans( order, shapeA[0], shapeA[1], A, stridesA[1], out, stridesOut[1] ); // eslint-disable-line max-len +console.log( ndarray2array( out, shapeOut, stridesOut, 0, order ) ); + +// Input and output arrays have different layouts... +stridesA = shape2strides( shapeA, 'row-major' ); +stridesOut = shape2strides( shapeOut, 'column-major' ); + +A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +console.log( ndarray2array( A, shapeA, stridesA, 0, 'row-major' ) ); + +out = new Float32Array( numel( shapeA ) ); + +out = sgetrans.ndarray( shapeA[0], shapeA[1], A, stridesA[0], stridesA[1], 0, out, stridesOut[0], stridesOut[1], 0 ); // eslint-disable-line max-len +console.log( ndarray2array( out, shapeOut, stridesOut, 0, 'column-major' ) ); + +// Input and output arrays have different layouts... +stridesA = shape2strides( shapeA, 'column-major' ); +stridesOut = shape2strides( shapeOut, 'row-major' ); + +A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +console.log( ndarray2array( A, shapeA, stridesA, 0, 'column-major' ) ); + +out = new Float32Array( numel( shapeA ) ); + +out = sgetrans.ndarray( shapeA[0], shapeA[1], A, stridesA[0], stridesA[1], 0, out, stridesOut[0], stridesOut[1], 0 ); // eslint-disable-line max-len +console.log( ndarray2array( out, shapeOut, stridesOut, 0, 'row-major' ) ); diff --git a/lib/node_modules/@stdlib/lapack/base/sge-trans/lib/base.js b/lib/node_modules/@stdlib/lapack/base/sge-trans/lib/base.js new file mode 100644 index 00000000000..7c68181d6e7 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/sge-trans/lib/base.js @@ -0,0 +1,106 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 */ + +'use strict'; + +// MODULES // + +var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major' ); + + +// MAIN // + +/** +* Converts a matrix from row-major layout to column-major layout or vice versa. +* +* @private +* @param {NonNegativeInteger} M - number of rows in matrix `A` +* @param {NonNegativeInteger} N - number of columns in matrix `A` +* @param {Float32Array} A - input matrix +* @param {integer} strideA1 - stride of the first dimension of `A` +* @param {integer} strideA2 - stride of the second dimension of `A` +* @param {NonNegativeInteger} offsetA - starting index for `A` +* @param {Float32Array} out - output matrix +* @param {integer} strideO1 - stride of the first dimension of `out` +* @param {integer} strideO2 - stride of the second dimension of `out` +* @param {NonNegativeInteger} offsetO - starting index for `out` +* @returns {Float32Array} `out` +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var out = new Float32Array( 6 ); +* +* out = sgetrans( 2, 3, A, 3, 1, 0, out, 2, 1, 0 ); +* // returns [ 1.0, 4.0, 2.0, 5.0, 3.0, 6.0 ] +*/ +function sgetrans( M, N, A, strideA1, strideA2, offsetA, out, strideO1, strideO2, offsetO ) { + var isrm; + var da0; + var da1; + var do0; + var do1; + var ia; + var io; + var i0; + var i1; + var S0; + var S1; + + // Note on variable naming convention: S#, da#, do#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Perform loop interchange based on the layout format of the output matrix... + isrm = isRowMajor( [ strideO1, strideO2 ] ); + if ( isrm ) { + // For row-major matrices, the last dimensions have the fastest changing indices... + S0 = M; + S1 = N; + da0 = strideA1; // offset increment for innermost loop + da1 = strideA2 - ( S0*strideA1 ); // offset increment for outermost loop + do0 = strideO2; + do1 = strideO1 - ( S0*strideO2 ); + } else { + // For column-major matrices, the first dimensions have the fastest changing indices... + S0 = N; + S1 = M; + da0 = strideA2; // offset increment for innermost loop + da1 = strideA1 - ( S0*strideA2 ); // offset increment for outermost loop + do0 = strideO1; + do1 = strideO2 - ( S0*strideO1 ); + } + ia = offsetA; + io = offsetO; + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + out[ io ] = A[ ia ]; + ia += da0; + io += do0; + } + ia += da1; + io += do1; + } + return out; +} + + +// EXPORTS // + +module.exports = sgetrans; diff --git a/lib/node_modules/@stdlib/lapack/base/sge-trans/lib/index.js b/lib/node_modules/@stdlib/lapack/base/sge-trans/lib/index.js new file mode 100644 index 00000000000..df737877415 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/sge-trans/lib/index.js @@ -0,0 +1,68 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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'; + +/** +* LAPACK routine to convert a matrix from row-major layout to column-major layout or vice versa. +* +* @module @stdlib/lapack/base/sge-trans +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var sgetrans = require( '@stdlib/lapack/base/sge-trans' ); +* +* var A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var out = new Float32Array( 6 ); +* +* out = sgetrans( 'row-major', 2, 3, A, 3, out, 2 ); +* // returns [ 1.0, 4.0, 2.0, 5.0, 3.0, 6.0 ] +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var sgetrans = require( '@stdlib/lapack/base/sge-trans' ); +* +* var A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var out = new Float32Array( 6 ); +* +* out = sgetrans.ndarray( 2, 3, A, 3, 1, 0, out, 2, 1, 0 ); +* // returns [ 1.0, 4.0, 2.0, 5.0, 3.0, 6.0 ] +*/ + +// MODULES // + +var join = require( 'path' ).join; +var tryRequire = require( '@stdlib/utils/try-require' ); +var isError = require( '@stdlib/assert/is-error' ); +var main = require( './main.js' ); + + +// MAIN // + +var sgetrans; +var tmp = tryRequire( join( __dirname, './native.js' ) ); +if ( isError( tmp ) ) { + sgetrans = main; +} else { + sgetrans = tmp; +} + + +// EXPORTS // + +module.exports = sgetrans; diff --git a/lib/node_modules/@stdlib/lapack/base/sge-trans/lib/main.js b/lib/node_modules/@stdlib/lapack/base/sge-trans/lib/main.js new file mode 100644 index 00000000000..56a9044533b --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/sge-trans/lib/main.js @@ -0,0 +1,35 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var sgetrans = require( './sgetrans.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( sgetrans, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = sgetrans; diff --git a/lib/node_modules/@stdlib/lapack/base/sge-trans/lib/ndarray.js b/lib/node_modules/@stdlib/lapack/base/sge-trans/lib/ndarray.js new file mode 100644 index 00000000000..b363c4ac1e3 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/sge-trans/lib/ndarray.js @@ -0,0 +1,61 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 */ + +'use strict'; + +// MODULES // + +var base = require( './base.js' ); + + +// MAIN // + +/** +* Converts a matrix from row-major layout to column-major layout or vice versa using alternative indexing semantics. +* +* @param {NonNegativeInteger} M - number of rows in matrix `A` +* @param {NonNegativeInteger} N - number of columns in matrix `A` +* @param {Float32Array} A - input matrix +* @param {integer} strideA1 - stride of the first dimension of `A` +* @param {integer} strideA2 - stride of the second dimension of `A` +* @param {NonNegativeInteger} offsetA - starting index for `A` +* @param {Float32Array} out - output matrix +* @param {integer} strideO1 - stride of the first dimension of `out` +* @param {integer} strideO2 - stride of the second dimension of `out` +* @param {NonNegativeInteger} offsetO - starting index for `out` +* @returns {Float32Array} `out` +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var out = new Float32Array( 6 ); +* +* out = sgetrans( 2, 3, A, 3, 1, 0, out, 2, 1, 0 ); +* // returns [ 1.0, 4.0, 2.0, 5.0, 3.0, 6.0 ] +*/ +function sgetrans( M, N, A, strideA1, strideA2, offsetA, out, strideO1, strideO2, offsetO ) { + return base( M, N, A, strideA1, strideA2, offsetA, out, strideO1, strideO2, offsetO ); +} + + +// EXPORTS // + +module.exports = sgetrans; diff --git a/lib/node_modules/@stdlib/lapack/base/sge-trans/lib/sgetrans.js b/lib/node_modules/@stdlib/lapack/base/sge-trans/lib/sgetrans.js new file mode 100644 index 00000000000..81acee14c72 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/sge-trans/lib/sgetrans.js @@ -0,0 +1,78 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 format = require( '@stdlib/string/format' ); +var base = require( './base.js' ); + + +// MAIN // + +/** +* Converts a matrix from row-major layout to column-major layout or vice versa. +* +* @param {string} order - storage layout +* @param {NonNegativeInteger} M - number of rows in matrix `A` +* @param {NonNegativeInteger} N - number of columns in matrix `A` +* @param {Float32Array} A - input matrix +* @param {PositiveInteger} LDA - stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`) +* @param {Float32Array} out - output matrix +* @param {PositiveInteger} LDO - stride of the first dimension of `out` (a.k.a., leading dimension of the matrix `out`) +* @throws {TypeError} first argument must be a valid order +* @returns {Float32Array} `out` +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var out = new Float32Array( 6 ); +* +* out = sgetrans( 'row-major', 2, 3, A, 3, out, 2 ); +* // returns [ 1.0, 4.0, 2.0, 5.0, 3.0, 6.0 ] +*/ +function sgetrans( order, M, N, A, LDA, out, LDO ) { + var sa1; + var sa2; + var so1; + var so2; + + if ( !isLayout( order ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a valid order. Value: `%s`.', order ) ); + } + if ( order === 'column-major' ) { + sa1 = 1; + sa2 = LDA; + so1 = 1; + so2 = LDO; + } else { // order === 'row-major' + sa1 = LDA; + sa2 = 1; + so1 = LDO; + so2 = 1; + } + return base( M, N, A, sa1, sa2, 0, out, so1, so2, 0 ); +} + + +// EXPORTS // + +module.exports = sgetrans; diff --git a/lib/node_modules/@stdlib/lapack/base/sge-trans/package.json b/lib/node_modules/@stdlib/lapack/base/sge-trans/package.json new file mode 100644 index 00000000000..dee0aa72cc0 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/sge-trans/package.json @@ -0,0 +1,68 @@ +{ + "name": "@stdlib/lapack/base/sge-trans", + "version": "0.0.0", + "description": "Convert a matrix from row-major layout to column-major layout or vice versa.", + "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", + "lapack", + "transpose", + "copy", + "linear", + "algebra", + "subroutines", + "array", + "ndarray", + "matrix", + "float32", + "float32array" + ] +} diff --git a/lib/node_modules/@stdlib/lapack/base/sge-trans/test/test.js b/lib/node_modules/@stdlib/lapack/base/sge-trans/test/test.js new file mode 100644 index 00000000000..93fe3403d2f --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/sge-trans/test/test.js @@ -0,0 +1,82 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 proxyquire = require( 'proxyquire' ); +var IS_BROWSER = require( '@stdlib/assert/is-browser' ); +var sgetrans = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': IS_BROWSER +}; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof sgetrans, '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 sgetrans.ndarray, 'function', 'method is a function' ); + t.end(); +}); + +tape( 'if a native implementation is available, the main export is the native implementation', opts, function test( t ) { + var sgetrans = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( sgetrans, mock, 'returns expected value' ); + t.end(); + + function tryRequire() { + return mock; + } + + function mock() { + // Mock... + } +}); + +tape( 'if a native implementation is not available, the main export is a JavaScript implementation', opts, function test( t ) { + var sgetrans; + var main; + + main = require( './../lib/sgetrans.js' ); + + sgetrans = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( sgetrans, main, 'returns expected value' ); + t.end(); + + function tryRequire() { + return new Error( 'Cannot find module' ); + } +}); diff --git a/lib/node_modules/@stdlib/lapack/base/sge-trans/test/test.ndarray.js b/lib/node_modules/@stdlib/lapack/base/sge-trans/test/test.ndarray.js new file mode 100644 index 00000000000..98753366c65 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/sge-trans/test/test.ndarray.js @@ -0,0 +1,713 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 flatten2d = require( '@stdlib/array/base/flatten2d' ); +var Float32Array = require( '@stdlib/array/float32' ); +var sgetrans = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof sgetrans, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 10', function test( t ) { + t.strictEqual( sgetrans.length, 10, 'returns expected value' ); + t.end(); +}); + +tape( 'the function transposes a matrix (tall rectangular, row-major, row-major)', function test( t ) { + var expected; + var actual; + var out; + var A; + var M; + var N; + + M = 4; + N = 2; + + A = [ + [ 1.0, 2.0 ], + [ 3.0, 4.0 ], + [ 5.0, 6.0 ], + [ 7.0, 8.0 ] + ]; + A = new Float32Array( flatten2d( A, [ M, N ], false ) ); + out = new Float32Array( M*N ); + + expected = [ + [ 1.0, 3.0, 5.0, 7.0 ], + [ 2.0, 4.0, 6.0, 8.0 ] + ]; + expected = new Float32Array( flatten2d( expected, [ N, M ], false ) ); + + actual = sgetrans( M, N, A, N, 1, 0, out, M, 1, 0 ); + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function transposes a matrix (tall rectangular, row-major, column-major)', function test( t ) { + var expected; + var actual; + var out; + var A; + var M; + var N; + + M = 4; + N = 2; + + A = [ + [ 1.0, 2.0 ], + [ 3.0, 4.0 ], + [ 5.0, 6.0 ], + [ 7.0, 8.0 ] + ]; + A = new Float32Array( flatten2d( A, [ M, N ], false ) ); + out = new Float32Array( M*N ); + + expected = [ + [ 1.0, 3.0, 5.0, 7.0 ], + [ 2.0, 4.0, 6.0, 8.0 ] + ]; + expected = new Float32Array( flatten2d( expected, [ N, M ], true ) ); + + actual = sgetrans( M, N, A, N, 1, 0, out, 1, N, 0 ); + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function transposes a matrix (tall rectangular, column-major, column-major)', function test( t ) { + var expected; + var actual; + var out; + var A; + var M; + var N; + + M = 4; + N = 2; + + A = [ + [ 1.0, 2.0 ], + [ 3.0, 4.0 ], + [ 5.0, 6.0 ], + [ 7.0, 8.0 ] + ]; + A = new Float32Array( flatten2d( A, [ M, N ], true ) ); + out = new Float32Array( M*N ); + + expected = [ + [ 1.0, 3.0, 5.0, 7.0 ], + [ 2.0, 4.0, 6.0, 8.0 ] + ]; + expected = new Float32Array( flatten2d( expected, [ N, M ], true ) ); + + actual = sgetrans( M, N, A, 1, M, 0, out, 1, N, 0 ); + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function transposes a matrix (tall rectangular, column-major, row-major)', function test( t ) { + var expected; + var actual; + var out; + var A; + var M; + var N; + + M = 4; + N = 2; + + A = [ + [ 1.0, 2.0 ], + [ 3.0, 4.0 ], + [ 5.0, 6.0 ], + [ 7.0, 8.0 ] + ]; + A = new Float32Array( flatten2d( A, [ M, N ], true ) ); + out = new Float32Array( M*N ); + + expected = [ + [ 1.0, 3.0, 5.0, 7.0 ], + [ 2.0, 4.0, 6.0, 8.0 ] + ]; + expected = new Float32Array( flatten2d( expected, [ N, M ], false ) ); + + actual = sgetrans( M, N, A, 1, M, 0, out, M, 1, 0 ); + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function transposes a matrix (wide rectangular, row-major, row-major)', function test( t ) { + var expected; + var actual; + var out; + var A; + var M; + var N; + + M = 2; + N = 4; + + A = [ + [ 1.0, 2.0, 3.0, 4.0 ], + [ 5.0, 6.0, 7.0, 8.0 ] + ]; + A = new Float32Array( flatten2d( A, [ M, N ], false ) ); + out = new Float32Array( M*N ); + + expected = [ + [ 1.0, 5.0 ], + [ 2.0, 6.0 ], + [ 3.0, 7.0 ], + [ 4.0, 8.0 ] + ]; + expected = new Float32Array( flatten2d( expected, [ N, M ], false ) ); + + actual = sgetrans( M, N, A, N, 1, 0, out, M, 1, 0 ); + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function transposes a matrix (wide rectangular, row-major, column-major)', function test( t ) { + var expected; + var actual; + var out; + var A; + var M; + var N; + + M = 2; + N = 4; + + A = [ + [ 1.0, 2.0, 3.0, 4.0 ], + [ 5.0, 6.0, 7.0, 8.0 ] + ]; + A = new Float32Array( flatten2d( A, [ M, N ], false ) ); + out = new Float32Array( M*N ); + + expected = [ + [ 1.0, 5.0 ], + [ 2.0, 6.0 ], + [ 3.0, 7.0 ], + [ 4.0, 8.0 ] + ]; + expected = new Float32Array( flatten2d( expected, [ N, M ], true ) ); + + actual = sgetrans( M, N, A, N, 1, 0, out, 1, N, 0 ); + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function transposes a matrix (wide rectangular, column-major, column-major)', function test( t ) { + var expected; + var actual; + var out; + var A; + var M; + var N; + + M = 2; + N = 4; + + A = [ + [ 1.0, 2.0, 3.0, 4.0 ], + [ 5.0, 6.0, 7.0, 8.0 ] + ]; + A = new Float32Array( flatten2d( A, [ M, N ], true ) ); + out = new Float32Array( M*N ); + + expected = [ + [ 1.0, 5.0 ], + [ 2.0, 6.0 ], + [ 3.0, 7.0 ], + [ 4.0, 8.0 ] + ]; + expected = new Float32Array( flatten2d( expected, [ N, M ], true ) ); + + actual = sgetrans( M, N, A, 1, M, 0, out, 1, N, 0 ); + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function transposes a matrix (wide rectangular, column-major, row-major)', function test( t ) { + var expected; + var actual; + var out; + var A; + var M; + var N; + + M = 2; + N = 4; + + A = [ + [ 1.0, 2.0, 3.0, 4.0 ], + [ 5.0, 6.0, 7.0, 8.0 ] + ]; + A = new Float32Array( flatten2d( A, [ M, N ], true ) ); + out = new Float32Array( M*N ); + + expected = [ + [ 1.0, 5.0 ], + [ 2.0, 6.0 ], + [ 3.0, 7.0 ], + [ 4.0, 8.0 ] + ]; + expected = new Float32Array( flatten2d( expected, [ N, M ], false ) ); + + actual = sgetrans( M, N, A, 1, M, 0, out, M, 1, 0 ); + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function transposes a matrix (square, row-major, row-major)', function test( t ) { + var expected; + var actual; + var out; + var A; + var M; + var N; + + M = 2; + N = 2; + + A = [ + [ 1.0, 2.0 ], + [ 3.0, 4.0 ] + ]; + A = new Float32Array( flatten2d( A, [ M, N ], false ) ); + out = new Float32Array( M*N ); + + expected = [ + [ 1.0, 3.0 ], + [ 2.0, 4.0 ] + ]; + expected = new Float32Array( flatten2d( expected, [ N, M ], false ) ); + + actual = sgetrans( M, N, A, N, 1, 0, out, M, 1, 0 ); + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function transposes a matrix (square, row-major, column-major)', function test( t ) { + var expected; + var actual; + var out; + var A; + var M; + var N; + + M = 2; + N = 2; + + A = [ + [ 1.0, 2.0 ], + [ 3.0, 4.0 ] + ]; + A = new Float32Array( flatten2d( A, [ M, N ], false ) ); + out = new Float32Array( M*N ); + + expected = [ + [ 1.0, 3.0 ], + [ 2.0, 4.0 ] + ]; + expected = new Float32Array( flatten2d( expected, [ N, M ], true ) ); + + actual = sgetrans( M, N, A, N, 1, 0, out, 1, N, 0 ); + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function transposes a matrix (square, column-major, column-major)', function test( t ) { + var expected; + var actual; + var out; + var A; + var M; + var N; + + M = 2; + N = 2; + + A = [ + [ 1.0, 2.0 ], + [ 3.0, 4.0 ] + ]; + A = new Float32Array( flatten2d( A, [ M, N ], true ) ); + out = new Float32Array( M*N ); + + expected = [ + [ 1.0, 3.0 ], + [ 2.0, 4.0 ] + ]; + expected = new Float32Array( flatten2d( expected, [ N, M ], true ) ); + + actual = sgetrans( M, N, A, 1, M, 0, out, 1, N, 0 ); + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function transposes a matrix (square, column-major, row-major)', function test( t ) { + var expected; + var actual; + var out; + var A; + var M; + var N; + + M = 2; + N = 2; + + A = [ + [ 1.0, 2.0 ], + [ 3.0, 4.0 ] + ]; + A = new Float32Array( flatten2d( A, [ M, N ], true ) ); + out = new Float32Array( M*N ); + + expected = [ + [ 1.0, 3.0 ], + [ 2.0, 4.0 ] + ]; + expected = new Float32Array( flatten2d( expected, [ N, M ], false ) ); + + actual = sgetrans( M, N, A, 1, M, 0, out, M, 1, 0 ); + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a reference to the output matrix', function test( t ) { + var actual; + var out; + var A; + var M; + var N; + + M = 2; + N = 2; + + A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + out = new Float32Array( M*N ); + + actual = sgetrans( M, N, A, N, 1, 0, out, N, 1, 0 ); + t.strictEqual( actual, out, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying the strides of the first and second dimensions of `A`', function test( t ) { + var expected; + var actual; + var out; + var A; + var M; + var N; + + M = 4; + N = 3; + + /* eslint-disable array-element-newline, no-multi-spaces, no-mixed-spaces-and-tabs */ + + A = new Float32Array([ + 1, 999, 2, 999, 3, 999, + 999, 999, 999, 999, 999, 999, + 4, 999, 5, 999, 6, 999, + 999, 999, 999, 999, 999, 999, + 7, 999, 8, 999, 9, 999, + 999, 999, 999, 999, 999, 999, + 10, 999, 11, 999, 12, 999, + 999, 999, 999, 999, 999, 999 + ]); + + /* eslint-enable array-element-newline, no-multi-spaces, no-mixed-spaces-and-tabs */ + + out = new Float32Array( M*N ); + + expected = new Float32Array( [ 1.0, 4.0, 7.0, 10.0, 2.0, 5.0, 8.0, 11.0, 3.0, 6.0, 9.0, 12.0 ] ); // eslint-disable-line max-len + + actual = sgetrans( M, N, A, 12, 2, 0, out, M, 1, 0 ); + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying the strides of the first and second dimensions of `out`', function test( t ) { + var expected; + var actual; + var out; + var A; + var M; + var N; + + M = 4; + N = 3; + + A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); // eslint-disable-line max-len + + out = new Float32Array( 48 ); + + /* eslint-disable array-element-newline, no-multi-spaces */ + + expected = new Float32Array([ + 1, 0, 4, 0, 7, 0, 10, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 2, 0, 5, 0, 8, 0, 11, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 3, 0, 6, 0, 9, 0, 12, 0, + 0, 0, 0, 0, 0, 0, 0, 0 + ]); + + /* eslint-enable array-element-newline, no-multi-spaces */ + + actual = sgetrans( M, N, A, N, 1, 0, out, 16, 2, 0 ); + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying an offset for `A`', function test( t ) { + var expected; + var actual; + var out; + var A; + var M; + var N; + + M = 4; + N = 3; + + /* eslint-disable array-element-newline, no-multi-spaces */ + + A = new Float32Array([ + 999, 999, 999, 999, 999, 999, 999, + 999, 1, 999, 2, 999, 3, 999, + 999, 999, 999, 999, 999, 999, 999, + 999, 4, 999, 5, 999, 6, 999, + 999, 999, 999, 999, 999, 999, 999, + 999, 7, 999, 8, 999, 9, 999, + 999, 999, 999, 999, 999, 999, 999, + 999, 10, 999, 11, 999, 12, 999, + 999, 999, 999, 999, 999, 999, 999 + ]); + + /* eslint-enable array-element-newline, no-multi-spaces */ + + out = new Float32Array( M*N ); + + expected = new Float32Array( [ 1.0, 4.0, 7.0, 10.0, 2.0, 5.0, 8.0, 11.0, 3.0, 6.0, 9.0, 12.0 ] ); // eslint-disable-line max-len + + actual = sgetrans( M, N, A, 14, 2, 8, out, M, 1, 0 ); + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying an offset for `out`', function test( t ) { + var expected; + var actual; + var out; + var A; + var M; + var N; + + M = 4; + N = 3; + + A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); // eslint-disable-line max-len + + out = new Float32Array( 63 ); + + /* eslint-disable array-element-newline, no-multi-spaces */ + + expected = new Float32Array([ + 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1, 0, 4, 0, 7, 0, 10, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 2, 0, 5, 0, 8, 0, 11, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 3, 0, 6, 0, 9, 0, 12, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0 + ]); + + /* eslint-enable array-element-newline, no-multi-spaces */ + + actual = sgetrans( M, N, A, N, 1, 0, out, 18, 2, 10 ); + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying negative strides for `A`', function test( t ) { + var expected; + var actual; + var out; + var A; + var M; + var N; + + M = 4; + N = 3; + + /* eslint-disable array-element-newline, no-multi-spaces */ + + A = new Float32Array([ + 999, 999, 999, 999, 999, 999, 999, + 999, 1, 999, 2, 999, 3, 999, + 999, 999, 999, 999, 999, 999, 999, + 999, 4, 999, 5, 999, 6, 999, + 999, 999, 999, 999, 999, 999, 999, + 999, 7, 999, 8, 999, 9, 999, + 999, 999, 999, 999, 999, 999, 999, + 999, 10, 999, 11, 999, 12, 999, + 999, 999, 999, 999, 999, 999, 999 + ]); + + /* eslint-enable array-element-newline, no-multi-spaces */ + + out = new Float32Array( M*N ); + + expected = new Float32Array( [ 12.0, 9.0, 6.0, 3.0, 11.0, 8.0, 5.0, 2.0, 10.0, 7.0, 4.0, 1.0 ] ); // eslint-disable-line max-len + + actual = sgetrans( M, N, A, -14, -2, 54, out, M, 1, 0 ); + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying negative strides for `out`', function test( t ) { + var expected; + var actual; + var out; + var A; + var M; + var N; + + M = 4; + N = 3; + + A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); // eslint-disable-line max-len + + out = new Float32Array( 63 ); + + /* eslint-disable array-element-newline, no-multi-spaces */ + + expected = new Float32Array([ + 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 12, 0, 9, 0, 6, 0, 3, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 11, 0, 8, 0, 5, 0, 2, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 10, 0, 7, 0, 4, 0, 1, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0 + ]); + + /* eslint-enable array-element-newline, no-multi-spaces */ + + actual = sgetrans( M, N, A, N, 1, 0, out, -18, -2, 52 ); + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports complex access patterns', function test( t ) { + var expected; + var actual; + var out; + var A; + var M; + var N; + + M = 4; + N = 3; + + /* eslint-disable array-element-newline, no-multi-spaces */ + + A = new Float32Array([ + 999, 999, 999, 999, 999, 999, 999, + 999, 1, 999, 2, 999, 3, 999, + 999, 999, 999, 999, 999, 999, 999, + 999, 4, 999, 5, 999, 6, 999, + 999, 999, 999, 999, 999, 999, 999, + 999, 7, 999, 8, 999, 9, 999, + 999, 999, 999, 999, 999, 999, 999, + 999, 10, 999, 11, 999, 12, 999, + 999, 999, 999, 999, 999, 999, 999 + ]); + + out = new Float32Array( 63 ); + + expected = new Float32Array([ + 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 12, 0, 9, 0, 6, 0, 3, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 11, 0, 8, 0, 5, 0, 2, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 10, 0, 7, 0, 4, 0, 1, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0 + ]); + + /* eslint-enable array-element-newline, no-multi-spaces */ + + actual = sgetrans( M, N, A, 14, 2, 8, out, -18, -2, 52 ); + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/lapack/base/sge-trans/test/test.sgetrans.js b/lib/node_modules/@stdlib/lapack/base/sge-trans/test/test.sgetrans.js new file mode 100644 index 00000000000..feadf81c80b --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/sge-trans/test/test.sgetrans.js @@ -0,0 +1,419 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 flatten2d = require( '@stdlib/array/base/flatten2d' ); +var Float32Array = require( '@stdlib/array/float32' ); +var sgetrans = require( './../lib/sgetrans.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof sgetrans, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 7', function test( t ) { + t.strictEqual( sgetrans.length, 7, 'returns expected value' ); + t.end(); +}); + +tape( 'the function throws an error if provided an invalid first argument', function test( t ) { + var values; + var out; + var A; + var i; + + values = [ + 'foo', + 'bar', + 'beep', + 'boop' + ]; + + A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + out = new Float32Array( 4 ); + + 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() { + sgetrans( value, 2, 2, A, 2, out, 2 ); + }; + } +}); + +tape( 'the function transposes a matrix (tall rectangular, row-major)', function test( t ) { + var expected; + var actual; + var out; + var A; + var M; + var N; + + M = 4; + N = 2; + + A = [ + [ 1.0, 2.0 ], + [ 3.0, 4.0 ], + [ 5.0, 6.0 ], + [ 7.0, 8.0 ] + ]; + A = new Float32Array( flatten2d( A, [ M, N ], false ) ); + out = new Float32Array( M*N ); + + expected = [ + [ 1.0, 3.0, 5.0, 7.0 ], + [ 2.0, 4.0, 6.0, 8.0 ] + ]; + expected = new Float32Array( flatten2d( expected, [ N, M ], false ) ); + + actual = sgetrans( 'row-major', M, N, A, N, out, M ); + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function transposes a matrix (tall rectangular, column-major)', function test( t ) { + var expected; + var actual; + var out; + var A; + var M; + var N; + + M = 4; + N = 2; + + A = [ + [ 1.0, 2.0 ], + [ 3.0, 4.0 ], + [ 5.0, 6.0 ], + [ 7.0, 8.0 ] + ]; + A = new Float32Array( flatten2d( A, [ M, N ], true ) ); + out = new Float32Array( M*N ); + + expected = [ + [ 1.0, 3.0, 5.0, 7.0 ], + [ 2.0, 4.0, 6.0, 8.0 ] + ]; + expected = new Float32Array( flatten2d( expected, [ N, M ], true ) ); + + actual = sgetrans( 'column-major', M, N, A, M, out, N ); + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function transposes a matrix (wide rectangular, row-major)', function test( t ) { + var expected; + var actual; + var out; + var A; + var M; + var N; + + M = 2; + N = 4; + + A = [ + [ 1.0, 2.0, 3.0, 4.0 ], + [ 5.0, 6.0, 7.0, 8.0 ] + ]; + A = new Float32Array( flatten2d( A, [ M, N ], false ) ); + out = new Float32Array( M*N ); + + expected = [ + [ 1.0, 5.0 ], + [ 2.0, 6.0 ], + [ 3.0, 7.0 ], + [ 4.0, 8.0 ] + ]; + expected = new Float32Array( flatten2d( expected, [ N, M ], false ) ); + + actual = sgetrans( 'row-major', M, N, A, N, out, M ); + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function transposes a matrix (wide rectangular, column-major)', function test( t ) { + var expected; + var actual; + var out; + var A; + var M; + var N; + + M = 2; + N = 4; + + A = [ + [ 1.0, 2.0, 3.0, 4.0 ], + [ 5.0, 6.0, 7.0, 8.0 ] + ]; + A = new Float32Array( flatten2d( A, [ M, N ], true ) ); + out = new Float32Array( M*N ); + + expected = [ + [ 1.0, 5.0 ], + [ 2.0, 6.0 ], + [ 3.0, 7.0 ], + [ 4.0, 8.0 ] + ]; + expected = new Float32Array( flatten2d( expected, [ N, M ], true ) ); + + actual = sgetrans( 'column-major', M, N, A, M, out, N ); + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function transposes a matrix (square, row-major)', function test( t ) { + var expected; + var actual; + var out; + var A; + var M; + var N; + + M = 2; + N = 2; + + A = [ + [ 1.0, 2.0 ], + [ 3.0, 4.0 ] + ]; + A = new Float32Array( flatten2d( A, [ M, N ], false ) ); + out = new Float32Array( M*N ); + + expected = [ + [ 1.0, 3.0 ], + [ 2.0, 4.0 ] + ]; + expected = new Float32Array( flatten2d( expected, [ N, M ], false ) ); + + actual = sgetrans( 'row-major', M, N, A, N, out, M ); + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function transposes a matrix (square, column-major)', function test( t ) { + var expected; + var actual; + var out; + var A; + var M; + var N; + + M = 2; + N = 2; + + A = [ + [ 1.0, 2.0 ], + [ 3.0, 4.0 ] + ]; + A = new Float32Array( flatten2d( A, [ M, N ], true ) ); + out = new Float32Array( M*N ); + + expected = [ + [ 1.0, 3.0 ], + [ 2.0, 4.0 ] + ]; + expected = new Float32Array( flatten2d( expected, [ N, M ], true ) ); + + actual = sgetrans( 'column-major', M, N, A, M, out, N ); + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a reference to the output matrix', function test( t ) { + var actual; + var out; + var A; + var M; + var N; + + M = 2; + N = 2; + + A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + out = new Float32Array( M*N ); + + actual = sgetrans( 'column-major', M, N, A, M, out, N ); + t.strictEqual( actual, out, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a stride for `A` (row-major)', function test( t ) { + var expected; + var actual; + var out; + var A; + var M; + var N; + + M = 4; + N = 2; + + A = [ + [ 1.0, 2.0, 999, 999 ], + [ 3.0, 4.0, 999, 999 ], + [ 5.0, 6.0, 999, 999 ], + [ 7.0, 8.0, 999, 999 ] + ]; + A = new Float32Array( flatten2d( A, [ M, N*2 ], false ) ); + out = new Float32Array( M*N ); + + expected = [ + [ 1.0, 3.0, 5.0, 7.0 ], + [ 2.0, 4.0, 6.0, 8.0 ] + ]; + expected = new Float32Array( flatten2d( expected, [ N, M ], false ) ); + + actual = sgetrans( 'row-major', M, N, A, N*2, out, M ); + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a stride for `A` (column-major)', function test( t ) { + var expected; + var actual; + var out; + var A; + var M; + var N; + + M = 4; + N = 2; + + A = [ + [ 1.0, 2.0 ], + [ 3.0, 4.0 ], + [ 5.0, 6.0 ], + [ 7.0, 8.0 ], + [ 999, 999 ], + [ 999, 999 ], + [ 999, 999 ], + [ 999, 999 ] + ]; + A = new Float32Array( flatten2d( A, [ M*2, N ], true ) ); + out = new Float32Array( M*N ); + + expected = [ + [ 1.0, 3.0, 5.0, 7.0 ], + [ 2.0, 4.0, 6.0, 8.0 ] + ]; + expected = new Float32Array( flatten2d( expected, [ N, M ], true ) ); + + actual = sgetrans( 'column-major', M, N, A, M*2, out, N ); + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a stride for `out` (row-major)', function test( t ) { + var expected; + var actual; + var out; + var A; + var M; + var N; + + M = 4; + N = 2; + + A = [ + [ 1.0, 2.0 ], + [ 3.0, 4.0 ], + [ 5.0, 6.0 ], + [ 7.0, 8.0 ] + ]; + A = new Float32Array( flatten2d( A, [ M, N ], false ) ); + out = new Float32Array( M*N*2 ); + + expected = [ + [ 1.0, 3.0, 5.0, 7.0, 0.0, 0.0, 0.0, 0.0 ], + [ 2.0, 4.0, 6.0, 8.0, 0.0, 0.0, 0.0, 0.0 ] + ]; + expected = new Float32Array( flatten2d( expected, [ N, M*2 ], false ) ); + + actual = sgetrans( 'row-major', M, N, A, N, out, M*2 ); + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a stride for `out` (column-major)', function test( t ) { + var expected; + var actual; + var out; + var A; + var M; + var N; + + M = 4; + N = 2; + + A = [ + [ 1.0, 2.0 ], + [ 3.0, 4.0 ], + [ 5.0, 6.0 ], + [ 7.0, 8.0 ] + ]; + A = new Float32Array( flatten2d( A, [ M, N ], true ) ); + out = new Float32Array( M*N*2 ); + + expected = [ + [ 1.0, 3.0, 5.0, 7.0 ], + [ 2.0, 4.0, 6.0, 8.0 ], + [ 0.0, 0.0, 0.0, 0.0 ], + [ 0.0, 0.0, 0.0, 0.0 ] + ]; + expected = new Float32Array( flatten2d( expected, [ N*2, M ], true ) ); + + actual = sgetrans( 'column-major', M, N, A, M, out, N*2 ); + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +});