From c3344066017219f54245973d7a3c263127cc6674 Mon Sep 17 00:00:00 2001 From: kaustubh Date: Mon, 20 Jul 2026 12:21:38 +0530 Subject: [PATCH] feat: add blas/ext/base/gtriu --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: passed - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../@stdlib/blas/ext/base/gtriu/README.md | 187 +++++++++ .../ext/base/gtriu/benchmark/benchmark.js | 112 ++++++ .../base/gtriu/benchmark/benchmark.ndarray.js | 126 ++++++ .../@stdlib/blas/ext/base/gtriu/docs/repl.txt | 111 ++++++ .../blas/ext/base/gtriu/docs/types/index.d.ts | 120 ++++++ .../blas/ext/base/gtriu/docs/types/test.ts | 350 ++++++++++++++++ .../blas/ext/base/gtriu/examples/index.js | 44 ++ .../blas/ext/base/gtriu/lib/accessors.js | 108 +++++ .../@stdlib/blas/ext/base/gtriu/lib/base.js | 105 +++++ .../@stdlib/blas/ext/base/gtriu/lib/index.js | 61 +++ .../@stdlib/blas/ext/base/gtriu/lib/main.js | 100 +++++ .../blas/ext/base/gtriu/lib/ndarray.js | 65 +++ .../@stdlib/blas/ext/base/gtriu/package.json | 67 ++++ .../@stdlib/blas/ext/base/gtriu/test/test.js | 38 ++ .../blas/ext/base/gtriu/test/test.main.js | 375 ++++++++++++++++++ .../blas/ext/base/gtriu/test/test.ndarray.js | 300 ++++++++++++++ 16 files changed, 2269 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gtriu/README.md create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gtriu/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gtriu/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gtriu/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gtriu/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gtriu/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gtriu/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gtriu/lib/accessors.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gtriu/lib/base.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gtriu/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gtriu/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gtriu/lib/ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gtriu/package.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gtriu/test/test.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gtriu/test/test.main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gtriu/test/test.ndarray.js diff --git a/lib/node_modules/@stdlib/blas/ext/base/gtriu/README.md b/lib/node_modules/@stdlib/blas/ext/base/gtriu/README.md new file mode 100644 index 000000000000..5ee0892d0315 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gtriu/README.md @@ -0,0 +1,187 @@ + + +# gtriu + +> Copy the upper triangular part of a matrix `A` to another matrix `B`. + +
+ +## Usage + +```javascript +var gtriu = require( '@stdlib/blas/ext/base/gtriu' ); +``` + +#### gtriu( order, M, N, k, A, LDA, B, LDB ) + +Copies the upper triangular part of a matrix `A` to another matrix `B`. + +```javascript +var A = [ 1.0, 2.0, 3.0, 4.0 ]; +var B = [ 0.0, 0.0, 0.0, 0.0 ]; + +gtriu( 'row-major', 2, 2, 0, A, 2, B, 2 ); +// B => [ 1.0, 2.0, 0.0, 4.0 ] +``` + +The function has the following parameters: + +- **order**: storage layout. +- **M**: number of rows in `A`. +- **N**: number of columns in `A`. +- **k**: diagonal below which to ignore. A value of `k = 0` refers to the main diagonal, `k < 0` refers to a diagonal below the main diagonal, and `k > 0` refers to a diagonal above the main diagonal. Accordingly, when `k < 0`, the function copies the upper triangle **and** one or more sub-diagonals (i.e., part of the lower triangle), and, when `k > 0`, the function copies only part of the upper triangle. +- **A**: input matrix. +- **LDA**: stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`). +- **B**: output matrix. +- **LDB**: stride of the first dimension of `B` (a.k.a., leading dimension of the matrix `B`). + +The `k` parameter follows the same triangular indexing convention as the Array API. For example, to copy the upper triangle and the first sub-diagonal, + +```javascript +var A = [ 1.0, 2.0, 3.0, 4.0 ]; +var B = [ 0.0, 0.0, 0.0, 0.0 ]; + +gtriu( 'row-major', 2, 2, -1, A, 2, B, 2 ); +// B => [ 1.0, 2.0, 3.0, 4.0 ] +``` + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +// Initial arrays... +var A0 = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +var B0 = new Float64Array( 5 ); + +// Create offset views... +var A1 = new Float64Array( A0.buffer, A0.BYTES_PER_ELEMENT*1 ); // start at 2nd element +var B1 = new Float64Array( B0.buffer, B0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +gtriu( 'row-major', 2, 2, 0, A1, 2, B1, 2 ); +// B0 => [ 0.0, 2.0, 3.0, 0.0, 5.0 ] +``` + +#### gtriu.ndarray( M, N, k, A, sa1, sa2, oa, B, sb1, sb2, ob ) + +Copies the upper triangular part of a matrix `A` to another matrix `B` using alternative indexing semantics. + +```javascript +var A = [ 1.0, 2.0, 3.0, 4.0 ]; +var B = [ 0.0, 0.0, 0.0, 0.0 ]; + +gtriu.ndarray( 2, 2, 0, A, 2, 1, 0, B, 2, 1, 0 ); +// B => [ 1.0, 2.0, 0.0, 4.0 ] +``` + +The function has the following parameters: + +- **M**: number of rows in `A`. +- **N**: number of columns in `A`. +- **k**: diagonal below which to ignore. +- **A**: input matrix. +- **sa1**: stride of the first dimension of `A`. +- **sa2**: stride of the second dimension of `A`. +- **oa**: starting index for `A`. +- **B**: output matrix. +- **sb1**: stride of the first dimension of `B`. +- **sb2**: stride of the second dimension of `B`. +- **ob**: starting index for `B`. + +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 A = [ 1.0, 2.0, 3.0, 4.0 ]; +var B = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + +gtriu.ndarray( 2, 2, 0, A, 2, 1, 0, B, 2, 1, 2 ); +// B => [ 0.0, 0.0, 1.0, 2.0, 0.0, 4.0 ] +``` + +
+ + + +
+ +## Notes + +- `gtriu()` provides a generic implementation supporting both row- and column-major storage layouts and any array-like object supporting the get/set [accessor protocol][@stdlib/array/base/accessor]. +- Elements outside of the copied region are left unchanged. + +
+ + + +
+ +## Examples + + + +```javascript +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var uniform = require( '@stdlib/random/array/discrete-uniform' ); +var numel = require( '@stdlib/ndarray/base/numel' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var gtriu = require( '@stdlib/blas/ext/base/gtriu' ); + +var shape = [ 5, 8 ]; +var order = 'row-major'; +var strides = shape2strides( shape, order ); + +var N = numel( shape ); + +var A = uniform( N, -10, 10, { + 'dtype': 'generic' +}); +console.log( ndarray2array( A, shape, strides, 0, order ) ); + +var B = uniform( N, -10, 10, { + 'dtype': 'generic' +}); +console.log( ndarray2array( B, shape, strides, 0, order ) ); + +gtriu( order, shape[ 0 ], shape[ 1 ], 0, A, strides[ 0 ], B, strides[ 0 ] ); +console.log( ndarray2array( B, shape, strides, 0, order ) ); +``` + +
+ + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/gtriu/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/gtriu/benchmark/benchmark.js new file mode 100644 index 000000000000..5feac5d4e5ce --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gtriu/benchmark/benchmark.js @@ -0,0 +1,112 @@ +/** +* @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 gtriu = 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 A = zeros( N*N, 'generic' ); + var B = zeros( N*N, 'generic' ); + 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 = gtriu( order, N, N, 0, A, N, B, N ); + 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/gtriu/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gtriu/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..1632fb88674e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gtriu/benchmark/benchmark.ndarray.js @@ -0,0 +1,126 @@ +/** +* @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 gtriu = require( './../lib' ).ndarray; + + +// 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 sa1; + var sa2; + var A; + var B; + + A = zeros( N*N, 'generic' ); + B = zeros( N*N, 'generic' ); + + if ( isColumnMajor( order ) ) { + sa1 = 1; + sa2 = N; + } else { // order === 'row-major' + sa1 = N; + sa2 = 1; + } + 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 = gtriu( N, N, 0, A, sa1, sa2, 0, B, sa1, sa2, 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:ndarray:square_matrix:order=%s,size=%d', pkg, ord, N*N ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gtriu/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/gtriu/docs/repl.txt new file mode 100644 index 000000000000..6542e5e7e6a9 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gtriu/docs/repl.txt @@ -0,0 +1,111 @@ + +{{alias}}( order, M, N, k, A, LDA, B, LDB ) + Copies the upper triangular part of a matrix `A` to another matrix `B`. + + Indexing is relative to the first index. To introduce an offset, use typed + array views. + + The diagonal parameter `k` specifies the diagonal below which to ignore. A + value of `k = 0` refers to the main diagonal, `k < 0` refers to a diagonal + below the main diagonal, and `k > 0` refers to a diagonal above the main + diagonal. + + 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`. + + k: integer + Diagonal below which to ignore. + + A: Array|TypedArray + Input matrix `A`. + + LDA: integer + Stride of the first dimension of `A` (a.k.a., leading dimension of the + matrix `A`). + + B: Array|TypedArray + Output matrix `B`. + + LDB: integer + Stride of the first dimension of `B` (a.k.a., leading dimension of the + matrix `B`). + + Returns + ------- + B: Array|TypedArray + Output matrix. + + Examples + -------- + > var A = [ 1.0, 2.0, 3.0, 4.0 ]; + > var B = [ 0.0, 0.0, 0.0, 0.0 ]; + > {{alias}}( 'row-major', 2, 2, 0, A, 2, B, 2 ) + [ 1.0, 2.0, 0.0, 4.0 ] + + +{{alias}}.ndarray( M, N, k, A, sa1, sa2, oa, B, sb1, sb2, ob ) + Copies the upper triangular part of a matrix `A` to another matrix `B` 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`. + + k: integer + Diagonal below which to ignore. + + A: Array|TypedArray + 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`. + + B: Array|TypedArray + Output matrix `B`. + + sb1: integer + Stride of the first dimension of `B`. + + sb2: integer + Stride of the second dimension of `B`. + + ob: integer + Starting index for `B`. + + Returns + ------- + B: Array|TypedArray + Output matrix. + + Examples + -------- + > var A = [ 1.0, 2.0, 3.0, 4.0 ]; + > var B = [ 0.0, 0.0, 0.0, 0.0 ]; + > {{alias}}.ndarray( 2, 2, 0, A, 2, 1, 0, B, 2, 1, 0 ) + [ 1.0, 2.0, 0.0, 4.0 ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/blas/ext/base/gtriu/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/gtriu/docs/types/index.d.ts new file mode 100644 index 000000000000..032a11fb3a20 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gtriu/docs/types/index.d.ts @@ -0,0 +1,120 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +import { Collection, AccessorArrayLike } from '@stdlib/types/array'; +import { Layout } from '@stdlib/types/blas'; + +/** +* Input array. +*/ +type InputArray = Collection | AccessorArrayLike; + +/** +* Output array. +*/ +type OutputArray = Collection | AccessorArrayLike; + +/** +* Interface describing `gtriu`. +*/ +interface Routine { + /** + * Copies the upper triangular part of a matrix `A` to another matrix `B`. + * + * @param order - storage layout of `A` and `B` + * @param M - number of rows in matrix `A` + * @param N - number of columns in matrix `A` + * @param k - diagonal below which to ignore + * @param A - input matrix + * @param LDA - stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`) + * @param B - output matrix + * @param LDB - stride of the first dimension of `B` (a.k.a., leading dimension of the matrix `B`) + * @returns `B` + * + * @example + * var A = [ 1.0, 2.0, 3.0, 4.0 ]; + * var B = [ 0.0, 0.0, 0.0, 0.0 ]; + * + * gtriu( 'row-major', 2, 2, 0, A, 2, B, 2 ); + * // B => [ 1.0, 2.0, 0.0, 4.0 ] + */ + = OutputArray>( order: Layout, M: number, N: number, k: number, A: InputArray, LDA: number, B: U, LDB: number ): U; + + /** + * Copies the upper triangular part of a matrix `A` to another matrix `B` using alternative indexing semantics. + * + * @param M - number of rows in matrix `A` + * @param N - number of columns in matrix `A` + * @param k - diagonal below which to ignore + * @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 B - output matrix + * @param strideB1 - stride of the first dimension of `B` + * @param strideB2 - stride of the second dimension of `B` + * @param offsetB - starting index for `B` + * @returns `B` + * + * @example + * var A = [ 1.0, 2.0, 3.0, 4.0 ]; + * var B = [ 0.0, 0.0, 0.0, 0.0 ]; + * + * gtriu.ndarray( 2, 2, 0, A, 2, 1, 0, B, 2, 1, 0 ); + * // B => [ 1.0, 2.0, 0.0, 4.0 ] + */ + ndarray = OutputArray>( M: number, N: number, k: number, A: InputArray, strideA1: number, strideA2: number, offsetA: number, B: U, strideB1: number, strideB2: number, offsetB: number ): U; +} + +/** +* Copies the upper triangular part of a matrix `A` to another matrix `B`. +* +* @param order - storage layout of `A` and `B` +* @param M - number of rows in matrix `A` +* @param N - number of columns in matrix `A` +* @param k - diagonal below which to ignore +* @param A - input matrix +* @param LDA - stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`) +* @param B - output matrix +* @param LDB - stride of the first dimension of `B` (a.k.a., leading dimension of the matrix `B`) +* @returns `B` +* +* @example +* var A = [ 1.0, 2.0, 3.0, 4.0 ]; +* var B = [ 0.0, 0.0, 0.0, 0.0 ]; +* +* gtriu( 'row-major', 2, 2, 0, A, 2, B, 2 ); +* // B => [ 1.0, 2.0, 0.0, 4.0 ] +* +* @example +* var A = [ 1.0, 2.0, 3.0, 4.0 ]; +* var B = [ 0.0, 0.0, 0.0, 0.0 ]; +* +* gtriu.ndarray( 2, 2, 0, A, 2, 1, 0, B, 2, 1, 0 ); +* // B => [ 1.0, 2.0, 0.0, 4.0 ] +*/ +declare var gtriu: Routine; + + +// EXPORTS // + +export = gtriu; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gtriu/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/gtriu/docs/types/test.ts new file mode 100644 index 000000000000..6311fb5afba4 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gtriu/docs/types/test.ts @@ -0,0 +1,350 @@ +/* +* @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 gtriu = require( './index' ); + + +// TESTS // + +// The function returns a collection... +{ + const A = [ 1.0, 2.0, 3.0, 4.0 ]; + const B = [ 0.0, 0.0, 0.0, 0.0 ]; + + gtriu( 'row-major', 2, 2, 0, A, 2, B, 2 ); // $ExpectType number[] +} + +// The compiler throws an error if the function is provided a first argument which is not a valid order... +{ + const A = [ 1.0, 2.0, 3.0, 4.0 ]; + const B = [ 0.0, 0.0, 0.0, 0.0 ]; + + gtriu( 5, 2, 2, 0, A, 2, B, 2 ); // $ExpectError + gtriu( true, 2, 2, 0, A, 2, B, 2 ); // $ExpectError + gtriu( false, 2, 2, 0, A, 2, B, 2 ); // $ExpectError + gtriu( null, 2, 2, 0, A, 2, B, 2 ); // $ExpectError + gtriu( void 0, 2, 2, 0, A, 2, B, 2 ); // $ExpectError + gtriu( [], 2, 2, 0, A, 2, B, 2 ); // $ExpectError + gtriu( {}, 2, 2, 0, A, 2, B, 2 ); // $ExpectError + gtriu( ( x: number ): number => x, 2, 2, 0, A, 2, B, 2 ); // $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 ]; + const B = [ 0.0, 0.0, 0.0, 0.0 ]; + + gtriu( 'row-major', '5', 2, 0, A, 2, B, 2 ); // $ExpectError + gtriu( 'row-major', true, 2, 0, A, 2, B, 2 ); // $ExpectError + gtriu( 'row-major', false, 2, 0, A, 2, B, 2 ); // $ExpectError + gtriu( 'row-major', null, 2, 0, A, 2, B, 2 ); // $ExpectError + gtriu( 'row-major', void 0, 2, 0, A, 2, B, 2 ); // $ExpectError + gtriu( 'row-major', [], 2, 0, A, 2, B, 2 ); // $ExpectError + gtriu( 'row-major', {}, 2, 0, A, 2, B, 2 ); // $ExpectError + gtriu( 'row-major', ( x: number ): number => x, 2, 0, A, 2, B, 2 ); // $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 ]; + const B = [ 0.0, 0.0, 0.0, 0.0 ]; + + gtriu( 'row-major', 2, '5', 0, A, 2, B, 2 ); // $ExpectError + gtriu( 'row-major', 2, true, 0, A, 2, B, 2 ); // $ExpectError + gtriu( 'row-major', 2, false, 0, A, 2, B, 2 ); // $ExpectError + gtriu( 'row-major', 2, null, 0, A, 2, B, 2 ); // $ExpectError + gtriu( 'row-major', 2, void 0, 0, A, 2, B, 2 ); // $ExpectError + gtriu( 'row-major', 2, [], 0, A, 2, B, 2 ); // $ExpectError + gtriu( 'row-major', 2, {}, 0, A, 2, B, 2 ); // $ExpectError + gtriu( 'row-major', 2, ( x: number ): number => x, 0, A, 2, B, 2 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a number... +{ + const A = [ 1.0, 2.0, 3.0, 4.0 ]; + const B = [ 0.0, 0.0, 0.0, 0.0 ]; + + gtriu( 'row-major', 2, 2, '5', A, 2, B, 2 ); // $ExpectError + gtriu( 'row-major', 2, 2, true, A, 2, B, 2 ); // $ExpectError + gtriu( 'row-major', 2, 2, false, A, 2, B, 2 ); // $ExpectError + gtriu( 'row-major', 2, 2, null, A, 2, B, 2 ); // $ExpectError + gtriu( 'row-major', 2, 2, void 0, A, 2, B, 2 ); // $ExpectError + gtriu( 'row-major', 2, 2, [], A, 2, B, 2 ); // $ExpectError + gtriu( 'row-major', 2, 2, {}, A, 2, B, 2 ); // $ExpectError + gtriu( 'row-major', 2, 2, ( x: number ): number => x, A, 2, B, 2 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not a collection... +{ + const B = [ 0.0, 0.0, 0.0, 0.0 ]; + + gtriu( 'row-major', 2, 2, 0, 5, 2, B, 2 ); // $ExpectError + gtriu( 'row-major', 2, 2, 0, true, 2, B, 2 ); // $ExpectError + gtriu( 'row-major', 2, 2, 0, false, 2, B, 2 ); // $ExpectError + gtriu( 'row-major', 2, 2, 0, null, 2, B, 2 ); // $ExpectError + gtriu( 'row-major', 2, 2, 0, void 0, 2, B, 2 ); // $ExpectError + gtriu( 'row-major', 2, 2, 0, {}, 2, B, 2 ); // $ExpectError + gtriu( 'row-major', 2, 2, 0, ( x: number ): number => x, 2, B, 2 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a sixth argument which is not a number... +{ + const A = [ 1.0, 2.0, 3.0, 4.0 ]; + const B = [ 0.0, 0.0, 0.0, 0.0 ]; + + gtriu( 'row-major', 2, 2, 0, A, '5', B, 2 ); // $ExpectError + gtriu( 'row-major', 2, 2, 0, A, true, B, 2 ); // $ExpectError + gtriu( 'row-major', 2, 2, 0, A, false, B, 2 ); // $ExpectError + gtriu( 'row-major', 2, 2, 0, A, null, B, 2 ); // $ExpectError + gtriu( 'row-major', 2, 2, 0, A, void 0, B, 2 ); // $ExpectError + gtriu( 'row-major', 2, 2, 0, A, [], B, 2 ); // $ExpectError + gtriu( 'row-major', 2, 2, 0, A, {}, B, 2 ); // $ExpectError + gtriu( 'row-major', 2, 2, 0, A, ( x: number ): number => x, B, 2 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a seventh argument which is not a collection... +{ + const A = [ 1.0, 2.0, 3.0, 4.0 ]; + + gtriu( 'row-major', 2, 2, 0, A, 2, 5, 2 ); // $ExpectError + gtriu( 'row-major', 2, 2, 0, A, 2, true, 2 ); // $ExpectError + gtriu( 'row-major', 2, 2, 0, A, 2, false, 2 ); // $ExpectError + gtriu( 'row-major', 2, 2, 0, A, 2, null, 2 ); // $ExpectError + gtriu( 'row-major', 2, 2, 0, A, 2, void 0, 2 ); // $ExpectError + gtriu( 'row-major', 2, 2, 0, A, 2, {}, 2 ); // $ExpectError + gtriu( 'row-major', 2, 2, 0, A, 2, ( x: number ): number => x, 2 ); // $ExpectError +} + +// The compiler throws an error if the function is provided an eighth argument which is not a number... +{ + const A = [ 1.0, 2.0, 3.0, 4.0 ]; + const B = [ 0.0, 0.0, 0.0, 0.0 ]; + + gtriu( 'row-major', 2, 2, 0, A, 2, B, '5' ); // $ExpectError + gtriu( 'row-major', 2, 2, 0, A, 2, B, true ); // $ExpectError + gtriu( 'row-major', 2, 2, 0, A, 2, B, false ); // $ExpectError + gtriu( 'row-major', 2, 2, 0, A, 2, B, null ); // $ExpectError + gtriu( 'row-major', 2, 2, 0, A, 2, B, void 0 ); // $ExpectError + gtriu( 'row-major', 2, 2, 0, A, 2, B, [] ); // $ExpectError + gtriu( 'row-major', 2, 2, 0, A, 2, B, {} ); // $ExpectError + gtriu( 'row-major', 2, 2, 0, A, 2, B, ( 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 ]; + const B = [ 0.0, 0.0, 0.0, 0.0 ]; + + gtriu(); // $ExpectError + gtriu( 'row-major' ); // $ExpectError + gtriu( 'row-major', 2 ); // $ExpectError + gtriu( 'row-major', 2, 2 ); // $ExpectError + gtriu( 'row-major', 2, 2, 0 ); // $ExpectError + gtriu( 'row-major', 2, 2, 0, A ); // $ExpectError + gtriu( 'row-major', 2, 2, 0, A, 2 ); // $ExpectError + gtriu( 'row-major', 2, 2, 0, A, 2, B ); // $ExpectError + gtriu( 'row-major', 2, 2, 0, A, 2, B, 2, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a collection... +{ + const A = [ 1.0, 2.0, 3.0, 4.0 ]; + const B = [ 0.0, 0.0, 0.0, 0.0 ]; + + gtriu.ndarray( 2, 2, 0, A, 2, 1, 0, B, 2, 1, 0 ); // $ExpectType number[] +} + +// 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 ]; + const B = [ 0.0, 0.0, 0.0, 0.0 ]; + + gtriu.ndarray( '5', 2, 0, A, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError + gtriu.ndarray( true, 2, 0, A, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError + gtriu.ndarray( false, 2, 0, A, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError + gtriu.ndarray( null, 2, 0, A, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError + gtriu.ndarray( void 0, 2, 0, A, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError + gtriu.ndarray( [], 2, 0, A, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError + gtriu.ndarray( {}, 2, 0, A, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError + gtriu.ndarray( ( x: number ): number => x, 2, 0, A, 2, 1, 0, B, 2, 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 ]; + const B = [ 0.0, 0.0, 0.0, 0.0 ]; + + gtriu.ndarray( 2, '5', 0, A, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError + gtriu.ndarray( 2, true, 0, A, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError + gtriu.ndarray( 2, false, 0, A, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError + gtriu.ndarray( 2, null, 0, A, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError + gtriu.ndarray( 2, void 0, 0, A, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError + gtriu.ndarray( 2, [], 0, A, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError + gtriu.ndarray( 2, {}, 0, A, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError + gtriu.ndarray( 2, ( x: number ): number => x, 0, A, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a number... +{ + const A = [ 1.0, 2.0, 3.0, 4.0 ]; + const B = [ 0.0, 0.0, 0.0, 0.0 ]; + + gtriu.ndarray( 2, 2, '5', A, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError + gtriu.ndarray( 2, 2, true, A, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError + gtriu.ndarray( 2, 2, false, A, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError + gtriu.ndarray( 2, 2, null, A, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError + gtriu.ndarray( 2, 2, void 0, A, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError + gtriu.ndarray( 2, 2, [], A, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError + gtriu.ndarray( 2, 2, {}, A, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError + gtriu.ndarray( 2, 2, ( x: number ): number => x, A, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a collection... +{ + const B = [ 0.0, 0.0, 0.0, 0.0 ]; + + gtriu.ndarray( 2, 2, 0, 5, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError + gtriu.ndarray( 2, 2, 0, true, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError + gtriu.ndarray( 2, 2, 0, false, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError + gtriu.ndarray( 2, 2, 0, null, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError + gtriu.ndarray( 2, 2, 0, void 0, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError + gtriu.ndarray( 2, 2, 0, {}, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError + gtriu.ndarray( 2, 2, 0, ( x: number ): number => x, 2, 1, 0, B, 2, 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 ]; + const B = [ 0.0, 0.0, 0.0, 0.0 ]; + + gtriu.ndarray( 2, 2, 0, A, '5', 1, 0, B, 2, 1, 0 ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A, true, 1, 0, B, 2, 1, 0 ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A, false, 1, 0, B, 2, 1, 0 ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A, null, 1, 0, B, 2, 1, 0 ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A, void 0, 1, 0, B, 2, 1, 0 ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A, [], 1, 0, B, 2, 1, 0 ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A, {}, 1, 0, B, 2, 1, 0 ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A, ( x: number ): number => x, 1, 0, B, 2, 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 ]; + const B = [ 0.0, 0.0, 0.0, 0.0 ]; + + gtriu.ndarray( 2, 2, 0, A, 2, '5', 0, B, 2, 1, 0 ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A, 2, true, 0, B, 2, 1, 0 ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A, 2, false, 0, B, 2, 1, 0 ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A, 2, null, 0, B, 2, 1, 0 ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A, 2, void 0, 0, B, 2, 1, 0 ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A, 2, [], 0, B, 2, 1, 0 ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A, 2, {}, 0, B, 2, 1, 0 ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A, 2, ( x: number ): number => x, 0, B, 2, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a seventh argument which is not a number... +{ + const A = [ 1.0, 2.0, 3.0, 4.0 ]; + const B = [ 0.0, 0.0, 0.0, 0.0 ]; + + gtriu.ndarray( 2, 2, 0, A, 2, 1, '5', B, 2, 1, 0 ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A, 2, 1, true, B, 2, 1, 0 ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A, 2, 1, false, B, 2, 1, 0 ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A, 2, 1, null, B, 2, 1, 0 ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A, 2, 1, void 0, B, 2, 1, 0 ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A, 2, 1, [], B, 2, 1, 0 ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A, 2, 1, {}, B, 2, 1, 0 ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A, 2, 1, ( x: number ): number => x, B, 2, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an eighth argument which is not a collection... +{ + const A = [ 1.0, 2.0, 3.0, 4.0 ]; + + gtriu.ndarray( 2, 2, 0, A, 2, 1, 0, 5, 2, 1, 0 ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A, 2, 1, 0, true, 2, 1, 0 ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A, 2, 1, 0, false, 2, 1, 0 ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A, 2, 1, 0, null, 2, 1, 0 ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A, 2, 1, 0, void 0, 2, 1, 0 ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A, 2, 1, 0, {}, 2, 1, 0 ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A, 2, 1, 0, ( x: number ): number => x, 2, 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 ]; + const B = [ 0.0, 0.0, 0.0, 0.0 ]; + + gtriu.ndarray( 2, 2, 0, A, 2, 1, 0, B, '5', 1, 0 ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A, 2, 1, 0, B, true, 1, 0 ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A, 2, 1, 0, B, false, 1, 0 ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A, 2, 1, 0, B, null, 1, 0 ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A, 2, 1, 0, B, void 0, 1, 0 ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A, 2, 1, 0, B, [], 1, 0 ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A, 2, 1, 0, B, {}, 1, 0 ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A, 2, 1, 0, B, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a tenth argument which is not a number... +{ + const A = [ 1.0, 2.0, 3.0, 4.0 ]; + const B = [ 0.0, 0.0, 0.0, 0.0 ]; + + gtriu.ndarray( 2, 2, 0, A, 2, 1, 0, B, 2, '5', 0 ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A, 2, 1, 0, B, 2, true, 0 ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A, 2, 1, 0, B, 2, false, 0 ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A, 2, 1, 0, B, 2, null, 0 ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A, 2, 1, 0, B, 2, void 0, 0 ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A, 2, 1, 0, B, 2, [], 0 ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A, 2, 1, 0, B, 2, {}, 0 ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A, 2, 1, 0, B, 2, ( x: number ): number => x, 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 ]; + const B = [ 0.0, 0.0, 0.0, 0.0 ]; + + gtriu.ndarray( 2, 2, 0, A, 2, 1, 0, B, 2, 1, '5' ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A, 2, 1, 0, B, 2, 1, true ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A, 2, 1, 0, B, 2, 1, false ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A, 2, 1, 0, B, 2, 1, null ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A, 2, 1, 0, B, 2, 1, void 0 ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A, 2, 1, 0, B, 2, 1, [] ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A, 2, 1, 0, B, 2, 1, {} ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A, 2, 1, 0, B, 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 = [ 1.0, 2.0, 3.0, 4.0 ]; + const B = [ 0.0, 0.0, 0.0, 0.0 ]; + + gtriu.ndarray(); // $ExpectError + gtriu.ndarray( 2 ); // $ExpectError + gtriu.ndarray( 2, 2 ); // $ExpectError + gtriu.ndarray( 2, 2, 0 ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A, 2 ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A, 2, 1 ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A, 2, 1, 0 ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A, 2, 1, 0, B ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A, 2, 1, 0, B, 2 ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A, 2, 1, 0, B, 2, 1 ); // $ExpectError + gtriu.ndarray( 2, 2, 0, A, 2, 1, 0, B, 2, 1, 0, 0 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gtriu/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/gtriu/examples/index.js new file mode 100644 index 000000000000..079176648365 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gtriu/examples/index.js @@ -0,0 +1,44 @@ +/** +* @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 uniform = require( '@stdlib/random/array/discrete-uniform' ); +var numel = require( '@stdlib/ndarray/base/numel' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var gtriu = require( './../lib' ); + +var shape = [ 5, 8 ]; +var order = 'row-major'; +var strides = shape2strides( shape, order ); + +var N = numel( shape ); + +var A = uniform( N, -10, 10, { + 'dtype': 'generic' +}); +console.log( ndarray2array( A, shape, strides, 0, order ) ); + +var B = uniform( N, -10, 10, { + 'dtype': 'generic' +}); +console.log( ndarray2array( B, shape, strides, 0, order ) ); + +gtriu( order, shape[ 0 ], shape[ 1 ], 0, A, strides[ 0 ], B, strides[ 0 ] ); +console.log( ndarray2array( B, shape, strides, 0, order ) ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gtriu/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/gtriu/lib/accessors.js new file mode 100644 index 000000000000..a46f02108886 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gtriu/lib/accessors.js @@ -0,0 +1,108 @@ +/** +* @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 isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major' ); +var max = require( '@stdlib/math/base/special/fast/max' ); +var min = require( '@stdlib/math/base/special/fast/min' ); + + +// MAIN // + +/** +* Copies the upper triangular part of a matrix `A` to another matrix `B`. +* +* @private +* @param {NonNegativeInteger} M - number of rows in matrix `A` +* @param {NonNegativeInteger} N - number of columns in matrix `A` +* @param {integer} k - diagonal below which to ignore +* @param {Object} A - input matrix object +* @param {Collection} A.data - input matrix data +* @param {Array} A.accessors - matrix element accessors +* @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 {Object} B - output matrix object +* @param {Collection} B.data - output matrix data +* @param {Array} B.accessors - matrix element accessors +* @param {integer} strideB1 - stride of the first dimension of `B` +* @param {integer} strideB2 - stride of the second dimension of `B` +* @param {NonNegativeInteger} offsetB - starting index for `B` +* @returns {Object} `B` +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +* +* var A = arraylike2object( toAccessorArray( [ 1.0, 2.0, 3.0, 4.0 ] ) ); +* var B = arraylike2object( toAccessorArray( [ 0.0, 0.0, 0.0, 0.0 ] ) ); +* +* gtriu( 2, 2, 0, A, 2, 1, 0, B, 2, 1, 0 ); +* // B.data => [ 1.0, 2.0, 0.0, 4.0 ] +*/ +function gtriu( M, N, k, A, strideA1, strideA2, offsetA, B, strideB1, strideB2, offsetB ) { + var abuf; + var bbuf; + var aget; + var bset; + var ia; + var ib; + var i0; + var i1; + + // Cache references to array data: + abuf = A.data; + bbuf = B.data; + + // Cache references to the element accessors: + aget = A.accessors[ 0 ]; + bset = B.accessors[ 1 ]; + + ia = offsetA; + ib = offsetB; + if ( isRowMajor( [ strideA1, strideA2 ] ) ) { + // Copy row-by-row in order to ensure cache-optimal traversal... + for ( i1 = 0; i1 < M; i1++ ) { + for ( i0 = max( 0, i1+k ); i0 < N; i0++ ) { + bset( bbuf, ib+(i0*strideB2), aget( abuf, ia+(i0*strideA2) ) ); + } + ia += strideA1; + ib += strideB1; + } + return B; + } + // Copy column-by-column in order to ensure cache-optimal traversal... + for ( i1 = 0; i1 < N; i1++ ) { + for ( i0 = 0; i0 <= min( i1-k, M-1 ); i0++ ) { + bset( bbuf, ib+(i0*strideB1), aget( abuf, ia+(i0*strideA1) ) ); + } + ia += strideA2; + ib += strideB2; + } + return B; +} + + +// EXPORTS // + +module.exports = gtriu; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gtriu/lib/base.js b/lib/node_modules/@stdlib/blas/ext/base/gtriu/lib/base.js new file mode 100644 index 000000000000..27bfc41b86df --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gtriu/lib/base.js @@ -0,0 +1,105 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-len, max-params */ + +'use strict'; + +// MODULES // + +var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major' ); +var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +var max = require( '@stdlib/math/base/special/fast/max' ); +var min = require( '@stdlib/math/base/special/fast/min' ); +var accessors = require( './accessors.js' ); + + +// MAIN // + +/** +* Copies the upper triangular part of a matrix `A` to another matrix `B`. +* +* @private +* @param {NonNegativeInteger} M - number of rows in matrix `A` +* @param {NonNegativeInteger} N - number of columns in matrix `A` +* @param {integer} k - diagonal below which to ignore +* @param {Collection} 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 {Collection} B - output matrix +* @param {integer} strideB1 - stride of the first dimension of `B` +* @param {integer} strideB2 - stride of the second dimension of `B` +* @param {NonNegativeInteger} offsetB - starting index for `B` +* @returns {Collection} `B` +* +* @example +* var A = [ 1.0, 2.0, 3.0, 4.0 ]; +* var B = [ 0.0, 0.0, 0.0, 0.0 ]; +* +* gtriu( 2, 2, 0, A, 2, 1, 0, B, 2, 1, 0 ); +* // B => [ 1.0, 2.0, 0.0, 4.0 ] +* +* @example +* var A = [ 1.0, 2.0, 3.0, 4.0 ]; +* var B = [ 0.0, 0.0, 0.0, 0.0 ]; +* +* gtriu( 2, 2, -1, A, 2, 1, 0, B, 2, 1, 0 ); +* // B => [ 1.0, 2.0, 3.0, 4.0 ] +*/ +function gtriu( M, N, k, A, strideA1, strideA2, offsetA, B, strideB1, strideB2, offsetB ) { + var oa; + var ob; + var ia; + var ib; + var i0; + var i1; + + oa = arraylike2object( A ); + ob = arraylike2object( B ); + if ( oa.accessorProtocol || ob.accessorProtocol ) { + accessors( M, N, k, oa, strideA1, strideA2, offsetA, ob, strideB1, strideB2, offsetB ); + return B; + } + ia = offsetA; + ib = offsetB; + if ( isRowMajor( [ strideA1, strideA2 ] ) ) { + for ( i1 = 0; i1 < M; i1++ ) { + for ( i0 = max( 0, i1+k ); i0 < N; i0++ ) { + B[ ib+(i0*strideB2) ] = A[ ia+(i0*strideA2) ]; + } + ia += strideA1; + ib += strideB1; + } + return B; + } + + for ( i1 = 0; i1 < N; i1++ ) { + for ( i0 = 0; i0 <= min( i1-k, M-1 ); i0++ ) { + B[ ib+(i0*strideB1) ] = A[ ia+(i0*strideA1) ]; + } + ia += strideA2; + ib += strideB2; + } + return B; +} + + +// EXPORTS // + +module.exports = gtriu; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gtriu/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/gtriu/lib/index.js new file mode 100644 index 000000000000..54f5c9b615b2 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gtriu/lib/index.js @@ -0,0 +1,61 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Copy the upper triangular part of a matrix `A` to another matrix `B`. +* +* @module @stdlib/blas/ext/base/gtriu +* +* @example +* var gtriu = require( '@stdlib/blas/ext/base/gtriu' ); +* +* var A = [ 1.0, 2.0, 3.0, 4.0 ]; +* var B = [ 0.0, 0.0, 0.0, 0.0 ]; +* +* gtriu( 'row-major', 2, 2, 0, A, 2, B, 2 ); +* // B => [ 1.0, 2.0, 0.0, 4.0 ] +* +* @example +* var gtriu = require( '@stdlib/blas/ext/base/gtriu' ); +* +* var A = [ 1.0, 2.0, 3.0, 4.0 ]; +* var B = [ 0.0, 0.0, 0.0, 0.0 ]; +* +* gtriu.ndarray( 2, 2, 0, A, 2, 1, 0, B, 2, 1, 0 ); +* // B => [ 1.0, 2.0, 0.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/gtriu/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/gtriu/lib/main.js new file mode 100644 index 000000000000..74ff81795247 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gtriu/lib/main.js @@ -0,0 +1,100 @@ +/** +* @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 isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major-string' ); +var isColumnMajor = require( '@stdlib/ndarray/base/assert/is-column-major-string' ); +var max = require( '@stdlib/math/base/special/fast/max' ); +var format = require( '@stdlib/string/format' ); +var base = require( './base.js' ); + + +// MAIN // + +/** +* Copies the upper triangular part of a matrix `A` to another matrix `B`. +* +* @param {string} order - storage layout of `A` and `B` +* @param {NonNegativeInteger} M - number of rows in matrix `A` +* @param {NonNegativeInteger} N - number of columns in matrix `A` +* @param {integer} k - diagonal below which to ignore +* @param {Collection} A - input matrix +* @param {PositiveInteger} LDA - stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`) +* @param {Collection} B - output matrix +* @param {PositiveInteger} LDB - stride of the first dimension of `B` (a.k.a., leading dimension of the matrix `B`) +* @throws {TypeError} first argument must be a valid order +* @throws {RangeError} sixth argument must be greater than or equal to max(1,N) (row-major) or max(1,M) (column-major) +* @throws {RangeError} eighth argument must be greater than or equal to max(1,N) (row-major) or max(1,M) (column-major) +* @returns {Collection} `B` +* +* @example +* var A = [ 1.0, 2.0, 3.0, 4.0 ]; +* var B = [ 0.0, 0.0, 0.0, 0.0 ]; +* +* gtriu( 'row-major', 2, 2, 0, A, 2, B, 2 ); +* // B => [ 1.0, 2.0, 0.0, 4.0 ] +* +* @example +* var A = [ 1.0, 2.0, 3.0, 4.0 ]; +* var B = [ 0.0, 0.0, 0.0, 0.0 ]; +* +* gtriu( 'row-major', 2, 2, 1, A, 2, B, 2 ); +* // B => [ 0.0, 2.0, 0.0, 0.0 ] +*/ +function gtriu( order, M, N, k, A, LDA, B, LDB ) { + var sa1; + var sa2; + var sb1; + var sb2; + var s; + if ( !isLayout( order ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a valid order. Value: `%s`.', order ) ); + } + if ( isRowMajor( order ) ) { + s = N; + } else { + s = M; + } + if ( LDA < max( 1, s ) ) { + throw new RangeError( format( 'invalid argument. Sixth argument must be greater than or equal to max(1,%d). Value: `%d`.', s, LDA ) ); + } + if ( LDB < max( 1, s ) ) { + throw new RangeError( format( 'invalid argument. Eighth argument must be greater than or equal to max(1,%d). Value: `%d`.', s, LDB ) ); + } + if ( isColumnMajor( order ) ) { + sa1 = 1; + sa2 = LDA; + sb1 = 1; + sb2 = LDB; + } else { // order === 'row-major' + sa1 = LDA; + sa2 = 1; + sb1 = LDB; + sb2 = 1; + } + return base( M, N, k, A, sa1, sa2, 0, B, sb1, sb2, 0 ); +} + + +// EXPORTS // + +module.exports = gtriu; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gtriu/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gtriu/lib/ndarray.js new file mode 100644 index 000000000000..e0821e7666c2 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gtriu/lib/ndarray.js @@ -0,0 +1,65 @@ +/** +* @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 base = require( './base.js' ); + + +// MAIN // + +/** +* Copies the upper triangular part of a matrix `A` to another matrix `B` using alternative indexing semantics. +* +* @param {NonNegativeInteger} M - number of rows in matrix `A` +* @param {NonNegativeInteger} N - number of columns in matrix `A` +* @param {integer} k - diagonal below which to ignore +* @param {Collection} 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 {Collection} B - output matrix +* @param {integer} strideB1 - stride of the first dimension of `B` +* @param {integer} strideB2 - stride of the second dimension of `B` +* @param {NonNegativeInteger} offsetB - starting index for `B` +* @returns {Collection} `B` +* +* @example +* var A = [ 1.0, 2.0, 3.0, 4.0 ]; +* var B = [ 0.0, 0.0, 0.0, 0.0 ]; +* +* gtriu( 2, 2, 0, A, 2, 1, 0, B, 2, 1, 0 ); +* // B => [ 1.0, 2.0, 0.0, 4.0 ] +* +* @example +* var A = [ 1.0, 2.0, 3.0, 4.0 ]; +* var B = [ 0.0, 0.0, 0.0, 0.0 ]; +* +* gtriu( 2, 2, -1, A, 2, 1, 0, B, 2, 1, 0 ); +* // B => [ 1.0, 2.0, 3.0, 4.0 ] +*/ +function gtriu( M, N, k, A, strideA1, strideA2, offsetA, B, strideB1, strideB2, offsetB ) { // eslint-disable-line max-len, max-params + return base( M, N, k, A, strideA1, strideA2, offsetA, B, strideB1, strideB2, offsetB ); // eslint-disable-line max-len +} + + +// EXPORTS // + +module.exports = gtriu; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gtriu/package.json b/lib/node_modules/@stdlib/blas/ext/base/gtriu/package.json new file mode 100644 index 000000000000..08dc388c196c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gtriu/package.json @@ -0,0 +1,67 @@ +{ + "name": "@stdlib/blas/ext/base/gtriu", + "version": "0.0.0", + "description": "Copy the upper triangular part of a matrix A to another matrix B.", + "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", + "linear", + "algebra", + "matrix", + "triangular", + "triangle", + "upper", + "triu", + "copy", + "array", + "ndarray" + ] +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gtriu/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/gtriu/test/test.js new file mode 100644 index 000000000000..ae04bc88b101 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gtriu/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 gtriu = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gtriu, '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 gtriu.ndarray, 'function', 'method is a function' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gtriu/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/gtriu/test/test.main.js new file mode 100644 index 000000000000..0e2a176f5ae2 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gtriu/test/test.main.js @@ -0,0 +1,375 @@ +/** +* @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 gtriu = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gtriu, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 8', function test( t ) { + t.strictEqual( gtriu.length, 8, '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() { + var A = [ 1.0, 2.0, 3.0, 4.0 ]; + var B = [ 0.0, 0.0, 0.0, 0.0 ]; + gtriu( value, 2, 2, 0, A, 2, B, 2 ); + }; + } +}); + +tape( 'the function throws an error if provided a sixth 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() { + var A = [ 1.0, 2.0, 3.0, 4.0 ]; + var B = [ 0.0, 0.0, 0.0, 0.0 ]; + gtriu( 'row-major', 2, 2, 0, A, value, B, 2 ); + }; + } +}); + +tape( 'the function throws an error if provided an eighth argument which is not a valid LDB 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() { + var A = [ 1.0, 2.0, 3.0, 4.0 ]; + var B = [ 0.0, 0.0, 0.0, 0.0 ]; + gtriu( 'row-major', 2, 2, 0, A, 2, B, value ); + }; + } +}); + +tape( 'the function throws an error if provided a sixth 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() { + var A = [ 1.0, 2.0, 3.0, 4.0 ]; + var B = [ 0.0, 0.0, 0.0, 0.0 ]; + gtriu( 'column-major', 2, 2, 0, A, value, B, 2 ); + }; + } +}); + +tape( 'the function throws an error if provided an eighth argument which is not a valid LDB 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() { + var A = [ 1.0, 2.0, 3.0, 4.0 ]; + var B = [ 0.0, 0.0, 0.0, 0.0 ]; + gtriu( 'column-major', 2, 2, 0, A, 2, B, value ); + }; + } +}); + +tape( 'the function copies the upper triangular part of `A` to `B` (row-major, k=0)', function test( t ) { + var expected; + var out; + var A; + var B; + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ]; + B = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + out = gtriu( 'row-major', 3, 3, 0, A, 3, B, 3 ); + + expected = [ 1.0, 2.0, 3.0, 0.0, 5.0, 6.0, 0.0, 0.0, 9.0 ]; + t.strictEqual( out, B, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function copies the upper triangular part of `A` to `B` (row-major, k>0)', function test( t ) { + var expected; + var out; + var A; + var B; + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ]; + B = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + out = gtriu( 'row-major', 3, 3, 1, A, 3, B, 3 ); + + expected = [ 0.0, 2.0, 3.0, 0.0, 0.0, 6.0, 0.0, 0.0, 0.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function copies the upper triangular part of `A` to `B` (row-major, k<0)', function test( t ) { + var expected; + var out; + var A; + var B; + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ]; + B = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + out = gtriu( 'row-major', 3, 3, -1, A, 3, B, 3 ); + + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 0.0, 8.0, 9.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function copies the upper triangular part of `A` to `B` (column-major, k=0)', function test( t ) { + var expected; + var out; + var A; + var B; + + A = [ 1.0, 4.0, 7.0, 2.0, 5.0, 8.0, 3.0, 6.0, 9.0 ]; + B = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + out = gtriu( 'column-major', 3, 3, 0, A, 3, B, 3 ); + + expected = [ 1.0, 0.0, 0.0, 2.0, 5.0, 0.0, 3.0, 6.0, 9.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function copies the upper triangular part of `A` to `B` (column-major, k<0)', function test( t ) { + var expected; + var out; + var A; + var B; + + A = [ 1.0, 4.0, 7.0, 2.0, 5.0, 8.0, 3.0, 6.0, 9.0 ]; + B = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + out = gtriu( 'column-major', 3, 3, -1, A, 3, B, 3 ); + + expected = [ 1.0, 4.0, 0.0, 2.0, 5.0, 8.0, 3.0, 6.0, 9.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function copies the upper triangular part of `A` to `B` (column-major, k>0)', function test( t ) { + var expected; + var out; + var A; + var B; + + A = [ 1.0, 4.0, 7.0, 2.0, 5.0, 8.0, 3.0, 6.0, 9.0 ]; + B = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + out = gtriu( 'column-major', 3, 3, 1, A, 3, B, 3 ); + + expected = [ 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 3.0, 6.0, 0.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports non-square matrices (row-major)', function test( t ) { + var expected; + var out; + var A; + var B; + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + B = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + out = gtriu( 'row-major', 2, 3, 0, A, 3, B, 3 ); + expected = [ 1.0, 2.0, 3.0, 0.0, 5.0, 6.0 ]; + t.deepEqual( out, expected, 'returns expected value (2x3)' ); + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + B = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + out = gtriu( 'row-major', 3, 2, 0, A, 2, B, 2 ); + expected = [ 1.0, 2.0, 0.0, 4.0, 0.0, 0.0 ]; + t.deepEqual( out, expected, 'returns expected value (3x2)' ); + + t.end(); +}); + +tape( 'the function supports non-square matrices (column-major)', function test( t ) { + var expected; + var out; + var A; + var B; + + A = [ 1.0, 4.0, 2.0, 5.0, 3.0, 6.0 ]; + B = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + out = gtriu( 'column-major', 2, 3, 0, A, 2, B, 2 ); + expected = [ 1.0, 0.0, 2.0, 5.0, 3.0, 6.0 ]; + t.deepEqual( out, expected, 'returns expected value (2x3)' ); + + A = [ 1.0, 3.0, 5.0, 2.0, 4.0, 6.0 ]; + B = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + out = gtriu( 'column-major', 3, 2, 0, A, 3, B, 3 ); + expected = [ 1.0, 0.0, 0.0, 2.0, 4.0, 0.0 ]; + t.deepEqual( out, expected, 'returns expected value (3x2)' ); + + t.end(); +}); + +tape( 'the function leaves elements outside of the copied region unchanged', function test( t ) { + var expected; + var out; + var A; + var B; + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ]; + B = [ -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0 ]; + + out = gtriu( 'row-major', 3, 3, 0, A, 3, B, 3 ); + + expected = [ 1.0, 2.0, 3.0, -1.0, 5.0, 6.0, -1.0, -1.0, 9.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'when `k` is greater than or equal to `N`, the function copies nothing', function test( t ) { + var expected; + var out; + var A; + var B; + + A = [ 1.0, 2.0, 3.0, 4.0 ]; + B = [ 9.0, 9.0, 9.0, 9.0 ]; + + out = gtriu( 'row-major', 2, 2, 2, A, 2, B, 2 ); + + expected = [ 9.0, 9.0, 9.0, 9.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'when `k` is sufficiently negative, the function copies the entire matrix', function test( t ) { + var expected; + var out; + var A; + var B; + + A = [ 1.0, 2.0, 3.0, 4.0 ]; + B = [ 0.0, 0.0, 0.0, 0.0 ]; + + out = gtriu( 'row-major', 2, 2, -2, A, 2, B, 2 ); + + expected = [ 1.0, 2.0, 3.0, 4.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function leaves `B` unchanged when `M` or `N` is equal to zero', function test( t ) { + var expected; + var out; + var A; + var B; + + A = [ 1.0, 2.0, 3.0, 4.0 ]; + expected = [ 9.0, 9.0, 9.0, 9.0 ]; + + B = [ 9.0, 9.0, 9.0, 9.0 ]; + out = gtriu( 'row-major', 0, 2, 0, A, 2, B, 2 ); + t.deepEqual( out, expected, 'returns expected value (M=0)' ); + + B = [ 9.0, 9.0, 9.0, 9.0 ]; + out = gtriu( 'row-major', 2, 0, 0, A, 2, B, 2 ); + t.deepEqual( out, expected, 'returns expected value (N=0)' ); + + t.end(); +}); + +tape( 'the function supports accessor arrays', function test( t ) { + var expected; + var out; + var A; + var B; + var i; + + A = toAccessorArray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] ); + B = toAccessorArray( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + out = gtriu( 'row-major', 3, 3, 0, A, 3, B, 3 ); + + expected = [ 1.0, 2.0, 3.0, 0.0, 5.0, 6.0, 0.0, 0.0, 9.0 ]; + t.strictEqual( out, B, 'returns expected value' ); + for ( i = 0; i < expected.length; i++ ) { + t.strictEqual( out.get( i ), expected[ i ], 'returns expected value for element ' + i ); + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gtriu/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gtriu/test/test.ndarray.js new file mode 100644 index 000000000000..e321e3ef3900 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gtriu/test/test.ndarray.js @@ -0,0 +1,300 @@ +/** +* @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 gtriu = require( './../lib' ).ndarray; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gtriu, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 11', function test( t ) { + t.strictEqual( gtriu.length, 11, 'returns expected value' ); + t.end(); +}); + +tape( 'the function copies the upper triangular part of `A` to `B` (row-major, k=0)', function test( t ) { + var expected; + var out; + var A; + var B; + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ]; + B = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + out = gtriu( 3, 3, 0, A, 3, 1, 0, B, 3, 1, 0 ); + + expected = [ 1.0, 2.0, 3.0, 0.0, 5.0, 6.0, 0.0, 0.0, 9.0 ]; + t.strictEqual( out, B, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function copies the upper triangular part of `A` to `B` (row-major, k>0)', function test( t ) { + var expected; + var out; + var A; + var B; + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ]; + B = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + out = gtriu( 3, 3, 1, A, 3, 1, 0, B, 3, 1, 0 ); + + expected = [ 0.0, 2.0, 3.0, 0.0, 0.0, 6.0, 0.0, 0.0, 0.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function copies the upper triangular part of `A` to `B` (row-major, k<0)', function test( t ) { + var expected; + var out; + var A; + var B; + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ]; + B = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + out = gtriu( 3, 3, -1, A, 3, 1, 0, B, 3, 1, 0 ); + + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 0.0, 8.0, 9.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function copies the upper triangular part of `A` to `B` (column-major, k=0)', function test( t ) { + var expected; + var out; + var A; + var B; + + A = [ 1.0, 4.0, 7.0, 2.0, 5.0, 8.0, 3.0, 6.0, 9.0 ]; + B = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + out = gtriu( 3, 3, 0, A, 1, 3, 0, B, 1, 3, 0 ); + + expected = [ 1.0, 0.0, 0.0, 2.0, 5.0, 0.0, 3.0, 6.0, 9.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function copies the upper triangular part of `A` to `B` (column-major, k<0)', function test( t ) { + var expected; + var out; + var A; + var B; + + A = [ 1.0, 4.0, 7.0, 2.0, 5.0, 8.0, 3.0, 6.0, 9.0 ]; + B = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + out = gtriu( 3, 3, -1, A, 1, 3, 0, B, 1, 3, 0 ); + + expected = [ 1.0, 4.0, 0.0, 2.0, 5.0, 8.0, 3.0, 6.0, 9.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function copies the upper triangular part of `A` to `B` (column-major, k>0)', function test( t ) { + var expected; + var out; + var A; + var B; + + A = [ 1.0, 4.0, 7.0, 2.0, 5.0, 8.0, 3.0, 6.0, 9.0 ]; + B = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + out = gtriu( 3, 3, 1, A, 1, 3, 0, B, 1, 3, 0 ); + + expected = [ 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 3.0, 6.0, 0.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports non-square matrices (row-major)', function test( t ) { + var expected; + var out; + var A; + var B; + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + B = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + out = gtriu( 2, 3, 0, A, 3, 1, 0, B, 3, 1, 0 ); + expected = [ 1.0, 2.0, 3.0, 0.0, 5.0, 6.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports non-square matrices (column-major)', function test( t ) { + var expected; + var out; + var A; + var B; + + A = [ 1.0, 3.0, 5.0, 2.0, 4.0, 6.0 ]; + B = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + out = gtriu( 3, 2, 0, A, 1, 3, 0, B, 1, 3, 0 ); + expected = [ 1.0, 0.0, 0.0, 2.0, 4.0, 0.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an `A` offset', function test( t ) { + var expected; + var out; + var A; + var B; + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + B = [ 0.0, 0.0, 0.0, 0.0 ]; + + out = gtriu( 2, 2, 0, A, 2, 1, 1, B, 2, 1, 0 ); + + expected = [ 2.0, 3.0, 0.0, 5.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `B` offset', function test( t ) { + var expected; + var out; + var A; + var B; + + A = [ 1.0, 2.0, 3.0, 4.0 ]; + B = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + out = gtriu( 2, 2, 0, A, 2, 1, 0, B, 2, 1, 2 ); + + expected = [ 0.0, 0.0, 1.0, 2.0, 0.0, 4.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports negative strides', function test( t ) { + var expected; + var out; + var A; + var B; + + A = [ 2.0, 1.0, 4.0, 3.0 ]; + B = [ 0.0, 0.0, 0.0, 0.0 ]; + + out = gtriu( 2, 2, 0, A, 2, -1, 1, B, 2, 1, 0 ); + + expected = [ 1.0, 2.0, 0.0, 4.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function leaves elements outside of the copied region unchanged', function test( t ) { + var expected; + var out; + var A; + var B; + + A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ]; + B = [ -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0 ]; + + out = gtriu( 3, 3, 0, A, 3, 1, 0, B, 3, 1, 0 ); + + expected = [ 1.0, 2.0, 3.0, -1.0, 5.0, 6.0, -1.0, -1.0, 9.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'when `k` is greater than or equal to `N`, the function copies nothing', function test( t ) { + var expected; + var out; + var A; + var B; + + A = [ 1.0, 2.0, 3.0, 4.0 ]; + B = [ 9.0, 9.0, 9.0, 9.0 ]; + + out = gtriu( 2, 2, 2, A, 2, 1, 0, B, 2, 1, 0 ); + + expected = [ 9.0, 9.0, 9.0, 9.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'when `k` is sufficiently negative, the function copies the entire matrix', function test( t ) { + var expected; + var out; + var A; + var B; + + A = [ 1.0, 2.0, 3.0, 4.0 ]; + B = [ 0.0, 0.0, 0.0, 0.0 ]; + + out = gtriu( 2, 2, -2, A, 2, 1, 0, B, 2, 1, 0 ); + + expected = [ 1.0, 2.0, 3.0, 4.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function leaves `B` unchanged when `M` or `N` is equal to zero', function test( t ) { + var expected; + var out; + var A; + var B; + + A = [ 1.0, 2.0, 3.0, 4.0 ]; + expected = [ 9.0, 9.0, 9.0, 9.0 ]; + + B = [ 9.0, 9.0, 9.0, 9.0 ]; + out = gtriu( 0, 2, 0, A, 2, 1, 0, B, 2, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value (M=0)' ); + + B = [ 9.0, 9.0, 9.0, 9.0 ]; + out = gtriu( 2, 0, 0, A, 2, 1, 0, B, 2, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value (N=0)' ); + + t.end(); +}); + +tape( 'the function supports accessor arrays', function test( t ) { + var expected; + var out; + var A; + var B; + var i; + + A = toAccessorArray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] ); + B = toAccessorArray( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + out = gtriu( 3, 3, 0, A, 3, 1, 0, B, 3, 1, 0 ); + + expected = [ 1.0, 2.0, 3.0, 0.0, 5.0, 6.0, 0.0, 0.0, 9.0 ]; + t.strictEqual( out, B, 'returns expected value' ); + for ( i = 0; i < expected.length; i++ ) { + t.strictEqual( out.get( i ), expected[ i ], 'returns expected value for element ' + i ); + } + t.end(); +});