From 86be1adb034b2ee4f32ae691a32e6454736a72be Mon Sep 17 00:00:00 2001 From: kaustubh Date: Thu, 30 Jul 2026 00:34:08 +0530 Subject: [PATCH 1/3] feat: add blas/ext/base/striu --- 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/striu/README.md | 192 +++++++++ .../ext/base/striu/benchmark/benchmark.js | 112 ++++++ .../base/striu/benchmark/benchmark.ndarray.js | 126 ++++++ .../@stdlib/blas/ext/base/striu/docs/repl.txt | 112 ++++++ .../blas/ext/base/striu/docs/types/index.d.ts | 117 ++++++ .../blas/ext/base/striu/docs/types/test.ts | 354 +++++++++++++++++ .../blas/ext/base/striu/examples/index.js | 44 ++ .../@stdlib/blas/ext/base/striu/lib/base.js | 98 +++++ .../@stdlib/blas/ext/base/striu/lib/index.js | 63 +++ .../@stdlib/blas/ext/base/striu/lib/main.js | 105 +++++ .../blas/ext/base/striu/lib/ndarray.js | 69 ++++ .../@stdlib/blas/ext/base/striu/package.json | 71 ++++ .../@stdlib/blas/ext/base/striu/test/test.js | 38 ++ .../blas/ext/base/striu/test/test.main.js | 376 ++++++++++++++++++ .../blas/ext/base/striu/test/test.ndarray.js | 296 ++++++++++++++ 15 files changed, 2173 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/striu/README.md create mode 100644 lib/node_modules/@stdlib/blas/ext/base/striu/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/striu/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/striu/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/ext/base/striu/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/striu/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/striu/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/striu/lib/base.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/striu/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/striu/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/striu/lib/ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/striu/package.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/striu/test/test.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/striu/test/test.main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/striu/test/test.ndarray.js diff --git a/lib/node_modules/@stdlib/blas/ext/base/striu/README.md b/lib/node_modules/@stdlib/blas/ext/base/striu/README.md new file mode 100644 index 000000000000..9e54cb302610 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/striu/README.md @@ -0,0 +1,192 @@ + + +# striu + +> Copy the upper triangular part of a single-precision floating-point matrix `A` to another matrix `B`. + +
+ +## Usage + +```javascript +var striu = require( '@stdlib/blas/ext/base/striu' ); +``` + +#### striu( order, M, N, k, A, LDA, B, LDB ) + +Copies the upper triangular part of a single-precision floating-point matrix `A` to another matrix `B`. + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); + +var A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +var B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + +striu( '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`). + +Setting the `k` parameter to a value other than `0` allows including and excluding sub- and super-diagonals, respectively. For example, to copy the upper triangle and the first sub-diagonal, + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); + +var A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +var B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + +striu( '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 Float32Array = require( '@stdlib/array/float32' ); + +// Initial arrays... +var A0 = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +var B0 = new Float32Array( 5 ); + +// Create offset views... +var A1 = new Float32Array( A0.buffer, A0.BYTES_PER_ELEMENT*1 ); // start at 2nd element +var B1 = new Float32Array( B0.buffer, B0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +striu( 'row-major', 2, 2, 0, A1, 2, B1, 2 ); +// B0 => [ 0.0, 2.0, 3.0, 0.0, 5.0 ] +``` + +#### striu.ndarray( M, N, k, A, sa1, sa2, oa, B, sb1, sb2, ob ) + +Copies the upper triangular part of a single-precision floating-point matrix `A` to another matrix `B` using alternative indexing semantics. + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); + +var A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +var B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + +striu.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 Float32Array = require( '@stdlib/array/float32' ); + +var A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +var B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + +striu.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 + +- 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 striu = require( '@stdlib/blas/ext/base/striu' ); + +var shape = [ 5, 8 ]; +var order = 'row-major'; +var strides = shape2strides( shape, order ); + +var N = numel( shape ); + +var A = uniform( N, -10, 10, { + 'dtype': 'float32' +}); +console.log( ndarray2array( A, shape, strides, 0, order ) ); + +var B = uniform( N, -10, 10, { + 'dtype': 'float32' +}); +console.log( ndarray2array( B, shape, strides, 0, order ) ); + +striu( 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/striu/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/striu/benchmark/benchmark.js new file mode 100644 index 000000000000..fd16dd4b42ea --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/striu/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 striu = 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, 'float32' ); + var B = zeros( N*N, 'float32' ); + 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 = striu( 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/striu/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/striu/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..4026000ec99f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/striu/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 striu = 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, 'float32' ); + B = zeros( N*N, 'float32' ); + + 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 = striu( 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::square_matrix:ndarray:order=%s,size=%d', pkg, ord, N*N ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/striu/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/striu/docs/repl.txt new file mode 100644 index 000000000000..ae494b87dd1f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/striu/docs/repl.txt @@ -0,0 +1,112 @@ + +{{alias}}( order, M, N, k, A, LDA, B, LDB ) + Copies the upper triangular part of a single-precision floating-point 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: Float32Array + Input matrix `A`. + + LDA: integer + Stride of the first dimension of `A` (a.k.a., leading dimension of the + matrix `A`). + + B: Float32Array + Output matrix `B`. + + LDB: integer + Stride of the first dimension of `B` (a.k.a., leading dimension of the + matrix `B`). + + Returns + ------- + B: Float32Array + Output matrix. + + Examples + -------- + > var A = new {{alias:@stdlib/array/float32}}( [ 1.0, 2.0, 3.0, 4.0 ] ); + > var B = new {{alias:@stdlib/array/float32}}( [ 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 single-precision floating-point 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: 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`. + + B: Float32Array + 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: Float32Array + Output matrix. + + Examples + -------- + > var A = new {{alias:@stdlib/array/float32}}( [ 1.0, 2.0, 3.0, 4.0 ] ); + > var B = new {{alias:@stdlib/array/float32}}( [ 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/striu/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/striu/docs/types/index.d.ts new file mode 100644 index 000000000000..8c93cbc06999 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/striu/docs/types/index.d.ts @@ -0,0 +1,117 @@ +/* +* @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 { Layout } from '@stdlib/types/blas'; + +/** +* Interface describing `striu`. +*/ +interface Routine { + /** + * Copies the upper triangular part of a single-precision floating-point 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 Float32Array = require( '@stdlib/array/float32' ); + * + * var A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + * var B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + * + * striu( 'row-major', 2, 2, 0, A, 2, B, 2 ); + * // B => [ 1.0, 2.0, 0.0, 4.0 ] + */ + ( order: Layout, M: number, N: number, k: number, A: Float32Array, LDA: number, B: Float32Array, LDB: number ): Float32Array; + + /** + * Copies the upper triangular part of a single-precision floating-point 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 Float32Array = require( '@stdlib/array/float32' ); + * + * var A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + * var B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + * + * striu.ndarray( 2, 2, 0, A, 2, 1, 0, B, 2, 1, 0 ); + * // B => [ 1.0, 2.0, 0.0, 4.0 ] + */ + ndarray( M: number, N: number, k: number, A: Float32Array, strideA1: number, strideA2: number, offsetA: number, B: Float32Array, strideB1: number, strideB2: number, offsetB: number ): Float32Array; +} + +/** +* Copies the upper triangular part of a single-precision floating-point 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 Float32Array = require( '@stdlib/array/float32' ); +* +* var A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +* var B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); +* +* striu( 'row-major', 2, 2, 0, A, 2, B, 2 ); +* // B => [ 1.0, 2.0, 0.0, 4.0 ] +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +* var B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); +* +* striu.ndarray( 2, 2, 0, A, 2, 1, 0, B, 2, 1, 0 ); +* // B => [ 1.0, 2.0, 0.0, 4.0 ] +*/ +declare var striu: Routine; + + +// EXPORTS // + +export = striu; diff --git a/lib/node_modules/@stdlib/blas/ext/base/striu/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/striu/docs/types/test.ts new file mode 100644 index 000000000000..5f62b262928a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/striu/docs/types/test.ts @@ -0,0 +1,354 @@ +/* +* @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 striu = require( './index' ); + + +// TESTS // + +// The function returns a Float32Array... +{ + const A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + const B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + + striu( 'row-major', 2, 2, 0, A, 2, B, 2 ); // $ExpectType Float32Array +} + +// The compiler throws an error if the function is provided a first argument which is not a valid order... +{ + const A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + const B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + + striu( 5, 2, 2, 0, A, 2, B, 2 ); // $ExpectError + striu( true, 2, 2, 0, A, 2, B, 2 ); // $ExpectError + striu( false, 2, 2, 0, A, 2, B, 2 ); // $ExpectError + striu( null, 2, 2, 0, A, 2, B, 2 ); // $ExpectError + striu( void 0, 2, 2, 0, A, 2, B, 2 ); // $ExpectError + striu( [], 2, 2, 0, A, 2, B, 2 ); // $ExpectError + striu( {}, 2, 2, 0, A, 2, B, 2 ); // $ExpectError + striu( ( 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 = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + const B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + + striu( 'row-major', '5', 2, 0, A, 2, B, 2 ); // $ExpectError + striu( 'row-major', true, 2, 0, A, 2, B, 2 ); // $ExpectError + striu( 'row-major', false, 2, 0, A, 2, B, 2 ); // $ExpectError + striu( 'row-major', null, 2, 0, A, 2, B, 2 ); // $ExpectError + striu( 'row-major', void 0, 2, 0, A, 2, B, 2 ); // $ExpectError + striu( 'row-major', [], 2, 0, A, 2, B, 2 ); // $ExpectError + striu( 'row-major', {}, 2, 0, A, 2, B, 2 ); // $ExpectError + striu( '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 = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + const B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + + striu( 'row-major', 2, '5', 0, A, 2, B, 2 ); // $ExpectError + striu( 'row-major', 2, true, 0, A, 2, B, 2 ); // $ExpectError + striu( 'row-major', 2, false, 0, A, 2, B, 2 ); // $ExpectError + striu( 'row-major', 2, null, 0, A, 2, B, 2 ); // $ExpectError + striu( 'row-major', 2, void 0, 0, A, 2, B, 2 ); // $ExpectError + striu( 'row-major', 2, [], 0, A, 2, B, 2 ); // $ExpectError + striu( 'row-major', 2, {}, 0, A, 2, B, 2 ); // $ExpectError + striu( '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 = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + const B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + + striu( 'row-major', 2, 2, '5', A, 2, B, 2 ); // $ExpectError + striu( 'row-major', 2, 2, true, A, 2, B, 2 ); // $ExpectError + striu( 'row-major', 2, 2, false, A, 2, B, 2 ); // $ExpectError + striu( 'row-major', 2, 2, null, A, 2, B, 2 ); // $ExpectError + striu( 'row-major', 2, 2, void 0, A, 2, B, 2 ); // $ExpectError + striu( 'row-major', 2, 2, [], A, 2, B, 2 ); // $ExpectError + striu( 'row-major', 2, 2, {}, A, 2, B, 2 ); // $ExpectError + striu( '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 Float32Array... +{ + const B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + + striu( 'row-major', 2, 2, 0, 5, 2, B, 2 ); // $ExpectError + striu( 'row-major', 2, 2, 0, true, 2, B, 2 ); // $ExpectError + striu( 'row-major', 2, 2, 0, false, 2, B, 2 ); // $ExpectError + striu( 'row-major', 2, 2, 0, null, 2, B, 2 ); // $ExpectError + striu( 'row-major', 2, 2, 0, void 0, 2, B, 2 ); // $ExpectError + striu( 'row-major', 2, 2, 0, [], 2, B, 2 ); // $ExpectError + striu( 'row-major', 2, 2, 0, {}, 2, B, 2 ); // $ExpectError + striu( '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 = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + const B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + + striu( 'row-major', 2, 2, 0, A, '5', B, 2 ); // $ExpectError + striu( 'row-major', 2, 2, 0, A, true, B, 2 ); // $ExpectError + striu( 'row-major', 2, 2, 0, A, false, B, 2 ); // $ExpectError + striu( 'row-major', 2, 2, 0, A, null, B, 2 ); // $ExpectError + striu( 'row-major', 2, 2, 0, A, void 0, B, 2 ); // $ExpectError + striu( 'row-major', 2, 2, 0, A, [], B, 2 ); // $ExpectError + striu( 'row-major', 2, 2, 0, A, {}, B, 2 ); // $ExpectError + striu( '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 Float32Array... +{ + const A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + + striu( 'row-major', 2, 2, 0, A, 2, 5, 2 ); // $ExpectError + striu( 'row-major', 2, 2, 0, A, 2, true, 2 ); // $ExpectError + striu( 'row-major', 2, 2, 0, A, 2, false, 2 ); // $ExpectError + striu( 'row-major', 2, 2, 0, A, 2, null, 2 ); // $ExpectError + striu( 'row-major', 2, 2, 0, A, 2, void 0, 2 ); // $ExpectError + striu( 'row-major', 2, 2, 0, A, 2, [], 2 ); // $ExpectError + striu( 'row-major', 2, 2, 0, A, 2, {}, 2 ); // $ExpectError + striu( '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 = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + const B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + + striu( 'row-major', 2, 2, 0, A, 2, B, '5' ); // $ExpectError + striu( 'row-major', 2, 2, 0, A, 2, B, true ); // $ExpectError + striu( 'row-major', 2, 2, 0, A, 2, B, false ); // $ExpectError + striu( 'row-major', 2, 2, 0, A, 2, B, null ); // $ExpectError + striu( 'row-major', 2, 2, 0, A, 2, B, void 0 ); // $ExpectError + striu( 'row-major', 2, 2, 0, A, 2, B, [] ); // $ExpectError + striu( 'row-major', 2, 2, 0, A, 2, B, {} ); // $ExpectError + striu( '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 = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + const B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + + striu(); // $ExpectError + striu( 'row-major' ); // $ExpectError + striu( 'row-major', 2 ); // $ExpectError + striu( 'row-major', 2, 2 ); // $ExpectError + striu( 'row-major', 2, 2, 0 ); // $ExpectError + striu( 'row-major', 2, 2, 0, A ); // $ExpectError + striu( 'row-major', 2, 2, 0, A, 2 ); // $ExpectError + striu( 'row-major', 2, 2, 0, A, 2, B ); // $ExpectError + striu( '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 = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + const B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + + striu.ndarray( 2, 2, 0, A, 2, 1, 0, B, 2, 1, 0 ); // $ExpectType Float32Array +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + const B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + + striu.ndarray( '5', 2, 0, A, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError + striu.ndarray( true, 2, 0, A, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError + striu.ndarray( false, 2, 0, A, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError + striu.ndarray( null, 2, 0, A, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError + striu.ndarray( void 0, 2, 0, A, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError + striu.ndarray( [], 2, 0, A, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError + striu.ndarray( {}, 2, 0, A, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError + striu.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 = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + const B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + + striu.ndarray( 2, '5', 0, A, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError + striu.ndarray( 2, true, 0, A, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError + striu.ndarray( 2, false, 0, A, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError + striu.ndarray( 2, null, 0, A, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError + striu.ndarray( 2, void 0, 0, A, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError + striu.ndarray( 2, [], 0, A, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError + striu.ndarray( 2, {}, 0, A, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError + striu.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 = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + const B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + + striu.ndarray( 2, 2, '5', A, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError + striu.ndarray( 2, 2, true, A, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError + striu.ndarray( 2, 2, false, A, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError + striu.ndarray( 2, 2, null, A, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError + striu.ndarray( 2, 2, void 0, A, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError + striu.ndarray( 2, 2, [], A, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError + striu.ndarray( 2, 2, {}, A, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError + striu.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 Float32Array... +{ + const B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + + striu.ndarray( 2, 2, 0, 5, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError + striu.ndarray( 2, 2, 0, true, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError + striu.ndarray( 2, 2, 0, false, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError + striu.ndarray( 2, 2, 0, null, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError + striu.ndarray( 2, 2, 0, void 0, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError + striu.ndarray( 2, 2, 0, [], 2, 1, 0, B, 2, 1, 0 ); // $ExpectError + striu.ndarray( 2, 2, 0, {}, 2, 1, 0, B, 2, 1, 0 ); // $ExpectError + striu.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 = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + const B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + + striu.ndarray( 2, 2, 0, A, '5', 1, 0, B, 2, 1, 0 ); // $ExpectError + striu.ndarray( 2, 2, 0, A, true, 1, 0, B, 2, 1, 0 ); // $ExpectError + striu.ndarray( 2, 2, 0, A, false, 1, 0, B, 2, 1, 0 ); // $ExpectError + striu.ndarray( 2, 2, 0, A, null, 1, 0, B, 2, 1, 0 ); // $ExpectError + striu.ndarray( 2, 2, 0, A, void 0, 1, 0, B, 2, 1, 0 ); // $ExpectError + striu.ndarray( 2, 2, 0, A, [], 1, 0, B, 2, 1, 0 ); // $ExpectError + striu.ndarray( 2, 2, 0, A, {}, 1, 0, B, 2, 1, 0 ); // $ExpectError + striu.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 = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + const B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + + striu.ndarray( 2, 2, 0, A, 2, '5', 0, B, 2, 1, 0 ); // $ExpectError + striu.ndarray( 2, 2, 0, A, 2, true, 0, B, 2, 1, 0 ); // $ExpectError + striu.ndarray( 2, 2, 0, A, 2, false, 0, B, 2, 1, 0 ); // $ExpectError + striu.ndarray( 2, 2, 0, A, 2, null, 0, B, 2, 1, 0 ); // $ExpectError + striu.ndarray( 2, 2, 0, A, 2, void 0, 0, B, 2, 1, 0 ); // $ExpectError + striu.ndarray( 2, 2, 0, A, 2, [], 0, B, 2, 1, 0 ); // $ExpectError + striu.ndarray( 2, 2, 0, A, 2, {}, 0, B, 2, 1, 0 ); // $ExpectError + striu.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 = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + const B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + + striu.ndarray( 2, 2, 0, A, 2, 1, '5', B, 2, 1, 0 ); // $ExpectError + striu.ndarray( 2, 2, 0, A, 2, 1, true, B, 2, 1, 0 ); // $ExpectError + striu.ndarray( 2, 2, 0, A, 2, 1, false, B, 2, 1, 0 ); // $ExpectError + striu.ndarray( 2, 2, 0, A, 2, 1, null, B, 2, 1, 0 ); // $ExpectError + striu.ndarray( 2, 2, 0, A, 2, 1, void 0, B, 2, 1, 0 ); // $ExpectError + striu.ndarray( 2, 2, 0, A, 2, 1, [], B, 2, 1, 0 ); // $ExpectError + striu.ndarray( 2, 2, 0, A, 2, 1, {}, B, 2, 1, 0 ); // $ExpectError + striu.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 Float32Array... +{ + const A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + + striu.ndarray( 2, 2, 0, A, 2, 1, 0, 5, 2, 1, 0 ); // $ExpectError + striu.ndarray( 2, 2, 0, A, 2, 1, 0, true, 2, 1, 0 ); // $ExpectError + striu.ndarray( 2, 2, 0, A, 2, 1, 0, false, 2, 1, 0 ); // $ExpectError + striu.ndarray( 2, 2, 0, A, 2, 1, 0, null, 2, 1, 0 ); // $ExpectError + striu.ndarray( 2, 2, 0, A, 2, 1, 0, void 0, 2, 1, 0 ); // $ExpectError + striu.ndarray( 2, 2, 0, A, 2, 1, 0, [], 2, 1, 0 ); // $ExpectError + striu.ndarray( 2, 2, 0, A, 2, 1, 0, {}, 2, 1, 0 ); // $ExpectError + striu.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 = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + const B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + + striu.ndarray( 2, 2, 0, A, 2, 1, 0, B, '5', 1, 0 ); // $ExpectError + striu.ndarray( 2, 2, 0, A, 2, 1, 0, B, true, 1, 0 ); // $ExpectError + striu.ndarray( 2, 2, 0, A, 2, 1, 0, B, false, 1, 0 ); // $ExpectError + striu.ndarray( 2, 2, 0, A, 2, 1, 0, B, null, 1, 0 ); // $ExpectError + striu.ndarray( 2, 2, 0, A, 2, 1, 0, B, void 0, 1, 0 ); // $ExpectError + striu.ndarray( 2, 2, 0, A, 2, 1, 0, B, [], 1, 0 ); // $ExpectError + striu.ndarray( 2, 2, 0, A, 2, 1, 0, B, {}, 1, 0 ); // $ExpectError + striu.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 = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + const B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + + striu.ndarray( 2, 2, 0, A, 2, 1, 0, B, 2, '5', 0 ); // $ExpectError + striu.ndarray( 2, 2, 0, A, 2, 1, 0, B, 2, true, 0 ); // $ExpectError + striu.ndarray( 2, 2, 0, A, 2, 1, 0, B, 2, false, 0 ); // $ExpectError + striu.ndarray( 2, 2, 0, A, 2, 1, 0, B, 2, null, 0 ); // $ExpectError + striu.ndarray( 2, 2, 0, A, 2, 1, 0, B, 2, void 0, 0 ); // $ExpectError + striu.ndarray( 2, 2, 0, A, 2, 1, 0, B, 2, [], 0 ); // $ExpectError + striu.ndarray( 2, 2, 0, A, 2, 1, 0, B, 2, {}, 0 ); // $ExpectError + striu.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 = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + const B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + + striu.ndarray( 2, 2, 0, A, 2, 1, 0, B, 2, 1, '5' ); // $ExpectError + striu.ndarray( 2, 2, 0, A, 2, 1, 0, B, 2, 1, true ); // $ExpectError + striu.ndarray( 2, 2, 0, A, 2, 1, 0, B, 2, 1, false ); // $ExpectError + striu.ndarray( 2, 2, 0, A, 2, 1, 0, B, 2, 1, null ); // $ExpectError + striu.ndarray( 2, 2, 0, A, 2, 1, 0, B, 2, 1, void 0 ); // $ExpectError + striu.ndarray( 2, 2, 0, A, 2, 1, 0, B, 2, 1, [] ); // $ExpectError + striu.ndarray( 2, 2, 0, A, 2, 1, 0, B, 2, 1, {} ); // $ExpectError + striu.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 = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + const B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + + striu.ndarray(); // $ExpectError + striu.ndarray( 2 ); // $ExpectError + striu.ndarray( 2, 2 ); // $ExpectError + striu.ndarray( 2, 2, 0 ); // $ExpectError + striu.ndarray( 2, 2, 0, A ); // $ExpectError + striu.ndarray( 2, 2, 0, A, 2 ); // $ExpectError + striu.ndarray( 2, 2, 0, A, 2, 1 ); // $ExpectError + striu.ndarray( 2, 2, 0, A, 2, 1, 0 ); // $ExpectError + striu.ndarray( 2, 2, 0, A, 2, 1, 0, B ); // $ExpectError + striu.ndarray( 2, 2, 0, A, 2, 1, 0, B, 2 ); // $ExpectError + striu.ndarray( 2, 2, 0, A, 2, 1, 0, B, 2, 1 ); // $ExpectError + striu.ndarray( 2, 2, 0, A, 2, 1, 0, B, 2, 1, 0, 0 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/striu/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/striu/examples/index.js new file mode 100644 index 000000000000..b8ed1870f7f7 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/striu/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 striu = 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': 'float32' +}); +console.log( ndarray2array( A, shape, strides, 0, order ) ); + +var B = uniform( N, -10, 10, { + 'dtype': 'float32' +}); +console.log( ndarray2array( B, shape, strides, 0, order ) ); + +striu( 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/striu/lib/base.js b/lib/node_modules/@stdlib/blas/ext/base/striu/lib/base.js new file mode 100644 index 000000000000..91fb9d4b5325 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/striu/lib/base.js @@ -0,0 +1,98 @@ +/** +* @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 single-precision floating-point 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 {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} 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 {Float32Array} `B` +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +* var B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); +* +* striu( 2, 2, 0, A, 2, 1, 0, B, 2, 1, 0 ); +* // B => [ 1.0, 2.0, 0.0, 4.0 ] +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +* var B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); +* +* striu( 2, 2, -1, A, 2, 1, 0, B, 2, 1, 0 ); +* // B => [ 1.0, 2.0, 3.0, 4.0 ] +*/ +function striu( M, N, k, A, strideA1, strideA2, offsetA, B, strideB1, strideB2, offsetB ) { + var ia; + var ib; + var i0; + var i1; + + 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 = striu; diff --git a/lib/node_modules/@stdlib/blas/ext/base/striu/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/striu/lib/index.js new file mode 100644 index 000000000000..0b64568318eb --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/striu/lib/index.js @@ -0,0 +1,63 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Copy the upper triangular part of a single-precision floating-point matrix `A` to another matrix `B`. +* +* @module @stdlib/blas/ext/base/striu +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var striu = require( '@stdlib/blas/ext/base/striu' ); +* +* var A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +* var B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); +* +* striu( 'row-major', 2, 2, 0, A, 2, B, 2 ); +* // B => [ 1.0, 2.0, 0.0, 4.0 ] +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var striu = require( '@stdlib/blas/ext/base/striu' ); +* +* var A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +* var B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); +* +* striu.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/striu/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/striu/lib/main.js new file mode 100644 index 000000000000..017d520117e9 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/striu/lib/main.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. +*/ + +'use strict'; + +// MODULES // + +var isLayout = require( '@stdlib/blas/base/assert/is-layout' ); +var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-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 single-precision floating-point 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 {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} 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 a valid stride +* @throws {RangeError} eighth argument must be a valid stride +* @returns {Float32Array} `B` +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +* var B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); +* +* striu( 'row-major', 2, 2, 0, A, 2, B, 2 ); +* // B => [ 1.0, 2.0, 0.0, 4.0 ] +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +* var B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); +* +* striu( 'row-major', 2, 2, 1, A, 2, B, 2 ); +* // B => [ 0.0, 2.0, 0.0, 0.0 ] +*/ +function striu( order, M, N, k, A, LDA, B, LDB ) { + var isrm; + 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 ) ); + } + isrm = isRowMajor( order ); + if ( isrm ) { + 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 ( isrm ) { + sa1 = LDA; + sa2 = 1; + sb1 = LDB; + sb2 = 1; + } else { // order === 'column-major' + sa1 = 1; + sa2 = LDA; + sb1 = 1; + sb2 = LDB; + } + return base( M, N, k, A, sa1, sa2, 0, B, sb1, sb2, 0 ); +} + + +// EXPORTS // + +module.exports = striu; diff --git a/lib/node_modules/@stdlib/blas/ext/base/striu/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/striu/lib/ndarray.js new file mode 100644 index 000000000000..3a7ea7713072 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/striu/lib/ndarray.js @@ -0,0 +1,69 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var base = require( './base.js' ); + + +// MAIN // + +/** +* Copies the upper triangular part of a single-precision floating-point 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 {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} 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 {Float32Array} `B` +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +* var B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); +* +* striu( 2, 2, 0, A, 2, 1, 0, B, 2, 1, 0 ); +* // B => [ 1.0, 2.0, 0.0, 4.0 ] +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +* var B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); +* +* striu( 2, 2, -1, A, 2, 1, 0, B, 2, 1, 0 ); +* // B => [ 1.0, 2.0, 3.0, 4.0 ] +*/ +function striu( 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 = striu; diff --git a/lib/node_modules/@stdlib/blas/ext/base/striu/package.json b/lib/node_modules/@stdlib/blas/ext/base/striu/package.json new file mode 100644 index 000000000000..865d4c6ce15c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/striu/package.json @@ -0,0 +1,71 @@ +{ + "name": "@stdlib/blas/ext/base/striu", + "version": "0.0.0", + "description": "Copy the upper triangular part of a single-precision floating-point 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", + "striu", + "copy", + "array", + "ndarray", + "float32", + "single", + "float32array" + ] +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/striu/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/striu/test/test.js new file mode 100644 index 000000000000..2313815f84f4 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/striu/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 striu = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof striu, '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 striu.ndarray, 'function', 'method is a function' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/striu/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/striu/test/test.main.js new file mode 100644 index 000000000000..6a118910c698 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/striu/test/test.main.js @@ -0,0 +1,376 @@ +/** +* @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 Float32Array = require( '@stdlib/array/float32' ); +var striu = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof striu, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 8', function test( t ) { + t.strictEqual( striu.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 = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + var B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + striu( 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 = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + var B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + striu( '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 = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + var B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + striu( '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 = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + var B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + striu( '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 = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + var B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + striu( '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 = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] ); + B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + out = striu( 'row-major', 3, 3, 0, A, 3, B, 3 ); + + expected = new Float32Array( [ 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 = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] ); + B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + out = striu( 'row-major', 3, 3, 1, A, 3, B, 3 ); + + expected = new Float32Array( [ 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 = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] ); + B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + out = striu( 'row-major', 3, 3, -1, A, 3, B, 3 ); + + expected = new Float32Array( [ 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 = new Float32Array( [ 1.0, 4.0, 7.0, 2.0, 5.0, 8.0, 3.0, 6.0, 9.0 ] ); + B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + out = striu( 'column-major', 3, 3, 0, A, 3, B, 3 ); + + expected = new Float32Array( [ 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 = new Float32Array( [ 1.0, 4.0, 7.0, 2.0, 5.0, 8.0, 3.0, 6.0, 9.0 ] ); + B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + out = striu( 'column-major', 3, 3, -1, A, 3, B, 3 ); + + expected = new Float32Array( [ 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 = new Float32Array( [ 1.0, 4.0, 7.0, 2.0, 5.0, 8.0, 3.0, 6.0, 9.0 ] ); + B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + out = striu( 'column-major', 3, 3, 1, A, 3, B, 3 ); + + expected = new Float32Array( [ 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 = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + out = striu( 'row-major', 2, 3, 0, A, 3, B, 3 ); + expected = new Float32Array( [ 1.0, 2.0, 3.0, 0.0, 5.0, 6.0 ] ); + t.deepEqual( out, expected, 'returns expected value (2x3)' ); + + A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + out = striu( 'row-major', 3, 2, 0, A, 2, B, 2 ); + expected = new Float32Array( [ 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 = new Float32Array( [ 1.0, 4.0, 2.0, 5.0, 3.0, 6.0 ] ); + B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + out = striu( 'column-major', 2, 3, 0, A, 2, B, 2 ); + expected = new Float32Array( [ 1.0, 0.0, 2.0, 5.0, 3.0, 6.0 ] ); + t.deepEqual( out, expected, 'returns expected value (2x3)' ); + + A = new Float32Array( [ 1.0, 3.0, 5.0, 2.0, 4.0, 6.0 ] ); + B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + out = striu( 'column-major', 3, 2, 0, A, 3, B, 3 ); + expected = new Float32Array( [ 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 supports a leading dimension greater than the number of rows/columns (padded matrix)', function test( t ) { + var expected; + var out; + var A; + var B; + + A = new Float32Array( [ 1.0, 2.0, 9.0, 3.0, 4.0, 9.0 ] ); + B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + out = striu( 'row-major', 2, 2, 0, A, 3, B, 3 ); + expected = new Float32Array( [ 1.0, 2.0, 0.0, 0.0, 4.0, 0.0 ] ); + t.deepEqual( out, expected, 'returns expected value (row-major)' ); + + A = new Float32Array( [ 1.0, 3.0, 9.0, 2.0, 4.0, 9.0 ] ); + B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + out = striu( 'column-major', 2, 2, 0, A, 3, B, 3 ); + expected = new Float32Array( [ 1.0, 0.0, 0.0, 2.0, 4.0, 0.0 ] ); + t.deepEqual( out, expected, 'returns expected value (column-major)' ); + + 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 = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] ); + B = new Float32Array( [ -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0 ] ); + + out = striu( 'row-major', 3, 3, 0, A, 3, B, 3 ); + + expected = new Float32Array( [ 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 = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + B = new Float32Array( [ 9.0, 9.0, 9.0, 9.0 ] ); + + out = striu( 'row-major', 2, 2, 2, A, 2, B, 2 ); + + expected = new Float32Array( [ 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 = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + + out = striu( 'row-major', 2, 2, -2, A, 2, B, 2 ); + + expected = new Float32Array( [ 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 = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + expected = new Float32Array( [ 9.0, 9.0, 9.0, 9.0 ] ); + + B = new Float32Array( [ 9.0, 9.0, 9.0, 9.0 ] ); + out = striu( 'row-major', 0, 2, 0, A, 2, B, 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + B = new Float32Array( [ 9.0, 9.0, 9.0, 9.0 ] ); + out = striu( 'row-major', 2, 0, 0, A, 2, B, 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/striu/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/striu/test/test.ndarray.js new file mode 100644 index 000000000000..f1a18a2454a5 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/striu/test/test.ndarray.js @@ -0,0 +1,296 @@ +/** +* @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 Float32Array = require( '@stdlib/array/float32' ); +var striu = require( './../lib' ).ndarray; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof striu, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 11', function test( t ) { + t.strictEqual( striu.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 = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] ); + B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + out = striu( 3, 3, 0, A, 3, 1, 0, B, 3, 1, 0 ); + + expected = new Float32Array( [ 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 = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] ); + B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + out = striu( 3, 3, 1, A, 3, 1, 0, B, 3, 1, 0 ); + + expected = new Float32Array( [ 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 = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] ); + B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + out = striu( 3, 3, -1, A, 3, 1, 0, B, 3, 1, 0 ); + + expected = new Float32Array( [ 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 = new Float32Array( [ 1.0, 4.0, 7.0, 2.0, 5.0, 8.0, 3.0, 6.0, 9.0 ] ); + B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + out = striu( 3, 3, 0, A, 1, 3, 0, B, 1, 3, 0 ); + + expected = new Float32Array( [ 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 = new Float32Array( [ 1.0, 4.0, 7.0, 2.0, 5.0, 8.0, 3.0, 6.0, 9.0 ] ); + B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + out = striu( 3, 3, -1, A, 1, 3, 0, B, 1, 3, 0 ); + + expected = new Float32Array( [ 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 = new Float32Array( [ 1.0, 4.0, 7.0, 2.0, 5.0, 8.0, 3.0, 6.0, 9.0 ] ); + B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + out = striu( 3, 3, 1, A, 1, 3, 0, B, 1, 3, 0 ); + + expected = new Float32Array( [ 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 = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + out = striu( 2, 3, 0, A, 3, 1, 0, B, 3, 1, 0 ); + expected = new Float32Array( [ 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 = new Float32Array( [ 1.0, 3.0, 5.0, 2.0, 4.0, 6.0 ] ); + B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + out = striu( 3, 2, 0, A, 1, 3, 0, B, 1, 3, 0 ); + expected = new Float32Array( [ 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 = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + + out = striu( 2, 2, 0, A, 2, 1, 1, B, 2, 1, 0 ); + + expected = new Float32Array( [ 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 = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + out = striu( 2, 2, 0, A, 2, 1, 0, B, 2, 1, 2 ); + + expected = new Float32Array( [ 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 = new Float32Array( [ 2.0, 1.0, 4.0, 3.0 ] ); + B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + + out = striu( 2, 2, 0, A, 2, -1, 1, B, 2, 1, 0 ); + + expected = new Float32Array( [ 1.0, 2.0, 0.0, 4.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports complex access patterns (non-unit strides and offsets on both `A` and `B`)', function test( t ) { + var expected; + var out; + var A; + var B; + + A = new Float32Array( [ 9.0, 1.0, 9.0, 2.0, 9.0, 3.0, 9.0, 4.0 ] ); + B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + out = striu( 2, 2, 0, A, 4, 2, 1, B, 4, 2, 1 ); + + expected = new Float32Array( [ 0.0, 1.0, 0.0, 2.0, 0.0, 0.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 = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] ); + B = new Float32Array( [ -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0 ] ); + + out = striu( 3, 3, 0, A, 3, 1, 0, B, 3, 1, 0 ); + + expected = new Float32Array( [ 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 = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + B = new Float32Array( [ 9.0, 9.0, 9.0, 9.0 ] ); + + out = striu( 2, 2, 2, A, 2, 1, 0, B, 2, 1, 0 ); + + expected = new Float32Array( [ 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 = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + + out = striu( 2, 2, -2, A, 2, 1, 0, B, 2, 1, 0 ); + + expected = new Float32Array( [ 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 = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + expected = new Float32Array( [ 9.0, 9.0, 9.0, 9.0 ] ); + + B = new Float32Array( [ 9.0, 9.0, 9.0, 9.0 ] ); + out = striu( 0, 2, 0, A, 2, 1, 0, B, 2, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value (M=0)' ); + + B = new Float32Array( [ 9.0, 9.0, 9.0, 9.0 ] ); + out = striu( 2, 0, 0, A, 2, 1, 0, B, 2, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value (N=0)' ); + + t.end(); +}); From 724120a6bba66d4b6d0918aaeccbc6303edb4a11 Mon Sep 17 00:00:00 2001 From: kaustubh Date: Thu, 30 Jul 2026 00:41:45 +0530 Subject: [PATCH 2/3] fix: import single-precision utility --- 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: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - 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: na - task: lint_license_headers status: passed --- --- .../@stdlib/blas/ext/base/striu/benchmark/benchmark.js | 6 +++--- .../blas/ext/base/striu/benchmark/benchmark.ndarray.js | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/striu/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/striu/benchmark/benchmark.js index fd16dd4b42ea..906e0ece222d 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/striu/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/striu/benchmark/benchmark.js @@ -21,7 +21,7 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var zeros = require( '@stdlib/array/zeros' ); var pow = require( '@stdlib/math/base/special/pow' ); var floor = require( '@stdlib/math/base/special/floor' ); @@ -66,12 +66,12 @@ function createBenchmark( order, N ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { z = striu( order, N, N, 0, A, N, B, N ); - if ( isnan( z[ i%z.length ] ) ) { + if ( isnanf( z[ i%z.length ] ) ) { b.fail( 'should not return NaN' ); } } b.toc(); - if ( isnan( z[ i%z.length ] ) ) { + if ( isnanf( z[ i%z.length ] ) ) { b.fail( 'should not return NaN' ); } b.pass( 'benchmark finished' ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/striu/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/striu/benchmark/benchmark.ndarray.js index 4026000ec99f..24fb4af2cc93 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/striu/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/striu/benchmark/benchmark.ndarray.js @@ -21,7 +21,7 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var zeros = require( '@stdlib/array/zeros' ); var pow = require( '@stdlib/math/base/special/pow' ); var floor = require( '@stdlib/math/base/special/floor' ); @@ -80,12 +80,12 @@ function createBenchmark( order, N ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { z = striu( N, N, 0, A, sa1, sa2, 0, B, sa1, sa2, 0 ); - if ( isnan( z[ i%z.length ] ) ) { + if ( isnanf( z[ i%z.length ] ) ) { b.fail( 'should not return NaN' ); } } b.toc(); - if ( isnan( z[ i%z.length ] ) ) { + if ( isnanf( z[ i%z.length ] ) ) { b.fail( 'should not return NaN' ); } b.pass( 'benchmark finished' ); From b870be4b20bcef1070911ec2e40ef8c567c64b4e Mon Sep 17 00:00:00 2001 From: kaustubh Date: Fri, 31 Jul 2026 00:31:15 +0530 Subject: [PATCH 3/3] feat: add c implementation --- 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: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - 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: missing_dependencies - task: lint_c_examples status: missing_dependencies - task: lint_c_benchmarks status: missing_dependencies - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/blas/ext/base/striu/README.md | 161 ++++++++ .../base/striu/benchmark/benchmark.native.js | 117 ++++++ .../benchmark/benchmark.ndarray.native.js | 131 ++++++ .../blas/ext/base/striu/benchmark/c/Makefile | 146 +++++++ .../base/striu/benchmark/c/benchmark.length.c | 208 ++++++++++ .../@stdlib/blas/ext/base/striu/binding.gyp | 170 ++++++++ .../blas/ext/base/striu/examples/c/Makefile | 146 +++++++ .../blas/ext/base/striu/examples/c/example.c | 53 +++ .../@stdlib/blas/ext/base/striu/include.gypi | 53 +++ .../include/stdlib/blas/ext/base/striu.h | 45 ++ .../@stdlib/blas/ext/base/striu/lib/index.js | 17 +- .../@stdlib/blas/ext/base/striu/lib/main.js | 78 +--- .../@stdlib/blas/ext/base/striu/lib/native.js | 35 ++ .../blas/ext/base/striu/lib/ndarray.native.js | 61 +++ .../@stdlib/blas/ext/base/striu/lib/striu.js | 105 +++++ .../blas/ext/base/striu/lib/striu.native.js | 81 ++++ .../@stdlib/blas/ext/base/striu/manifest.json | 79 ++++ .../@stdlib/blas/ext/base/striu/package.json | 9 +- .../@stdlib/blas/ext/base/striu/src/Makefile | 70 ++++ .../@stdlib/blas/ext/base/striu/src/addon.c | 100 +++++ .../@stdlib/blas/ext/base/striu/src/main.c | 107 +++++ .../@stdlib/blas/ext/base/striu/test/test.js | 44 ++ .../blas/ext/base/striu/test/test.ndarray.js | 28 +- .../base/striu/test/test.ndarray.native.js | 305 ++++++++++++++ .../test/{test.main.js => test.striu.js} | 38 +- .../ext/base/striu/test/test.striu.native.js | 385 ++++++++++++++++++ 26 files changed, 2659 insertions(+), 113 deletions(-) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/striu/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/striu/benchmark/benchmark.ndarray.native.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/striu/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/blas/ext/base/striu/benchmark/c/benchmark.length.c create mode 100644 lib/node_modules/@stdlib/blas/ext/base/striu/binding.gyp create mode 100644 lib/node_modules/@stdlib/blas/ext/base/striu/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/blas/ext/base/striu/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/blas/ext/base/striu/include.gypi create mode 100644 lib/node_modules/@stdlib/blas/ext/base/striu/include/stdlib/blas/ext/base/striu.h create mode 100644 lib/node_modules/@stdlib/blas/ext/base/striu/lib/native.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/striu/lib/ndarray.native.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/striu/lib/striu.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/striu/lib/striu.native.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/striu/manifest.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/striu/src/Makefile create mode 100644 lib/node_modules/@stdlib/blas/ext/base/striu/src/addon.c create mode 100644 lib/node_modules/@stdlib/blas/ext/base/striu/src/main.c create mode 100644 lib/node_modules/@stdlib/blas/ext/base/striu/test/test.ndarray.native.js rename lib/node_modules/@stdlib/blas/ext/base/striu/test/{test.main.js => test.striu.js} (89%) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/striu/test/test.striu.native.js diff --git a/lib/node_modules/@stdlib/blas/ext/base/striu/README.md b/lib/node_modules/@stdlib/blas/ext/base/striu/README.md index 9e54cb302610..436d3a91cd8b 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/striu/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/striu/README.md @@ -22,6 +22,12 @@ limitations under the License. > Copy the upper triangular part of a single-precision floating-point matrix `A` to another matrix `B`. +
+ +
+ + +
## Usage @@ -177,6 +183,161 @@ console.log( ndarray2array( B, shape, strides, 0, order ) ); + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/blas/ext/base/striu.h" +``` + +#### stdlib_strided_striu( layout, M, N, k, \*A, LDA, \*B, LDB ) + +Copies the upper triangular part of a single-precision floating-point matrix `A` to another matrix `B`. + +```c +#include "stdlib/blas/base/shared.h" + +const float A[] = { 1.0f, 2.0f, 3.0f, 4.0f }; +float B[] = { 0.0f, 0.0f, 0.0f, 0.0f }; + +stdlib_strided_striu( CblasRowMajor, 2, 2, 0, A, 2, B, 2 ); +``` + +The function accepts the following arguments: + +- **layout**: `[in] CBLAS_LAYOUT` storage layout. +- **M**: `[in] CBLAS_INT` number of rows in `A`. +- **N**: `[in] CBLAS_INT` number of columns in `A`. +- **k**: `[in] CBLAS_INT` diagonal below which to ignore. +- **A**: `[in] float*` input matrix. +- **LDA**: `[in] CBLAS_INT` stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`). +- **B**: `[out] float*` output matrix. +- **LDB**: `[in] CBLAS_INT` stride of the first dimension of `B` (a.k.a., leading dimension of the matrix `B`). + +```c +void API_SUFFIX(stdlib_strided_striu)( const CBLAS_LAYOUT layout, const CBLAS_INT M, const CBLAS_INT N, const CBLAS_INT k, const float *A, const CBLAS_INT LDA, float *B, const CBLAS_INT LDB ); +``` + +#### stdlib_strided_striu_ndarray( M, N, k, \*A, sa1, sa2, oa, \*B, sb1, sb2, ob ) + +Copies the upper triangular part of a single-precision floating-point matrix `A` to another matrix `B` using alternative indexing semantics. + +```c +#include "stdlib/blas/base/shared.h" + +const float A[] = { 1.0f, 2.0f, 3.0f, 4.0f }; +float B[] = { 0.0f, 0.0f, 0.0f, 0.0f }; + +stdlib_strided_striu_ndarray( 2, 2, 0, A, 2, 1, 0, B, 2, 1, 0 ); +``` + +The function accepts the following arguments: + +- **M**: `[in] CBLAS_INT` number of rows in `A`. +- **N**: `[in] CBLAS_INT` number of columns in `A`. +- **k**: `[in] CBLAS_INT` diagonal below which to ignore. +- **A**: `[in] float*` input matrix. +- **sa1**: `[in] CBLAS_INT` stride of the first dimension of `A`. +- **sa2**: `[in] CBLAS_INT` stride of the second dimension of `A`. +- **oa**: `[in] CBLAS_INT` starting index for `A`. +- **B**: `[out] float*` output matrix. +- **sb1**: `[in] CBLAS_INT` stride of the first dimension of `B`. +- **sb2**: `[in] CBLAS_INT` stride of the second dimension of `B`. +- **ob**: `[in] CBLAS_INT` starting index for `B`. + +```c +void API_SUFFIX(stdlib_strided_striu_ndarray)( const CBLAS_INT M, const CBLAS_INT N, const CBLAS_INT k, const float *A, const CBLAS_INT strideA1, const CBLAS_INT strideA2, const CBLAS_INT offsetA, float *B, const CBLAS_INT strideB1, const CBLAS_INT strideB2, const CBLAS_INT offsetB ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/blas/ext/base/striu.h" +#include "stdlib/blas/base/shared.h" +#include + +int main( void ) { + // Define a 3x3 input matrix stored in row-major order: + const float A[ 3*3 ] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f }; + + // Define a 3x3 output matrix: + float B[ 3*3 ] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; + + // Specify the number of elements along each dimension of `A`: + const CBLAS_INT M = 3; + const CBLAS_INT N = 3; + + // Copy the upper triangular part of `A` to `B`: + stdlib_strided_striu( CblasRowMajor, M, N, 0, A, N, B, N ); + + // Print the result: + for ( int i = 0; i < M; i++ ) { + for ( int j = 0; j < N; j++ ) { + printf( "B[ %i,%i ] = %f\n", i, j, B[ (i*N)+j ] ); + } + } + + // Copy the upper triangular part of `A`, including the first sub-diagonal, to `B` using alternative indexing semantics: + stdlib_strided_striu_ndarray( M, N, -1, A, N, 1, 0, B, N, 1, 0 ); + + // Print the result: + for ( int i = 0; i < M; i++ ) { + for ( int j = 0; j < N; j++ ) { + printf( "B[ %i,%i ] = %f\n", i, j, B[ (i*N)+j ] ); + } + } +} +``` + +
+ + + +
+ + + +
+ +
+ + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/striu/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/ext/base/striu/benchmark/benchmark.native.js new file mode 100644 index 000000000000..c523b5d9e829 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/striu/benchmark/benchmark.native.js @@ -0,0 +1,117 @@ +/** +* @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 resolve = require( 'path' ).resolve; +var bench = require( '@stdlib/bench' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var zeros = require( '@stdlib/array/zeros' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var striu = tryRequire( resolve( __dirname, './../lib/striu.native.js' ) ); +var opts = { + 'skip': ( striu instanceof Error ) +}; +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, 'float32' ); + var B = zeros( N*N, 'float32' ); + 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 = striu( order, N, N, 0, 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 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::native,square_matrix:order=%s,size=%d', pkg, ord, N*N ), opts, f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/striu/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/striu/benchmark/benchmark.ndarray.native.js new file mode 100644 index 000000000000..fb5b869b89e3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/striu/benchmark/benchmark.ndarray.native.js @@ -0,0 +1,131 @@ +/** +* @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 resolve = require( 'path' ).resolve; +var bench = require( '@stdlib/bench' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +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 tryRequire = require( '@stdlib/utils/try-require' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var striu = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); +var opts = { + 'skip': ( striu instanceof Error ) +}; +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, 'float32' ); + B = zeros( N*N, 'float32' ); + + 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 = striu( N, N, 0, A, sa1, sa2, 0, B, sa1, sa2, 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 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::native,square_matrix:ndarray:order=%s,size=%d', pkg, ord, N*N ), opts, f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/striu/benchmark/c/Makefile b/lib/node_modules/@stdlib/blas/ext/base/striu/benchmark/c/Makefile new file mode 100644 index 000000000000..0756dc7da20a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/striu/benchmark/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @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. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := benchmark.length.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled benchmarks. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/blas/ext/base/striu/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/ext/base/striu/benchmark/c/benchmark.length.c new file mode 100644 index 000000000000..ce170126391f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/striu/benchmark/c/benchmark.length.c @@ -0,0 +1,208 @@ +/** +* @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. +*/ + +#include "stdlib/blas/ext/base/striu.h" +#include "stdlib/blas/base/shared.h" +#include +#include +#include +#include +#include + +#define NAME "striu" +#define ITERATIONS 1000000 +#define REPEATS 3 +#define MIN 1 +#define MAX 3 + +/** +* Prints the TAP version. +*/ +static void print_version( void ) { + printf( "TAP version 13\n" ); +} + +/** +* Prints the TAP summary. +* +* @param total total number of tests +* @param passing total number of passing tests +*/ +static void print_summary( int total, int passing ) { + printf( "#\n" ); + printf( "1..%d\n", total ); // TAP plan + printf( "# total %d\n", total ); + printf( "# pass %d\n", passing ); + printf( "#\n" ); + printf( "# ok\n" ); +} + +/** +* Prints benchmarks results. +* +* @param iterations number of iterations +* @param elapsed elapsed time in seconds +*/ +static void print_results( int iterations, double elapsed ) { + double rate = (double)iterations / elapsed; + printf( " ---\n" ); + printf( " iterations: %d\n", iterations ); + printf( " elapsed: %0.9f\n", elapsed ); + printf( " rate: %0.9f\n", rate ); + printf( " ...\n" ); +} + +/** +* Returns a clock time. +* +* @return clock time +*/ +static double tic( void ) { + struct timeval now; + gettimeofday( &now, NULL ); + return (double)now.tv_sec + (double)now.tv_usec/1.0e6; +} + +/** +* Generates a random number on the interval [min,max). +* +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number +*/ +static double random_uniform( const double min, const double max ) { + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); + return min + ( v*(max-min) ); +} + +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param len array length +* @return elapsed time in seconds +*/ +static double benchmark1( int iterations, int len ) { + double elapsed; + float *A; + float *B; + double t; + int i; + + A = (float *)malloc( len * len * sizeof( float ) ); + B = (float *)malloc( len * len * sizeof( float ) ); + for ( i = 0; i < len * len; i++ ) { + A[ i ] = (float)random_uniform( -10.0, 10.0 ); + B[ i ] = 0.0f; + } + t = tic(); + for ( i = 0; i < iterations; i++ ) { + // cppcheck-suppress uninitvar + stdlib_strided_striu( CblasRowMajor, len, len, 0, A, len, B, len ); + if ( B[ 0 ] != B[ 0 ] ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( B[ 0 ] != B[ 0 ] ) { + printf( "should not return NaN\n" ); + } + free( A ); + free( B ); + return elapsed; +} + +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param len array length +* @return elapsed time in seconds +*/ +static double benchmark2( int iterations, int len ) { + double elapsed; + float *A; + float *B; + double t; + int i; + + A = (float *)malloc( len * len * sizeof( float ) ); + B = (float *)malloc( len * len * sizeof( float ) ); + for ( i = 0; i < len * len; i++ ) { + A[ i ] = (float)random_uniform( -10.0, 10.0 ); + B[ i ] = 0.0f; + } + t = tic(); + for ( i = 0; i < iterations; i++ ) { + // cppcheck-suppress uninitvar + stdlib_strided_striu_ndarray( len, len, 0, A, len, 1, 0, B, len, 1, 0 ); + if ( B[ 0 ] != B[ 0 ] ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( B[ 0 ] != B[ 0 ] ) { + printf( "should not return NaN\n" ); + } + free( A ); + free( B ); + return elapsed; +} + +/** +* Main execution sequence. +*/ +int main( void ) { + double elapsed; + int count; + int iter; + int N; + int i; + int j; + + // Use the current time to seed the random number generator: + srand( time( NULL ) ); + + print_version(); + count = 0; + for ( i = MIN; i <= MAX; i++ ) { + N = (int)floor( pow( pow( 10, i ), 1.0/2.0 ) ); + iter = ITERATIONS / pow( 10, i-1 ); + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::native::%s:square_matrix:order=row-major,size=%d\n", NAME, N*N ); + elapsed = benchmark1( iter, N ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + } + for ( i = MIN; i <= MAX; i++ ) { + N = (int)floor( pow( pow( 10, i ), 1.0/2.0 ) ); + iter = ITERATIONS / pow( 10, i-1 ); + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::native::%s:square_matrix:ndarray:order=row-major,size=%d\n", NAME, N*N ); + elapsed = benchmark2( iter, N ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + } + print_summary( count, count ); +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/striu/binding.gyp b/lib/node_modules/@stdlib/blas/ext/base/striu/binding.gyp new file mode 100644 index 000000000000..0d6508a12e99 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/striu/binding.gyp @@ -0,0 +1,170 @@ +# @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. + +# A `.gyp` file for building a Node.js native add-on. +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # List of files to include in this file: + 'includes': [ + './include.gypi', + ], + + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Target name should match the add-on export name: + 'addon_target_name%': 'addon', + + # Set variables based on the host OS: + 'conditions': [ + [ + 'OS=="win"', + { + # Define the object file suffix: + 'obj': 'obj', + }, + { + # Define the object file suffix: + 'obj': 'o', + } + ], # end condition (OS=="win") + ], # end conditions + }, # end variables + + # Define compile targets: + 'targets': [ + + # Target to generate an add-on: + { + # The target name should match the add-on export name: + 'target_name': '<(addon_target_name)', + + # Define dependencies: + 'dependencies': [], + + # Define directories which contain relevant include headers: + 'include_dirs': [ + # Local include directory: + '<@(include_dirs)', + ], + + # List of source files: + 'sources': [ + '<@(src_files)', + ], + + # Settings which should be applied when a target's object files are used as linker input: + 'link_settings': { + # Define libraries: + 'libraries': [ + '<@(libraries)', + ], + + # Define library directories: + 'library_dirs': [ + '<@(library_dirs)', + ], + }, + + # C/C++ compiler flags: + 'cflags': [ + # Enable commonly used warning options: + '-Wall', + + # Aggressive optimization: + '-O3', + ], + + # C specific compiler flags: + 'cflags_c': [ + # Specify the C standard to which a program is expected to conform: + '-std=c99', + ], + + # C++ specific compiler flags: + 'cflags_cpp': [ + # Specify the C++ standard to which a program is expected to conform: + '-std=c++11', + ], + + # Linker flags: + 'ldflags': [], + + # Apply conditions based on the host OS: + 'conditions': [ + [ + 'OS=="mac"', + { + # Linker flags: + 'ldflags': [ + '-undefined dynamic_lookup', + '-Wl,-no-pie', + '-Wl,-search_paths_first', + ], + }, + ], # end condition (OS=="mac") + [ + 'OS!="win"', + { + # C/C++ flags: + 'cflags': [ + # Generate platform-independent code: + '-fPIC', + ], + }, + ], # end condition (OS!="win") + ], # end conditions + }, # end target <(addon_target_name) + + # Target to copy a generated add-on to a standard location: + { + 'target_name': 'copy_addon', + + # Declare that the output of this target is not linked: + 'type': 'none', + + # Define dependencies: + 'dependencies': [ + # Require that the add-on be generated before building this target: + '<(addon_target_name)', + ], + + # Define a list of actions: + 'actions': [ + { + 'action_name': 'copy_addon', + 'message': 'Copying addon...', + + # Explicitly list the inputs in the command-line invocation below: + 'inputs': [], + + # Declare the expected outputs: + 'outputs': [ + '<(addon_output_dir)/<(addon_target_name).node', + ], + + # Define the command-line invocation: + 'action': [ + 'cp', + '<(PRODUCT_DIR)/<(addon_target_name).node', + '<(addon_output_dir)/<(addon_target_name).node', + ], + }, + ], # end actions + }, # end target copy_addon + ], # end targets +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/striu/examples/c/Makefile b/lib/node_modules/@stdlib/blas/ext/base/striu/examples/c/Makefile new file mode 100644 index 000000000000..c8f8e9a1517b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/striu/examples/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @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. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := example.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled examples. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/blas/ext/base/striu/examples/c/example.c b/lib/node_modules/@stdlib/blas/ext/base/striu/examples/c/example.c new file mode 100644 index 000000000000..e8d5edf487f2 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/striu/examples/c/example.c @@ -0,0 +1,53 @@ +/** +* @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. +*/ + +#include "stdlib/blas/ext/base/striu.h" +#include "stdlib/blas/base/shared.h" +#include + +int main( void ) { + // Define a 3x3 input matrix stored in row-major order: + const float A[ 3*3 ] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f }; + + // Define a 3x3 output matrix: + float B[ 3*3 ] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; + + // Specify the number of elements along each dimension of `A`: + const CBLAS_INT M = 3; + const CBLAS_INT N = 3; + + // Copy the upper triangular part of `A` to `B`: + stdlib_strided_striu( CblasRowMajor, M, N, 0, A, N, B, N ); + + // Print the result: + for ( int i = 0; i < M; i++ ) { + for ( int j = 0; j < N; j++ ) { + printf( "B[ %i,%i ] = %f\n", i, j, B[ (i*N)+j ] ); + } + } + + // Copy the upper triangular part of `A`, including the first sub-diagonal, to `B` using alternative indexing semantics: + stdlib_strided_striu_ndarray( M, N, -1, A, N, 1, 0, B, N, 1, 0 ); + + // Print the result: + for ( int i = 0; i < M; i++ ) { + for ( int j = 0; j < N; j++ ) { + printf( "B[ %i,%i ] = %f\n", i, j, B[ (i*N)+j ] ); + } + } +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/striu/include.gypi b/lib/node_modules/@stdlib/blas/ext/base/striu/include.gypi new file mode 100644 index 000000000000..bee8d41a2caf --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/striu/include.gypi @@ -0,0 +1,53 @@ +# @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. + +# A GYP include file for building a Node.js native add-on. +# +# Main documentation: +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Source directory: + 'src_dir': './src', + + # Include directories: + 'include_dirs': [ + ' [ 1.0, 2.0, 0.0, 4.0 ] -* -* @example -* var Float32Array = require( '@stdlib/array/float32' ); -* -* var A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); -* var B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); -* -* striu( 'row-major', 2, 2, 1, A, 2, B, 2 ); -* // B => [ 0.0, 2.0, 0.0, 0.0 ] -*/ -function striu( order, M, N, k, A, LDA, B, LDB ) { - var isrm; - 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 ) ); - } - isrm = isRowMajor( order ); - if ( isrm ) { - 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 ( isrm ) { - sa1 = LDA; - sa2 = 1; - sb1 = LDB; - sb2 = 1; - } else { // order === 'column-major' - sa1 = 1; - sa2 = LDA; - sb1 = 1; - sb2 = LDB; - } - return base( M, N, k, A, sa1, sa2, 0, B, sb1, sb2, 0 ); -} +setReadOnly( striu, 'ndarray', ndarray ); // EXPORTS // diff --git a/lib/node_modules/@stdlib/blas/ext/base/striu/lib/native.js b/lib/node_modules/@stdlib/blas/ext/base/striu/lib/native.js new file mode 100644 index 000000000000..cb66d8e3ac59 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/striu/lib/native.js @@ -0,0 +1,35 @@ +/** +* @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 setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './striu.native.js' ); +var ndarray = require( './ndarray.native.js' ); + + +// MAIN // + +setReadOnly( main, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/blas/ext/base/striu/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/striu/lib/ndarray.native.js new file mode 100644 index 000000000000..def05893a5df --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/striu/lib/ndarray.native.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'; + +// MODULES // + +var addon = require( './../src/addon.node' ); + + +// MAIN // + +/** +* Copies the upper triangular part of a single-precision floating-point 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 {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} 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 {Float32Array} `B` +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +* var B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); +* +* striu( 2, 2, 0, A, 2, 1, 0, B, 2, 1, 0 ); +* // B => [ 1.0, 2.0, 0.0, 4.0 ] +*/ +function striu( M, N, k, A, strideA1, strideA2, offsetA, B, strideB1, strideB2, offsetB ) { // eslint-disable-line max-len, max-params + addon.ndarray( M, N, k, A, strideA1, strideA2, offsetA, B, strideB1, strideB2, offsetB ); // eslint-disable-line max-len + return B; +} + + +// EXPORTS // + +module.exports = striu; diff --git a/lib/node_modules/@stdlib/blas/ext/base/striu/lib/striu.js b/lib/node_modules/@stdlib/blas/ext/base/striu/lib/striu.js new file mode 100644 index 000000000000..017d520117e9 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/striu/lib/striu.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. +*/ + +'use strict'; + +// MODULES // + +var isLayout = require( '@stdlib/blas/base/assert/is-layout' ); +var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-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 single-precision floating-point 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 {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} 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 a valid stride +* @throws {RangeError} eighth argument must be a valid stride +* @returns {Float32Array} `B` +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +* var B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); +* +* striu( 'row-major', 2, 2, 0, A, 2, B, 2 ); +* // B => [ 1.0, 2.0, 0.0, 4.0 ] +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +* var B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); +* +* striu( 'row-major', 2, 2, 1, A, 2, B, 2 ); +* // B => [ 0.0, 2.0, 0.0, 0.0 ] +*/ +function striu( order, M, N, k, A, LDA, B, LDB ) { + var isrm; + 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 ) ); + } + isrm = isRowMajor( order ); + if ( isrm ) { + 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 ( isrm ) { + sa1 = LDA; + sa2 = 1; + sb1 = LDB; + sb2 = 1; + } else { // order === 'column-major' + sa1 = 1; + sa2 = LDA; + sb1 = 1; + sb2 = LDB; + } + return base( M, N, k, A, sa1, sa2, 0, B, sb1, sb2, 0 ); +} + + +// EXPORTS // + +module.exports = striu; diff --git a/lib/node_modules/@stdlib/blas/ext/base/striu/lib/striu.native.js b/lib/node_modules/@stdlib/blas/ext/base/striu/lib/striu.native.js new file mode 100644 index 000000000000..68cfb57b6383 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/striu/lib/striu.native.js @@ -0,0 +1,81 @@ +/** +* @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 resolveOrder = require( '@stdlib/blas/base/layout-resolve-enum' ); +var max = require( '@stdlib/math/base/special/fast/max' ); +var format = require( '@stdlib/string/format' ); +var addon = require( './../src/addon.node' ); + + +// MAIN // + +/** +* Copies the upper triangular part of a single-precision floating-point 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 {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} 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 a valid stride +* @throws {RangeError} eighth argument must be a valid stride +* @returns {Float32Array} `B` +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +* var B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); +* +* striu( 'row-major', 2, 2, 0, A, 2, B, 2 ); +* // B => [ 1.0, 2.0, 0.0, 4.0 ] +*/ +function striu( order, M, N, k, A, LDA, B, LDB ) { + 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 ) ); + } + addon( resolveOrder( order ), M, N, k, A, LDA, B, LDB ); + return B; +} + + +// EXPORTS // + +module.exports = striu; diff --git a/lib/node_modules/@stdlib/blas/ext/base/striu/manifest.json b/lib/node_modules/@stdlib/blas/ext/base/striu/manifest.json new file mode 100644 index 000000000000..735912955420 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/striu/manifest.json @@ -0,0 +1,79 @@ +{ + "options": { + "task": "build" + }, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "task": "build", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/ndarray/base/assert/is-row-major", + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-int32", + "@stdlib/napi/argv-strided-float32array2d" + ] + }, + { + "task": "benchmark", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/ndarray/base/assert/is-row-major" + ] + }, + { + "task": "examples", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/ndarray/base/assert/is-row-major" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/striu/package.json b/lib/node_modules/@stdlib/blas/ext/base/striu/package.json index 865d4c6ce15c..9f452b587d57 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/striu/package.json +++ b/lib/node_modules/@stdlib/blas/ext/base/striu/package.json @@ -14,11 +14,15 @@ } ], "main": "./lib", + "browser": "./lib/main.js", + "gypfile": true, "directories": { "benchmark": "./benchmark", "doc": "./docs", "example": "./examples", + "include": "./include", "lib": "./lib", + "src": "./src", "test": "./test" }, "types": "./docs/types", @@ -67,5 +71,8 @@ "float32", "single", "float32array" - ] + ], + "__stdlib__": { + "wasm": false + } } diff --git a/lib/node_modules/@stdlib/blas/ext/base/striu/src/Makefile b/lib/node_modules/@stdlib/blas/ext/base/striu/src/Makefile new file mode 100644 index 000000000000..2caf905cedbe --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/striu/src/Makefile @@ -0,0 +1,70 @@ +#/ +# @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. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + + +# RULES # + +#/ +# Removes generated files for building an add-on. +# +# @example +# make clean-addon +#/ +clean-addon: + $(QUIET) -rm -f *.o *.node + +.PHONY: clean-addon + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: clean-addon + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/blas/ext/base/striu/src/addon.c b/lib/node_modules/@stdlib/blas/ext/base/striu/src/addon.c new file mode 100644 index 000000000000..e92ccddbedbd --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/striu/src/addon.c @@ -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. +*/ + +#include "stdlib/blas/ext/base/striu.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/napi/export.h" +#include "stdlib/napi/argv.h" +#include "stdlib/napi/argv_int64.h" +#include "stdlib/napi/argv_int32.h" +#include "stdlib/napi/argv_strided_float32array2d.h" +#include + +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon( napi_env env, napi_callback_info info ) { + CBLAS_INT sa1; + CBLAS_INT sa2; + CBLAS_INT sb1; + CBLAS_INT sb2; + + STDLIB_NAPI_ARGV( env, info, argv, argc, 8 ); + + STDLIB_NAPI_ARGV_INT32( env, layout, argv, 0 ); + + STDLIB_NAPI_ARGV_INT64( env, M, argv, 1 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 2 ); + STDLIB_NAPI_ARGV_INT64( env, k, argv, 3 ); + STDLIB_NAPI_ARGV_INT64( env, LDA, argv, 5 ); + STDLIB_NAPI_ARGV_INT64( env, LDB, argv, 7 ); + + if ( layout == CblasColMajor ) { + sa1 = 1; + sa2 = LDA; + sb1 = 1; + sb2 = LDB; + } else { // layout == CblasRowMajor + sa1 = LDA; + sa2 = 1; + sb1 = LDB; + sb2 = 1; + } + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY2D( env, A, M, N, sa1, sa2, argv, 4 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY2D( env, B, M, N, sb1, sb2, argv, 6 ); + + API_SUFFIX(stdlib_strided_striu)( layout, M, N, k, A, LDA, B, LDB ); + + return NULL; +} + +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon_method( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 11 ); + + STDLIB_NAPI_ARGV_INT64( env, M, argv, 0 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 1 ); + STDLIB_NAPI_ARGV_INT64( env, k, argv, 2 ); + + STDLIB_NAPI_ARGV_INT64( env, strideA1, argv, 4 ); + STDLIB_NAPI_ARGV_INT64( env, strideA2, argv, 5 ); + STDLIB_NAPI_ARGV_INT64( env, offsetA, argv, 6 ); + + STDLIB_NAPI_ARGV_INT64( env, strideB1, argv, 8 ); + STDLIB_NAPI_ARGV_INT64( env, strideB2, argv, 9 ); + STDLIB_NAPI_ARGV_INT64( env, offsetB, argv, 10 ); + + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY2D( env, A, M, N, strideA1, strideA2, argv, 3 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY2D( env, B, M, N, strideB1, strideB2, argv, 7 ); + + API_SUFFIX(stdlib_strided_striu_ndarray)( M, N, k, A, strideA1, strideA2, offsetA, B, strideB1, strideB2, offsetB ); + + return NULL; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method ) diff --git a/lib/node_modules/@stdlib/blas/ext/base/striu/src/main.c b/lib/node_modules/@stdlib/blas/ext/base/striu/src/main.c new file mode 100644 index 000000000000..862da9d94362 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/striu/src/main.c @@ -0,0 +1,107 @@ +/** +* @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. +*/ + +#include "stdlib/blas/ext/base/striu.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/ndarray/base/assert/is_row_major.h" +#include + +// Define macros for computing the minimum and maximum values: +#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y)) +#define MAX(X, Y) (((X) > (Y)) ? (X) : (Y)) + +/** +* Copies the upper triangular part of a single-precision floating-point matrix `A` to another matrix `B`. +* +* @param layout storage layout +* @param M number of rows in the matrix `A` +* @param N number of columns in the 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`) +*/ +void API_SUFFIX(stdlib_strided_striu)( const CBLAS_LAYOUT layout, const CBLAS_INT M, const CBLAS_INT N, const CBLAS_INT k, const float *A, const CBLAS_INT LDA, float *B, const CBLAS_INT LDB ) { + CBLAS_INT sa1; + CBLAS_INT sa2; + CBLAS_INT sb1; + CBLAS_INT sb2; + + if ( layout == CblasColMajor ) { + sa1 = 1; + sa2 = LDA; + sb1 = 1; + sb2 = LDB; + } else { // layout == CblasRowMajor + sa1 = LDA; + sa2 = 1; + sb1 = LDB; + sb2 = 1; + } + API_SUFFIX(stdlib_strided_striu_ndarray)( M, N, k, A, sa1, sa2, 0, B, sb1, sb2, 0 ); +} + +/** +* Copies the upper triangular part of a single-precision floating-point matrix `A` to another matrix `B` using alternative indexing semantics. +* +* @param M number of rows in the matrix `A` +* @param N number of columns in the 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` +*/ +void API_SUFFIX(stdlib_strided_striu_ndarray)( const CBLAS_INT M, const CBLAS_INT N, const CBLAS_INT k, const float *A, const CBLAS_INT strideA1, const CBLAS_INT strideA2, const CBLAS_INT offsetA, float *B, const CBLAS_INT strideB1, const CBLAS_INT strideB2, const CBLAS_INT offsetB ) { + int64_t sa[ 2 ]; + CBLAS_INT ia; + CBLAS_INT ib; + CBLAS_INT i0; + CBLAS_INT i1; + + ia = offsetA; + ib = offsetB; + + sa[ 0 ] = strideA1; + sa[ 1 ] = strideA2; + if ( stdlib_ndarray_is_row_major( 2, sa ) ) { + // 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++ ) { + B[ ib+(i0*strideB2) ] = A[ ia+(i0*strideA2) ]; + } + ia += strideA1; + ib += strideB1; + } + return; + } + // 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++ ) { + B[ ib+(i0*strideB1) ] = A[ ia+(i0*strideA1) ]; + } + ia += strideA2; + ib += strideB2; + } + return; +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/striu/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/striu/test/test.js index 2313815f84f4..47681a03ebb1 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/striu/test/test.js +++ b/lib/node_modules/@stdlib/blas/ext/base/striu/test/test.js @@ -21,9 +21,18 @@ // MODULES // var tape = require( 'tape' ); +var proxyquire = require( 'proxyquire' ); +var IS_BROWSER = require( '@stdlib/assert/is-browser' ); var striu = require( './../lib' ); +// VARIABLES // + +var opts = { + 'skip': IS_BROWSER +}; + + // TESTS // tape( 'main export is a function', function test( t ) { @@ -36,3 +45,38 @@ tape( 'attached to the main export is a method providing an ndarray interface', t.strictEqual( typeof striu.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 striu = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( striu, mock, 'returns native implementation' ); + 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 striu; + var main; + + main = require( './../lib/main.js' ); + + striu = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( striu, main, 'returns JavaScript implementation' ); + t.end(); + + function tryRequire() { + return new Error( 'Cannot find module' ); + } +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/striu/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/striu/test/test.ndarray.js index f1a18a2454a5..137bbd590002 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/striu/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/striu/test/test.ndarray.js @@ -22,7 +22,7 @@ var tape = require( 'tape' ); var Float32Array = require( '@stdlib/array/float32' ); -var striu = require( './../lib' ).ndarray; +var striu = require( './../lib/ndarray.js' ); // TESTS // @@ -45,7 +45,7 @@ tape( 'the function copies the upper triangular part of `A` to `B` (row-major, k var B; A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] ); - B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + B = new Float32Array( 9 ); out = striu( 3, 3, 0, A, 3, 1, 0, B, 3, 1, 0 ); @@ -62,7 +62,7 @@ tape( 'the function copies the upper triangular part of `A` to `B` (row-major, k var B; A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] ); - B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + B = new Float32Array( 9 ); out = striu( 3, 3, 1, A, 3, 1, 0, B, 3, 1, 0 ); @@ -78,7 +78,7 @@ tape( 'the function copies the upper triangular part of `A` to `B` (row-major, k var B; A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] ); - B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + B = new Float32Array( 9 ); out = striu( 3, 3, -1, A, 3, 1, 0, B, 3, 1, 0 ); @@ -94,7 +94,7 @@ tape( 'the function copies the upper triangular part of `A` to `B` (column-major var B; A = new Float32Array( [ 1.0, 4.0, 7.0, 2.0, 5.0, 8.0, 3.0, 6.0, 9.0 ] ); - B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + B = new Float32Array( 9 ); out = striu( 3, 3, 0, A, 1, 3, 0, B, 1, 3, 0 ); @@ -110,7 +110,7 @@ tape( 'the function copies the upper triangular part of `A` to `B` (column-major var B; A = new Float32Array( [ 1.0, 4.0, 7.0, 2.0, 5.0, 8.0, 3.0, 6.0, 9.0 ] ); - B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + B = new Float32Array( 9 ); out = striu( 3, 3, -1, A, 1, 3, 0, B, 1, 3, 0 ); @@ -126,7 +126,7 @@ tape( 'the function copies the upper triangular part of `A` to `B` (column-major var B; A = new Float32Array( [ 1.0, 4.0, 7.0, 2.0, 5.0, 8.0, 3.0, 6.0, 9.0 ] ); - B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + B = new Float32Array( 9 ); out = striu( 3, 3, 1, A, 1, 3, 0, B, 1, 3, 0 ); @@ -142,7 +142,7 @@ tape( 'the function supports non-square matrices (row-major)', function test( t var B; A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + B = new Float32Array( 6 ); out = striu( 2, 3, 0, A, 3, 1, 0, B, 3, 1, 0 ); expected = new Float32Array( [ 1.0, 2.0, 3.0, 0.0, 5.0, 6.0 ] ); t.deepEqual( out, expected, 'returns expected value' ); @@ -156,7 +156,7 @@ tape( 'the function supports non-square matrices (column-major)', function test( var B; A = new Float32Array( [ 1.0, 3.0, 5.0, 2.0, 4.0, 6.0 ] ); - B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + B = new Float32Array( 6 ); out = striu( 3, 2, 0, A, 1, 3, 0, B, 1, 3, 0 ); expected = new Float32Array( [ 1.0, 0.0, 0.0, 2.0, 4.0, 0.0 ] ); t.deepEqual( out, expected, 'returns expected value' ); @@ -170,7 +170,7 @@ tape( 'the function supports an `A` offset', function test( t ) { var B; A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); - B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + B = new Float32Array( 4 ); out = striu( 2, 2, 0, A, 2, 1, 1, B, 2, 1, 0 ); @@ -186,7 +186,7 @@ tape( 'the function supports a `B` offset', function test( t ) { var B; A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + B = new Float32Array( 6 ); out = striu( 2, 2, 0, A, 2, 1, 0, B, 2, 1, 2 ); @@ -202,7 +202,7 @@ tape( 'the function supports negative strides', function test( t ) { var B; A = new Float32Array( [ 2.0, 1.0, 4.0, 3.0 ] ); - B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + B = new Float32Array( 4 ); out = striu( 2, 2, 0, A, 2, -1, 1, B, 2, 1, 0 ); @@ -218,7 +218,7 @@ tape( 'the function supports complex access patterns (non-unit strides and offse var B; A = new Float32Array( [ 9.0, 1.0, 9.0, 2.0, 9.0, 3.0, 9.0, 4.0 ] ); - B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + B = new Float32Array( 8 ); out = striu( 2, 2, 0, A, 4, 2, 1, B, 4, 2, 1 ); @@ -266,7 +266,7 @@ tape( 'when `k` is sufficiently negative, the function copies the entire matrix' var B; A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + B = new Float32Array( 4 ); out = striu( 2, 2, -2, A, 2, 1, 0, B, 2, 1, 0 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/striu/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/striu/test/test.ndarray.native.js new file mode 100644 index 000000000000..3c535eff0c04 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/striu/test/test.ndarray.native.js @@ -0,0 +1,305 @@ +/** +* @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 resolve = require( 'path' ).resolve; +var tape = require( 'tape' ); +var Float32Array = require( '@stdlib/array/float32' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var striu = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); +var opts = { + 'skip': ( striu instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof striu, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 11', opts, function test( t ) { + t.strictEqual( striu.length, 11, 'returns expected value' ); + t.end(); +}); + +tape( 'the function copies the upper triangular part of `A` to `B` (row-major, k=0)', opts, function test( t ) { + var expected; + var out; + var A; + var B; + + A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] ); + B = new Float32Array( 9 ); + + out = striu( 3, 3, 0, A, 3, 1, 0, B, 3, 1, 0 ); + + expected = new Float32Array( [ 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)', opts, function test( t ) { + var expected; + var out; + var A; + var B; + + A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] ); + B = new Float32Array( 9 ); + + out = striu( 3, 3, 1, A, 3, 1, 0, B, 3, 1, 0 ); + + expected = new Float32Array( [ 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)', opts, function test( t ) { + var expected; + var out; + var A; + var B; + + A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] ); + B = new Float32Array( 9 ); + + out = striu( 3, 3, -1, A, 3, 1, 0, B, 3, 1, 0 ); + + expected = new Float32Array( [ 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)', opts, function test( t ) { + var expected; + var out; + var A; + var B; + + A = new Float32Array( [ 1.0, 4.0, 7.0, 2.0, 5.0, 8.0, 3.0, 6.0, 9.0 ] ); + B = new Float32Array( 9 ); + + out = striu( 3, 3, 0, A, 1, 3, 0, B, 1, 3, 0 ); + + expected = new Float32Array( [ 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)', opts, function test( t ) { + var expected; + var out; + var A; + var B; + + A = new Float32Array( [ 1.0, 4.0, 7.0, 2.0, 5.0, 8.0, 3.0, 6.0, 9.0 ] ); + B = new Float32Array( 9 ); + + out = striu( 3, 3, -1, A, 1, 3, 0, B, 1, 3, 0 ); + + expected = new Float32Array( [ 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)', opts, function test( t ) { + var expected; + var out; + var A; + var B; + + A = new Float32Array( [ 1.0, 4.0, 7.0, 2.0, 5.0, 8.0, 3.0, 6.0, 9.0 ] ); + B = new Float32Array( 9 ); + + out = striu( 3, 3, 1, A, 1, 3, 0, B, 1, 3, 0 ); + + expected = new Float32Array( [ 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)', opts, function test( t ) { + var expected; + var out; + var A; + var B; + + A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + B = new Float32Array( 6 ); + out = striu( 2, 3, 0, A, 3, 1, 0, B, 3, 1, 0 ); + expected = new Float32Array( [ 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)', opts, function test( t ) { + var expected; + var out; + var A; + var B; + + A = new Float32Array( [ 1.0, 3.0, 5.0, 2.0, 4.0, 6.0 ] ); + B = new Float32Array( 6 ); + out = striu( 3, 2, 0, A, 1, 3, 0, B, 1, 3, 0 ); + expected = new Float32Array( [ 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', opts, function test( t ) { + var expected; + var out; + var A; + var B; + + A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + B = new Float32Array( 4 ); + + out = striu( 2, 2, 0, A, 2, 1, 1, B, 2, 1, 0 ); + + expected = new Float32Array( [ 2.0, 3.0, 0.0, 5.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `B` offset', opts, function test( t ) { + var expected; + var out; + var A; + var B; + + A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + B = new Float32Array( 6 ); + + out = striu( 2, 2, 0, A, 2, 1, 0, B, 2, 1, 2 ); + + expected = new Float32Array( [ 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', opts, function test( t ) { + var expected; + var out; + var A; + var B; + + A = new Float32Array( [ 2.0, 1.0, 4.0, 3.0 ] ); + B = new Float32Array( 4 ); + + out = striu( 2, 2, 0, A, 2, -1, 1, B, 2, 1, 0 ); + + expected = new Float32Array( [ 1.0, 2.0, 0.0, 4.0 ] ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports complex access patterns (non-unit strides and offsets on both `A` and `B`)', opts, function test( t ) { + var expected; + var out; + var A; + var B; + + A = new Float32Array( [ 9.0, 1.0, 9.0, 2.0, 9.0, 3.0, 9.0, 4.0 ] ); + B = new Float32Array( 8 ); + + out = striu( 2, 2, 0, A, 4, 2, 1, B, 4, 2, 1 ); + + expected = new Float32Array( [ 0.0, 1.0, 0.0, 2.0, 0.0, 0.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', opts, function test( t ) { + var expected; + var out; + var A; + var B; + + A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] ); + B = new Float32Array( [ -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0 ] ); + + out = striu( 3, 3, 0, A, 3, 1, 0, B, 3, 1, 0 ); + + expected = new Float32Array( [ 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', opts, function test( t ) { + var expected; + var out; + var A; + var B; + + A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + B = new Float32Array( [ 9.0, 9.0, 9.0, 9.0 ] ); + + out = striu( 2, 2, 2, A, 2, 1, 0, B, 2, 1, 0 ); + + expected = new Float32Array( [ 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', opts, function test( t ) { + var expected; + var out; + var A; + var B; + + A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + B = new Float32Array( 4 ); + + out = striu( 2, 2, -2, A, 2, 1, 0, B, 2, 1, 0 ); + + expected = new Float32Array( [ 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', opts, function test( t ) { + var expected; + var out; + var A; + var B; + + A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + expected = new Float32Array( [ 9.0, 9.0, 9.0, 9.0 ] ); + + B = new Float32Array( [ 9.0, 9.0, 9.0, 9.0 ] ); + out = striu( 0, 2, 0, A, 2, 1, 0, B, 2, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value (M=0)' ); + + B = new Float32Array( [ 9.0, 9.0, 9.0, 9.0 ] ); + out = striu( 2, 0, 0, A, 2, 1, 0, B, 2, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value (N=0)' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/striu/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/striu/test/test.striu.js similarity index 89% rename from lib/node_modules/@stdlib/blas/ext/base/striu/test/test.main.js rename to lib/node_modules/@stdlib/blas/ext/base/striu/test/test.striu.js index 6a118910c698..c8b77e50cb28 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/striu/test/test.main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/striu/test/test.striu.js @@ -22,7 +22,7 @@ var tape = require( 'tape' ); var Float32Array = require( '@stdlib/array/float32' ); -var striu = require( './../lib' ); +var striu = require( './../lib/striu.js' ); // TESTS // @@ -65,7 +65,7 @@ tape( 'the function throws an error if provided an invalid first argument', func function badValue( value ) { return function badValue() { var A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - var B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + var B = new Float32Array( 4 ); striu( value, 2, 2, 0, A, 2, B, 2 ); }; } @@ -84,7 +84,7 @@ tape( 'the function throws an error if provided a sixth argument which is not a function badValue( value ) { return function badValue() { var A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - var B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + var B = new Float32Array( 4 ); striu( 'row-major', 2, 2, 0, A, value, B, 2 ); }; } @@ -103,7 +103,7 @@ tape( 'the function throws an error if provided an eighth argument which is not function badValue( value ) { return function badValue() { var A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - var B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + var B = new Float32Array( 4 ); striu( 'row-major', 2, 2, 0, A, 2, B, value ); }; } @@ -122,7 +122,7 @@ tape( 'the function throws an error if provided a sixth argument which is not a function badValue( value ) { return function badValue() { var A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - var B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + var B = new Float32Array( 4 ); striu( 'column-major', 2, 2, 0, A, value, B, 2 ); }; } @@ -141,7 +141,7 @@ tape( 'the function throws an error if provided an eighth argument which is not function badValue( value ) { return function badValue() { var A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - var B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + var B = new Float32Array( 4 ); striu( 'column-major', 2, 2, 0, A, 2, B, value ); }; } @@ -154,7 +154,7 @@ tape( 'the function copies the upper triangular part of `A` to `B` (row-major, k var B; A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] ); - B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + B = new Float32Array( 9 ); out = striu( 'row-major', 3, 3, 0, A, 3, B, 3 ); @@ -171,7 +171,7 @@ tape( 'the function copies the upper triangular part of `A` to `B` (row-major, k var B; A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] ); - B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + B = new Float32Array( 9 ); out = striu( 'row-major', 3, 3, 1, A, 3, B, 3 ); @@ -187,7 +187,7 @@ tape( 'the function copies the upper triangular part of `A` to `B` (row-major, k var B; A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] ); - B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + B = new Float32Array( 9 ); out = striu( 'row-major', 3, 3, -1, A, 3, B, 3 ); @@ -203,7 +203,7 @@ tape( 'the function copies the upper triangular part of `A` to `B` (column-major var B; A = new Float32Array( [ 1.0, 4.0, 7.0, 2.0, 5.0, 8.0, 3.0, 6.0, 9.0 ] ); - B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + B = new Float32Array( 9 ); out = striu( 'column-major', 3, 3, 0, A, 3, B, 3 ); @@ -219,7 +219,7 @@ tape( 'the function copies the upper triangular part of `A` to `B` (column-major var B; A = new Float32Array( [ 1.0, 4.0, 7.0, 2.0, 5.0, 8.0, 3.0, 6.0, 9.0 ] ); - B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + B = new Float32Array( 9 ); out = striu( 'column-major', 3, 3, -1, A, 3, B, 3 ); @@ -235,7 +235,7 @@ tape( 'the function copies the upper triangular part of `A` to `B` (column-major var B; A = new Float32Array( [ 1.0, 4.0, 7.0, 2.0, 5.0, 8.0, 3.0, 6.0, 9.0 ] ); - B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + B = new Float32Array( 9 ); out = striu( 'column-major', 3, 3, 1, A, 3, B, 3 ); @@ -251,13 +251,13 @@ tape( 'the function supports non-square matrices (row-major)', function test( t var B; A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + B = new Float32Array( 6 ); out = striu( 'row-major', 2, 3, 0, A, 3, B, 3 ); expected = new Float32Array( [ 1.0, 2.0, 3.0, 0.0, 5.0, 6.0 ] ); t.deepEqual( out, expected, 'returns expected value (2x3)' ); A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + B = new Float32Array( 6 ); out = striu( 'row-major', 3, 2, 0, A, 2, B, 2 ); expected = new Float32Array( [ 1.0, 2.0, 0.0, 4.0, 0.0, 0.0 ] ); t.deepEqual( out, expected, 'returns expected value (3x2)' ); @@ -272,13 +272,13 @@ tape( 'the function supports non-square matrices (column-major)', function test( var B; A = new Float32Array( [ 1.0, 4.0, 2.0, 5.0, 3.0, 6.0 ] ); - B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + B = new Float32Array( 6 ); out = striu( 'column-major', 2, 3, 0, A, 2, B, 2 ); expected = new Float32Array( [ 1.0, 0.0, 2.0, 5.0, 3.0, 6.0 ] ); t.deepEqual( out, expected, 'returns expected value (2x3)' ); A = new Float32Array( [ 1.0, 3.0, 5.0, 2.0, 4.0, 6.0 ] ); - B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + B = new Float32Array( 6 ); out = striu( 'column-major', 3, 2, 0, A, 3, B, 3 ); expected = new Float32Array( [ 1.0, 0.0, 0.0, 2.0, 4.0, 0.0 ] ); t.deepEqual( out, expected, 'returns expected value (3x2)' ); @@ -293,13 +293,13 @@ tape( 'the function supports a leading dimension greater than the number of rows var B; A = new Float32Array( [ 1.0, 2.0, 9.0, 3.0, 4.0, 9.0 ] ); - B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + B = new Float32Array( 6 ); out = striu( 'row-major', 2, 2, 0, A, 3, B, 3 ); expected = new Float32Array( [ 1.0, 2.0, 0.0, 0.0, 4.0, 0.0 ] ); t.deepEqual( out, expected, 'returns expected value (row-major)' ); A = new Float32Array( [ 1.0, 3.0, 9.0, 2.0, 4.0, 9.0 ] ); - B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + B = new Float32Array( 6 ); out = striu( 'column-major', 2, 2, 0, A, 3, B, 3 ); expected = new Float32Array( [ 1.0, 0.0, 0.0, 2.0, 4.0, 0.0 ] ); t.deepEqual( out, expected, 'returns expected value (column-major)' ); @@ -346,7 +346,7 @@ tape( 'when `k` is sufficiently negative, the function copies the entire matrix' var B; A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - B = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + B = new Float32Array( 4 ); out = striu( 'row-major', 2, 2, -2, A, 2, B, 2 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/striu/test/test.striu.native.js b/lib/node_modules/@stdlib/blas/ext/base/striu/test/test.striu.native.js new file mode 100644 index 000000000000..f0442ffa194a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/striu/test/test.striu.native.js @@ -0,0 +1,385 @@ +/** +* @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 resolve = require( 'path' ).resolve; +var tape = require( 'tape' ); +var Float32Array = require( '@stdlib/array/float32' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var striu = tryRequire( resolve( __dirname, './../lib/striu.native.js' ) ); +var opts = { + 'skip': ( striu instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof striu, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 8', opts, function test( t ) { + t.strictEqual( striu.length, 8, 'returns expected value' ); + t.end(); +}); + +tape( 'the function throws an error if provided an invalid first argument', opts, 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 = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + var B = new Float32Array( 4 ); + striu( 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)', opts, 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 = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + var B = new Float32Array( 4 ); + striu( '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)', opts, 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 = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + var B = new Float32Array( 4 ); + striu( '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)', opts, 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 = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + var B = new Float32Array( 4 ); + striu( '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)', opts, 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 = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + var B = new Float32Array( 4 ); + striu( '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)', opts, function test( t ) { + var expected; + var out; + var A; + var B; + + A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] ); + B = new Float32Array( 9 ); + + out = striu( 'row-major', 3, 3, 0, A, 3, B, 3 ); + + expected = new Float32Array( [ 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)', opts, function test( t ) { + var expected; + var out; + var A; + var B; + + A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] ); + B = new Float32Array( 9 ); + + out = striu( 'row-major', 3, 3, 1, A, 3, B, 3 ); + + expected = new Float32Array( [ 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)', opts, function test( t ) { + var expected; + var out; + var A; + var B; + + A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] ); + B = new Float32Array( 9 ); + + out = striu( 'row-major', 3, 3, -1, A, 3, B, 3 ); + + expected = new Float32Array( [ 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)', opts, function test( t ) { + var expected; + var out; + var A; + var B; + + A = new Float32Array( [ 1.0, 4.0, 7.0, 2.0, 5.0, 8.0, 3.0, 6.0, 9.0 ] ); + B = new Float32Array( 9 ); + + out = striu( 'column-major', 3, 3, 0, A, 3, B, 3 ); + + expected = new Float32Array( [ 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)', opts, function test( t ) { + var expected; + var out; + var A; + var B; + + A = new Float32Array( [ 1.0, 4.0, 7.0, 2.0, 5.0, 8.0, 3.0, 6.0, 9.0 ] ); + B = new Float32Array( 9 ); + + out = striu( 'column-major', 3, 3, -1, A, 3, B, 3 ); + + expected = new Float32Array( [ 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)', opts, function test( t ) { + var expected; + var out; + var A; + var B; + + A = new Float32Array( [ 1.0, 4.0, 7.0, 2.0, 5.0, 8.0, 3.0, 6.0, 9.0 ] ); + B = new Float32Array( 9 ); + + out = striu( 'column-major', 3, 3, 1, A, 3, B, 3 ); + + expected = new Float32Array( [ 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)', opts, function test( t ) { + var expected; + var out; + var A; + var B; + + A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + B = new Float32Array( 6 ); + out = striu( 'row-major', 2, 3, 0, A, 3, B, 3 ); + expected = new Float32Array( [ 1.0, 2.0, 3.0, 0.0, 5.0, 6.0 ] ); + t.deepEqual( out, expected, 'returns expected value (2x3)' ); + + A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + B = new Float32Array( 6 ); + out = striu( 'row-major', 3, 2, 0, A, 2, B, 2 ); + expected = new Float32Array( [ 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)', opts, function test( t ) { + var expected; + var out; + var A; + var B; + + A = new Float32Array( [ 1.0, 4.0, 2.0, 5.0, 3.0, 6.0 ] ); + B = new Float32Array( 6 ); + out = striu( 'column-major', 2, 3, 0, A, 2, B, 2 ); + expected = new Float32Array( [ 1.0, 0.0, 2.0, 5.0, 3.0, 6.0 ] ); + t.deepEqual( out, expected, 'returns expected value (2x3)' ); + + A = new Float32Array( [ 1.0, 3.0, 5.0, 2.0, 4.0, 6.0 ] ); + B = new Float32Array( 6 ); + out = striu( 'column-major', 3, 2, 0, A, 3, B, 3 ); + expected = new Float32Array( [ 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 supports a leading dimension greater than the number of rows/columns (padded matrix)', opts, function test( t ) { + var expected; + var out; + var A; + var B; + + A = new Float32Array( [ 1.0, 2.0, 9.0, 3.0, 4.0, 9.0 ] ); + B = new Float32Array( 6 ); + out = striu( 'row-major', 2, 2, 0, A, 3, B, 3 ); + expected = new Float32Array( [ 1.0, 2.0, 0.0, 0.0, 4.0, 0.0 ] ); + t.deepEqual( out, expected, 'returns expected value (row-major)' ); + + A = new Float32Array( [ 1.0, 3.0, 9.0, 2.0, 4.0, 9.0 ] ); + B = new Float32Array( 6 ); + out = striu( 'column-major', 2, 2, 0, A, 3, B, 3 ); + expected = new Float32Array( [ 1.0, 0.0, 0.0, 2.0, 4.0, 0.0 ] ); + t.deepEqual( out, expected, 'returns expected value (column-major)' ); + + t.end(); +}); + +tape( 'the function leaves elements outside of the copied region unchanged', opts, function test( t ) { + var expected; + var out; + var A; + var B; + + A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] ); + B = new Float32Array( [ -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0 ] ); + + out = striu( 'row-major', 3, 3, 0, A, 3, B, 3 ); + + expected = new Float32Array( [ 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', opts, function test( t ) { + var expected; + var out; + var A; + var B; + + A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + B = new Float32Array( [ 9.0, 9.0, 9.0, 9.0 ] ); + + out = striu( 'row-major', 2, 2, 2, A, 2, B, 2 ); + + expected = new Float32Array( [ 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', opts, function test( t ) { + var expected; + var out; + var A; + var B; + + A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + B = new Float32Array( 4 ); + + out = striu( 'row-major', 2, 2, -2, A, 2, B, 2 ); + + expected = new Float32Array( [ 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', opts, function test( t ) { + var expected; + var out; + var A; + var B; + + A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + expected = new Float32Array( [ 9.0, 9.0, 9.0, 9.0 ] ); + + B = new Float32Array( [ 9.0, 9.0, 9.0, 9.0 ] ); + out = striu( 'row-major', 0, 2, 0, A, 2, B, 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + B = new Float32Array( [ 9.0, 9.0, 9.0, 9.0 ] ); + out = striu( 'row-major', 2, 0, 0, A, 2, B, 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +});