diff --git a/lib/node_modules/@stdlib/lapack/base/dlantr/NOTICE b/lib/node_modules/@stdlib/lapack/base/dlantr/NOTICE new file mode 100644 index 000000000000..65a3d8bcdea6 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlantr/NOTICE @@ -0,0 +1,51 @@ +This package adapts the DLANTR algorithm and interface from LAPACK. +Reference: https://github.com/Reference-LAPACK/lapack/blob/master/SRC/dlantr.f + +Copyright (c) 1992-2025 The University of Tennessee and The University + of Tennessee Research Foundation. All rights + reserved. +Copyright (c) 2000-2025 The University of California Berkeley. All + rights reserved. +Copyright (c) 2006-2025 The University of Colorado Denver. All rights + reserved. + +$COPYRIGHT$ + +Additional copyrights may follow + +$HEADER$ + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + +- Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +- Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer listed + in this license in the documentation and/or other materials + provided with the distribution. + +- Neither the name of the copyright holders nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +The copyright holders provide no reassurances that the source code +provided does not infringe any patent, copyright, or any other +intellectual property rights of third parties. The copyright holders +disclaim any liability to any recipient for claims brought against +recipient by any third party for infringement of that parties +intellectual property rights. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/lib/node_modules/@stdlib/lapack/base/dlantr/README.md b/lib/node_modules/@stdlib/lapack/base/dlantr/README.md new file mode 100644 index 000000000000..10ec7443e7a8 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlantr/README.md @@ -0,0 +1,231 @@ + + +# dlantr + +> Compute a norm of a double-precision triangular or trapezoidal matrix. + +
+ +## Usage + +```javascript +var dlantr = require( '@stdlib/lapack/base/dlantr' ); +``` + +#### dlantr( order, norm, uplo, diag, M, N, A, LDA, work ) + +Computes a norm of an `M` by `N` triangular or trapezoidal matrix `A`. + +- `order`: storage layout, either `'row-major'` or `'column-major'` (or the corresponding BLAS enumeration). +- `norm`: `'max'` for the largest absolute entry, `'one'` for the maximum column sum, `'infinity'` for the maximum row sum, or `'frobenius'` for the square root of the sum of squared entries. +- `uplo`: either `'upper'` or `'lower'` (or the corresponding BLAS enumeration). +- `diag`: either `'unit'` or `'non-unit'` (or the corresponding BLAS enumeration). +- `M`, `N`: nonnegative integer dimensions. Upper trapezoidal matrices require `M <= N`; lower trapezoidal matrices require `N <= M`. +- `A`: a `Float64Array` containing the rectangular matrix storage, including the unused triangle. +- `LDA`: leading dimension, at least `max(1,N)` for row-major storage or `max(1,M)` for column-major storage. +- `work`: scratch `Float64Array` with at least `M` elements for the infinity norm. Other norms do not reference workspace storage. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var A = new Float64Array( [ 2.0, -3.0, 4.0, NaN, 5.0, -6.0 ] ); +var work = new Float64Array( 2 ); + +var v = dlantr( 'row-major', 'max', 'upper', 'non-unit', 2, 3, A, 3, work ); +// returns 6.0 + +v = dlantr( 'row-major', 'one', 'upper', 'non-unit', 2, 3, A, 3, work ); +// returns 10.0 + +v = dlantr( 'row-major', 'infinity', 'upper', 'non-unit', 2, 3, A, 3, work ); +// returns 11.0 + +v = dlantr( 'row-major', 'frobenius', 'upper', 'non-unit', 2, 3, A, 3, work ); +// returns ~9.487 +``` + +When `diag` is `'unit'`, diagonal elements are implicitly one and are never read from `A`. The opposite triangle and storage padding are also not referenced. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var A = new Float64Array( [ NaN, -3.0, 4.0, NaN, NaN, -6.0 ] ); +var work = new Float64Array( 2 ); + +var v = dlantr( 'row-major', 'infinity', 'upper', 'unit', 2, 3, A, 3, work ); +// returns 8.0 +``` + +The function throws an error for invalid options, dimensions, leading dimensions, matrix storage, or required workspace storage. + +#### dlantr.ndarray( norm, uplo, diag, M, N, A, sa1, sa2, oa, work, sw, ow ) + +Computes a matrix norm using alternative indexing semantics. `strideA1` and `strideA2` are row and column strides, and `offsetA` is the index of the first logical matrix element. Matrix strides may be positive, negative, or zero. For the infinity norm, `strideWork` must be a nonzero integer and `offsetWork` must locate sufficient workspace entries. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var A = new Float64Array( [ -6.0, 5.0, NaN, 4.0, -3.0, 2.0 ] ); +var work = new Float64Array( [ 0.0, 0.0 ] ); + +var v = dlantr.ndarray( 'infinity', 'upper', 'non-unit', 2, 3, A, -3, -1, 5, work, -1, 1 ); +// returns 11.0 +``` + +
+ + + +
+ +## Notes + +- The matrix is not mutated. For the infinity norm, only the `M` indexed workspace entries are overwritten; workspace must not overlap the referenced input matrix storage. +- If `M` or `N` is zero, the function returns positive zero without accessing either array. +- Non-infinity norms ignore workspace storage and its indexing metadata. An empty workspace array is sufficient. +- A referenced `NaN` propagates to the result, including when other entries are infinite. Unreferenced `NaN` values do not affect the result. +- Frobenius accumulation uses scaled sums of squares to avoid unnecessary overflow and underflow. An infinite referenced entry yields infinity unless a referenced `NaN` is present. +- The JavaScript interface accepts only the four documented norm names. The C interface accepts LAPACK character aliases, as documented below. +- Test fixtures were generated independently using SciPy 1.17.0 and LAPACK. To regenerate their expected norms from the stored input matrices, run `python3 test/fixtures/scipy/runner.py` from this package directory with NumPy and SciPy installed. +- Input storage must contain the full indexed rectangular view. The function does not read the ignored triangle or unit diagonal, but bounds validation still covers the rectangular view. + +
+ + + +
+ +## Examples + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var dlantr = require( '@stdlib/lapack/base/dlantr' ); + +var A = new Float64Array( [ 1.0e300, 0.0, NaN, 1.0e300 ] ); +var work = new Float64Array( 0 ); + +var v = dlantr( 'row-major', 'frobenius', 'upper', 'non-unit', 2, 2, A, 2, work ); +console.log( v ); +// => ~1.414e300 +``` + +
+ + + + + +
+ +## C APIs + +
+ +### Usage + +```c +#include "stdlib/lapack/base/dlantr.h" +``` + +#### c_dlantr( layout, norm, uplo, diag, M, N, A, LDA, work ) + +Computes a triangular or trapezoidal matrix norm. `layout`, `uplo`, and `diag` are the corresponding `LAPACK_LAYOUT`, `LAPACK_UPLO`, and `LAPACK_DIAGONAL` enumerations. Dimensions and indices use `LAPACK_INT`. + +`norm` accepts the following case-insensitive LAPACK characters: + +- `'M'`: largest absolute entry. +- `'1'` or `'O'`: maximum column sum. +- `'I'`: maximum row sum. +- `'F'` or `'E'`: Frobenius norm. + +```c +const double A[] = { 2.0, -3.0, 4.0, 0.0, 5.0, -6.0 }; +double work[ 2 ]; + +double v = c_dlantr( LAPACK_ROW_MAJOR, 'I', LAPACK_UPPER_TRIANGLE, LAPACK_NON_UNIT_DIAGONAL, 2, 3, A, 3, work ); +``` + +The leading dimension and trapezoidal dimension constraints match the JavaScript interface. Workspace must provide `M` elements for the infinity norm, must not overlap input storage, and may be `NULL` for other norms. Invalid options or dimensions yield `NaN`. The caller must supply valid indexed storage. + +#### c_dlantr_ndarray( norm, uplo, diag, M, N, A, sa1, sa2, oa, work, sw, ow ) + +Computes a matrix norm using alternative indexing semantics. Strides and offsets are in elements. For the infinity norm, workspace entries must be distinct and `strideWork` must be nonzero. Other norms do not reference workspace storage or its indices. + +```c +const double A[] = { -6.0, 5.0, 0.0, 4.0, -3.0, 2.0 }; +double work[ 2 ]; + +double v = c_dlantr_ndarray( 'I', LAPACK_UPPER_TRIANGLE, LAPACK_NON_UNIT_DIAGONAL, 2, 3, A, -3, -1, 5, work, -1, 1 ); +``` + +
+ + + +
+ +### Examples + +```c +#include "stdlib/lapack/base/dlantr.h" +#include + +int main( void ) { + const double A[] = { 2.0, -3.0, 4.0, 0.0, 5.0, -6.0 }; + double work[ 2 ]; + double v = c_dlantr( LAPACK_ROW_MAJOR, 'I', LAPACK_UPPER_TRIANGLE, LAPACK_NON_UNIT_DIAGONAL, 2, 3, A, 3, work ); + printf( "%f\n", v ); + return 0; +} +``` + +
+ + + +
+ + + +
+ +## References + +- LAPACK. "DLANTR." [Reference-LAPACK][lapack-dlantr]. Adaptation provenance and the LAPACK redistribution terms are retained in the accompanying `NOTICE`. + +
+ + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/lapack/base/dlantr/benchmark/benchmark.js b/lib/node_modules/@stdlib/lapack/base/dlantr/benchmark/benchmark.js new file mode 100644 index 000000000000..abe0ced44708 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlantr/benchmark/benchmark.js @@ -0,0 +1,94 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var dlantr = require( './../lib/main.js' ); + + +// VARIABLES // + +var sizes = [ 10, 100 ]; +var norms = [ 'max', 'one', 'infinity', 'frobenius' ]; +var i; +var j; + + +// FUNCTIONS // + +/** +* Creates a matrix norm benchmark. +* +* @private +* @param {PositiveInteger} N - matrix dimension +* @param {string} norm - norm type +* @returns {Function} benchmark function +*/ +function createBenchmark( N, norm ) { + var work; + var A; + var i; + + A = new Float64Array( N*N ); + work = new Float64Array( N ); + for ( i = 0; i < A.length; i++ ) { + A[i] = (i%19) - 9; + } + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = dlantr( 'row-major', norm, 'upper', 'non-unit', N, N, A, N, work ); + if ( isnan( out ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( out ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +for ( i = 0; i < sizes.length; i++ ) { + for ( j = 0; j < norms.length; j++ ) { + bench( format( '%s::norm=%s,N=%d', pkg, norms[j], sizes[i] ), createBenchmark( sizes[i], norms[j] ) ); + } +} diff --git a/lib/node_modules/@stdlib/lapack/base/dlantr/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/lapack/base/dlantr/benchmark/benchmark.native.js new file mode 100644 index 000000000000..f8c44338c078 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlantr/benchmark/benchmark.native.js @@ -0,0 +1,99 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var bench = require( '@stdlib/bench' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var Float64Array = require( '@stdlib/array/float64' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var dlantr = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( dlantr instanceof Error ) +}; + + +// VARIABLES // + +var sizes = [ 10, 100 ]; +var norms = [ 'max', 'one', 'infinity', 'frobenius' ]; +var i; +var j; + + +// FUNCTIONS // + +/** +* Creates a matrix norm benchmark. +* +* @private +* @param {PositiveInteger} N - matrix dimension +* @param {string} norm - norm type +* @returns {Function} benchmark function +*/ +function createBenchmark( N, norm ) { + var work; + var A; + var i; + + A = new Float64Array( N*N ); + work = new Float64Array( N ); + for ( i = 0; i < A.length; i++ ) { + A[i] = (i%19) - 9; + } + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = dlantr( 'row-major', norm, 'upper', 'non-unit', N, N, A, N, work ); + if ( isnan( out ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( out ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +for ( i = 0; i < sizes.length; i++ ) { + for ( j = 0; j < norms.length; j++ ) { + bench( format( '%s::norm=%s,N=%d', pkg, norms[j], sizes[i] ), opts, createBenchmark( sizes[i], norms[j] ) ); + } +} diff --git a/lib/node_modules/@stdlib/lapack/base/dlantr/benchmark/c/Makefile b/lib/node_modules/@stdlib/lapack/base/dlantr/benchmark/c/Makefile new file mode 100644 index 000000000000..979768abbcec --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlantr/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.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/lapack/base/dlantr/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/lapack/base/dlantr/benchmark/c/benchmark.c new file mode 100644 index 000000000000..b70bbf969e1a --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlantr/benchmark/c/benchmark.c @@ -0,0 +1,87 @@ +/** +* @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/lapack/base/dlantr.h" +#include +#include +#include + +#define NAME "dlantr" +#define REPEATS 3 +#define ITERATIONS 10000 + +/** +* Runs a matrix norm benchmark. +* +* @param N matrix dimension +* @param norm norm type +* @return elapsed time in seconds +*/ +static double benchmark( const LAPACK_INT N, const char norm ) { + double *work; + double *A; + double out; + clock_t t; + LAPACK_INT i; + + A = (double *)malloc( N*N*sizeof( double ) ); + work = (double *)malloc( N*sizeof( double ) ); + if ( A == NULL || work == NULL ) { + free( A ); + free( work ); + exit( 1 ); + } + for ( i = 0; i < N*N; i++ ) { + A[ i ] = (i%19) - 9; + } + t = clock(); + for ( i = 0; i < ITERATIONS; i++ ) { + out = API_SUFFIX(c_dlantr)( LAPACK_ROW_MAJOR, norm, LAPACK_UPPER_TRIANGLE, LAPACK_NON_UNIT_DIAGONAL, N, N, A, N, work ); + if ( out != out ) { + free( A ); + free( work ); + exit( 1 ); + } + } + t = clock() - t; + free( A ); + free( work ); + return (double)t / CLOCKS_PER_SEC; +} + +int main( void ) { + const char norms[] = { 'M', '1', 'I', 'F' }; + double elapsed; + int count; + int i; + int j; + + printf( "TAP version 13\n" ); + count = 0; + for ( i = 0; i < 4; i++ ) { + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + elapsed = benchmark( 10, norms[ i ] ); + printf( "# c::%s:norm=%c,N=10\n", NAME, norms[ i ] ); + printf( " ---\n iterations: %d\n elapsed: %0.9f\n rate: %0.9f\n ...\n", ITERATIONS, elapsed, ITERATIONS/elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + } + printf( "1..%d\n# total %d\n# pass %d\n# ok\n", count, count, count ); + return 0; +} diff --git a/lib/node_modules/@stdlib/lapack/base/dlantr/binding.gyp b/lib/node_modules/@stdlib/lapack/base/dlantr/binding.gyp new file mode 100644 index 000000000000..ea4770f8ac53 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlantr/binding.gyp @@ -0,0 +1,173 @@ +# @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': [], + + # Match Node-API integer arguments without narrowing indices: + 'defines': [ 'LAPACK_ILP64' ], + + # 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/lapack/base/dlantr/docs/repl.txt b/lib/node_modules/@stdlib/lapack/base/dlantr/docs/repl.txt new file mode 100644 index 000000000000..e01707355c50 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlantr/docs/repl.txt @@ -0,0 +1,89 @@ +{{alias}}( order, norm, uplo, diag, M, N, A, LDA, work ) + Computes a norm of a triangular or trapezoidal matrix. + + Upper matrices require M <= N; lower matrices require N <= M. + Unit diagonal values and the opposite triangle are not referenced. + Infinity workspace must contain M elements and must not overlap A. + + Parameters + ---------- + order: string|integer + Row-major or column-major storage layout. + norm: string + Norm name: 'max', 'one', 'infinity', or 'frobenius'. + uplo: string|integer + Upper or lower triangular storage. + diag: string|integer + Unit or non-unit diagonal. + M: integer + Number of rows. + N: integer + Number of columns. + A: Float64Array + Input matrix storage. + LDA: integer + Leading dimension. + work: Float64Array + Infinity norm workspace; ignored by other norms. + + Returns + ------- + v: number + Matrix norm. + + Examples + -------- + > var values = [ 2, -3, 4, NaN, 5, -6 ]; + > var A = new {{alias:@stdlib/array/float64}}( values ); + > var work = new {{alias:@stdlib/array/float64}}( 2 ); + > {{alias}}( 101, 'infinity', 121, 131, 2, 3, A, 3, work ) + 11 + + +{{alias}}.ndarray( norm, uplo, diag, M, N, A, sa1, sa2, oa, work, sw, ow ) + Computes a matrix norm with explicit strides and offsets. + + Parameters + ---------- + norm: string + Norm name: 'max', 'one', 'infinity', or 'frobenius'. + uplo: string|integer + Upper or lower triangular storage. + diag: string|integer + Unit or non-unit diagonal. + M: integer + Number of rows. + N: integer + Number of columns. + A: Float64Array + Input matrix storage. + sa1: integer + Row stride. + sa2: integer + Column stride. + oa: integer + Matrix starting index. + work: Float64Array + Infinity norm workspace; ignored by other norms. + sw: integer + Nonzero workspace stride for the infinity norm. + ow: integer + Workspace starting index. + + Returns + ------- + v: number + Matrix norm. + + Examples + -------- + > var values = [ -6, 5, NaN, 4, -3, 2 ]; + > var A = new {{alias:@stdlib/array/float64}}( values ); + > var work = new {{alias:@stdlib/array/float64}}( 2 ); + > var f = {{alias}}.ndarray; + > f( 'infinity', 'upper', 'non-unit', 2, 3, A, -3, -1, 5, work, -1, 1 ) + 11 + + + See Also + -------- diff --git a/lib/node_modules/@stdlib/lapack/base/dlantr/docs/types/index.d.ts b/lib/node_modules/@stdlib/lapack/base/dlantr/docs/types/index.d.ts new file mode 100644 index 000000000000..b726fde714b6 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlantr/docs/types/index.d.ts @@ -0,0 +1,116 @@ +/* +* @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, MatrixTriangle, DiagonalType } from '@stdlib/types/blas'; + +/** +* Supported JavaScript norm names. +*/ +type Norm = 'max' | 'one' | 'infinity' | 'frobenius'; + +/** +* Interface describing `dlantr`. +*/ +interface Routine { + /** + * Computes a norm of a triangular or trapezoidal matrix. + * + * @param order - storage layout + * @param norm - max, one, infinity, or frobenius norm + * @param uplo - upper or lower triangle + * @param diag - unit or non-unit diagonal + * @param M - number of rows + * @param N - number of columns + * @param A - input matrix + * @param LDA - leading dimension + * @param work - infinity norm workspace (must not overlap A) + * @returns matrix norm + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * + * var A = new Float64Array( [ 2.0, -3.0, 4.0, NaN, 5.0, -6.0 ] ); + * var work = new Float64Array( 2 ); + * + * var v = dlantr( 'row-major', 'infinity', 'upper', 'non-unit', 2, 3, A, 3, work ); + * // returns 11.0 + */ + ( order: Layout | 101 | 102, norm: Norm, uplo: MatrixTriangle | 121 | 122, diag: DiagonalType | 131 | 132, M: number, N: number, A: Float64Array, LDA: number, work: Float64Array ): number; + + /** + * Computes a matrix norm using alternative indexing semantics. + * + * @param norm - max, one, infinity, or frobenius norm + * @param uplo - upper or lower triangle + * @param diag - unit or non-unit diagonal + * @param M - number of rows + * @param N - number of columns + * @param A - input matrix + * @param strideA1 - row stride + * @param strideA2 - column stride + * @param offsetA - starting index of A + * @param work - infinity norm workspace (must not overlap A) + * @param strideWork - nonzero workspace stride + * @param offsetWork - workspace starting index + * @returns matrix norm + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * + * var A = new Float64Array( [ -6.0, 5.0, NaN, 4.0, -3.0, 2.0 ] ); + * var work = new Float64Array( 2 ); + * + * var v = dlantr.ndarray( 'infinity', 'upper', 'non-unit', 2, 3, A, -3, -1, 5, work, -1, 1 ); + * // returns 11.0 + */ + ndarray( norm: Norm, uplo: MatrixTriangle | 121 | 122, diag: DiagonalType | 131 | 132, M: number, N: number, A: Float64Array, strideA1: number, strideA2: number, offsetA: number, work: Float64Array, strideWork: number, offsetWork: number ): number; +} + +/** +* Computes a norm of a triangular or trapezoidal matrix. +* +* @param order - storage layout +* @param norm - max, one, infinity, or frobenius norm +* @param uplo - upper or lower triangle +* @param diag - unit or non-unit diagonal +* @param M - number of rows +* @param N - number of columns +* @param A - input matrix +* @param LDA - leading dimension +* @param work - infinity norm workspace (must not overlap A) +* @returns matrix norm +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var A = new Float64Array( [ 2.0, -3.0, 4.0, NaN, 5.0, -6.0 ] ); +* var work = new Float64Array( 2 ); +* +* var v = dlantr( 'row-major', 'infinity', 'upper', 'non-unit', 2, 3, A, 3, work ); +* // returns 11.0 +*/ +declare var dlantr: Routine; + + +// EXPORTS // + +export = dlantr; diff --git a/lib/node_modules/@stdlib/lapack/base/dlantr/docs/types/test.ts b/lib/node_modules/@stdlib/lapack/base/dlantr/docs/types/test.ts new file mode 100644 index 000000000000..97185c462f80 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlantr/docs/types/test.ts @@ -0,0 +1,39 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import dlantr = require( './index' ); + +var A = new Float64Array( 4 ); +var work = new Float64Array( 2 ); + +dlantr( 'row-major', 'max', 'upper', 'non-unit', 2, 2, A, 2, work ); // $ExpectType number +dlantr.ndarray( 'infinity', 'lower', 'unit', 2, 2, A, 2, 1, 0, work, -1, 1 ); // $ExpectType number + +dlantr( 101, 'max', 121, 131, 2, 2, A, 2, work ); // $ExpectType number +dlantr.ndarray( 'one', 122, 132, 2, 2, A, 2, 1, 0, work, 1, 0 ); // $ExpectType number + +dlantr( 'bad', 'max', 'upper', 'unit', 2, 2, A, 2, work ); // $ExpectError +dlantr( 'row-major', 'M', 'upper', 'unit', 2, 2, A, 2, work ); // $ExpectError +dlantr( 'row-major', 'max', 'all', 'unit', 2, 2, A, 2, work ); // $ExpectError +dlantr( 'row-major', 'max', 'upper', 'bad', 2, 2, A, 2, work ); // $ExpectError +dlantr( 'row-major', 'max', 'upper', 'unit', 2, 2, [], 2, work ); // $ExpectError +dlantr( 'row-major', 'max', 'upper', 'unit', 2, 2, A, 2 ); // $ExpectError +dlantr.ndarray( 'bad', 'lower', 'unit', 2, 2, A, 2, 1, 0, work, 1, 0 ); // $ExpectError +dlantr.ndarray( 'max', 'all', 'unit', 2, 2, A, 2, 1, 0, work, 1, 0 ); // $ExpectError +dlantr.ndarray( 'max', 'lower', 'bad', 2, 2, A, 2, 1, 0, work, 1, 0 ); // $ExpectError +dlantr.ndarray( 'max', 'lower', 'unit', 2, 2, [], 2, 1, 0, work, 1, 0 ); // $ExpectError diff --git a/lib/node_modules/@stdlib/lapack/base/dlantr/examples/c/Makefile b/lib/node_modules/@stdlib/lapack/base/dlantr/examples/c/Makefile new file mode 100644 index 000000000000..c8f8e9a1517b --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlantr/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/lapack/base/dlantr/examples/c/example.c b/lib/node_modules/@stdlib/lapack/base/dlantr/examples/c/example.c new file mode 100644 index 000000000000..16c8329edc5d --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlantr/examples/c/example.c @@ -0,0 +1,32 @@ +/** +* @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/lapack/base/dlantr.h" +#include + +int main( void ) { + const double A[] = { 2.0, -3.0, 4.0, 0.0, 5.0, -6.0 }; + double work[ 2 ]; + double v; + + v = API_SUFFIX(c_dlantr)( LAPACK_ROW_MAJOR, 'I', LAPACK_UPPER_TRIANGLE, LAPACK_NON_UNIT_DIAGONAL, 2, 3, A, 3, work ); + printf( "infinity norm: %f\n", v ); + v = API_SUFFIX(c_dlantr)( LAPACK_ROW_MAJOR, 'F', LAPACK_UPPER_TRIANGLE, LAPACK_NON_UNIT_DIAGONAL, 2, 3, A, 3, NULL ); + printf( "Frobenius norm: %f\n", v ); + return 0; +} diff --git a/lib/node_modules/@stdlib/lapack/base/dlantr/examples/index.js b/lib/node_modules/@stdlib/lapack/base/dlantr/examples/index.js new file mode 100644 index 000000000000..1af123573ea9 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlantr/examples/index.js @@ -0,0 +1,33 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var dlantr = require( './../lib' ); + + +// MAIN // + +var A = new Float64Array( [ 2.0, -3.0, 4.0, NaN, 5.0, -6.0 ] ); +var work = new Float64Array( 2 ); + +console.log( dlantr( 'row-major', 'infinity', 'upper', 'non-unit', 2, 3, A, 3, work ) ); +console.log( dlantr( 'row-major', 'frobenius', 'upper', 'non-unit', 2, 3, A, 3, work ) ); diff --git a/lib/node_modules/@stdlib/lapack/base/dlantr/include.gypi b/lib/node_modules/@stdlib/lapack/base/dlantr/include.gypi new file mode 100644 index 000000000000..bee8d41a2caf --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlantr/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': [ + ' value || isnan( ax ) ) { + value = ax; + } + } else if ( norm === 49 ) { + sum += ax; + } else if ( norm === 73 ) { + work[ ow+(i*sw) ] += ax; + } else { + if ( isnan( ax ) ) { + return NaN; + } + if ( ax === PINF ) { + scale = PINF; + } else if ( ax !== 0.0 && scale !== PINF ) { + if ( scale < ax ) { + r = scale / ax; + sumsq = 1.0 + ( sumsq*r*r ); + scale = ax; + } else { + r = ax / scale; + sumsq += r*r; + } + } + } + } + if ( norm === 49 && ( sum > value || isnan( sum ) ) ) { + value = sum; + } + } + if ( norm === 73 ) { + for ( i = 0; i < M; i++ ) { + sum = work[ ow+(i*sw) ]; + if ( sum > value || isnan( sum ) ) { + value = sum; + } + } + } else if ( norm === 70 ) { + value = scale * sqrt( sumsq ); + } + return value; +} + + +// EXPORTS // + +module.exports = dlantr; diff --git a/lib/node_modules/@stdlib/lapack/base/dlantr/lib/factory.js b/lib/node_modules/@stdlib/lapack/base/dlantr/lib/factory.js new file mode 100644 index 000000000000..75c561d83588 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlantr/lib/factory.js @@ -0,0 +1,119 @@ +/** +* @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 resolveLayout = require( '@stdlib/blas/base/layout-resolve-enum' ); +var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimitive; +var validate = require( './validate.js' ); +var validateArrays = require( './validate_arrays.js' ); + + +// MAIN // + +/** +* Creates the public interfaces for a numerical implementation. +* +* @private +* @param {Function} base - numerical implementation +* @returns {Function} public interface +*/ +function factory( base ) { + setReadOnly( dlantr, 'ndarray', ndarray ); + return dlantr; + + /** + * Computes a norm of a triangular or trapezoidal matrix. + * + * @private + * @param {(string|integer)} order - storage layout + * @param {string} norm - norm type + * @param {(string|integer)} uplo - triangle type + * @param {(string|integer)} diag - diagonal type + * @param {NonNegativeInteger} M - number of rows + * @param {NonNegativeInteger} N - number of columns + * @param {Float64Array} A - input matrix + * @param {PositiveInteger} LDA - leading dimension + * @param {Float64Array} work - infinity norm scratch storage + * @throws {TypeError} invalid option or storage type + * @throws {RangeError} invalid dimension, leading dimension, or storage length + * @returns {number} norm + */ + function dlantr( order, norm, uplo, diag, M, N, A, LDA, work ) { + var opts; + var sa1; + var sa2; + var l; + + l = resolveLayout( order ); + if ( l === null ) { + throw new TypeError( 'invalid argument. First argument must be a valid order.' ); + } + opts = validate( norm, uplo, diag, M, N ); + if ( + !isPositiveInteger( LDA ) || + ( l === 101 && LDA < N ) || + ( l === 102 && LDA < M ) + ) { + throw new RangeError( 'invalid argument. Leading dimension must be at least max(1,N) for row-major storage or max(1,M) for column-major storage.' ); + } + if ( l === 102 ) { + sa1 = 1; + sa2 = LDA; + } else { + sa1 = LDA; + sa2 = 1; + } + validateArrays( opts[0], M, N, A, sa1, sa2, 0, work, 1, 0 ); + return base( opts[0], opts[1], opts[2], M, N, A, sa1, sa2, 0, work, 1, 0 ); // eslint-disable-line max-len + } + + /** + * Computes a matrix norm using alternative indexing semantics. + * + * @private + * @param {string} norm - norm type + * @param {(string|integer)} uplo - triangle type + * @param {(string|integer)} diag - diagonal type + * @param {NonNegativeInteger} M - number of rows + * @param {NonNegativeInteger} N - number of columns + * @param {Float64Array} A - matrix storage + * @param {integer} strideA1 - row stride + * @param {integer} strideA2 - column stride + * @param {NonNegativeInteger} offsetA - matrix offset + * @param {Float64Array} work - scratch storage + * @param {NonZeroInteger} strideWork - workspace stride + * @param {NonNegativeInteger} offsetWork - workspace offset + * @throws {TypeError} invalid option or storage type + * @throws {RangeError} invalid dimensions or indexed storage + * @returns {number} norm + */ + function ndarray( norm, uplo, diag, M, N, A, strideA1, strideA2, offsetA, work, strideWork, offsetWork ) { // eslint-disable-line max-len, max-params + var opts = validate( norm, uplo, diag, M, N ); + validateArrays( opts[0], M, N, A, strideA1, strideA2, offsetA, work, strideWork, offsetWork ); // eslint-disable-line max-len + return base( opts[0], opts[1], opts[2], M, N, A, strideA1, strideA2, offsetA, work, strideWork, offsetWork ); // eslint-disable-line max-len + } +} + + +// EXPORTS // + +module.exports = factory; diff --git a/lib/node_modules/@stdlib/lapack/base/dlantr/lib/index.js b/lib/node_modules/@stdlib/lapack/base/dlantr/lib/index.js new file mode 100644 index 000000000000..5091fcf310e2 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlantr/lib/index.js @@ -0,0 +1,60 @@ +/** +* @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'; + +/** +* Compute a norm of a double-precision triangular or trapezoidal matrix. +* +* @module @stdlib/lapack/base/dlantr +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var dlantr = require( '@stdlib/lapack/base/dlantr' ); +* +* var A = new Float64Array( [ 2.0, -3.0, 4.0, NaN, 5.0, -6.0 ] ); +* var work = new Float64Array( 2 ); +* +* var v = dlantr( 'row-major', 'infinity', 'upper', 'non-unit', 2, 3, A, 3, work ); +* // returns 11.0 +*/ + +// MODULES // + +var join = require( 'path' ).join; +var tryRequire = require( '@stdlib/utils/try-require' ); +var isError = require( '@stdlib/assert/is-error' ); +var main = require( './main.js' ); + + +// MAIN // + +var dlantr; +var tmp = tryRequire( join( __dirname, './native.js' ) ); +if ( isError( tmp ) ) { + dlantr = main; +} else { + dlantr = tmp; +} + + +// EXPORTS // + +module.exports = dlantr; + +// exports: { "ndarray": "dlantr.ndarray" } diff --git a/lib/node_modules/@stdlib/lapack/base/dlantr/lib/main.js b/lib/node_modules/@stdlib/lapack/base/dlantr/lib/main.js new file mode 100644 index 000000000000..4161ffa24f04 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlantr/lib/main.js @@ -0,0 +1,34 @@ +/** +* @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 factory = require( './factory.js' ); +var base = require( './base.js' ); + + +// MAIN // + +var dlantr = factory( base ); + + +// EXPORTS // + +module.exports = dlantr; diff --git a/lib/node_modules/@stdlib/lapack/base/dlantr/lib/native.js b/lib/node_modules/@stdlib/lapack/base/dlantr/lib/native.js new file mode 100644 index 000000000000..012fa15aef29 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlantr/lib/native.js @@ -0,0 +1,34 @@ +/** +* @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 factory = require( './factory.js' ); +var addon = require( './../src/addon.node' ); + + +// MAIN // + +var dlantr = factory( addon ); + + +// EXPORTS // + +module.exports = dlantr; diff --git a/lib/node_modules/@stdlib/lapack/base/dlantr/lib/validate.js b/lib/node_modules/@stdlib/lapack/base/dlantr/lib/validate.js new file mode 100644 index 000000000000..c5ab0b210f9f --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlantr/lib/validate.js @@ -0,0 +1,85 @@ +/** +* @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. +*/ + +// Cspell:ignore frobenius + +'use strict'; + +// MODULES // + +var resolveTriangle = require( '@stdlib/blas/base/matrix-triangle-resolve-enum' ); +var resolveDiagonal = require( '@stdlib/blas/base/diagonal-type-resolve-enum' ); +var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive; +var format = require( '@stdlib/string/format' ); + + +// VARIABLES // + +var NORMS = { + 'max': 77, + 'one': 49, + 'infinity': 73, + 'frobenius': 70 +}; + + +// MAIN // + +/** +* Validates the norm, triangular storage, diagonal type, and dimensions. +* +* @private +* @param {string} norm - norm type +* @param {(string|integer)} uplo - triangle type +* @param {(string|integer)} diag - diagonal type +* @param {NonNegativeInteger} M - number of rows +* @param {NonNegativeInteger} N - number of columns +* @throws {TypeError} invalid norm, triangle, or diagonal type +* @throws {RangeError} invalid trapezoidal dimensions +* @returns {Array} normalized options +*/ +function validate( norm, uplo, diag, M, N ) { + var n; + var u; + var d; + + if ( typeof norm !== 'string' || !Object.prototype.hasOwnProperty.call( NORMS, norm ) ) { + throw new TypeError( format( 'invalid argument. Norm must be "max", "one", "infinity", or "frobenius". Value: `%s`.', norm ) ); + } + n = NORMS[ norm ]; + u = resolveTriangle( uplo ); + if ( u === null ) { + throw new TypeError( format( 'invalid argument. Triangle must be "upper" or "lower". Value: `%s`.', uplo ) ); + } + d = resolveDiagonal( diag ); + if ( d === null ) { + throw new TypeError( format( 'invalid argument. Diagonal must be "unit" or "non-unit". Value: `%s`.', diag ) ); + } + if ( !isNonNegativeInteger( M ) || !isNonNegativeInteger( N ) ) { + throw new RangeError( 'invalid argument. Matrix dimensions must be nonnegative integers.' ); + } + if ( ( u === 121 && M > N ) || ( u === 122 && N > M ) ) { + throw new RangeError( 'invalid argument. Upper trapezoidal matrices require M <= N; lower trapezoidal matrices require N <= M.' ); + } + return [ n, u, d ]; +} + + +// EXPORTS // + +module.exports = validate; diff --git a/lib/node_modules/@stdlib/lapack/base/dlantr/lib/validate_arrays.js b/lib/node_modules/@stdlib/lapack/base/dlantr/lib/validate_arrays.js new file mode 100644 index 000000000000..223a19ca253f --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlantr/lib/validate_arrays.js @@ -0,0 +1,94 @@ +/** +* @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 isFloat64Array = require( '@stdlib/assert/is-float64array' ); +var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; +var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive; +var min = require( '@stdlib/math/base/special/min' ); +var max = require( '@stdlib/math/base/special/max' ); + + +// MAIN // + +/** +* Validates indexed input and workspace storage. +* +* @private +* @param {integer} norm - normalized norm +* @param {NonNegativeInteger} M - number of rows +* @param {NonNegativeInteger} N - number of columns +* @param {Float64Array} A - matrix +* @param {integer} sa1 - row stride +* @param {integer} sa2 - column stride +* @param {NonNegativeInteger} oa - matrix offset +* @param {Float64Array} work - scratch storage +* @param {integer} sw - workspace stride +* @param {NonNegativeInteger} ow - workspace offset +* @throws {TypeError} invalid storage +* @throws {RangeError} insufficient indexed elements +* @returns {void} +*/ +function validate( norm, M, N, A, sa1, sa2, oa, work, sw, ow ) { + var lo; + var hi; + var a; + var b; + + if ( M === 0 || N === 0 ) { + return; + } + if ( !isFloat64Array( A ) ) { + throw new TypeError( 'invalid argument. Matrix must be a Float64Array.' ); + } + if ( + !isInteger( sa1 ) || + !isInteger( sa2 ) || + !isNonNegativeInteger( oa ) + ) { + throw new RangeError( 'invalid argument. Matrix strides must be integers and its offset must be a nonnegative integer.' ); + } + a = (M-1)*sa1; + b = (N-1)*sa2; + lo = oa + min( 0, a ) + min( 0, b ); + hi = oa + max( 0, a ) + max( 0, b ); + if ( lo < 0 || hi >= A.length ) { + throw new RangeError( 'invalid argument. Matrix has insufficient indexed elements.' ); + } + if ( norm !== 73 ) { + return; + } + if ( !isFloat64Array( work ) ) { + throw new TypeError( 'invalid argument. Workspace must be a Float64Array.' ); + } + if ( !isInteger( sw ) || sw === 0 || !isNonNegativeInteger( ow ) ) { + throw new RangeError( 'invalid argument. Workspace stride must be a nonzero integer and its offset must be a nonnegative integer.' ); + } + a = (M-1)*sw; + if ( ow + min( 0, a ) < 0 || ow + max( 0, a ) >= work.length ) { + throw new RangeError( 'invalid argument. Workspace has insufficient indexed elements.' ); + } +} + + +// EXPORTS // + +module.exports = validate; diff --git a/lib/node_modules/@stdlib/lapack/base/dlantr/manifest.json b/lib/node_modules/@stdlib/lapack/base/dlantr/manifest.json new file mode 100644 index 000000000000..b663ab5b97bd --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlantr/manifest.json @@ -0,0 +1,120 @@ +{ + "options": { + "task": "build", + "wasm": false + }, + "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", + "wasm": false, + "src": [ + "./src/dlantr.c", + "./src/dlantr_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/lapack/base/shared", + "@stdlib/math/base/special/abs", + "@stdlib/math/base/special/sqrt", + "@stdlib/math/base/assert/is-nan", + "@stdlib/constants/float64/nan", + "@stdlib/constants/float64/pinf", + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-int32", + "@stdlib/napi/argv-float64array", + "@stdlib/napi/create-double" + ] + }, + { + "task": "benchmark", + "wasm": false, + "src": [ + "./src/dlantr.c", + "./src/dlantr_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/lapack/base/shared", + "@stdlib/math/base/special/abs", + "@stdlib/math/base/special/sqrt", + "@stdlib/math/base/assert/is-nan", + "@stdlib/constants/float64/nan", + "@stdlib/constants/float64/pinf" + ] + }, + { + "task": "examples", + "wasm": false, + "src": [ + "./src/dlantr.c", + "./src/dlantr_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/lapack/base/shared", + "@stdlib/math/base/special/abs", + "@stdlib/math/base/special/sqrt", + "@stdlib/math/base/assert/is-nan", + "@stdlib/constants/float64/nan", + "@stdlib/constants/float64/pinf" + ] + }, + { + "task": "", + "wasm": true, + "src": [ + "./src/dlantr.c", + "./src/dlantr_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/lapack/base/shared", + "@stdlib/math/base/special/abs", + "@stdlib/math/base/special/sqrt", + "@stdlib/math/base/assert/is-nan", + "@stdlib/constants/float64/nan", + "@stdlib/constants/float64/pinf" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/lapack/base/dlantr/package.json b/lib/node_modules/@stdlib/lapack/base/dlantr/package.json new file mode 100644 index 000000000000..fe52e01a9bfd --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlantr/package.json @@ -0,0 +1,75 @@ +{ + "name": "@stdlib/lapack/base/dlantr", + "version": "0.0.0", + "description": "Compute a norm of a double-precision triangular or trapezoidal matrix.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "browser": "./lib/main.js", + "gypfile": true, + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "include": "./include", + "lib": "./lib", + "src": "./src", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "math", + "mathematics", + "lapack", + "dlantr", + "norm", + "matrix", + "triangular", + "trapezoidal", + "frobenius", + "infinity", + "linear", + "algebra", + "float64", + "double", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/lapack/base/dlantr/src/Makefile b/lib/node_modules/@stdlib/lapack/base/dlantr/src/Makefile new file mode 100644 index 000000000000..2caf905cedbe --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlantr/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/lapack/base/dlantr/src/addon.c b/lib/node_modules/@stdlib/lapack/base/dlantr/src/addon.c new file mode 100644 index 000000000000..b548a492dee9 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlantr/src/addon.c @@ -0,0 +1,89 @@ +/** +* @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/lapack/base/dlantr.h" +#include "stdlib/napi/export.h" +#include "stdlib/napi/argv.h" +#include "stdlib/napi/argv_int32.h" +#include "stdlib/napi/argv_int64.h" +#include "stdlib/napi/argv_float64array.h" +#include "stdlib/napi/create_double.h" +#include +#include + +/** +* Receives JavaScript callback invocation data for the normalized ndarray kernel. +* +* @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 ) { + int64_t sw; + int64_t ow; + double *work; + double lo; + double hi; + double a; + double b; + + STDLIB_NAPI_ARGV( env, info, argv, argc, 12 ); + STDLIB_NAPI_ARGV_INT32( env, norm, argv, 0 ); + STDLIB_NAPI_ARGV_INT32( env, uplo, argv, 1 ); + STDLIB_NAPI_ARGV_INT32( env, diag, argv, 2 ); + STDLIB_NAPI_ARGV_INT64( env, M, argv, 3 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 4 ); + if ( M == 0 || N == 0 ) { + STDLIB_NAPI_CREATE_DOUBLE( env, 0.0, zero ); + return zero; + } + STDLIB_NAPI_ARGV_INT64( env, sa1, argv, 6 ); + STDLIB_NAPI_ARGV_INT64( env, sa2, argv, 7 ); + STDLIB_NAPI_ARGV_INT64( env, oa, argv, 8 ); + STDLIB_NAPI_ARGV_FLOAT64ARRAY( env, A, alen, argv, 5 ); + a = (double)(M-1) * (double)sa1; + b = (double)(N-1) * (double)sa2; + lo = (double)oa + ( (a < 0.0) ? a : 0.0 ) + ( (b < 0.0) ? b : 0.0 ); + hi = (double)oa + ( (a > 0.0) ? a : 0.0 ) + ( (b > 0.0) ? b : 0.0 ); + if ( M < 0 || N < 0 || oa < 0 || lo < 0.0 || hi >= (double)alen ) { + napi_throw_range_error( env, NULL, "invalid argument. Matrix has insufficient indexed elements." ); + return NULL; + } + sw = 1; + ow = 0; + work = NULL; + if ( norm == 'I' ) { + STDLIB_NAPI_ARGV_INT64( env, strideWork, argv, 10 ); + STDLIB_NAPI_ARGV_INT64( env, offsetWork, argv, 11 ); + sw = strideWork; + ow = offsetWork; + STDLIB_NAPI_ARGV_FLOAT64ARRAY( env, scratch, wlen, argv, 9 ); + a = (double)(M-1) * (double)sw; + lo = (double)ow + ( (a < 0.0) ? a : 0.0 ); + hi = (double)ow + ( (a > 0.0) ? a : 0.0 ); + if ( sw == 0 || ow < 0 || lo < 0.0 || hi >= (double)wlen ) { + napi_throw_range_error( env, NULL, "invalid argument. Workspace has insufficient indexed elements." ); + return NULL; + } + work = scratch; + } + STDLIB_NAPI_CREATE_DOUBLE( env, API_SUFFIX(c_dlantr_ndarray)( (char)norm, (LAPACK_UPLO)uplo, (LAPACK_DIAGONAL)diag, M, N, A, sa1, sa2, oa, work, sw, ow ), out ); + return out; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) diff --git a/lib/node_modules/@stdlib/lapack/base/dlantr/src/dlantr.c b/lib/node_modules/@stdlib/lapack/base/dlantr/src/dlantr.c new file mode 100644 index 000000000000..5c2fa094aed4 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlantr/src/dlantr.c @@ -0,0 +1,54 @@ +/** +* @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/lapack/base/dlantr.h" +#include "stdlib/constants/float64/nan.h" + +/** +* Computes a norm of a triangular or trapezoidal matrix. +* +* @param layout storage layout +* @param norm norm type: M, 1/O, I, or F/E (case-insensitive) +* @param uplo upper or lower trapezoidal storage +* @param diag unit or non-unit diagonal +* @param M number of rows +* @param N number of columns +* @param A input matrix +* @param LDA leading dimension +* @param work M-element scratch array for the infinity norm +* @return norm (NaN for invalid options or dimensions) +*/ +double API_SUFFIX(c_dlantr)( const LAPACK_LAYOUT layout, const char norm, const LAPACK_UPLO uplo, const LAPACK_DIAGONAL diag, const LAPACK_INT M, const LAPACK_INT N, const double *A, const LAPACK_INT LDA, double *work ) { + LAPACK_INT sa1; + LAPACK_INT sa2; + + if ( layout != LAPACK_ROW_MAJOR && layout != LAPACK_COL_MAJOR ) { + return STDLIB_CONSTANT_FLOAT64_NAN; + } + if ( LDA < 1 || ( layout == LAPACK_ROW_MAJOR && LDA < N ) || ( layout == LAPACK_COL_MAJOR && LDA < M ) ) { + return STDLIB_CONSTANT_FLOAT64_NAN; + } + if ( layout == LAPACK_COL_MAJOR ) { + sa1 = 1; + sa2 = LDA; + } else { + sa1 = LDA; + sa2 = 1; + } + return API_SUFFIX(c_dlantr_ndarray)( norm, uplo, diag, M, N, A, sa1, sa2, 0, work, 1, 0 ); +} diff --git a/lib/node_modules/@stdlib/lapack/base/dlantr/src/dlantr_ndarray.c b/lib/node_modules/@stdlib/lapack/base/dlantr/src/dlantr_ndarray.c new file mode 100644 index 000000000000..45ba716a3060 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlantr/src/dlantr_ndarray.c @@ -0,0 +1,152 @@ +/** +* @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/lapack/base/dlantr.h" +#include "stdlib/math/base/special/abs.h" +#include "stdlib/math/base/special/sqrt.h" +#include "stdlib/math/base/assert/is_nan.h" +#include "stdlib/constants/float64/nan.h" +#include "stdlib/constants/float64/pinf.h" +#include + +/** +* Computes a norm of a triangular or trapezoidal matrix using alternative indexing semantics. +* +* ## Notes +* +* - Adapted from LAPACK's DLANTR; see the accompanying NOTICE. +* - Frobenius accumulation uses scaled sums of squares, independently of DLASSQ's interface. +* +* @param norm norm type: M, 1/O, I, or F/E (case-insensitive) +* @param uplo upper or lower trapezoidal storage +* @param diag unit or non-unit diagonal +* @param M number of rows +* @param N number of columns +* @param A input matrix +* @param strideA1 row stride +* @param strideA2 column stride +* @param offsetA matrix offset +* @param work infinity norm scratch storage +* @param strideWork workspace stride +* @param offsetWork workspace offset +* @return norm (NaN for invalid options or dimensions) +*/ +double API_SUFFIX(c_dlantr_ndarray)( const char norm, const LAPACK_UPLO uplo, const LAPACK_DIAGONAL diag, const LAPACK_INT M, const LAPACK_INT N, const double *A, const LAPACK_INT strideA1, const LAPACK_INT strideA2, const LAPACK_INT offsetA, double *work, const LAPACK_INT strideWork, const LAPACK_INT offsetWork ) { + LAPACK_INT start; + LAPACK_INT stop; + LAPACK_INT i; + LAPACK_INT j; + double sumsq; + double scale; + double value; + double sum; + double ax; + double r; + bool unit; + char n; + + n = norm; + if ( n == 'm' ) { + n = 'M'; + } else if ( n == 'O' || n == 'o' ) { + n = '1'; + } else if ( n == 'i' ) { + n = 'I'; + } else if ( n == 'f' || n == 'E' || n == 'e' ) { + n = 'F'; + } + if ( n != 'M' && n != '1' && n != 'I' && n != 'F' ) { + return STDLIB_CONSTANT_FLOAT64_NAN; + } + if ( uplo != LAPACK_UPPER_TRIANGLE && uplo != LAPACK_LOWER_TRIANGLE ) { + return STDLIB_CONSTANT_FLOAT64_NAN; + } + if ( diag != LAPACK_UNIT_DIAGONAL && diag != LAPACK_NON_UNIT_DIAGONAL ) { + return STDLIB_CONSTANT_FLOAT64_NAN; + } + if ( M < 0 || N < 0 || ( uplo == LAPACK_UPPER_TRIANGLE && M > N ) || ( uplo == LAPACK_LOWER_TRIANGLE && N > M ) ) { + return STDLIB_CONSTANT_FLOAT64_NAN; + } + if ( M == 0 || N == 0 ) { + return 0.0; + } + if ( n == 'I' && strideWork == 0 ) { + return STDLIB_CONSTANT_FLOAT64_NAN; + } + unit = ( diag == LAPACK_UNIT_DIAGONAL ); + value = 0.0; + scale = 0.0; + sumsq = 1.0; + if ( n == 'I' ) { + for ( i = 0; i < M; i++ ) { + work[ offsetWork+(i*strideWork) ] = 0.0; + } + } + for ( j = 0; j < N; j++ ) { + if ( uplo == LAPACK_UPPER_TRIANGLE ) { + start = 0; + stop = ( j < M ) ? j : M-1; + } else { + start = j; + stop = M-1; + } + sum = 0.0; + for ( i = start; i <= stop; i++ ) { + ax = ( unit && i == j ) ? 1.0 : stdlib_base_abs( A[ offsetA+(i*strideA1)+(j*strideA2) ] ); + if ( n == 'M' ) { + if ( ax > value || stdlib_base_is_nan( ax ) ) { + value = ax; + } + } else if ( n == '1' ) { + sum += ax; + } else if ( n == 'I' ) { + work[ offsetWork+(i*strideWork) ] += ax; + } else { + if ( stdlib_base_is_nan( ax ) ) { + return STDLIB_CONSTANT_FLOAT64_NAN; + } + if ( ax == STDLIB_CONSTANT_FLOAT64_PINF ) { + scale = STDLIB_CONSTANT_FLOAT64_PINF; + } else if ( ax != 0.0 && scale != STDLIB_CONSTANT_FLOAT64_PINF ) { + if ( scale < ax ) { + r = scale / ax; + sumsq = 1.0 + ( sumsq*r*r ); + scale = ax; + } else { + r = ax / scale; + sumsq += r*r; + } + } + } + } + if ( n == '1' && ( sum > value || stdlib_base_is_nan( sum ) ) ) { + value = sum; + } + } + if ( n == 'I' ) { + for ( i = 0; i < M; i++ ) { + sum = work[ offsetWork+(i*strideWork) ]; + if ( sum > value || stdlib_base_is_nan( sum ) ) { + value = sum; + } + } + } else if ( n == 'F' ) { + value = scale * stdlib_base_sqrt( sumsq ); + } + return value; +} diff --git a/lib/node_modules/@stdlib/lapack/base/dlantr/test/fixtures/scipy/data.json b/lib/node_modules/@stdlib/lapack/base/dlantr/test/fixtures/scipy/data.json new file mode 100644 index 000000000000..c59b69b0cbf0 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlantr/test/fixtures/scipy/data.json @@ -0,0 +1,991 @@ +{ + "provenance": "SciPy 1.17.0 scipy.linalg.lapack.dlantr; seed12345; independently executed LAPACK oracle", + "records": [ + { + "name": "upper-rectangular-N", + "M": 2, + "N": 3, + "uplo": "upper", + "diag": "non-unit", + "A": [ + [ + 2.0, + -3.0, + 4.0 + ], + [ + "nan", + 5.0, + -6.0 + ] + ], + "expected": { + "max": 6.0, + "one": 10.0, + "infinity": 11.0, + "frobenius": 9.486832980505138 + } + }, + { + "name": "upper-rectangular-U", + "M": 2, + "N": 3, + "uplo": "upper", + "diag": "unit", + "A": [ + [ + "nan", + -3.0, + 4.0 + ], + [ + "nan", + "nan", + -6.0 + ] + ], + "expected": { + "max": 6.0, + "one": 10.0, + "infinity": 8.0, + "frobenius": 7.937253933193772 + } + }, + { + "name": "lower-rectangular-N", + "M": 3, + "N": 2, + "uplo": "lower", + "diag": "non-unit", + "A": [ + [ + 2.0, + "nan" + ], + [ + -3.0, + 5.0 + ], + [ + 4.0, + -6.0 + ] + ], + "expected": { + "max": 6.0, + "one": 11.0, + "infinity": 10.0, + "frobenius": 9.486832980505138 + } + }, + { + "name": "lower-rectangular-U", + "M": 3, + "N": 2, + "uplo": "lower", + "diag": "unit", + "A": [ + [ + "nan", + "nan" + ], + [ + -3.0, + "nan" + ], + [ + 4.0, + -6.0 + ] + ], + "expected": { + "max": 6.0, + "one": 8.0, + "infinity": 10.0, + "frobenius": 7.937253933193772 + } + }, + { + "name": "single-N", + "M": 1, + "N": 1, + "uplo": "upper", + "diag": "non-unit", + "A": [ + [ + 3.0 + ] + ], + "expected": { + "max": 3.0, + "one": 3.0, + "infinity": 3.0, + "frobenius": 3.0 + } + }, + { + "name": "single-U", + "M": 1, + "N": 1, + "uplo": "upper", + "diag": "unit", + "A": [ + [ + "nan" + ] + ], + "expected": { + "max": 1.0, + "one": 1.0, + "infinity": 1.0, + "frobenius": 1.0 + } + }, + { + "name": "zero-upper-N", + "M": 2, + "N": 2, + "uplo": "upper", + "diag": "non-unit", + "A": [ + [ + -0.0, + 0.0 + ], + [ + "nan", + -0.0 + ] + ], + "expected": { + "max": 0.0, + "one": 0.0, + "infinity": 0.0, + "frobenius": 0.0 + } + }, + { + "name": "zero-upper-U", + "M": 2, + "N": 2, + "uplo": "upper", + "diag": "unit", + "A": [ + [ + "nan", + 0.0 + ], + [ + "nan", + "nan" + ] + ], + "expected": { + "max": 1.0, + "one": 1.0, + "infinity": 1.0, + "frobenius": 1.4142135623730951 + } + }, + { + "name": "one-inf-N", + "M": 2, + "N": 2, + "uplo": "upper", + "diag": "non-unit", + "A": [ + [ + "pinf", + 2.0 + ], + [ + "nan", + 3.0 + ] + ], + "expected": { + "max": "pinf", + "one": "pinf", + "infinity": "pinf", + "frobenius": "pinf" + } + }, + { + "name": "one-inf-U", + "M": 2, + "N": 2, + "uplo": "upper", + "diag": "unit", + "A": [ + [ + "nan", + 2.0 + ], + [ + "nan", + "nan" + ] + ], + "expected": { + "max": 2.0, + "one": 3.0, + "infinity": 3.0, + "frobenius": 2.449489742783178 + } + }, + { + "name": "two-inf-N", + "M": 2, + "N": 2, + "uplo": "upper", + "diag": "non-unit", + "A": [ + [ + "pinf", + "pinf" + ], + [ + "nan", + 3.0 + ] + ], + "expected": { + "max": "pinf", + "one": "pinf", + "infinity": "pinf", + "frobenius": "pinf" + } + }, + { + "name": "two-inf-U", + "M": 2, + "N": 2, + "uplo": "upper", + "diag": "unit", + "A": [ + [ + "nan", + "pinf" + ], + [ + "nan", + "nan" + ] + ], + "expected": { + "max": "pinf", + "one": "pinf", + "infinity": "pinf", + "frobenius": "pinf" + } + }, + { + "name": "inf-nan-N", + "M": 2, + "N": 2, + "uplo": "upper", + "diag": "non-unit", + "A": [ + [ + "pinf", + "nan" + ], + [ + "nan", + 3.0 + ] + ], + "expected": { + "max": "nan", + "one": "nan", + "infinity": "nan", + "frobenius": "nan" + } + }, + { + "name": "inf-nan-U", + "M": 2, + "N": 2, + "uplo": "upper", + "diag": "unit", + "A": [ + [ + "nan", + "nan" + ], + [ + "nan", + "nan" + ] + ], + "expected": { + "max": "nan", + "one": "nan", + "infinity": "nan", + "frobenius": "nan" + } + }, + { + "name": "nan-inf-N", + "M": 2, + "N": 2, + "uplo": "upper", + "diag": "non-unit", + "A": [ + [ + "nan", + "pinf" + ], + [ + "nan", + 3.0 + ] + ], + "expected": { + "max": "nan", + "one": "nan", + "infinity": "nan", + "frobenius": "nan" + } + }, + { + "name": "nan-inf-U", + "M": 2, + "N": 2, + "uplo": "upper", + "diag": "unit", + "A": [ + [ + "nan", + "pinf" + ], + [ + "nan", + "nan" + ] + ], + "expected": { + "max": "pinf", + "one": "pinf", + "infinity": "pinf", + "frobenius": "pinf" + } + }, + { + "name": "huge-N", + "M": 2, + "N": 2, + "uplo": "upper", + "diag": "non-unit", + "A": [ + [ + 1e+300, + 1e+300 + ], + [ + "nan", + 1e+300 + ] + ], + "expected": { + "max": 1e+300, + "one": 2e+300, + "infinity": 2e+300, + "frobenius": 1.7320508075688774e+300 + } + }, + { + "name": "huge-U", + "M": 2, + "N": 2, + "uplo": "upper", + "diag": "unit", + "A": [ + [ + "nan", + 1e+300 + ], + [ + "nan", + "nan" + ] + ], + "expected": { + "max": 1e+300, + "one": 1e+300, + "infinity": 1e+300, + "frobenius": 1e+300 + } + }, + { + "name": "tiny-N", + "M": 2, + "N": 2, + "uplo": "upper", + "diag": "non-unit", + "A": [ + [ + 1e-300, + 1e-300 + ], + [ + "nan", + 1e-300 + ] + ], + "expected": { + "max": 1e-300, + "one": 2e-300, + "infinity": 2e-300, + "frobenius": 1.7320508075688774e-300 + } + }, + { + "name": "tiny-U", + "M": 2, + "N": 2, + "uplo": "upper", + "diag": "unit", + "A": [ + [ + "nan", + 1e-300 + ], + [ + "nan", + "nan" + ] + ], + "expected": { + "max": 1.0, + "one": 1.0, + "infinity": 1.0, + "frobenius": 1.4142135623730951 + } + }, + { + "name": "subnormal-N", + "M": 2, + "N": 2, + "uplo": "upper", + "diag": "non-unit", + "A": [ + [ + 5e-324, + 5e-324 + ], + [ + "nan", + 5e-324 + ] + ], + "expected": { + "max": 5e-324, + "one": 1e-323, + "infinity": 1e-323, + "frobenius": 1e-323 + } + }, + { + "name": "subnormal-U", + "M": 2, + "N": 2, + "uplo": "upper", + "diag": "unit", + "A": [ + [ + "nan", + 5e-324 + ], + [ + "nan", + "nan" + ] + ], + "expected": { + "max": 1.0, + "one": 1.0, + "infinity": 1.0, + "frobenius": 1.4142135623730951 + } + }, + { + "name": "mixed-scales-N", + "M": 2, + "N": 2, + "uplo": "upper", + "diag": "non-unit", + "A": [ + [ + 1e+300, + 1e-300 + ], + [ + "nan", + 1e+150 + ] + ], + "expected": { + "max": 1e+300, + "one": 1e+300, + "infinity": 1e+300, + "frobenius": 1e+300 + } + }, + { + "name": "mixed-scales-U", + "M": 2, + "N": 2, + "uplo": "upper", + "diag": "unit", + "A": [ + [ + "nan", + 1e-300 + ], + [ + "nan", + "nan" + ] + ], + "expected": { + "max": 1.0, + "one": 1.0, + "infinity": 1.0, + "frobenius": 1.4142135623730951 + } + }, + { + "name": "random-2x5-U-N", + "M": 2, + "N": 5, + "uplo": "upper", + "diag": "non-unit", + "A": [ + [ + -1.4238250364546312, + 1.2637284581291104, + -0.8706617379590857, + -0.2591732349343976, + -0.07534330701052097 + ], + [ + "nan", + -1.3677927017829434, + 0.6488928021930399, + 0.361058113054895, + -1.95286306301219 + ] + ], + "expected": { + "max": 1.95286306301219, + "one": 2.6315211599120536, + "infinity": 4.3306066800430685, + "frobenius": 3.2697312488265333 + } + }, + { + "name": "random-2x5-U-U", + "M": 2, + "N": 5, + "uplo": "upper", + "diag": "unit", + "A": [ + [ + "nan", + 1.2637284581291104, + -0.8706617379590857, + -0.2591732349343976, + -0.07534330701052097 + ], + [ + "nan", + "nan", + 0.6488928021930399, + 0.361058113054895, + -1.95286306301219 + ] + ], + "expected": { + "max": 1.95286306301219, + "one": 2.26372845812911, + "infinity": 3.962813978260125, + "frobenius": 2.965300630638824 + } + }, + { + "name": "random-5x2-L-N", + "M": 5, + "N": 2, + "uplo": "lower", + "diag": "non-unit", + "A": [ + [ + 2.347409654378852, + "nan" + ], + [ + -0.7593871804245066, + 0.9021982742122517 + ], + [ + -0.46695317332055025, + -0.06068951873702798 + ], + [ + 0.7888443445192008, + -1.2566681331396765 + ], + [ + 0.5758575143959287, + 1.3989789947237192 + ] + ], + "expected": { + "max": 2.347409654378852, + "one": 4.938451867039038, + "infinity": 2.347409654378852, + "frobenius": 3.4077757388518815 + } + }, + { + "name": "random-5x2-L-U", + "M": 5, + "N": 2, + "uplo": "lower", + "diag": "unit", + "A": [ + [ + "nan", + "nan" + ], + [ + -0.7593871804245066, + "nan" + ], + [ + -0.46695317332055025, + -0.06068951873702798 + ], + [ + 0.7888443445192008, + -1.2566681331396765 + ], + [ + 0.5758575143959287, + 1.3989789947237192 + ] + ], + "expected": { + "max": 1.3989789947237192, + "one": 3.716336646600424, + "infinity": 2.0455124776588773, + "frobenius": 2.6997484465862516 + } + }, + { + "name": "random-5x5-U-N", + "M": 5, + "N": 5, + "uplo": "upper", + "diag": "non-unit", + "A": [ + [ + 1.3222980607327857, + -0.29969851529910546, + 0.9029193414250598, + -1.6215827341822058, + -0.15818926067687128 + ], + [ + "nan", + -1.343601072486395, + -0.08168759069683368, + 1.7247399323163304, + 2.61815942636784 + ], + [ + "nan", + "nan", + -0.9589883130180109, + -1.2093882869743162, + -1.4122920134741184 + ], + [ + "nan", + "nan", + "nan", + -1.2286749856452768, + 0.2575577684128723 + ], + [ + "nan", + "nan", + "nan", + "nan", + -0.06615088900166237 + ] + ], + "expected": { + "max": 2.61815942636784, + "one": 5.784385939118129, + "infinity": 5.768188021867399, + "frobenius": 4.78609798626201 + } + }, + { + "name": "random-5x5-U-U", + "M": 5, + "N": 5, + "uplo": "upper", + "diag": "unit", + "A": [ + [ + "nan", + -0.29969851529910546, + 0.9029193414250598, + -1.6215827341822058, + -0.15818926067687128 + ], + [ + "nan", + "nan", + -0.08168759069683368, + 1.7247399323163304, + 2.61815942636784 + ], + [ + "nan", + "nan", + "nan", + -1.2093882869743162, + -1.4122920134741184 + ], + [ + "nan", + "nan", + "nan", + "nan", + 0.2575577684128723 + ], + [ + "nan", + "nan", + "nan", + "nan", + "nan" + ] + ], + "expected": { + "max": 2.61815942636784, + "one": 5.555710953472852, + "infinity": 5.424586949381004, + "frobenius": 4.681807469954924 + } + }, + { + "name": "random-5x5-L-N", + "M": 5, + "N": 5, + "uplo": "lower", + "diag": "non-unit", + "A": [ + [ + -1.1082144670930707, + "nan", + "nan", + "nan", + "nan" + ], + [ + 0.4336545370528692, + 0.277483659870901, + "nan", + "nan", + "nan" + ], + [ + -0.7950174561466702, + 0.3000309462866171, + -1.6027015921637315, + "nan", + "nan" + ], + [ + -0.07127080619178035, + 0.4740497302500454, + -0.4148537610713306, + 0.09771650001494636, + "nan" + ], + [ + -0.8572588238845005, + 0.6882817881370419, + -1.1545295832450446, + 0.6504523890909877, + -1.3883599526797445 + ] + ], + "expected": { + "max": 1.6027015921637315, + "one": 3.2654160903688907, + "infinity": 4.738882537037319, + "frobenius": 3.176092887841848 + } + }, + { + "name": "random-5x5-L-U", + "M": 5, + "N": 5, + "uplo": "lower", + "diag": "unit", + "A": [ + [ + "nan", + "nan", + "nan", + "nan", + "nan" + ], + [ + 0.4336545370528692, + "nan", + "nan", + "nan", + "nan" + ], + [ + -0.7950174561466702, + 0.3000309462866171, + "nan", + "nan", + "nan" + ], + [ + -0.07127080619178035, + 0.4740497302500454, + -0.4148537610713306, + "nan", + "nan" + ], + [ + -0.8572588238845005, + 0.6882817881370419, + -1.1545295832450446, + 0.6504523890909877, + "nan" + ] + ], + "expected": { + "max": 1.1545295832450446, + "one": 3.15720162327582, + "infinity": 4.3505225843575746, + "frobenius": 3.0457651386023863 + } + }, + { + "name": "random-1x5-U-N", + "M": 1, + "N": 5, + "uplo": "upper", + "diag": "non-unit", + "A": [ + [ + -0.9073824573718444, + -1.0954253073243774, + 0.007145694940042956, + 0.5343599029557071, + -1.0658078466234504 + ] + ], + "expected": { + "max": 1.0954253073243774, + "one": 1.0954253073243774, + "infinity": 3.610121209215422, + "frobenius": 1.8560273329452879 + } + }, + { + "name": "random-1x5-U-U", + "M": 1, + "N": 5, + "uplo": "upper", + "diag": "unit", + "A": [ + [ + "nan", + -1.0954253073243774, + 0.007145694940042956, + 0.5343599029557071, + -1.0658078466234504 + ] + ], + "expected": { + "max": 1.0954253073243774, + "one": 1.0954253073243774, + "infinity": 3.7027387518435773, + "frobenius": 1.903022474038032 + } + }, + { + "name": "random-5x1-L-N", + "M": 5, + "N": 1, + "uplo": "lower", + "diag": "non-unit", + "A": [ + [ + -0.18147274021444693 + ], + [ + 1.621951798510875 + ], + [ + -0.3173919456610792 + ], + [ + -0.8158149668879264 + ], + [ + 0.38657901734760186 + ] + ], + "expected": { + "max": 1.621951798510875, + "one": 3.3232104686219293, + "infinity": 1.621951798510875, + "frobenius": 1.8919289194248057 + } + }, + { + "name": "random-5x1-L-U", + "M": 5, + "N": 1, + "uplo": "lower", + "diag": "unit", + "A": [ + [ + "nan" + ], + [ + 1.621951798510875 + ], + [ + -0.3173919456610792 + ], + [ + -0.8158149668879264 + ], + [ + 0.38657901734760186 + ] + ], + "expected": { + "max": 1.621951798510875, + "one": 4.141737728407483, + "infinity": 1.621951798510875, + "frobenius": 2.13224357912387 + } + } + ] +} diff --git a/lib/node_modules/@stdlib/lapack/base/dlantr/test/fixtures/scipy/runner.py b/lib/node_modules/@stdlib/lapack/base/dlantr/test/fixtures/scipy/runner.py new file mode 100644 index 000000000000..7b4fb2480807 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlantr/test/fixtures/scipy/runner.py @@ -0,0 +1,83 @@ +#!/usr/bin/env python +# +# @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. + +"""Regenerate DLANTR fixtures using SciPy's independent LAPACK implementation.""" + +import json +import math +from pathlib import Path + +import numpy as np +import scipy +from scipy.linalg.lapack import dlantr + + +FILENAME = Path(__file__).with_name('data.json') +NORMS = {'max': 'M', 'one': '1', 'infinity': 'I', 'frobenius': 'F'} + + +def decode(value): + """Decode non-finite values stored as JSON strings.""" + if value == 'nan': + return math.nan + if value == 'pinf': + return math.inf + if value == 'ninf': + return -math.inf + return value + + +def encode(value): + """Encode non-finite values without non-standard JSON numbers.""" + if math.isnan(value): + return 'nan' + if math.isinf(value): + return 'pinf' if value > 0.0 else 'ninf' + return value + + +with FILENAME.open(encoding='utf-8') as handle: + data = json.load(handle) + +for record in data['records']: + matrix = np.array( + [[decode(x) for x in row] for row in record['A']], + dtype=np.float64, + order='F' + ) + assert matrix.shape == (record['M'], record['N']) + for name, norm in NORMS.items(): + oracle_result = dlantr( + norm, + matrix, + uplo='U' if record['uplo'] == 'upper' else 'L', + diag='U' if record['diag'] == 'unit' else 'N' + ) + record['expected'][name] = encode(oracle_result) + +data['provenance'] = ( + 'SciPy ' + scipy.__version__ + ' scipy.linalg.lapack.dlantr; ' + 'seed12345; independently executed LAPACK oracle' +) +with FILENAME.open('w', encoding='utf-8') as handle: + json.dump(data, handle, indent=2, allow_nan=False) + handle.write('\n') +print( + 'Regenerated ' + str(len(data['records'])*len(NORMS)) + + ' LAPACK results.' +) diff --git a/lib/node_modules/@stdlib/lapack/base/dlantr/test/shared.js b/lib/node_modules/@stdlib/lapack/base/dlantr/test/shared.js new file mode 100644 index 000000000000..eb6658343d73 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlantr/test/shared.js @@ -0,0 +1,281 @@ +/** +* @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 */ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Uint8Array = require( '@stdlib/array/uint8' ); +var ulpdiff = require( '@stdlib/number/float64/base/ulp-difference' ); +var max = require( '@stdlib/math/base/special/max' ); +var data = require( './fixtures/scipy/data.json' ); + + +// FUNCTIONS // + +/** +* Decodes JSON representations of non-finite floating-point values. +* +* @private +* @param {(number|string)} value - encoded value +* @returns {number} decoded value +*/ +function decode( value ) { + if ( value === 'nan' ) { + return NaN; + } + if ( value === 'pinf' ) { + return Infinity; + } + if ( value === 'ninf' ) { + return -Infinity; + } + return value; +} + +/** +* Asserts that a result agrees with the independently generated LAPACK oracle. +* +* @private +* @param {Object} t - test harness +* @param {number} actual - actual result +* @param {number} expected - expected result +* @param {string} message - test label +* @returns {void} +*/ +function compare( t, actual, expected, message ) { + if ( expected !== expected ) { + t.strictEqual( actual !== actual, true, message ); + } else if ( expected === Infinity || expected === 0.0 ) { + t.strictEqual( actual, expected, message ); + } else { + t.ok( ulpdiff( actual, expected ) <= 8, message ); + } +} + +/** +* Creates padded matrix storage with a nonzero backing-buffer byte offset. +* +* @private +* @param {Object} record - fixture record +* @param {integer} sa1 - row stride +* @param {integer} sa2 - column stride +* @param {NonNegativeInteger} oa - matrix offset +* @returns {Float64Array} matrix storage +*/ +function storage( record, sa1, sa2, oa ) { + var backing; + var span; + var out; + var i; + var j; + + span = oa + max( 0, (record.M-1)*sa1 ) + max( 0, (record.N-1)*sa2 ) + 4; + backing = new Float64Array( span+3 ); + out = new Float64Array( backing.buffer, 24, span ); + for ( i = 0; i < out.length; i++ ) { + out[ i ] = NaN; + } + for ( i = 0; i < record.M; i++ ) { + for ( j = 0; j < record.N; j++ ) { + out[ oa+(i*sa1)+(j*sa2) ] = decode( record.A[i][j] ); + } + } + return out; +} + + +// MAIN // + +/** +* Registers the public, JavaScript, or native interface behavior suite. +* +* @private +* @param {Function} dlantr - interface to test +* @param {string} name - backend name +* @param {Object} [opts] - test options +* @returns {void} +*/ +function suite( dlantr, name, opts ) { + opts = opts || {}; + + tape( name+': LAPACK oracle in padded row-major and column-major storage', opts, function test( t ) { + var record; + var before; + var norms; + var order; + var work; + var norm; + var lda; + var sa1; + var sa2; + var out; + var A; + var i; + var j; + var k; + + norms = [ 'max', 'one', 'infinity', 'frobenius' ]; + for ( i = 0; i < data.records.length; i++ ) { + record = data.records[i]; + for ( j = 0; j < 2; j++ ) { + order = ( j === 0 ) ? 'row-major' : 'column-major'; + lda = ( j === 0 ) ? record.N+2 : record.M+2; + sa1 = ( j === 0 ) ? lda : 1; + sa2 = ( j === 0 ) ? 1 : lda; + A = storage( record, sa1, sa2, 0 ); + before = new Uint8Array( new Uint8Array( A.buffer, A.byteOffset, A.byteLength ) ); + for ( k = 0; k < norms.length; k++ ) { + norm = norms[k]; + work = new Float64Array( record.M+2 ); + work[ record.M ] = 987.0; + out = dlantr( order, norm, record.uplo, record.diag, record.M, record.N, A, lda, work ); + compare( t, out, decode( record.expected[norm] ), record.name+' '+order+' '+norm ); + t.strictEqual( work[record.M], 987.0, 'workspace guard preserved' ); + } + t.deepEqual( new Uint8Array( A.buffer, A.byteOffset, A.byteLength ), before, 'input and matrix padding unchanged' ); + } + } + t.end(); + }); + + tape( name+': alternative strides, offsets, and negative workspace stride', opts, function test( t ) { + var record; + var before; + var norms; + var work; + var norm; + var sa1; + var sa2; + var out; + var oa; + var A; + var i; + var j; + var k; + var q; + + norms = [ 'max', 'one', 'infinity', 'frobenius' ]; + for ( i = 0; i < data.records.length; i++ ) { + record = data.records[i]; + for ( j = 0; j < 2; j++ ) { + sa1 = 2*(record.N+2); + sa2 = 2; + oa = 3; + if ( j === 1 ) { + oa += ((record.M-1)*sa1) + ((record.N-1)*sa2); + sa1 *= -1; + sa2 *= -1; + } + A = storage( record, sa1, sa2, oa ); + before = new Uint8Array( new Uint8Array( A.buffer, A.byteOffset, A.byteLength ) ); + for ( k = 0; k < norms.length; k++ ) { + norm = norms[k]; + work = new Float64Array( (record.M*2)+5 ); + for ( q = 0; q < work.length; q++ ) { + work[q] = 987.0; + } + out = dlantr.ndarray( norm, record.uplo, record.diag, record.M, record.N, A, sa1, sa2, oa, work, -2, record.M*2 ); + compare( t, out, decode( record.expected[norm] ), record.name+' ndarray '+norm ); + t.strictEqual( work[0], 987.0, 'workspace prefix guard preserved' ); + t.strictEqual( work[1], 987.0, 'workspace gap guard preserved' ); + t.strictEqual( work[work.length-1], 987.0, 'workspace suffix guard preserved' ); + } + t.deepEqual( new Uint8Array( A.buffer, A.byteOffset, A.byteLength ), before, 'input and matrix padding unchanged' ); + } + } + t.end(); + }); + + tape( name+': empty matrices and unused workspace are not accessed', opts, function test( t ) { + var norms; + var out; + var A; + var i; + + norms = [ 'max', 'one', 'infinity', 'frobenius' ]; + for ( i = 0; i < norms.length; i++ ) { + out = dlantr( 'row-major', norms[i], 'upper', 'unit', 0, 3, null, 3, null ); + t.strictEqual( 1.0/out, Infinity, 'zero rows return positive zero without storage' ); + out = dlantr.ndarray( norms[i], 'lower', 'non-unit', 3, 0, null, null, null, null, null, null, null ); + t.strictEqual( 1.0/out, Infinity, 'zero columns return positive zero without storage' ); + } + A = new Float64Array( [ 2.0 ] ); + out = dlantr.ndarray( 'max', 'upper', 'non-unit', 1, 1, A, 1, 1, 0, null, undefined, undefined ); + t.strictEqual( out, 2.0, 'non-infinity workspace and its indexing metadata ignored' ); + out = dlantr( 101, 'max', 121, 131, 1, 1, A, 1, null ); + t.strictEqual( out, 2.0, 'standard layout, triangle and diagonal enums supported' ); + out = dlantr.ndarray( 'one', 'upper', 'non-unit', 1, 3, A, 0, 0, 0, null, 0, 0 ); + t.strictEqual( out, 2.0, 'zero input strides preserve aliasing semantics for column sums' ); + t.end(); + }); + + tape( name+': invalid options and storage throw before numerical evaluation', opts, function test( t ) { + var work = new Float64Array( 2 ); + var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + t.throws( function f() { + dlantr( 'bad', 'max', 'upper', 'unit', 2, 2, A, 2, work ); + }, TypeError, 'invalid layout' ); + t.throws( function f() { + dlantr( 'row-major', '__proto__', 'upper', 'unit', 2, 2, A, 2, work ); + }, TypeError, 'inherited norm property rejected' ); + t.throws( function f() { + dlantr( 'row-major', 'max', 'all', 'unit', 2, 2, A, 2, work ); + }, TypeError, 'invalid triangle' ); + t.throws( function f() { + dlantr( 'row-major', 'max', 'upper', 'bad', 2, 2, A, 2, work ); + }, TypeError, 'invalid diagonal' ); + t.throws( function f() { + dlantr( 'row-major', 'max', 'upper', 'unit', 3, 2, A, 2, work ); + }, RangeError, 'invalid upper trapezoid' ); + t.throws( function f() { + dlantr( 'row-major', 'max', 'lower', 'unit', 2, 3, A, 3, work ); + }, RangeError, 'invalid lower trapezoid' ); + t.throws( function f() { + dlantr( 'row-major', 'max', 'upper', 'unit', -1, 2, A, 2, work ); + }, RangeError, 'negative dimensions' ); + t.throws( function f() { + dlantr( 'row-major', 'max', 'upper', 'unit', 1.5, 2, A, 2, work ); + }, RangeError, 'fractional dimensions' ); + t.throws( function f() { + dlantr( 'column-major', 'max', 'upper', 'unit', 2, 2, A, 1, work ); + }, RangeError, 'small leading dimension' ); + t.throws( function f() { + dlantr( 'row-major', 'max', 'upper', 'unit', 2, 2, [], 2, work ); + }, TypeError, 'matrix must be typed storage' ); + t.throws( function f() { + dlantr( 'row-major', 'infinity', 'upper', 'unit', 2, 2, A, 2, new Float64Array( 1 ) ); + }, RangeError, 'small workspace' ); + t.throws( function f() { + dlantr.ndarray( 'infinity', 'upper', 'unit', 2, 2, A, 2, 1, 0, work, 0, 0 ); + }, RangeError, 'zero workspace stride' ); + t.throws( function f() { + dlantr.ndarray( 'max', 'upper', 'unit', 2, 2, A, -2, -1, 0, work, 1, 0 ); + }, RangeError, 'negative indexed input position' ); + t.end(); + }); +} + + +// EXPORTS // + +module.exports = suite; diff --git a/lib/node_modules/@stdlib/lapack/base/dlantr/test/test.js b/lib/node_modules/@stdlib/lapack/base/dlantr/test/test.js new file mode 100644 index 000000000000..cb00d780e8c2 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlantr/test/test.js @@ -0,0 +1,39 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var dlantr = require( './../lib' ); +var suite = require( './shared.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dlantr, 'function', 'main export is a function' ); + t.strictEqual( dlantr.length, 9, 'main arity is 9' ); + t.strictEqual( typeof dlantr.ndarray, 'function', 'ndarray method exists' ); + t.strictEqual( dlantr.ndarray.length, 12, 'ndarray arity is 12' ); + t.end(); +}); + +suite( dlantr, 'public' ); diff --git a/lib/node_modules/@stdlib/lapack/base/dlantr/test/test.main.js b/lib/node_modules/@stdlib/lapack/base/dlantr/test/test.main.js new file mode 100644 index 000000000000..2cf84666bfca --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlantr/test/test.main.js @@ -0,0 +1,39 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var dlantr = require( './../lib/main.js' ); +var suite = require( './shared.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dlantr, 'function', 'main export is a function' ); + t.strictEqual( dlantr.length, 9, 'main arity is 9' ); + t.strictEqual( typeof dlantr.ndarray, 'function', 'ndarray method exists' ); + t.strictEqual( dlantr.ndarray.length, 12, 'ndarray arity is 12' ); + t.end(); +}); + +suite( dlantr, 'JavaScript' ); diff --git a/lib/node_modules/@stdlib/lapack/base/dlantr/test/test.native.js b/lib/node_modules/@stdlib/lapack/base/dlantr/test/test.native.js new file mode 100644 index 000000000000..d25212885168 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlantr/test/test.native.js @@ -0,0 +1,48 @@ +/** +* @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 tryRequire = require( '@stdlib/utils/try-require' ); +var suite = require( './shared.js' ); + + +// VARIABLES // + +var dlantr = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( dlantr instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dlantr, 'function', 'main export is a function' ); + t.strictEqual( dlantr.length, 9, 'main arity is 9' ); + t.strictEqual( typeof dlantr.ndarray, 'function', 'ndarray method exists' ); + t.strictEqual( dlantr.ndarray.length, 12, 'ndarray arity is 12' ); + t.end(); +}); + +suite( dlantr, 'native', opts );