diff --git a/lib/node_modules/@stdlib/blas/base/ctrsm/README.md b/lib/node_modules/@stdlib/blas/base/ctrsm/README.md new file mode 100644 index 000000000000..6e78e116804b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ctrsm/README.md @@ -0,0 +1,158 @@ + + +# ctrsm + +> Solve one of the matrix equations `op(A)*X = alpha*B` or `X*op(A) = alpha*B`. + +
+ +## Usage + +```javascript +var ctrsm = require( '@stdlib/blas/base/ctrsm' ); +``` + +#### ctrsm( order, side, uplo, transa, diag, M, N, alpha, A, LDA, B, LDB ) + +Solves one of the matrix equations `op(A)*X = alpha*B` or `X*op(A) = alpha*B` where `alpha` is a scalar, `X` and `B` are `M` by `N` matrices, `A` is a unit or non-unit upper or lower triangular matrix, and `op(A)` is one of `op(A) = A`, `op(A) = A^T`, or `op(A) = A^H`. The matrix `X` is overwritten on `B`. + +```javascript +var Complex64Array = require( '@stdlib/array/complex64' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); + +var A = new Complex64Array( [ 2.0, 0.0, 1.0, 0.0, 0.0, 0.0, 2.0, 0.0 ] ); +var B = new Complex64Array( [ 4.0, 0.0, 2.0, 0.0 ] ); +var alpha = new Complex64( 1.0, 0.0 ); + +ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, alpha, A, 2, B, 1 ); +// B => [ 1.5, 0.0, 1.0, 0.0 ] +``` + +The function has the following parameters: + +- **order**: storage layout. +- **side**: specifies whether `A` appears on the `'left'` or `'right'` of `X`. +- **uplo**: specifies whether the `'upper'` or `'lower'` triangular part of `A` is used. +- **transa**: transpose operation applied to `A` (`'no-transpose'`, `'transpose'`, or `'conjugate-transpose'`). +- **diag**: specifies whether `A` is `'unit'` or `'non-unit'` triangular. +- **M**: number of rows in `B`. +- **N**: number of columns in `B`. +- **alpha**: scalar constant of type `Complex64`. +- **A**: input triangular matrix stored in a `Complex64Array`. +- **LDA**: stride of the first dimension of `A` (a.k.a., leading dimension of `A`). +- **B**: input/output matrix stored in a `Complex64Array`. On exit, overwritten with solution `X`. +- **LDB**: stride of the first dimension of `B` (a.k.a., leading dimension of `B`). + +#### ctrsm.ndarray( ord, sd, ul, ta, dg, M, N, aRe, aIm, A, sa1, oa, B, sb1, ob ) + +Solves one of the matrix equations using alternative indexing semantics. + +```javascript +var Complex64Array = require( '@stdlib/array/complex64' ); + +var A = new Complex64Array( [ 2.0, 0.0, 1.0, 0.0, 0.0, 0.0, 2.0, 0.0 ] ); +var B = new Complex64Array( [ 4.0, 0.0, 2.0, 0.0 ] ); + +ctrsm.ndarray( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, 1.0, 0.0, A, 2, 0, B, 1, 0 ); +// B => [ 1.5, 0.0, 1.0, 0.0 ] +``` + +The function accepts the following additional parameters: + +- **aRe**: real part of scalar constant `alpha`. +- **aIm**: imaginary part of scalar constant `alpha`. +- **sa1**: stride of the first dimension of `A`. +- **oa**: starting index for `A`. +- **sb1**: stride of the first dimension of `B`. +- **ob**: starting index for `B`. + +
+ + + +
+ +## Notes + +- `ctrsm()` corresponds to the [BLAS][blas] level 3 function [`ctrsm`][blas-ctrsm]. +- Neither routine tests for singularity or near-singularity of `A`. Such tests must be performed before calling these routines. + +
+ + + +
+ +## Examples + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var ctrsm = require( '@stdlib/blas/base/ctrsm' ); + +var N = 3; + +var opts = { + 'dtype': 'complex64' +}; +var A = discreteUniform( N * N, -10, 10, opts ); +var B = discreteUniform( N * N, -10, 10, opts ); +var alpha = new Complex64( 1.0, 0.0 ); + +ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', N, N, alpha, A, N, B, N ); +console.log( B ); +``` + +
+ + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/base/ctrsm/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/base/ctrsm/benchmark/benchmark.js new file mode 100644 index 000000000000..b5c8cc85df08 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ctrsm/benchmark/benchmark.js @@ -0,0 +1,115 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var ctrsm = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} N - matrix dimension +* @returns {Function} benchmark function +*/ +function createBenchmark( N ) { + var alpha; + var abuf; + var bbuf; + var A; + var B; + + abuf = uniform( N*N*2, -100.0, 100.0, options ); + bbuf = uniform( N*N*2, -100.0, 100.0, options ); + A = new Complex64Array( abuf.buffer ); + B = new Complex64Array( bbuf.buffer ); + alpha = new Complex64( 1.0, 0.0 ); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', N, N, alpha, A, N, B, N ); + if ( isnanf( bbuf[ i%(N*N*2) ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( bbuf[ i%(N*N*2) ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 3; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:order=row-major,side=left,uplo=upper,trans=no-transpose,diag=non-unit,M=%d,N=%d', pkg, len, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/ctrsm/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/base/ctrsm/benchmark/benchmark.native.js new file mode 100644 index 000000000000..544d05243bbd --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ctrsm/benchmark/benchmark.native.js @@ -0,0 +1,120 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var ctrsm = tryRequire( resolve( __dirname, './../lib/ctrsm.native.js' ) ); +var opts = { + 'skip': ( ctrsm instanceof Error ) +}; +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} N - matrix dimension +* @returns {Function} benchmark function +*/ +function createBenchmark( N ) { + var alpha; + var abuf; + var bbuf; + var A; + var B; + + abuf = uniform( N*N*2, -100.0, 100.0, options ); + bbuf = uniform( N*N*2, -100.0, 100.0, options ); + A = new Complex64Array( abuf.buffer ); + B = new Complex64Array( bbuf.buffer ); + alpha = new Complex64( 1.0, 0.0 ); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', N, N, alpha, A, N, B, N ); + if ( isnanf( bbuf[ i%(N*N*2) ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( bbuf[ i%(N*N*2) ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 3; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s::native:order=row-major,side=left,uplo=upper,trans=no-transpose,diag=non-unit,M=%d,N=%d', pkg, len, len ), opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/ctrsm/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/base/ctrsm/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..7e81a62fc1a4 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ctrsm/benchmark/benchmark.ndarray.js @@ -0,0 +1,112 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var ctrsm = require( './../lib/ndarray.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} N - matrix dimension +* @returns {Function} benchmark function +*/ +function createBenchmark( N ) { + var abuf; + var bbuf; + var A; + var B; + + abuf = uniform( N*N*2, -100.0, 100.0, options ); + bbuf = uniform( N*N*2, -100.0, 100.0, options ); + A = new Complex64Array( abuf.buffer ); + B = new Complex64Array( bbuf.buffer ); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', N, N, 1.0, 0.0, A, N, 0, B, N, 0 ); + if ( isnanf( bbuf[ i%(N*N*2) ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( bbuf[ i%(N*N*2) ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 3; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:ndarray:order=row-major,side=left,uplo=upper,trans=no-transpose,diag=non-unit,M=%d,N=%d', pkg, len, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/ctrsm/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/base/ctrsm/benchmark/benchmark.ndarray.native.js new file mode 100644 index 000000000000..cbb46bce6c7b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ctrsm/benchmark/benchmark.ndarray.native.js @@ -0,0 +1,117 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var ctrsm = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); +var opts = { + 'skip': ( ctrsm instanceof Error ) +}; +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} N - matrix dimension +* @returns {Function} benchmark function +*/ +function createBenchmark( N ) { + var abuf; + var bbuf; + var A; + var B; + + abuf = uniform( N*N*2, -100.0, 100.0, options ); + bbuf = uniform( N*N*2, -100.0, 100.0, options ); + A = new Complex64Array( abuf.buffer ); + B = new Complex64Array( bbuf.buffer ); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', N, N, 1.0, 0.0, A, N, 0, B, N, 0 ); + if ( isnanf( bbuf[ i%(N*N*2) ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( bbuf[ i%(N*N*2) ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 3; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s::native:ndarray:order=row-major,side=left,uplo=upper,trans=no-transpose,diag=non-unit,M=%d,N=%d', pkg, len, len ), opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/ctrsm/benchmark/c/Makefile b/lib/node_modules/@stdlib/blas/base/ctrsm/benchmark/c/Makefile new file mode 100644 index 000000000000..0756dc7da20a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ctrsm/benchmark/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := benchmark.length.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled benchmarks. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/blas/base/ctrsm/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/base/ctrsm/benchmark/c/benchmark.length.c new file mode 100644 index 000000000000..24774af5cd8a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ctrsm/benchmark/c/benchmark.length.c @@ -0,0 +1,201 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/blas/base/ctrsm.h" +#include "stdlib/complex/float32/ctor.h" +#include +#include +#include +#include +#include + +#define NAME "ctrsm" +#define ITERATIONS 1000000 +#define REPEATS 3 +#define MIN 1 +#define MAX 3 + +/** +* Prints the TAP version. +*/ +static void print_version( void ) { + printf( "TAP version 13\n" ); +} + +/** +* Prints the TAP summary. +* +* @param total total number of tests +* @param passing total number of passing tests +*/ +static void print_summary( int total, int passing ) { + printf( "#\n" ); + printf( "1..%d\n", total ); + printf( "# total %d\n", total ); + printf( "# pass %d\n", passing ); + printf( "#\n" ); + printf( "# ok\n" ); +} + +/** +* Prints benchmark results. +* +* @param iterations number of iterations +* @param elapsed elapsed time in seconds +*/ +static void print_results( int iterations, double elapsed ) { + double rate = (double)iterations / elapsed; + printf( " ---\n" ); + printf( " iterations: %d\n", iterations ); + printf( " elapsed: %0.9f\n", elapsed ); + printf( " rate: %0.9f\n", rate ); + printf( " ...\n" ); +} + +/** +* Returns a clock time. +* +* @return clock time +*/ +static double tic( void ) { + struct timeval now; + gettimeofday( &now, NULL ); + return (double)now.tv_sec + (double)now.tv_usec/1.0e6; +} + +/** +* Generates a random float on the interval [0,1). +* +* @return random number +*/ +static float rand_float( void ) { + int r = rand(); + return (float)r / ( (float)RAND_MAX + 1.0f ); +} + +/** +* Runs a benchmark (base interface). +* +* @param iterations number of iterations +* @param N matrix dimension +* @return elapsed time in seconds +*/ +static double benchmark1( int iterations, int N ) { + stdlib_complex64_t alpha; + float *A; + float *B; + double elapsed; + double t; + int i; + + alpha = stdlib_complex64( 1.0f, 0.0f ); + A = (float *) malloc( N * N * 2 * sizeof( float ) ); + B = (float *) malloc( N * N * 2 * sizeof( float ) ); + for ( i = 0; i < N*N*2; i++ ) { + A[ i ] = ( rand_float()*2.0f ) - 1.0f; + B[ i ] = ( rand_float()*2.0f ) - 1.0f; + } + t = tic(); + for ( i = 0; i < iterations; i++ ) { + c_ctrsm( CblasRowMajor, CblasLeft, CblasUpper, CblasNoTrans, CblasNonUnit, N, N, alpha, (const void *)A, N, (void *)B, N ); + if ( B[ 0 ] != B[ 0 ] ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( B[ 0 ] != B[ 0 ] ) { + printf( "should not return NaN\n" ); + } + free( A ); + free( B ); + return elapsed; +} + +/** +* Runs a benchmark (ndarray interface). +* +* @param iterations number of iterations +* @param N matrix dimension +* @return elapsed time in seconds +*/ +static double benchmark2( int iterations, int N ) { + float *A; + float *B; + double elapsed; + double t; + int i; + + A = (float *) malloc( N * N * 2 * sizeof( float ) ); + B = (float *) malloc( N * N * 2 * sizeof( float ) ); + for ( i = 0; i < N*N*2; i++ ) { + A[ i ] = ( rand_float()*2.0f ) - 1.0f; + B[ i ] = ( rand_float()*2.0f ) - 1.0f; + } + t = tic(); + for ( i = 0; i < iterations; i++ ) { + c_ctrsm_ndarray( CblasRowMajor, CblasLeft, CblasUpper, CblasNoTrans, CblasNonUnit, N, N, 1.0f, 0.0f, (const void *)A, N, 0, (void *)B, N, 0 ); + if ( B[ 0 ] != B[ 0 ] ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( B[ 0 ] != B[ 0 ] ) { + printf( "should not return NaN\n" ); + } + free( A ); + free( B ); + return elapsed; +} + +/** +* Main execution sequence. +*/ +int main( void ) { + double elapsed; + int count; + int iter; + int len; + int i; + int j; + + srand( time( NULL ) ); + + print_version(); + count = 0; + for ( i = MIN; i <= MAX; i++ ) { + len = (int)pow( 10, i ); + iter = ITERATIONS / (int)pow( 10, i-1 ); + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s:N=%d\n", NAME, len ); + elapsed = benchmark1( iter, len ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s:ndarray:N=%d\n", NAME, len ); + elapsed = benchmark2( iter, len ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + } + print_summary( count, count ); +} diff --git a/lib/node_modules/@stdlib/blas/base/ctrsm/benchmark/fortran/Makefile b/lib/node_modules/@stdlib/blas/base/ctrsm/benchmark/fortran/Makefile new file mode 100644 index 000000000000..2af88088a9bb --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ctrsm/benchmark/fortran/Makefile @@ -0,0 +1,141 @@ +#/ +# @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 Fortran source files: +ifdef FORTRAN_COMPILER + FC := $(FORTRAN_COMPILER) +else + FC := gfortran +endif + +# Define the command-line options when compiling Fortran files: +FFLAGS ?= \ + -std=f95 \ + -ffree-form \ + -O3 \ + -Wall \ + -Wextra \ + -Wno-compare-reals \ + -Wimplicit-interface \ + -fno-underscoring \ + -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 ?= + +# List of Fortran source files: +SOURCE_FILES ?= ../../src/cscal.f + +# List of Fortran targets: +f_targets := benchmark.length.out + + +# RULES # + +#/ +# Compiles Fortran source files. +# +# @param {string} SOURCE_FILES - list of Fortran source files +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) +# @param {string} [FORTRAN_COMPILER] - Fortran compiler +# @param {string} [FFLAGS] - Fortran compiler flags +# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code +# +# @example +# make +# +# @example +# make all +#/ +all: $(f_targets) + +.PHONY: all + +#/ +# Compiles Fortran source files. +# +# @private +# @param {string} SOURCE_FILES - list of Fortran source files +# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) +# @param {string} FC - Fortran compiler +# @param {string} FFLAGS - Fortran compiler flags +# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code +#/ +$(f_targets): %.out: %.f + $(QUIET) $(FC) $(FFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< + +#/ +# Runs compiled benchmarks. +# +# @example +# make run +#/ +run: $(f_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/blas/base/ctrsm/benchmark/fortran/benchmark.length.f b/lib/node_modules/@stdlib/blas/base/ctrsm/benchmark/fortran/benchmark.length.f new file mode 100644 index 000000000000..f7c701c3c5f0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ctrsm/benchmark/fortran/benchmark.length.f @@ -0,0 +1,226 @@ +!> +! @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. +!< + +!> Benchmarks. +! +! ## Notes +! +! - Written in "free form" Fortran 95. +! +!< +program bench + implicit none + ! .. + ! Local constants: + character(5), parameter :: name = 'ctrsm' ! if changed, be sure to adjust length + integer, parameter :: iterations = 1000000 + integer, parameter :: repeats = 3 + integer, parameter :: min = 1 + integer, parameter :: max = 3 + ! .. + ! Run the benchmarks: + call main() + ! .. + ! Functions: +contains + ! .. + ! Prints the TAP version. + ! .. + subroutine print_version() + print '(A)', 'TAP version 13' + end subroutine print_version + ! .. + ! Prints the TAP summary. + ! + ! @param {integer} total - total number of tests + ! @param {integer} passing - total number of passing tests + ! .. + subroutine print_summary( total, passing ) + ! .. + ! Scalar arguments: + integer, intent(in) :: total, passing + ! .. + ! Local variables: + character(len=999) :: str, tmp + ! .. + ! Intrinsic functions: + intrinsic adjustl, trim + ! .. + print '(A)', '#' + ! .. + write (str, '(I15)') total ! TAP plan + tmp = adjustl( str ) + print '(A,A)', '1..', trim( tmp ) + ! .. + print '(A,A)', '# total ', trim( tmp ) + ! .. + write (str, '(I15)') passing + tmp = adjustl( str ) + print '(A,A)', '# pass ', trim( tmp ) + ! .. + print '(A)', '#' + print '(A)', '# ok' + end subroutine print_summary + ! .. + ! Prints benchmarks results. + ! + ! @param {integer} iterations - number of iterations + ! @param {double} elapsed - elapsed time in seconds + ! .. + subroutine print_results( iterations, elapsed ) + ! .. + ! Scalar arguments: + double precision, intent(in) :: elapsed + integer, intent(in) :: iterations + ! .. + ! Local variables: + double precision :: rate + character(len=999) :: str, tmp + ! .. + ! Intrinsic functions: + intrinsic dble, adjustl, trim + ! .. + rate = dble( iterations ) / elapsed + ! .. + print '(A)', ' ---' + ! .. + write (str, '(I15)') iterations + tmp = adjustl( str ) + print '(A,A)', ' iterations: ', trim( tmp ) + ! .. + write (str, '(f100.9)') elapsed + tmp = adjustl( str ) + print '(A,A)', ' elapsed: ', trim( tmp ) + ! .. + write( str, '(f100.9)') rate + tmp = adjustl( str ) + print '(A,A)', ' rate: ', trim( tmp ) + ! .. + print '(A)', ' ...' + end subroutine print_results + ! .. + ! Runs a benchmark. + ! + ! @param {integer} iterations - number of iterations + ! @param {integer} N - matrix dimension + ! @return {double} elapsed time in seconds + ! .. + double precision function benchmark( iterations, N ) + ! .. + ! External functions: + interface + subroutine ctrsm( side, uplo, transa, diag, M, N, alpha, A, LDA, B, LDB ) + complex :: alpha, A(*), B(*) + integer :: M, N, LDA, LDB + character :: side, uplo, transa, diag + end subroutine ctrsm + end interface + ! .. + ! Scalar arguments: + integer, intent(in) :: iterations, N + ! .. + ! Local scalars: + double precision :: elapsed, r1, r2 + real :: t1, t2 + integer :: i + ! .. + ! Local arrays: + complex, allocatable :: A(:,:), B(:,:) + ! .. + ! Local scalar: + complex :: alpha + ! .. + ! Intrinsic functions: + intrinsic random_number, cpu_time, cmplx + ! .. + ! Allocate arrays: + allocate( A(N,N) ) + allocate( B(N,N) ) + ! .. + call random_number( r1 ) + call random_number( r2 ) + alpha = cmplx( (real(r1)*0.5), (real(r2)*0.5) ) + do i = 1, N*N + call random_number( r1 ) + call random_number( r2 ) + A( mod(i-1,N)+1, (i-1)/N+1 ) = cmplx( real(r1)*10.0-5.0, real(r2)*10.0-5.0 ) + B( mod(i-1,N)+1, (i-1)/N+1 ) = cmplx( real(r1)*10.0-5.0, real(r2)*10.0-5.0 ) + end do + ! .. + call cpu_time( t1 ) + ! .. + do i = 1, iterations + call ctrsm( 'L', 'U', 'N', 'N', N, N, alpha, A, N, B, N ) + if ( B(1,1) /= B(1,1) ) then + print '(A)', 'should not return NaN' + exit + end if + end do + ! .. + call cpu_time( t2 ) + ! .. + elapsed = t2 - t1 + ! .. + if ( B(1,1) /= B(1,1) ) then + print '(A)', 'should not return NaN' + end if + ! .. + ! Deallocate arrays: + deallocate( A ) + deallocate( B ) + ! .. + benchmark = elapsed + return + end function benchmark + ! .. + ! Main execution sequence. + ! .. + subroutine main() + ! .. + ! Local variables: + integer :: count, iter, len, i, j + double precision :: elapsed + character(len=999) :: str, tmp + ! .. + ! Intrinsic functions: + intrinsic adjustl, trim + ! .. + call print_version() + count = 0 + do i = min, max + len = 10**i + iter = iterations / 10**(i-1) + do j = 1, repeats + count = count + 1 + ! .. + write (str, '(I15)') len + tmp = adjustl( str ) + print '(A,A,A,A)', '# fortran::', name, ':N=', trim( tmp ) + ! .. + elapsed = benchmark( iter, len ) + ! .. + call print_results( iter, elapsed ) + ! .. + write (str, '(I15)') count + tmp = adjustl( str ) + print '(A,A,A)', 'ok ', trim( tmp ), ' benchmark finished' + end do + end do + call print_summary( count, count ) + end subroutine main +end program bench diff --git a/lib/node_modules/@stdlib/blas/base/ctrsm/binding.gyp b/lib/node_modules/@stdlib/blas/base/ctrsm/binding.gyp new file mode 100644 index 000000000000..60dce9d0b31a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ctrsm/binding.gyp @@ -0,0 +1,265 @@ +# @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', + + # Fortran compiler (to override -Dfortran_compiler=): + 'fortran_compiler%': 'gfortran', + + # Fortran compiler flags: + 'fflags': [ + # Specify the Fortran standard to which a program is expected to conform: + '-std=f95', + + # Indicate that the layout is free-form source code: + '-ffree-form', + + # Aggressive optimization: + '-O3', + + # Enable commonly used warning options: + '-Wall', + + # Warn if source code contains problematic language features: + '-Wextra', + + # Warn if a procedure is called without an explicit interface: + '-Wimplicit-interface', + + # Do not transform names of entities specified in Fortran source files by appending underscores (i.e., don't mangle names, thus allowing easier usage in C wrappers): + '-fno-underscoring', + + # Warn if source code contains Fortran 95 extensions and C-language constructs: + '-pedantic', + + # Compile but do not link (output is an object file): + '-c', + ], + + # Set variables based on the host OS: + 'conditions': [ + [ + 'OS=="win"', + { + # Define the object file suffix: + 'obj': 'obj', + }, + { + # Define the object file suffix: + 'obj': 'o', + } + ], # end condition (OS=="win") + ], # end conditions + }, # end variables + + # Define compile targets: + 'targets': [ + + # Target to generate an add-on: + { + # The target name should match the add-on export name: + 'target_name': '<(addon_target_name)', + + # Define dependencies: + 'dependencies': [], + + # Define directories which contain relevant include headers: + 'include_dirs': [ + # Local include directory: + '<@(include_dirs)', + ], + + # List of source files: + 'sources': [ + '<@(src_files)', + ], + + # Settings which should be applied when a target's object files are used as linker input: + 'link_settings': { + # Define libraries: + 'libraries': [ + '<@(libraries)', + ], + + # Define library directories: + 'library_dirs': [ + '<@(library_dirs)', + ], + }, + + # C/C++ compiler flags: + 'cflags': [ + # Enable commonly used warning options: + '-Wall', + + # Aggressive optimization: + '-O3', + ], + + # C specific compiler flags: + 'cflags_c': [ + # Specify the C standard to which a program is expected to conform: + '-std=c99', + ], + + # C++ specific compiler flags: + 'cflags_cpp': [ + # Specify the C++ standard to which a program is expected to conform: + '-std=c++11', + ], + + # Linker flags: + 'ldflags': [], + + # Apply conditions based on the host OS: + 'conditions': [ + [ + 'OS=="mac"', + { + # Linker flags: + 'ldflags': [ + '-undefined dynamic_lookup', + '-Wl,-no-pie', + '-Wl,-search_paths_first', + ], + }, + ], # end condition (OS=="mac") + [ + 'OS!="win"', + { + # C/C++ flags: + 'cflags': [ + # Generate platform-independent code: + '-fPIC', + ], + }, + ], # end condition (OS!="win") + ], # end conditions + + # Define custom build actions for particular inputs: + 'rules': [ + { + # Define a rule for processing Fortran files: + 'extension': 'f', + + # Define the pathnames to be used as inputs when performing processing: + 'inputs': [ + # Full path of the current input: + '<(RULE_INPUT_PATH)' + ], + + # Define the outputs produced during processing: + 'outputs': [ + # Store an output object file in a directory for placing intermediate results (only accessible within a single target): + '<(INTERMEDIATE_DIR)/<(RULE_INPUT_ROOT).<(obj)' + ], + + # Define the rule for compiling Fortran based on the host OS: + 'conditions': [ + [ + 'OS=="win"', + + # Rule to compile Fortran on Windows: + { + 'rule_name': 'compile_fortran_windows', + 'message': 'Compiling Fortran file <(RULE_INPUT_PATH) on Windows...', + + 'process_outputs_as_sources': 0, + + # Define the command-line invocation: + 'action': [ + '<(fortran_compiler)', + '<@(fflags)', + '<@(_inputs)', + '-o', + '<@(_outputs)', + ], + }, + + # Rule to compile Fortran on non-Windows: + { + 'rule_name': 'compile_fortran_linux', + 'message': 'Compiling Fortran file <(RULE_INPUT_PATH) on Linux...', + + 'process_outputs_as_sources': 1, + + # Define the command-line invocation: + 'action': [ + '<(fortran_compiler)', + '<@(fflags)', + '-fPIC', # generate platform-independent code + '<@(_inputs)', + '-o', + '<@(_outputs)', + ], + } + ], # end condition (OS=="win") + ], # end conditions + }, # end rule (extension=="f") + ], # end rules + }, # end target <(addon_target_name) + + # Target to copy a generated add-on to a standard location: + { + 'target_name': 'copy_addon', + + # Declare that the output of this target is not linked: + 'type': 'none', + + # Define dependencies: + 'dependencies': [ + # Require that the add-on be generated before building this target: + '<(addon_target_name)', + ], + + # Define a list of actions: + 'actions': [ + { + 'action_name': 'copy_addon', + 'message': 'Copying addon...', + + # Explicitly list the inputs in the command-line invocation below: + 'inputs': [], + + # Declare the expected outputs: + 'outputs': [ + '<(addon_output_dir)/<(addon_target_name).node', + ], + + # Define the command-line invocation: + 'action': [ + 'cp', + '<(PRODUCT_DIR)/<(addon_target_name).node', + '<(addon_output_dir)/<(addon_target_name).node', + ], + }, + ], # end actions + }, # end target copy_addon + ], # end targets +} diff --git a/lib/node_modules/@stdlib/blas/base/ctrsm/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/ctrsm/docs/repl.txt new file mode 100644 index 000000000000..52115ae11f82 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ctrsm/docs/repl.txt @@ -0,0 +1,152 @@ +{{alias}}( order, side, uplo, transa, diag, M, N, alpha, A, LDA, B, LDB ) + Solves one of the matrix equations `op(A)*X = alpha*B` or + `X*op(A) = alpha*B` where `alpha` is a scalar, `X` and `B` are `M` by + `N` matrices, `A` is a unit or non-unit upper or lower triangular + matrix, and `op(A)` is either `op(A) = A` (no-transpose), + `op(A) = A^T` (transpose), or `op(A) = A^H` (conjugate-transpose). + + The matrix `X` is overwritten on `B`. + + `N` and stride parameters determine how values in the input matrices + are accessed at runtime. + + Indexing is relative to the first index. To introduce an offset, use + typed array views. + + If `M` or `N` is `0`, the function returns `B` unchanged. + + Parameters + ---------- + order: string + Row-major (C-style) or column-major (Fortran-style) order. Must be + either 'row-major' or 'column-major'. + + side: string + Specifies whether `op(A)` appears on the left or right of `X`. + Must be either 'left' or 'right'. + + uplo: string + Specifies whether the upper or lower triangular part of `A` is + used. Must be either 'upper' or 'lower'. + + transa: string + Transpose operation applied to `A`. Must be 'no-transpose', + 'transpose', or 'conjugate-transpose'. + + diag: string + Specifies whether `A` has a unit diagonal. Must be either 'unit' + or 'non-unit'. + + M: integer + Number of rows in `B`. + + N: integer + Number of columns in `B`. + + alpha: Complex64 + Scalar constant. + + A: Complex64Array + Input triangular matrix. + + LDA: integer + Stride of the first dimension of `A` (leading dimension). + + B: Complex64Array + Input/output matrix. + + LDB: integer + Stride of the first dimension of `B` (leading dimension). + + Returns + ------- + B: Complex64Array + Input/output matrix. + + Examples + -------- + // Standard usage: + > var A = new {{alias:@stdlib/array/complex64}}( [ + ... 1.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 0.0 + ... ] ); + > var B = new {{alias:@stdlib/array/complex64}}( [ 1.0, 0.0, 2.0, 0.0 ] ); + > var alpha = new {{alias:@stdlib/complex/float32/ctor}}( 1.0, 0.0 ); + > {{alias}}( 'row-major', 'left', 'upper', 'no-transpose', + ... 'non-unit', 2, 1, alpha, A, 2, B, 1 ) + [ -3.0, 0.0, 2.0, 0.0 ] + + +{{alias}}.ndarray( ord, sd, ul, ta, dg, M, N, aRe, aIm, A, sa1, oa, B, sb1, ob ) + Solves one of the matrix equations `op(A)*X = alpha*B` or + `X*op(A) = alpha*B` using alternative indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the offset parameters support indexing semantics based on + starting indices. + + Parameters + ---------- + ord: string + Row-major (C-style) or column-major (Fortran-style) order. + + sd: string + Specifies whether `op(A)` appears on the left or right of `X`. + + ul: string + Specifies whether the upper or lower triangular part of `A` is + used. + + ta: string + Transpose operation applied to `A`. + + dg: string + Specifies whether `A` has a unit diagonal. + + M: integer + Number of rows in `B`. + + N: integer + Number of columns in `B`. + + aRe: number + Real part of scalar constant. + + aIm: number + Imaginary part of scalar constant. + + A: Complex64Array + Input triangular matrix. + + sa1: integer + Stride of the first dimension of `A`. + + oa: integer + Starting index for `A`. + + B: Complex64Array + Input/output matrix. + + sb1: integer + Stride of the first dimension of `B`. + + ob: integer + Starting index for `B`. + + Returns + ------- + B: Complex64Array + Input/output matrix. + + Examples + -------- + > var A = new {{alias:@stdlib/array/complex64}}( [ + ... 1.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 0.0 + ... ] ); + > var B = new {{alias:@stdlib/array/complex64}}( [ 1.0, 0.0, 2.0, 0.0 ] ); + > {{alias}}.ndarray( 'row-major', 'left', 'upper', 'no-transpose', + ... 'non-unit', 2, 1, 1.0, 0.0, A, 2, 0, B, 1, 0 ) + [ -3.0, 0.0, 2.0, 0.0 ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/base/ctrsm/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/base/ctrsm/docs/types/index.d.ts new file mode 100644 index 000000000000..3087429efd5f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ctrsm/docs/types/index.d.ts @@ -0,0 +1,128 @@ +/* +* @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, OperationSide, MatrixTriangle, TransposeOperation, DiagonalType } from '@stdlib/types/blas'; +import { Complex64Array } from '@stdlib/types/array'; +import { Complex64 } from '@stdlib/types/complex'; + +/** +* Interface describing `ctrsm`. +*/ +interface Routine { + /** + * Solves one of the matrix equations `op(A)*X = alpha*B` or + * `X*op(A) = alpha*B` where `A` is a complex single-precision triangular + * matrix. + * + * @param order - storage layout + * @param side - specifies whether `A` appears on the left or right of `X` + * @param uplo - specifies whether the upper or lower triangular part of `A` is used + * @param transa - transpose operation applied to `A` + * @param diag - specifies whether `A` is unit triangular + * @param M - number of rows in `B` + * @param N - number of columns in `B` + * @param alpha - scalar constant + * @param A - input matrix + * @param LDA - stride of the first dimension of `A` + * @param B - input/output matrix + * @param LDB - stride of the first dimension of `B` + * @returns `B` + * + * @example + * var Complex64Array = require( '@stdlib/array/complex64' ); + * var Complex64 = require( '@stdlib/complex/float32/ctor' ); + * + * var A = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 0.0 ] ); + * var B = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0 ] ); + * var alpha = new Complex64( 1.0, 0.0 ); + * + * ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, alpha, A, 2, B, 1 ); + */ + ( order: Layout, side: OperationSide, uplo: MatrixTriangle, transa: TransposeOperation, diag: DiagonalType, M: number, N: number, alpha: Complex64, A: Complex64Array, LDA: number, B: Complex64Array, LDB: number ): Complex64Array; + + /** + * Solves one of the matrix equations `op(A)*X = alpha*B` or + * `X*op(A) = alpha*B` using alternative indexing semantics. + * + * @param order - storage layout + * @param side - specifies whether `A` appears on the left or right of `X` + * @param uplo - specifies whether the upper or lower triangular part of `A` is used + * @param transa - transpose operation applied to `A` + * @param diag - specifies whether `A` is unit triangular + * @param M - number of rows in `B` + * @param N - number of columns in `B` + * @param alphaRe - real part of scalar constant + * @param alphaIm - imaginary part of scalar constant + * @param A - input matrix + * @param strideA1 - stride of the first dimension of `A` + * @param offsetA - starting index for `A` + * @param B - input/output matrix + * @param strideB1 - stride of the first dimension of `B` + * @param offsetB - starting index for `B` + * @returns `B` + * + * @example + * var Complex64Array = require( '@stdlib/array/complex64' ); + * + * var A = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 0.0 ] ); + * var B = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0 ] ); + * + * ctrsm.ndarray( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, 1.0, 0.0, A, 2, 0, B, 1, 0 ); + */ + ndarray( order: Layout, side: OperationSide, uplo: MatrixTriangle, transa: TransposeOperation, diag: DiagonalType, M: number, N: number, alphaRe: number, alphaIm: number, A: Complex64Array, strideA1: number, offsetA: number, B: Complex64Array, strideB1: number, offsetB: number ): Complex64Array; +} + +/** +* Solves one of the matrix equations `op(A)*X = alpha*B` or +* `X*op(A) = alpha*B` where `A` is a complex single-precision triangular matrix. +* +* @param order - storage layout +* @param side - specifies whether `A` appears on the left or right of `X` +* @param uplo - specifies whether the upper or lower triangular part of `A` is used +* @param transa - transpose operation applied to `A` +* @param diag - specifies whether `A` is unit triangular +* @param M - number of rows in `B` +* @param N - number of columns in `B` +* @param alpha - scalar constant +* @param A - input matrix +* @param LDA - stride of the first dimension of `A` +* @param B - input/output matrix +* @param LDB - stride of the first dimension of `B` +* @returns `B` +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* +* var A = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 0.0 ] ); +* var B = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0 ] ); +* var alpha = new Complex64( 1.0, 0.0 ); +* +* ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, alpha, A, 2, B, 1 ); +* // B => [ -3.0, 0.0, 2.0, 0.0 ] +*/ +declare var ctrsm: Routine; + + +// EXPORTS // + +export = ctrsm; diff --git a/lib/node_modules/@stdlib/blas/base/ctrsm/docs/types/test.ts b/lib/node_modules/@stdlib/blas/base/ctrsm/docs/types/test.ts new file mode 100644 index 000000000000..47ca6d6bf261 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ctrsm/docs/types/test.ts @@ -0,0 +1,128 @@ +/* +* @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 Complex64Array = require( '@stdlib/array/complex64' ); +import Complex64 = require( '@stdlib/complex/float32/ctor' ); +import ctrsm = require( './index' ); + + +// TESTS // + +// The function returns a Complex64Array... +{ + const A = new Complex64Array( 4 ); + const B = new Complex64Array( 2 ); + const alpha = new Complex64( 1.0, 0.0 ); + + ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, alpha, A, 2, B, 1 ); // $ExpectType Complex64Array +} + +// The compiler throws an error if the function is provided a first argument which is not a string... +{ + const A = new Complex64Array( 4 ); + const B = new Complex64Array( 2 ); + const alpha = new Complex64( 1.0, 0.0 ); + + ctrsm( 10, 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, alpha, A, 2, B, 1 ); // $ExpectError + ctrsm( true, 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, alpha, A, 2, B, 1 ); // $ExpectError + ctrsm( false, 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, alpha, A, 2, B, 1 ); // $ExpectError + ctrsm( null, 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, alpha, A, 2, B, 1 ); // $ExpectError + ctrsm( undefined, 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, alpha, A, 2, B, 1 ); // $ExpectError + ctrsm( [], 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, alpha, A, 2, B, 1 ); // $ExpectError + ctrsm( {}, 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, alpha, A, 2, B, 1 ); // $ExpectError + ctrsm( ( x: number ): number => x, 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, alpha, A, 2, B, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a sixth argument which is not a number... +{ + const A = new Complex64Array( 4 ); + const B = new Complex64Array( 2 ); + const alpha = new Complex64( 1.0, 0.0 ); + + ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', '2', 1, alpha, A, 2, B, 1 ); // $ExpectError + ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', true, 1, alpha, A, 2, B, 1 ); // $ExpectError + ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', false, 1, alpha, A, 2, B, 1 ); // $ExpectError + ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', null, 1, alpha, A, 2, B, 1 ); // $ExpectError + ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', undefined, 1, alpha, A, 2, B, 1 ); // $ExpectError + ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', [], 1, alpha, A, 2, B, 1 ); // $ExpectError + ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', {}, 1, alpha, A, 2, B, 1 ); // $ExpectError + ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', ( x: number ): number => x, 1, alpha, A, 2, B, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided an eighth argument which is not a complex number... +{ + const A = new Complex64Array( 4 ); + const B = new Complex64Array( 2 ); + + ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, 1.0, A, 2, B, 1 ); // $ExpectError + ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, '1.0', A, 2, B, 1 ); // $ExpectError + ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, true, A, 2, B, 1 ); // $ExpectError + ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, false, A, 2, B, 1 ); // $ExpectError + ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, null, A, 2, B, 1 ); // $ExpectError + ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, undefined, A, 2, B, 1 ); // $ExpectError + ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, [], A, 2, B, 1 ); // $ExpectError + ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, {}, A, 2, B, 1 ); // $ExpectError + ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, ( x: number ): number => x, A, 2, B, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a ninth argument which is not a Complex64Array... +{ + const B = new Complex64Array( 2 ); + const alpha = new Complex64( 1.0, 0.0 ); + + ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, alpha, 10, 2, B, 1 ); // $ExpectError + ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, alpha, '10', 2, B, 1 ); // $ExpectError + ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, alpha, true, 2, B, 1 ); // $ExpectError + ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, alpha, false, 2, B, 1 ); // $ExpectError + ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, alpha, null, 2, B, 1 ); // $ExpectError + ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, alpha, undefined, 2, B, 1 ); // $ExpectError + ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, alpha, [ '1' ], 2, B, 1 ); // $ExpectError + ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, alpha, {}, 2, B, 1 ); // $ExpectError + ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, alpha, ( x: number ): number => x, 2, B, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const A = new Complex64Array( 4 ); + const B = new Complex64Array( 2 ); + const alpha = new Complex64( 1.0, 0.0 ); + + ctrsm(); // $ExpectError + ctrsm( 'row-major' ); // $ExpectError + ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, alpha, A, 2, B ); // $ExpectError + ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, alpha, A, 2, B, 1, 0 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a Complex64Array... +{ + const A = new Complex64Array( 4 ); + const B = new Complex64Array( 2 ); + + ctrsm.ndarray( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, 1.0, 0.0, A, 2, 0, B, 1, 0 ); // $ExpectType Complex64Array +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const A = new Complex64Array( 4 ); + const B = new Complex64Array( 2 ); + + ctrsm.ndarray(); // $ExpectError + ctrsm.ndarray( 'row-major' ); // $ExpectError + ctrsm.ndarray( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, 1.0, 0.0, A, 2, 0, B, 1 ); // $ExpectError + ctrsm.ndarray( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, 1.0, 0.0, A, 2, 0, B, 1, 0, 0 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/base/ctrsm/examples/c/Makefile b/lib/node_modules/@stdlib/blas/base/ctrsm/examples/c/Makefile new file mode 100644 index 000000000000..c8f8e9a1517b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ctrsm/examples/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := example.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled examples. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/blas/base/ctrsm/examples/c/example.c b/lib/node_modules/@stdlib/blas/base/ctrsm/examples/c/example.c new file mode 100644 index 000000000000..ededf358c66e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ctrsm/examples/c/example.c @@ -0,0 +1,53 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/blas/base/ctrsm.h" +#include "stdlib/complex/float32/ctor.h" +#include + +int main( void ) { + // Create a row-major 2x2 upper triangular matrix A: [[1+0i, 2+0i], [0+0i, 1+0i]] + float A[] = { 1.0f, 0.0f, 2.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f }; + + // Create a 2x1 right-hand side matrix B: [[1+0i], [2+0i]] + float B[] = { 1.0f, 0.0f, 2.0f, 0.0f }; + + // Create a complex scalar alpha: + const stdlib_complex64_t alpha = stdlib_complex64( 1.0f, 0.0f ); + + // Specify matrix dimensions: + const int M = 2; + const int N = 1; + + // Solve op(A)*X = alpha*B: + c_ctrsm( CblasRowMajor, CblasLeft, CblasUpper, CblasNoTrans, CblasNonUnit, M, N, alpha, (const void *)A, M, (void *)B, N ); + + // Print the result: + for ( int i = 0; i < M; i++ ) { + printf( "B[ %i ] = %f + %fj\n", i, B[ i*2 ], B[ (i*2)+1 ] ); + } + + // Solve using alternative indexing semantics: + float B2[] = { 1.0f, 0.0f, 2.0f, 0.0f }; + c_ctrsm_ndarray( CblasRowMajor, CblasLeft, CblasUpper, CblasNoTrans, CblasNonUnit, M, N, 1.0f, 0.0f, (const void *)A, M, 0, (void *)B2, N, 0 ); + + // Print the result: + for ( int i = 0; i < M; i++ ) { + printf( "B2[ %i ] = %f + %fj\n", i, B2[ i*2 ], B2[ (i*2)+1 ] ); + } +} diff --git a/lib/node_modules/@stdlib/blas/base/ctrsm/examples/index.js b/lib/node_modules/@stdlib/blas/base/ctrsm/examples/index.js new file mode 100644 index 000000000000..0e4562b268fe --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ctrsm/examples/index.js @@ -0,0 +1,120 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var Complex64Array = require( '@stdlib/array/complex64' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var realf = require( '@stdlib/complex/float32/real' ); +var imagf = require( '@stdlib/complex/float32/imag' ); +var ctrsm = require( './../lib' ); + +/* +* Example 1: Solve A * X = alpha * B (left, upper, no-transpose, non-unit) +* where A is 3x3 upper triangular and B is 3x2. +* +* A = | 2+0i 1+0i 0+1i | +* | 0+0i 3+0i 2+0i | +* | 0+0i 0+0i 1+0i | +* +* B = | 1+0i 2+0i | +* | 3+0i 4+0i | +* | 5+0i 6+0i | +*/ + +var A = new Complex64Array([ + 2.0, + 0.0, + 1.0, + 0.0, + 0.0, + 1.0, + 0.0, + 0.0, + 3.0, + 0.0, + 2.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 0.0 +]); + +var B = new Complex64Array([ + 1.0, + 0.0, + 2.0, + 0.0, + 3.0, + 0.0, + 4.0, + 0.0, + 5.0, + 0.0, + 6.0, + 0.0 +]); + +var alpha = new Complex64( 1.0, 0.0 ); + +console.log( 'Before:' ); +var i; +for ( i = 0; i < B.length; i++ ) { + console.log( ' B[%d] = %d + %di', i, realf( B.get( i ) ), imagf( B.get( i ) ) ); +} + +ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 3, 2, alpha, A, 3, B, 2 ); + +console.log( 'After ctrsm (solve A*X = B):' ); +for ( i = 0; i < B.length; i++ ) { + console.log( ' X[%d] = %d + %di', i, realf( B.get( i ) ), imagf( B.get( i ) ) ); +} + +/* +* Example 2: Use ndarray interface with complex alpha. +* +* Solve A * X = (2+1i) * B for a 2x2 system. +*/ +var A2 = new Complex64Array([ + 1.0, + 0.0, + 2.0, + 0.0, + 0.0, + 0.0, + 1.0, + 0.0 +]); + +var B2 = new Complex64Array([ + 4.0, + 0.0, + 2.0, + 0.0 +]); + +console.log( '\nndarray interface with complex alpha (2+1i):' ); + +ctrsm.ndarray( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, 2.0, 1.0, A2, 2, 0, B2, 1, 0 ); + +for ( i = 0; i < B2.length; i++ ) { + console.log( ' X[%d] = %d + %di', i, realf( B2.get( i ) ), imagf( B2.get( i ) ) ); +} diff --git a/lib/node_modules/@stdlib/blas/base/ctrsm/include.gypi b/lib/node_modules/@stdlib/blas/base/ctrsm/include.gypi new file mode 100644 index 000000000000..dcb556d250e8 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ctrsm/include.gypi @@ -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. + +# A GYP include file for building a Node.js native add-on. +# +# Note that nesting variables is required due to how GYP processes a configuration. Any variables defined within a nested 'variables' section is defined in the outer scope. Thus, conditions in the outer variable scope are free to use these variables without running into "variable undefined" errors. +# +# Main documentation: +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +# +# Variable nesting hacks: +# +# [3]: https://chromium.googlesource.com/external/skia/gyp/+/master/common_variables.gypi +# [4]: https://src.chromium.org/viewvc/chrome/trunk/src/build/common.gypi?revision=127004 +{ + # Define variables to be used throughout the configuration for all targets: + 'variables': { + 'variables': { + # Host BLAS library (to override -Dblas=): + 'blas%': '', + + # Path to BLAS library (to override -Dblas_dir=): + 'blas_dir%': '', + }, # end variables + + # Source directory: + 'src_dir': './src', + + # Include directories: + 'include_dirs': [ + '<@(blas_dir)', + ' [ -3.0, 0.0, 2.0, 0.0 ] +*/ +function ctrsm( order, side, uplo, transa, diag, M, N, alpha, A, LDA, B, LDB ) { // eslint-disable-line max-params + var viewA = reinterpret( A, 0 ); + var viewB = reinterpret( B, 0 ); + addon(str2enumLayout( order ), str2enumSide( side ), str2enumUplo( uplo ), str2enumTrans( transa ), str2enumDiag( diag ), M, N, alpha, viewA, LDA, viewB, LDB); + return B; +} + + +// EXPORTS // + +module.exports = ctrsm; diff --git a/lib/node_modules/@stdlib/blas/base/ctrsm/lib/index.js b/lib/node_modules/@stdlib/blas/base/ctrsm/lib/index.js new file mode 100644 index 000000000000..83cc7494bc37 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ctrsm/lib/index.js @@ -0,0 +1,72 @@ +/** +* @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'; + +/** +* BLAS level 3 routine to solve one of the matrix equations `op(A)*X = alpha*B` or `X*op(A) = alpha*B` where `A` is a complex single-precision triangular matrix. +* +* @module @stdlib/blas/base/ctrsm +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var ctrsm = require( '@stdlib/blas/base/ctrsm' ); +* +* var A = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 0.0 ] ); +* var B = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0 ] ); +* var alpha = new Complex64( 1.0, 0.0 ); +* +* ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, alpha, A, 2, B, 1 ); +* // B => [ -3.0, 0.0, 2.0, 0.0 ] +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var ctrsm = require( '@stdlib/blas/base/ctrsm' ); +* +* var A = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 0.0 ] ); +* var B = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0 ] ); +* +* ctrsm.ndarray( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, 1.0, 0.0, A, 2, 0, B, 1, 0 ); +* // B => [ -3.0, 0.0, 2.0, 0.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 ctrsm; +var tmp = tryRequire( join( __dirname, './native.js' ) ); +if ( isError( tmp ) ) { + ctrsm = main; +} else { + ctrsm = tmp; +} + + +// EXPORTS // + +module.exports = ctrsm; + +// exports: { "ndarray": "ctrsm.ndarray" } diff --git a/lib/node_modules/@stdlib/blas/base/ctrsm/lib/main.js b/lib/node_modules/@stdlib/blas/base/ctrsm/lib/main.js new file mode 100644 index 000000000000..bdfb9e3c7bed --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ctrsm/lib/main.js @@ -0,0 +1,35 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var ctrsm = require( './ctrsm.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( ctrsm, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = ctrsm; diff --git a/lib/node_modules/@stdlib/blas/base/ctrsm/lib/native.js b/lib/node_modules/@stdlib/blas/base/ctrsm/lib/native.js new file mode 100644 index 000000000000..5b8b40242b08 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ctrsm/lib/native.js @@ -0,0 +1,35 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var ctrsm = require( './ctrsm.native.js' ); +var ndarray = require( './ndarray.native.js' ); + + +// MAIN // + +setReadOnly( ctrsm, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = ctrsm; diff --git a/lib/node_modules/@stdlib/blas/base/ctrsm/lib/ndarray.js b/lib/node_modules/@stdlib/blas/base/ctrsm/lib/ndarray.js new file mode 100644 index 000000000000..d7a645e37139 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ctrsm/lib/ndarray.js @@ -0,0 +1,965 @@ +/** +* @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-lines, max-params */ + +'use strict'; + +// MODULES // + +var reinterpret = require( '@stdlib/strided/base/reinterpret-complex64' ); +var isLayout = require( '@stdlib/blas/base/assert/is-layout' ); +var isOperationSide = require( '@stdlib/blas/base/assert/is-operation-side' ); +var isMatrixTriangle = require( '@stdlib/blas/base/assert/is-matrix-triangle' ); +var isTransposeOperation = require( '@stdlib/blas/base/assert/is-transpose-operation' ); +var isDiagonalType = require( '@stdlib/blas/base/assert/is-diagonal-type' ); +var format = require( '@stdlib/string/format' ); + + +// FUNCTIONS // + +/** +* Returns the real part of complex division b/a. +* +* @private +* @param {number} bRe - real part of numerator +* @param {number} bIm - imaginary part of numerator +* @param {number} aRe - real part of denominator +* @param {number} aIm - imaginary part of denominator +* @returns {number} real part of b/a +*/ +function cdivRe( bRe, bIm, aRe, aIm ) { + var denom = ( aRe * aRe ) + ( aIm * aIm ); + return ( ( bRe * aRe ) + ( bIm * aIm ) ) / denom; +} + +/** +* Returns the imaginary part of complex division b/a. +* +* @private +* @param {number} bRe - real part of numerator +* @param {number} bIm - imaginary part of numerator +* @param {number} aRe - real part of denominator +* @param {number} aIm - imaginary part of denominator +* @returns {number} imaginary part of b/a +*/ +function cdivIm( bRe, bIm, aRe, aIm ) { + var denom = ( aRe * aRe ) + ( aIm * aIm ); + return ( ( bIm * aRe ) - ( bRe * aIm ) ) / denom; +} + +/** +* Scales matrix B by alpha in-place. +* +* @private +* @param {NonNegativeInteger} M - number of rows +* @param {NonNegativeInteger} N - number of columns +* @param {number} alphaRe - real part of scalar +* @param {number} alphaIm - imaginary part of scalar +* @param {Float32Array} bbuf - real view of B +* @param {integer} SB1 - stride of first dimension of B +* @param {integer} SB2 - stride of second dimension of B +* @param {NonNegativeInteger} offsetB - starting index for B +* @returns {void} +*/ +function scaleB( M, N, alphaRe, alphaIm, bbuf, SB1, SB2, offsetB ) { + var bRe; + var bIm; + var iB; + var i; + var j; + + for ( i = 0; i < M; i++ ) { + for ( j = 0; j < N; j++ ) { + iB = ( offsetB + ( i * SB1 ) + ( j * SB2 ) ) * 2; + bRe = bbuf[ iB ]; + bIm = bbuf[ iB + 1 ]; + bbuf[ iB ] = ( alphaRe * bRe ) - ( alphaIm * bIm ); + bbuf[ iB + 1 ] = ( alphaRe * bIm ) + ( alphaIm * bRe ); + } + } +} + +/** +* Solves op(A)*X=B, left, upper, no-transpose. +* +* @private +* @param {NonNegativeInteger} M - number of rows +* @param {NonNegativeInteger} N - number of columns +* @param {boolean} isUnitDiag - whether A has a unit diagonal +* @param {Float32Array} abuf - real view of A +* @param {integer} SA1 - stride of first dimension of A +* @param {integer} SA2 - stride of second dimension of A +* @param {NonNegativeInteger} offsetA - starting index for A +* @param {Float32Array} bbuf - real view of B +* @param {integer} SB1 - stride of first dimension of B +* @param {integer} SB2 - stride of second dimension of B +* @param {NonNegativeInteger} offsetB - starting index for B +* @returns {void} +*/ +function leftNoTransUpper( M, N, isUnitDiag, abuf, SA1, SA2, offsetA, bbuf, SB1, SB2, offsetB ) { // eslint-disable-line max-len + var tempRe; + var tempIm; + var aRe; + var aIm; + var bRe; + var bIm; + var iA; + var iB; + var i; + var j; + var k; + + for ( j = 0; j < N; j++ ) { + for ( k = M - 1; k >= 0; k-- ) { + iB = ( offsetB + ( k * SB1 ) + ( j * SB2 ) ) * 2; + bRe = bbuf[ iB ]; + bIm = bbuf[ iB + 1 ]; + if ( bRe !== 0.0 || bIm !== 0.0 ) { + if ( isUnitDiag === false ) { + iA = ( offsetA + ( k * SA1 ) + ( k * SA2 ) ) * 2; + aRe = abuf[ iA ]; + aIm = abuf[ iA + 1 ]; + tempRe = cdivRe( bRe, bIm, aRe, aIm ); + tempIm = cdivIm( bRe, bIm, aRe, aIm ); + bbuf[ iB ] = tempRe; + bbuf[ iB + 1 ] = tempIm; + bRe = tempRe; + bIm = tempIm; + } + for ( i = 0; i < k; i++ ) { + iA = ( offsetA + ( i * SA1 ) + ( k * SA2 ) ) * 2; + aRe = abuf[ iA ]; + aIm = abuf[ iA + 1 ]; + iB = ( offsetB + ( i * SB1 ) + ( j * SB2 ) ) * 2; + bbuf[ iB ] -= ( bRe * aRe ) - ( bIm * aIm ); + bbuf[ iB + 1 ] -= ( bRe * aIm ) + ( bIm * aRe ); + } + } + } + } +} + +/** +* Solves op(A)*X=B, left, lower, no-transpose. +* +* @private +* @param {NonNegativeInteger} M - number of rows +* @param {NonNegativeInteger} N - number of columns +* @param {boolean} isUnitDiag - whether A has a unit diagonal +* @param {Float32Array} abuf - real view of A +* @param {integer} SA1 - stride of first dimension of A +* @param {integer} SA2 - stride of second dimension of A +* @param {NonNegativeInteger} offsetA - starting index for A +* @param {Float32Array} bbuf - real view of B +* @param {integer} SB1 - stride of first dimension of B +* @param {integer} SB2 - stride of second dimension of B +* @param {NonNegativeInteger} offsetB - starting index for B +* @returns {void} +*/ +function leftNoTransLower( M, N, isUnitDiag, abuf, SA1, SA2, offsetA, bbuf, SB1, SB2, offsetB ) { // eslint-disable-line max-len + var tempRe; + var tempIm; + var aRe; + var aIm; + var bRe; + var bIm; + var iA; + var iB; + var i; + var j; + var k; + + for ( j = 0; j < N; j++ ) { + for ( k = 0; k < M; k++ ) { + iB = ( offsetB + ( k * SB1 ) + ( j * SB2 ) ) * 2; + bRe = bbuf[ iB ]; + bIm = bbuf[ iB + 1 ]; + if ( bRe !== 0.0 || bIm !== 0.0 ) { + if ( isUnitDiag === false ) { + iA = ( offsetA + ( k * SA1 ) + ( k * SA2 ) ) * 2; + aRe = abuf[ iA ]; + aIm = abuf[ iA + 1 ]; + tempRe = cdivRe( bRe, bIm, aRe, aIm ); + tempIm = cdivIm( bRe, bIm, aRe, aIm ); + bbuf[ iB ] = tempRe; + bbuf[ iB + 1 ] = tempIm; + bRe = tempRe; + bIm = tempIm; + } + for ( i = k + 1; i < M; i++ ) { + iA = ( offsetA + ( i * SA1 ) + ( k * SA2 ) ) * 2; + aRe = abuf[ iA ]; + aIm = abuf[ iA + 1 ]; + iB = ( offsetB + ( i * SB1 ) + ( j * SB2 ) ) * 2; + bbuf[ iB ] -= ( bRe * aRe ) - ( bIm * aIm ); + bbuf[ iB + 1 ] -= ( bRe * aIm ) + ( bIm * aRe ); + } + } + } + } +} + +/** +* Solves op(A)*X=B, left, upper, transpose. +* +* @private +* @param {NonNegativeInteger} M - number of rows +* @param {NonNegativeInteger} N - number of columns +* @param {boolean} isUnitDiag - whether A has a unit diagonal +* @param {Float32Array} abuf - real view of A +* @param {integer} SA1 - stride of first dimension of A +* @param {integer} SA2 - stride of second dimension of A +* @param {NonNegativeInteger} offsetA - starting index for A +* @param {Float32Array} bbuf - real view of B +* @param {integer} SB1 - stride of first dimension of B +* @param {integer} SB2 - stride of second dimension of B +* @param {NonNegativeInteger} offsetB - starting index for B +* @returns {void} +*/ +function leftTransUpper( M, N, isUnitDiag, abuf, SA1, SA2, offsetA, bbuf, SB1, SB2, offsetB ) { // eslint-disable-line max-len + var tempRe; + var tempIm; + var aRe; + var aIm; + var bRe; + var bIm; + var iA; + var iB; + var i; + var j; + var k; + + for ( j = 0; j < N; j++ ) { + for ( i = 0; i < M; i++ ) { + iB = ( offsetB + ( i * SB1 ) + ( j * SB2 ) ) * 2; + tempRe = bbuf[ iB ]; + tempIm = bbuf[ iB + 1 ]; + for ( k = 0; k < i; k++ ) { + iA = ( offsetA + ( k * SA1 ) + ( i * SA2 ) ) * 2; + aRe = abuf[ iA ]; + aIm = abuf[ iA + 1 ]; + iB = ( offsetB + ( k * SB1 ) + ( j * SB2 ) ) * 2; + bRe = bbuf[ iB ]; + bIm = bbuf[ iB + 1 ]; + tempRe -= ( aRe * bRe ) - ( aIm * bIm ); + tempIm -= ( aRe * bIm ) + ( aIm * bRe ); + } + iB = ( offsetB + ( i * SB1 ) + ( j * SB2 ) ) * 2; + if ( isUnitDiag === false ) { + iA = ( offsetA + ( i * SA1 ) + ( i * SA2 ) ) * 2; + aRe = abuf[ iA ]; + aIm = abuf[ iA + 1 ]; + bbuf[ iB ] = cdivRe( tempRe, tempIm, aRe, aIm ); + bbuf[ iB + 1 ] = cdivIm( tempRe, tempIm, aRe, aIm ); + } else { + bbuf[ iB ] = tempRe; + bbuf[ iB + 1 ] = tempIm; + } + } + } +} + +/** +* Solves op(A)*X=B, left, lower, transpose. +* +* @private +* @param {NonNegativeInteger} M - number of rows +* @param {NonNegativeInteger} N - number of columns +* @param {boolean} isUnitDiag - whether A has a unit diagonal +* @param {Float32Array} abuf - real view of A +* @param {integer} SA1 - stride of first dimension of A +* @param {integer} SA2 - stride of second dimension of A +* @param {NonNegativeInteger} offsetA - starting index for A +* @param {Float32Array} bbuf - real view of B +* @param {integer} SB1 - stride of first dimension of B +* @param {integer} SB2 - stride of second dimension of B +* @param {NonNegativeInteger} offsetB - starting index for B +* @returns {void} +*/ +function leftTransLower( M, N, isUnitDiag, abuf, SA1, SA2, offsetA, bbuf, SB1, SB2, offsetB ) { // eslint-disable-line max-len + var tempRe; + var tempIm; + var aRe; + var aIm; + var bRe; + var bIm; + var iA; + var iB; + var i; + var j; + var k; + + for ( j = 0; j < N; j++ ) { + for ( i = M - 1; i >= 0; i-- ) { + iB = ( offsetB + ( i * SB1 ) + ( j * SB2 ) ) * 2; + tempRe = bbuf[ iB ]; + tempIm = bbuf[ iB + 1 ]; + for ( k = i + 1; k < M; k++ ) { + iA = ( offsetA + ( k * SA1 ) + ( i * SA2 ) ) * 2; + aRe = abuf[ iA ]; + aIm = abuf[ iA + 1 ]; + iB = ( offsetB + ( k * SB1 ) + ( j * SB2 ) ) * 2; + bRe = bbuf[ iB ]; + bIm = bbuf[ iB + 1 ]; + tempRe -= ( aRe * bRe ) - ( aIm * bIm ); + tempIm -= ( aRe * bIm ) + ( aIm * bRe ); + } + iB = ( offsetB + ( i * SB1 ) + ( j * SB2 ) ) * 2; + if ( isUnitDiag === false ) { + iA = ( offsetA + ( i * SA1 ) + ( i * SA2 ) ) * 2; + aRe = abuf[ iA ]; + aIm = abuf[ iA + 1 ]; + bbuf[ iB ] = cdivRe( tempRe, tempIm, aRe, aIm ); + bbuf[ iB + 1 ] = cdivIm( tempRe, tempIm, aRe, aIm ); + } else { + bbuf[ iB ] = tempRe; + bbuf[ iB + 1 ] = tempIm; + } + } + } +} + +/** +* Solves op(A)*X=B, left, upper, conjugate-transpose. +* +* @private +* @param {NonNegativeInteger} M - number of rows +* @param {NonNegativeInteger} N - number of columns +* @param {boolean} isUnitDiag - whether A has a unit diagonal +* @param {Float32Array} abuf - real view of A +* @param {integer} SA1 - stride of first dimension of A +* @param {integer} SA2 - stride of second dimension of A +* @param {NonNegativeInteger} offsetA - starting index for A +* @param {Float32Array} bbuf - real view of B +* @param {integer} SB1 - stride of first dimension of B +* @param {integer} SB2 - stride of second dimension of B +* @param {NonNegativeInteger} offsetB - starting index for B +* @returns {void} +*/ +function leftConjTransUpper( M, N, isUnitDiag, abuf, SA1, SA2, offsetA, bbuf, SB1, SB2, offsetB ) { // eslint-disable-line max-len + var tempRe; + var tempIm; + var aRe; + var aIm; + var bRe; + var bIm; + var iA; + var iB; + var i; + var j; + var k; + + for ( j = 0; j < N; j++ ) { + for ( i = 0; i < M; i++ ) { + iB = ( offsetB + ( i * SB1 ) + ( j * SB2 ) ) * 2; + tempRe = bbuf[ iB ]; + tempIm = bbuf[ iB + 1 ]; + for ( k = 0; k < i; k++ ) { + iA = ( offsetA + ( k * SA1 ) + ( i * SA2 ) ) * 2; + aRe = abuf[ iA ]; + aIm = -abuf[ iA + 1 ]; // conjugate + iB = ( offsetB + ( k * SB1 ) + ( j * SB2 ) ) * 2; + bRe = bbuf[ iB ]; + bIm = bbuf[ iB + 1 ]; + tempRe -= ( aRe * bRe ) - ( aIm * bIm ); + tempIm -= ( aRe * bIm ) + ( aIm * bRe ); + } + iB = ( offsetB + ( i * SB1 ) + ( j * SB2 ) ) * 2; + if ( isUnitDiag === false ) { + iA = ( offsetA + ( i * SA1 ) + ( i * SA2 ) ) * 2; + aRe = abuf[ iA ]; + aIm = -abuf[ iA + 1 ]; // conjugate + bbuf[ iB ] = cdivRe( tempRe, tempIm, aRe, aIm ); + bbuf[ iB + 1 ] = cdivIm( tempRe, tempIm, aRe, aIm ); + } else { + bbuf[ iB ] = tempRe; + bbuf[ iB + 1 ] = tempIm; + } + } + } +} + +/** +* Solves op(A)*X=B, left, lower, conjugate-transpose. +* +* @private +* @param {NonNegativeInteger} M - number of rows +* @param {NonNegativeInteger} N - number of columns +* @param {boolean} isUnitDiag - whether A has a unit diagonal +* @param {Float32Array} abuf - real view of A +* @param {integer} SA1 - stride of first dimension of A +* @param {integer} SA2 - stride of second dimension of A +* @param {NonNegativeInteger} offsetA - starting index for A +* @param {Float32Array} bbuf - real view of B +* @param {integer} SB1 - stride of first dimension of B +* @param {integer} SB2 - stride of second dimension of B +* @param {NonNegativeInteger} offsetB - starting index for B +* @returns {void} +*/ +function leftConjTransLower( M, N, isUnitDiag, abuf, SA1, SA2, offsetA, bbuf, SB1, SB2, offsetB ) { // eslint-disable-line max-len + var tempRe; + var tempIm; + var aRe; + var aIm; + var bRe; + var bIm; + var iA; + var iB; + var i; + var j; + var k; + + for ( j = 0; j < N; j++ ) { + for ( i = M - 1; i >= 0; i-- ) { + iB = ( offsetB + ( i * SB1 ) + ( j * SB2 ) ) * 2; + tempRe = bbuf[ iB ]; + tempIm = bbuf[ iB + 1 ]; + for ( k = i + 1; k < M; k++ ) { + iA = ( offsetA + ( k * SA1 ) + ( i * SA2 ) ) * 2; + aRe = abuf[ iA ]; + aIm = -abuf[ iA + 1 ]; // conjugate + iB = ( offsetB + ( k * SB1 ) + ( j * SB2 ) ) * 2; + bRe = bbuf[ iB ]; + bIm = bbuf[ iB + 1 ]; + tempRe -= ( aRe * bRe ) - ( aIm * bIm ); + tempIm -= ( aRe * bIm ) + ( aIm * bRe ); + } + iB = ( offsetB + ( i * SB1 ) + ( j * SB2 ) ) * 2; + if ( isUnitDiag === false ) { + iA = ( offsetA + ( i * SA1 ) + ( i * SA2 ) ) * 2; + aRe = abuf[ iA ]; + aIm = -abuf[ iA + 1 ]; // conjugate + bbuf[ iB ] = cdivRe( tempRe, tempIm, aRe, aIm ); + bbuf[ iB + 1 ] = cdivIm( tempRe, tempIm, aRe, aIm ); + } else { + bbuf[ iB ] = tempRe; + bbuf[ iB + 1 ] = tempIm; + } + } + } +} + +/** +* Solves B*op(A)=B, right, upper, no-transpose. +* +* @private +* @param {NonNegativeInteger} M - number of rows +* @param {NonNegativeInteger} N - number of columns +* @param {boolean} isUnitDiag - whether A has a unit diagonal +* @param {Float32Array} abuf - real view of A +* @param {integer} SA1 - stride of first dimension of A +* @param {integer} SA2 - stride of second dimension of A +* @param {NonNegativeInteger} offsetA - starting index for A +* @param {Float32Array} bbuf - real view of B +* @param {integer} SB1 - stride of first dimension of B +* @param {integer} SB2 - stride of second dimension of B +* @param {NonNegativeInteger} offsetB - starting index for B +* @returns {void} +*/ +function rightNoTransUpper( M, N, isUnitDiag, abuf, SA1, SA2, offsetA, bbuf, SB1, SB2, offsetB ) { // eslint-disable-line max-len + var aRe; + var aIm; + var bRe; + var bIm; + var iA; + var iB; + var jB; + var i; + var j; + var k; + + for ( j = 0; j < N; j++ ) { + if ( isUnitDiag === false ) { + iA = ( offsetA + ( j * SA1 ) + ( j * SA2 ) ) * 2; + aRe = abuf[ iA ]; + aIm = abuf[ iA + 1 ]; + for ( i = 0; i < M; i++ ) { + iB = ( offsetB + ( i * SB1 ) + ( j * SB2 ) ) * 2; + bRe = bbuf[ iB ]; + bIm = bbuf[ iB + 1 ]; + bbuf[ iB ] = cdivRe( bRe, bIm, aRe, aIm ); + bbuf[ iB + 1 ] = cdivIm( bRe, bIm, aRe, aIm ); + } + } + for ( k = 0; k < j; k++ ) { + iA = ( offsetA + ( k * SA1 ) + ( j * SA2 ) ) * 2; + aRe = abuf[ iA ]; + aIm = abuf[ iA + 1 ]; + if ( aRe !== 0.0 || aIm !== 0.0 ) { + for ( i = 0; i < M; i++ ) { + iB = ( offsetB + ( i * SB1 ) + ( j * SB2 ) ) * 2; + jB = ( offsetB + ( i * SB1 ) + ( k * SB2 ) ) * 2; + bbuf[ iB ] -= ( aRe * bbuf[ jB ] ) - ( aIm * bbuf[ jB + 1 ] ); + bbuf[ iB + 1 ] -= ( aRe * bbuf[ jB + 1 ] ) + ( aIm * bbuf[ jB ] ); + } + } + } + } +} + +/** +* Solves B*op(A)=B, right, lower, no-transpose. +* +* @private +* @param {NonNegativeInteger} M - number of rows +* @param {NonNegativeInteger} N - number of columns +* @param {boolean} isUnitDiag - whether A has a unit diagonal +* @param {Float32Array} abuf - real view of A +* @param {integer} SA1 - stride of first dimension of A +* @param {integer} SA2 - stride of second dimension of A +* @param {NonNegativeInteger} offsetA - starting index for A +* @param {Float32Array} bbuf - real view of B +* @param {integer} SB1 - stride of first dimension of B +* @param {integer} SB2 - stride of second dimension of B +* @param {NonNegativeInteger} offsetB - starting index for B +* @returns {void} +*/ +function rightNoTransLower( M, N, isUnitDiag, abuf, SA1, SA2, offsetA, bbuf, SB1, SB2, offsetB ) { // eslint-disable-line max-len + var aRe; + var aIm; + var bRe; + var bIm; + var iA; + var iB; + var jB; + var i; + var j; + var k; + + for ( j = N - 1; j >= 0; j-- ) { + if ( isUnitDiag === false ) { + iA = ( offsetA + ( j * SA1 ) + ( j * SA2 ) ) * 2; + aRe = abuf[ iA ]; + aIm = abuf[ iA + 1 ]; + for ( i = 0; i < M; i++ ) { + iB = ( offsetB + ( i * SB1 ) + ( j * SB2 ) ) * 2; + bRe = bbuf[ iB ]; + bIm = bbuf[ iB + 1 ]; + bbuf[ iB ] = cdivRe( bRe, bIm, aRe, aIm ); + bbuf[ iB + 1 ] = cdivIm( bRe, bIm, aRe, aIm ); + } + } + for ( k = j + 1; k < N; k++ ) { + iA = ( offsetA + ( k * SA1 ) + ( j * SA2 ) ) * 2; + aRe = abuf[ iA ]; + aIm = abuf[ iA + 1 ]; + if ( aRe !== 0.0 || aIm !== 0.0 ) { + for ( i = 0; i < M; i++ ) { + iB = ( offsetB + ( i * SB1 ) + ( j * SB2 ) ) * 2; + jB = ( offsetB + ( i * SB1 ) + ( k * SB2 ) ) * 2; + bbuf[ iB ] -= ( aRe * bbuf[ jB ] ) - ( aIm * bbuf[ jB + 1 ] ); + bbuf[ iB + 1 ] -= ( aRe * bbuf[ jB + 1 ] ) + ( aIm * bbuf[ jB ] ); + } + } + } + } +} + +/** +* Solves B*op(A)=B, right, upper, conjugate-transpose. +* +* @private +* @param {NonNegativeInteger} M - number of rows +* @param {NonNegativeInteger} N - number of columns +* @param {boolean} isUnitDiag - whether A has a unit diagonal +* @param {Float32Array} abuf - real view of A +* @param {integer} SA1 - stride of first dimension of A +* @param {integer} SA2 - stride of second dimension of A +* @param {NonNegativeInteger} offsetA - starting index for A +* @param {Float32Array} bbuf - real view of B +* @param {integer} SB1 - stride of first dimension of B +* @param {integer} SB2 - stride of second dimension of B +* @param {NonNegativeInteger} offsetB - starting index for B +* @returns {void} +*/ +function rightConjTransUpper( M, N, isUnitDiag, abuf, SA1, SA2, offsetA, bbuf, SB1, SB2, offsetB ) { // eslint-disable-line max-len + var aRe; + var aIm; + var bRe; + var bIm; + var iA; + var iB; + var jB; + var i; + var j; + var k; + + for ( k = N - 1; k >= 0; k-- ) { + if ( isUnitDiag === false ) { + iA = ( offsetA + ( k * SA1 ) + ( k * SA2 ) ) * 2; + aRe = abuf[ iA ]; + aIm = -abuf[ iA + 1 ]; // conjugate + for ( i = 0; i < M; i++ ) { + iB = ( offsetB + ( i * SB1 ) + ( k * SB2 ) ) * 2; + bRe = bbuf[ iB ]; + bIm = bbuf[ iB + 1 ]; + bbuf[ iB ] = cdivRe( bRe, bIm, aRe, aIm ); + bbuf[ iB + 1 ] = cdivIm( bRe, bIm, aRe, aIm ); + } + } + for ( j = 0; j < k; j++ ) { + iA = ( offsetA + ( j * SA1 ) + ( k * SA2 ) ) * 2; + aRe = abuf[ iA ]; + aIm = -abuf[ iA + 1 ]; // conjugate + if ( aRe !== 0.0 || aIm !== 0.0 ) { + for ( i = 0; i < M; i++ ) { + iB = ( offsetB + ( i * SB1 ) + ( k * SB2 ) ) * 2; + jB = ( offsetB + ( i * SB1 ) + ( j * SB2 ) ) * 2; + bRe = bbuf[ iB ]; + bIm = bbuf[ iB + 1 ]; + bbuf[ jB ] -= ( aRe * bRe ) - ( aIm * bIm ); + bbuf[ jB + 1 ] -= ( aRe * bIm ) + ( aIm * bRe ); + } + } + } + } +} + +/** +* Solves B*op(A)=B, right, lower, conjugate-transpose. +* +* @private +* @param {NonNegativeInteger} M - number of rows +* @param {NonNegativeInteger} N - number of columns +* @param {boolean} isUnitDiag - whether A has a unit diagonal +* @param {Float32Array} abuf - real view of A +* @param {integer} SA1 - stride of first dimension of A +* @param {integer} SA2 - stride of second dimension of A +* @param {NonNegativeInteger} offsetA - starting index for A +* @param {Float32Array} bbuf - real view of B +* @param {integer} SB1 - stride of first dimension of B +* @param {integer} SB2 - stride of second dimension of B +* @param {NonNegativeInteger} offsetB - starting index for B +* @returns {void} +*/ +function rightConjTransLower( M, N, isUnitDiag, abuf, SA1, SA2, offsetA, bbuf, SB1, SB2, offsetB ) { // eslint-disable-line max-len + var aRe; + var aIm; + var bRe; + var bIm; + var iA; + var iB; + var jB; + var i; + var j; + var k; + + for ( k = 0; k < N; k++ ) { + if ( isUnitDiag === false ) { + iA = ( offsetA + ( k * SA1 ) + ( k * SA2 ) ) * 2; + aRe = abuf[ iA ]; + aIm = -abuf[ iA + 1 ]; // conjugate + for ( i = 0; i < M; i++ ) { + iB = ( offsetB + ( i * SB1 ) + ( k * SB2 ) ) * 2; + bRe = bbuf[ iB ]; + bIm = bbuf[ iB + 1 ]; + bbuf[ iB ] = cdivRe( bRe, bIm, aRe, aIm ); + bbuf[ iB + 1 ] = cdivIm( bRe, bIm, aRe, aIm ); + } + } + for ( j = k + 1; j < N; j++ ) { + iA = ( offsetA + ( j * SA1 ) + ( k * SA2 ) ) * 2; + aRe = abuf[ iA ]; + aIm = -abuf[ iA + 1 ]; // conjugate + if ( aRe !== 0.0 || aIm !== 0.0 ) { + for ( i = 0; i < M; i++ ) { + iB = ( offsetB + ( i * SB1 ) + ( k * SB2 ) ) * 2; + jB = ( offsetB + ( i * SB1 ) + ( j * SB2 ) ) * 2; + bRe = bbuf[ iB ]; + bIm = bbuf[ iB + 1 ]; + bbuf[ jB ] -= ( aRe * bRe ) - ( aIm * bIm ); + bbuf[ jB + 1 ] -= ( aRe * bIm ) + ( aIm * bRe ); + } + } + } + } +} + +/** +* Solves B*op(A)=B, right, upper, transpose. +* +* @private +* @param {NonNegativeInteger} M - number of rows +* @param {NonNegativeInteger} N - number of columns +* @param {boolean} isUnitDiag - whether A has a unit diagonal +* @param {Float32Array} abuf - real view of A +* @param {integer} SA1 - stride of first dimension of A +* @param {integer} SA2 - stride of second dimension of A +* @param {NonNegativeInteger} offsetA - starting index for A +* @param {Float32Array} bbuf - real view of B +* @param {integer} SB1 - stride of first dimension of B +* @param {integer} SB2 - stride of second dimension of B +* @param {NonNegativeInteger} offsetB - starting index for B +* @returns {void} +*/ +function rightTransUpper( M, N, isUnitDiag, abuf, SA1, SA2, offsetA, bbuf, SB1, SB2, offsetB ) { // eslint-disable-line max-len + var aRe; + var aIm; + var bRe; + var bIm; + var iA; + var iB; + var jB; + var i; + var j; + var k; + + for ( k = N - 1; k >= 0; k-- ) { + if ( isUnitDiag === false ) { + iA = ( offsetA + ( k * SA1 ) + ( k * SA2 ) ) * 2; + aRe = abuf[ iA ]; + aIm = abuf[ iA + 1 ]; + for ( i = 0; i < M; i++ ) { + iB = ( offsetB + ( i * SB1 ) + ( k * SB2 ) ) * 2; + bRe = bbuf[ iB ]; + bIm = bbuf[ iB + 1 ]; + bbuf[ iB ] = cdivRe( bRe, bIm, aRe, aIm ); + bbuf[ iB + 1 ] = cdivIm( bRe, bIm, aRe, aIm ); + } + } + for ( j = 0; j < k; j++ ) { + iA = ( offsetA + ( j * SA1 ) + ( k * SA2 ) ) * 2; + aRe = abuf[ iA ]; + aIm = abuf[ iA + 1 ]; + if ( aRe !== 0.0 || aIm !== 0.0 ) { + for ( i = 0; i < M; i++ ) { + jB = ( offsetB + ( i * SB1 ) + ( j * SB2 ) ) * 2; + iB = ( offsetB + ( i * SB1 ) + ( k * SB2 ) ) * 2; + bRe = bbuf[ iB ]; + bIm = bbuf[ iB + 1 ]; + bbuf[ jB ] -= ( aRe * bRe ) - ( aIm * bIm ); + bbuf[ jB + 1 ] -= ( aRe * bIm ) + ( aIm * bRe ); + } + } + } + } +} + +/** +* Solves B*op(A)=B, right, lower, transpose. +* +* @private +* @param {NonNegativeInteger} M - number of rows +* @param {NonNegativeInteger} N - number of columns +* @param {boolean} isUnitDiag - whether A has a unit diagonal +* @param {Float32Array} abuf - real view of A +* @param {integer} SA1 - stride of first dimension of A +* @param {integer} SA2 - stride of second dimension of A +* @param {NonNegativeInteger} offsetA - starting index for A +* @param {Float32Array} bbuf - real view of B +* @param {integer} SB1 - stride of first dimension of B +* @param {integer} SB2 - stride of second dimension of B +* @param {NonNegativeInteger} offsetB - starting index for B +* @returns {void} +*/ +function rightTransLower( M, N, isUnitDiag, abuf, SA1, SA2, offsetA, bbuf, SB1, SB2, offsetB ) { // eslint-disable-line max-len + var aRe; + var aIm; + var bRe; + var bIm; + var iA; + var iB; + var jB; + var i; + var j; + var k; + + for ( k = 0; k < N; k++ ) { + if ( isUnitDiag === false ) { + iA = ( offsetA + ( k * SA1 ) + ( k * SA2 ) ) * 2; + aRe = abuf[ iA ]; + aIm = abuf[ iA + 1 ]; + for ( i = 0; i < M; i++ ) { + iB = ( offsetB + ( i * SB1 ) + ( k * SB2 ) ) * 2; + bRe = bbuf[ iB ]; + bIm = bbuf[ iB + 1 ]; + bbuf[ iB ] = cdivRe( bRe, bIm, aRe, aIm ); + bbuf[ iB + 1 ] = cdivIm( bRe, bIm, aRe, aIm ); + } + } + for ( j = k + 1; j < N; j++ ) { + iA = ( offsetA + ( j * SA1 ) + ( k * SA2 ) ) * 2; + aRe = abuf[ iA ]; + aIm = abuf[ iA + 1 ]; + if ( aRe !== 0.0 || aIm !== 0.0 ) { + for ( i = 0; i < M; i++ ) { + jB = ( offsetB + ( i * SB1 ) + ( j * SB2 ) ) * 2; + iB = ( offsetB + ( i * SB1 ) + ( k * SB2 ) ) * 2; + bRe = bbuf[ iB ]; + bIm = bbuf[ iB + 1 ]; + bbuf[ jB ] -= ( aRe * bRe ) - ( aIm * bIm ); + bbuf[ jB + 1 ] -= ( aRe * bIm ) + ( aIm * bRe ); + } + } + } + } +} + + +// MAIN // + +/** +* Solves one of the matrix equations `op(A)*X = alpha*B` or `X*op(A) = alpha*B`. +* +* @param {string} order - storage layout +* @param {string} side - specifies whether _A_ appears on the left or right +* @param {string} uplo - specifies whether upper or lower triangular part is used +* @param {string} transa - transpose operation applied to _A_ +* @param {string} diag - specifies whether _A_ is unit triangular +* @param {NonNegativeInteger} M - number of rows in _B_ +* @param {NonNegativeInteger} N - number of columns in _B_ +* @param {number} alphaRe - real part of scalar constant +* @param {number} alphaIm - imaginary part of scalar constant +* @param {Complex64Array} A - input matrix +* @param {PositiveInteger} strideA1 - stride of the first dimension of _A_ +* @param {NonNegativeInteger} offsetA - starting index for _A_ +* @param {Complex64Array} B - input/output matrix +* @param {PositiveInteger} strideB1 - stride of the first dimension of _B_ +* @param {NonNegativeInteger} offsetB - starting index for _B_ +* @throws {TypeError} first argument must be a valid order +* @throws {TypeError} second argument must be a valid side +* @throws {TypeError} third argument must be a valid matrix triangle +* @throws {TypeError} fourth argument must be a valid transpose operation +* @throws {TypeError} fifth argument must be a valid diagonal type +* @throws {RangeError} sixth argument must be a nonnegative integer +* @throws {RangeError} seventh argument must be a nonnegative integer +* @returns {Complex64Array} _B_ +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* +* var A = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 0.0 ] ); +* var B = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0 ] ); +* +* ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, 1.0, 0.0, A, 2, 0, B, 1, 0 ); +* // B => [ -3.0, 0.0, 2.0, 0.0 ] +*/ +function ctrsm( order, side, uplo, transa, diag, M, N, alphaRe, alphaIm, A, strideA1, offsetA, B, strideB1, offsetB ) { + var isConjTrans; + var isUnitDiag; + var isRowMajor; + var isNoTrans; + var isUpper; + var isLeft; + var abuf; + var bbuf; + var SA1; + var SA2; + var SB1; + var SB2; + + if ( !isLayout( order ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a valid order. Value: `%s`.', order ) ); + } + if ( !isOperationSide( side ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be a valid side. Value: `%s`.', side ) ); + } + if ( !isMatrixTriangle( uplo ) ) { + throw new TypeError( format( 'invalid argument. Third argument must be a valid matrix triangle. Value: `%s`.', uplo ) ); + } + if ( !isTransposeOperation( transa ) ) { + throw new TypeError( format( 'invalid argument. Fourth argument must be a valid transpose operation. Value: `%s`.', transa ) ); + } + if ( !isDiagonalType( diag ) ) { + throw new TypeError( format( 'invalid argument. Fifth argument must be a valid diagonal type. Value: `%s`.', diag ) ); + } + if ( M < 0 ) { + throw new RangeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%d`.', M ) ); + } + if ( N < 0 ) { + throw new RangeError( format( 'invalid argument. Seventh argument must be a nonnegative integer. Value: `%d`.', N ) ); + } + // Quick return if possible: + if ( M === 0 || N === 0 ) { + return B; + } + isLeft = ( side === 'left' ); + isUpper = ( uplo === 'upper' ); + isNoTrans = ( transa === 'no-transpose' ); + isConjTrans = ( transa === 'conjugate-transpose' ); + isUnitDiag = ( diag === 'unit' ); + isRowMajor = ( order === 'row-major' ); + + // Get Float32 views of the complex arrays: + abuf = reinterpret( A, 0 ); + bbuf = reinterpret( B, 0 ); + + // Set strides based on layout: + if ( isRowMajor ) { + SA1 = strideA1; + SA2 = 1; + SB1 = strideB1; + SB2 = 1; + } else { + SA1 = 1; + SA2 = strideA1; + SB1 = 1; + SB2 = strideB1; + } + // Scale B by alpha: + if ( alphaRe !== 1.0 || alphaIm !== 0.0 ) { + scaleB( M, N, alphaRe, alphaIm, bbuf, SB1, SB2, offsetB ); + } + // Quick return if alpha is zero: + if ( alphaRe === 0.0 && alphaIm === 0.0 ) { + return B; + } + // Dispatch to the appropriate solver: + if ( isLeft ) { + if ( isNoTrans ) { + if ( isUpper ) { + leftNoTransUpper(M, N, isUnitDiag, abuf, SA1, SA2, offsetA, bbuf, SB1, SB2, offsetB); + } else { + leftNoTransLower(M, N, isUnitDiag, abuf, SA1, SA2, offsetA, bbuf, SB1, SB2, offsetB); + } + } else if ( isConjTrans ) { + if ( isUpper ) { + leftConjTransUpper(M, N, isUnitDiag, abuf, SA1, SA2, offsetA, bbuf, SB1, SB2, offsetB); + } else { + leftConjTransLower(M, N, isUnitDiag, abuf, SA1, SA2, offsetA, bbuf, SB1, SB2, offsetB); + } + } else if ( isUpper ) { + leftTransUpper(M, N, isUnitDiag, abuf, SA1, SA2, offsetA, bbuf, SB1, SB2, offsetB); + } else { + leftTransLower(M, N, isUnitDiag, abuf, SA1, SA2, offsetA, bbuf, SB1, SB2, offsetB); + } + } else if ( isNoTrans ) { + if ( isUpper ) { + rightNoTransUpper(M, N, isUnitDiag, abuf, SA1, SA2, offsetA, bbuf, SB1, SB2, offsetB); + } else { + rightNoTransLower(M, N, isUnitDiag, abuf, SA1, SA2, offsetA, bbuf, SB1, SB2, offsetB); + } + } else if ( isConjTrans ) { + if ( isUpper ) { + rightConjTransUpper(M, N, isUnitDiag, abuf, SA1, SA2, offsetA, bbuf, SB1, SB2, offsetB); + } else { + rightConjTransLower(M, N, isUnitDiag, abuf, SA1, SA2, offsetA, bbuf, SB1, SB2, offsetB); + } + } else if ( isUpper ) { + rightTransUpper(M, N, isUnitDiag, abuf, SA1, SA2, offsetA, bbuf, SB1, SB2, offsetB); + } else { + rightTransLower(M, N, isUnitDiag, abuf, SA1, SA2, offsetA, bbuf, SB1, SB2, offsetB); + } + return B; +} + + +// EXPORTS // + +module.exports = ctrsm; diff --git a/lib/node_modules/@stdlib/blas/base/ctrsm/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/base/ctrsm/lib/ndarray.native.js new file mode 100644 index 000000000000..f4094fc88341 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ctrsm/lib/ndarray.native.js @@ -0,0 +1,74 @@ +/** +* @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 reinterpret = require( '@stdlib/strided/base/reinterpret-complex64' ); +var str2enumLayout = require( '@stdlib/blas/base/layout-str2enum' ); +var str2enumSide = require( '@stdlib/blas/base/operation-side-str2enum' ); +var str2enumUplo = require( '@stdlib/blas/base/matrix-triangle-str2enum' ); +var str2enumTrans = require( '@stdlib/blas/base/transpose-operation-str2enum' ); +var str2enumDiag = require( '@stdlib/blas/base/diagonal-type-str2enum' ); +var addon = require( './../src/addon.node' ); + + +// MAIN // + +/** +* Solves one of the matrix equations `op(A)*X = alpha*B` or `X*op(A) = alpha*B` using alternative indexing semantics. +* +* @param {string} order - storage layout +* @param {string} side - specifies whether _A_ appears on the left or right +* @param {string} uplo - specifies whether the upper or lower triangular part +* @param {string} transa - transpose operation applied to _A_ +* @param {string} diag - specifies whether _A_ is unit triangular +* @param {NonNegativeInteger} M - number of rows in _B_ +* @param {NonNegativeInteger} N - number of columns in _B_ +* @param {number} alphaRe - real part of scalar constant +* @param {number} alphaIm - imaginary part of scalar constant +* @param {Complex64Array} A - input matrix +* @param {integer} strideA1 - stride of the first dimension of _A_ +* @param {NonNegativeInteger} offsetA - starting index for _A_ +* @param {Complex64Array} B - input/output matrix +* @param {integer} strideB1 - stride of the first dimension of _B_ +* @param {NonNegativeInteger} offsetB - starting index for _B_ +* @returns {Complex64Array} _B_ +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* +* var A = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 0.0 ] ); +* var B = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0 ] ); +* +* ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, +* 1.0, 0.0, A, 2, 0, B, 1, 0 ); +* // B => [ -3.0, 0.0, 2.0, 0.0 ] +*/ +function ctrsm( order, side, uplo, transa, diag, M, N, alphaRe, alphaIm, A, strideA1, offsetA, B, strideB1, offsetB ) { // eslint-disable-line max-params, max-len + var viewA = reinterpret( A, 0 ); + var viewB = reinterpret( B, 0 ); + addon.ndarray(str2enumLayout( order ), str2enumSide( side ), str2enumUplo( uplo ), str2enumTrans( transa ), str2enumDiag( diag ), M, N, alphaRe, alphaIm, viewA, strideA1, offsetA, viewB, strideB1, offsetB); + return B; +} + + +// EXPORTS // + +module.exports = ctrsm; diff --git a/lib/node_modules/@stdlib/blas/base/ctrsm/manifest.json b/lib/node_modules/@stdlib/blas/base/ctrsm/manifest.json new file mode 100644 index 000000000000..e3fa3f35c466 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ctrsm/manifest.json @@ -0,0 +1,444 @@ +{ + "options": { + "task": "build", + "os": "linux", + "blas": "", + "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", + "os": "linux", + "blas": "", + "wasm": false, + "src": [ + "./src/ctrsm.f", + "./src/ctrsm_f.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-strided-float32array", + "@stdlib/napi/argv-complex64", + "@stdlib/complex/float32/ctor" + ] + }, + { + "task": "benchmark", + "os": "linux", + "blas": "", + "wasm": false, + "src": [ + "./src/ctrsm.c", + "./src/ctrsm_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/complex/float32/ctor" + ] + }, + { + "task": "examples", + "os": "linux", + "blas": "", + "wasm": false, + "src": [ + "./src/ctrsm.c", + "./src/ctrsm_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/complex/float32/ctor" + ] + }, + + { + "task": "build", + "os": "linux", + "blas": "openblas", + "wasm": false, + "src": [ + "./src/ctrsm_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lopenblas", + "-lpthread" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-strided-float32array", + "@stdlib/napi/argv-complex64", + "@stdlib/complex/float32/ctor" + ] + }, + { + "task": "benchmark", + "os": "linux", + "blas": "openblas", + "wasm": false, + "src": [ + "./src/ctrsm_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lopenblas", + "-lpthread" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/complex/float32/ctor" + ] + }, + { + "task": "examples", + "os": "linux", + "blas": "openblas", + "wasm": false, + "src": [ + "./src/ctrsm_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lopenblas", + "-lpthread" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/complex/float32/ctor" + ] + }, + + { + "task": "build", + "os": "mac", + "blas": "", + "wasm": false, + "src": [ + "./src/ctrsm.f", + "./src/ctrsm_f.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-strided-float32array", + "@stdlib/napi/argv-complex64", + "@stdlib/complex/float32/ctor" + ] + }, + { + "task": "benchmark", + "os": "mac", + "blas": "", + "wasm": false, + "src": [ + "./src/ctrsm.c", + "./src/ctrsm_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/complex/float32/ctor" + ] + }, + { + "task": "examples", + "os": "mac", + "blas": "", + "wasm": false, + "src": [ + "./src/ctrsm.c", + "./src/ctrsm_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/complex/float32/ctor" + ] + }, + + { + "task": "build", + "os": "mac", + "blas": "apple_accelerate_framework", + "wasm": false, + "src": [ + "./src/ctrsm_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lblas" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-strided-float32array", + "@stdlib/napi/argv-complex64", + "@stdlib/complex/float32/ctor" + ] + }, + { + "task": "benchmark", + "os": "mac", + "blas": "apple_accelerate_framework", + "wasm": false, + "src": [ + "./src/ctrsm_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lblas" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/complex/float32/ctor" + ] + }, + { + "task": "examples", + "os": "mac", + "blas": "apple_accelerate_framework", + "wasm": false, + "src": [ + "./src/ctrsm_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lblas" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/complex/float32/ctor" + ] + }, + + { + "task": "build", + "os": "mac", + "blas": "openblas", + "wasm": false, + "src": [ + "./src/ctrsm_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lopenblas", + "-lpthread" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-strided-float32array", + "@stdlib/napi/argv-complex64", + "@stdlib/complex/float32/ctor" + ] + }, + { + "task": "benchmark", + "os": "mac", + "blas": "openblas", + "wasm": false, + "src": [ + "./src/ctrsm_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lopenblas", + "-lpthread" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/complex/float32/ctor" + ] + }, + { + "task": "examples", + "os": "mac", + "blas": "openblas", + "wasm": false, + "src": [ + "./src/ctrsm_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lopenblas", + "-lpthread" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/complex/float32/ctor" + ] + }, + + { + "task": "build", + "os": "win", + "blas": "", + "wasm": false, + "src": [ + "./src/ctrsm.c", + "./src/ctrsm_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-strided-float32array", + "@stdlib/napi/argv-complex64", + "@stdlib/complex/float32/ctor" + ] + }, + { + "task": "benchmark", + "os": "win", + "blas": "", + "wasm": false, + "src": [ + "./src/ctrsm.c", + "./src/ctrsm_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/complex/float32/ctor" + ] + }, + { + "task": "examples", + "os": "win", + "blas": "", + "wasm": false, + "src": [ + "./src/ctrsm.c", + "./src/ctrsm_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/complex/float32/ctor" + ] + }, + + { + "task": "build", + "os": "", + "blas": "", + "wasm": true, + "src": [ + "./src/ctrsm.c", + "./src/ctrsm_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/complex/float32/ctor" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/blas/base/ctrsm/package.json b/lib/node_modules/@stdlib/blas/base/ctrsm/package.json new file mode 100644 index 000000000000..52a9f6c6f9de --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ctrsm/package.json @@ -0,0 +1,109 @@ +{ + "name": "@stdlib/blas-base-ctrsm", + "version": "0.0.0", + "description": "Solve one of the matrix equations `op(A)*X = alpha*B` or `X*op(A) = alpha*B` where `A` is a complex single-precision floating-point triangular 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", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "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": { + "@stdlib/assert-is-error": "^0.2.2", + "@stdlib/blas-base-assert-is-diagonal-type": "^0.2.2", + "@stdlib/blas-base-assert-is-layout": "^0.2.2", + "@stdlib/blas-base-assert-is-matrix-triangle": "^0.2.2", + "@stdlib/blas-base-assert-is-operation-side": "^0.2.2", + "@stdlib/blas-base-assert-is-transpose-operation": "^0.2.2", + "@stdlib/blas-base-diagonal-type-str2enum": "^0.2.2", + "@stdlib/blas-base-layout-str2enum": "^0.2.2", + "@stdlib/blas-base-matrix-triangle-str2enum": "^0.2.2", + "@stdlib/blas-base-operation-side-str2enum": "^0.2.2", + "@stdlib/blas-base-transpose-operation-str2enum": "^0.2.2", + "@stdlib/complex-float32-imag": "^0.2.2", + "@stdlib/complex-float32-real": "^0.2.2", + "@stdlib/strided-base-reinterpret-complex64": "^0.2.2", + "@stdlib/string-format": "^0.2.2", + "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", + "@stdlib/utils-try-require": "^0.2.2" + }, + "devDependencies": { + "@stdlib/array-complex64": "^0.3.0", + "@stdlib/array-float32": "^0.2.2", + "@stdlib/complex-float32-ctor": "^0.3.0", + "@stdlib/constants-float32-eps": "^0.2.2", + "@stdlib/math-base-assert-is-nanf": "^0.2.2", + "@stdlib/math-base-special-abs": "^0.2.2", + "@stdlib/math-base-special-pow": "^0.3.0", + "@stdlib/random-array-discrete-uniform": "^0.3.0", + "@stdlib/random-array-uniform": "^0.2.2", + "@stdlib/random-base-randu": "^0.2.1" + }, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "mathematics", + "math", + "blas", + "level3", + "ctrsm", + "linear", + "algebra", + "subroutines", + "array", + "ndarray", + "float32", + "complex", + "triangular", + "solve", + "matrix", + "node", + "node-js", + "nodejs", + "javascript" + ], + "__stdlib__": { + "scaffold": { + "@stdlib/blas/base/ctrsm": "0.0.x" + } + } +} diff --git a/lib/node_modules/@stdlib/blas/base/ctrsm/src/Makefile b/lib/node_modules/@stdlib/blas/base/ctrsm/src/Makefile new file mode 100644 index 000000000000..2caf905cedbe --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ctrsm/src/Makefile @@ -0,0 +1,70 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + + +# RULES # + +#/ +# Removes generated files for building an add-on. +# +# @example +# make clean-addon +#/ +clean-addon: + $(QUIET) -rm -f *.o *.node + +.PHONY: clean-addon + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: clean-addon + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/blas/base/ctrsm/src/addon.c b/lib/node_modules/@stdlib/blas/base/ctrsm/src/addon.c new file mode 100644 index 000000000000..be588d6fa5fd --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ctrsm/src/addon.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/blas/base/ctrsm.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/napi/export.h" +#include "stdlib/napi/argv.h" +#include "stdlib/napi/argv_int64.h" +#include "stdlib/napi/argv_complex64.h" +#include "stdlib/napi/argv_strided_float32array.h" +#include + +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 12 ); + STDLIB_NAPI_ARGV_INT64( env, order, argv, 0 ); + STDLIB_NAPI_ARGV_INT64( env, side, argv, 1 ); + STDLIB_NAPI_ARGV_INT64( env, uplo, argv, 2 ); + STDLIB_NAPI_ARGV_INT64( env, transA, argv, 3 ); + STDLIB_NAPI_ARGV_INT64( env, diag, argv, 4 ); + STDLIB_NAPI_ARGV_INT64( env, M, argv, 5 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 6 ); + STDLIB_NAPI_ARGV_COMPLEX64( env, alpha, argv, 7 ); + STDLIB_NAPI_ARGV_INT64( env, LDA, argv, 9 ); + STDLIB_NAPI_ARGV_INT64( env, LDB, argv, 11 ); + int64_t nA = ( side == 141 ) ? M : N; /* 141 = CblasLeft */ + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, A, nA, LDA*2, argv, 8 ); + int64_t nB = ( order == 101 ) ? M : N; /* 101 = CblasRowMajor */ + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, B, nB, LDB*2, argv, 10 ); + API_SUFFIX(c_ctrsm)( (CBLAS_LAYOUT)order, (CBLAS_SIDE)side, (CBLAS_UPLO)uplo, (CBLAS_TRANSPOSE)transA, (CBLAS_DIAG)diag, M, N, alpha, (const void *)A, LDA, (void *)B, LDB ); + return NULL; +} + +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon_method( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 15 ); + STDLIB_NAPI_ARGV_INT64( env, order, argv, 0 ); + STDLIB_NAPI_ARGV_INT64( env, side, argv, 1 ); + STDLIB_NAPI_ARGV_INT64( env, uplo, argv, 2 ); + STDLIB_NAPI_ARGV_INT64( env, transA, argv, 3 ); + STDLIB_NAPI_ARGV_INT64( env, diag, argv, 4 ); + STDLIB_NAPI_ARGV_INT64( env, M, argv, 5 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 6 ); + STDLIB_NAPI_ARGV_INT64( env, alphaRe_raw, argv, 7 ); + STDLIB_NAPI_ARGV_INT64( env, alphaIm_raw, argv, 8 ); + STDLIB_NAPI_ARGV_INT64( env, sa1, argv, 10 ); + STDLIB_NAPI_ARGV_INT64( env, offsetA, argv, 11 ); + STDLIB_NAPI_ARGV_INT64( env, sb1, argv, 13 ); + STDLIB_NAPI_ARGV_INT64( env, offsetB, argv, 14 ); + int64_t nA = ( side == 141 ) ? M : N; + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, A, nA, sa1*2, argv, 9 ); + int64_t nB = ( order == 101 ) ? M : N; + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, B, nB, sb1*2, argv, 12 ); + float alphaRe = (float)alphaRe_raw; + float alphaIm = (float)alphaIm_raw; + API_SUFFIX(c_ctrsm_ndarray)( (CBLAS_LAYOUT)order, (CBLAS_SIDE)side, (CBLAS_UPLO)uplo, (CBLAS_TRANSPOSE)transA, (CBLAS_DIAG)diag, M, N, alphaRe, alphaIm, (const void *)A, sa1, offsetA, (void *)B, sb1, offsetB ); + return NULL; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method ) diff --git a/lib/node_modules/@stdlib/blas/base/ctrsm/src/ctrsm.c b/lib/node_modules/@stdlib/blas/base/ctrsm/src/ctrsm.c new file mode 100644 index 000000000000..6c1f6c7d8626 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ctrsm/src/ctrsm.c @@ -0,0 +1,43 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/blas/base/ctrsm.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/complex/float32/ctor.h" + +/** +* Solves one of the matrix equations `op(A)*X = alpha*B` or `X*op(A) = alpha*B`. +* +* @param order storage layout +* @param side specifies whether A appears on the left or right +* @param uplo specifies whether upper or lower triangular part of A is used +* @param transA transpose operation applied to A +* @param diag specifies whether A is unit triangular +* @param M number of rows in B +* @param N number of columns in B +* @param alpha scalar constant +* @param A input triangular matrix +* @param LDA leading dimension of A +* @param B input/output matrix +* @param LDB leading dimension of B +*/ +void API_SUFFIX(c_ctrsm)( const CBLAS_LAYOUT order, const CBLAS_SIDE side, const CBLAS_UPLO uplo, const CBLAS_TRANSPOSE transA, const CBLAS_DIAG diag, const CBLAS_INT M, const CBLAS_INT N, const stdlib_complex64_t alpha, const void *A, const CBLAS_INT LDA, void *B, const CBLAS_INT LDB ) { + float alphaRe = stdlib_complex64_real( alpha ); + float alphaIm = stdlib_complex64_imag( alpha ); + API_SUFFIX(c_ctrsm_ndarray)( order, side, uplo, transA, diag, M, N, alphaRe, alphaIm, A, LDA, 0, B, LDB, 0 ); +} diff --git a/lib/node_modules/@stdlib/blas/base/ctrsm/src/ctrsm_cblas.c b/lib/node_modules/@stdlib/blas/base/ctrsm/src/ctrsm_cblas.c new file mode 100644 index 000000000000..ebfe6be68da3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ctrsm/src/ctrsm_cblas.c @@ -0,0 +1,69 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/blas/base/ctrsm.h" +#include "stdlib/blas/base/ctrsm_cblas.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/complex/float32/ctor.h" + +/** +* Solves one of the matrix equations `op(A)*X = alpha*B` or `X*op(A) = alpha*B`. +* +* @param order storage layout +* @param side specifies whether A appears on the left or right +* @param uplo specifies whether upper or lower triangular part of A is used +* @param transA transpose operation applied to A +* @param diag specifies whether A is unit triangular +* @param M number of rows in B +* @param N number of columns in B +* @param alpha scalar constant +* @param A input triangular matrix +* @param LDA leading dimension of A +* @param B input/output matrix +* @param LDB leading dimension of B +*/ +void API_SUFFIX(c_ctrsm)( const CBLAS_LAYOUT order, const CBLAS_SIDE side, const CBLAS_UPLO uplo, const CBLAS_TRANSPOSE transA, const CBLAS_DIAG diag, const CBLAS_INT M, const CBLAS_INT N, const stdlib_complex64_t alpha, const void *A, const CBLAS_INT LDA, void *B, const CBLAS_INT LDB ) { + API_SUFFIX(cblas_ctrsm)( order, side, uplo, transA, diag, M, N, (const void *)&alpha, A, LDA, B, LDB ); +} + +/** +* Solves one of the matrix equations `op(A)*X = alpha*B` or `X*op(A) = alpha*B` +* using alternative indexing semantics. +* +* @param order storage layout +* @param side specifies whether A appears on the left or right +* @param uplo specifies whether upper or lower triangular part of A is used +* @param transA transpose operation applied to A +* @param diag specifies whether A is unit triangular +* @param M number of rows in B +* @param N number of columns in B +* @param alphaRe real part of scalar constant +* @param alphaIm imaginary part of scalar constant +* @param A input triangular matrix +* @param strideA1 leading dimension stride of A +* @param offsetA starting index for A +* @param B input/output matrix +* @param strideB1 leading dimension stride of B +* @param offsetB starting index for B +*/ +void API_SUFFIX(c_ctrsm_ndarray)( const CBLAS_LAYOUT order, const CBLAS_SIDE side, const CBLAS_UPLO uplo, const CBLAS_TRANSPOSE transA, const CBLAS_DIAG diag, const CBLAS_INT M, const CBLAS_INT N, const float alphaRe, const float alphaIm, const void *A, const CBLAS_INT strideA1, const CBLAS_INT offsetA, void *B, const CBLAS_INT strideB1, const CBLAS_INT offsetB ) { + stdlib_complex64_t alpha = stdlib_complex64( alphaRe, alphaIm ); + const float *abuf = (const float *)A + ( offsetA * 2 ); + float *bbuf = (float *)B + ( offsetB * 2 ); + API_SUFFIX(cblas_ctrsm)( order, side, uplo, transA, diag, M, N, (const void *)&alpha, (const void *)abuf, strideA1, (void *)bbuf, strideB1 ); +} diff --git a/lib/node_modules/@stdlib/blas/base/ctrsm/src/ctrsm_f.c b/lib/node_modules/@stdlib/blas/base/ctrsm/src/ctrsm_f.c new file mode 100644 index 000000000000..91960f31e79f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ctrsm/src/ctrsm_f.c @@ -0,0 +1,82 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/blas/base/ctrsm.h" +#include "stdlib/blas/base/ctrsm_fortran.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/complex/float32/ctor.h" + +/** +* Solves one of the matrix equations `op(A)*X = alpha*B` or `X*op(A) = alpha*B`. +* +* @param order storage layout +* @param side specifies whether A appears on the left or right +* @param uplo specifies whether upper or lower triangular part of A is used +* @param transA transpose operation applied to A +* @param diag specifies whether A is unit triangular +* @param M number of rows in B +* @param N number of columns in B +* @param alpha scalar constant +* @param A input triangular matrix +* @param LDA leading dimension of A +* @param B input/output matrix +* @param LDB leading dimension of B +*/ +void API_SUFFIX(c_ctrsm)( const CBLAS_LAYOUT order, const CBLAS_SIDE side, const CBLAS_UPLO uplo, const CBLAS_TRANSPOSE transA, const CBLAS_DIAG diag, const CBLAS_INT M, const CBLAS_INT N, const stdlib_complex64_t alpha, const void *A, const CBLAS_INT LDA, void *B, const CBLAS_INT LDB ) { + char sideChar = ( side == CblasLeft ) ? 'L' : 'R'; + char uploChar = ( uplo == CblasUpper ) ? 'U' : 'L'; + char transChar = ( transA == CblasNoTrans ) ? 'N' : ( transA == CblasTrans ) ? 'T' : 'C'; + char diagChar = ( diag == CblasUnit ) ? 'U' : 'N'; + /* For column-major Fortran interface, swap M/N if row-major: */ + CBLAS_INT fm = ( order == CblasRowMajor ) ? N : M; + CBLAS_INT fn = ( order == CblasRowMajor ) ? M : N; + ctrsm( &sideChar, &uploChar, &transChar, &diagChar, &fm, &fn, (const void *)&alpha, A, &LDA, B, &LDB ); +} + +/** +* Solves one of the matrix equations `op(A)*X = alpha*B` or `X*op(A) = alpha*B` +* using alternative indexing semantics. +* +* @param order storage layout +* @param side specifies whether A appears on the left or right +* @param uplo specifies whether upper or lower triangular part of A is used +* @param transA transpose operation applied to A +* @param diag specifies whether A is unit triangular +* @param M number of rows in B +* @param N number of columns in B +* @param alphaRe real part of scalar constant +* @param alphaIm imaginary part of scalar constant +* @param A input triangular matrix +* @param strideA1 leading dimension stride of A +* @param offsetA starting index for A +* @param B input/output matrix +* @param strideB1 leading dimension stride of B +* @param offsetB starting index for B +*/ +void API_SUFFIX(c_ctrsm_ndarray)( const CBLAS_LAYOUT order, const CBLAS_SIDE side, const CBLAS_UPLO uplo, const CBLAS_TRANSPOSE transA, const CBLAS_DIAG diag, const CBLAS_INT M, const CBLAS_INT N, const float alphaRe, const float alphaIm, const void *A, const CBLAS_INT strideA1, const CBLAS_INT offsetA, void *B, const CBLAS_INT strideB1, const CBLAS_INT offsetB ) { + stdlib_complex64_t alpha = stdlib_complex64( alphaRe, alphaIm ); + const float *abuf = (const float *)A + ( offsetA * 2 ); + float *bbuf = (float *)B + ( offsetB * 2 ); + char sideChar = ( side == CblasLeft ) ? 'L' : 'R'; + char uploChar = ( uplo == CblasUpper ) ? 'U' : 'L'; + char transChar = ( transA == CblasNoTrans ) ? 'N' : ( transA == CblasTrans ) ? 'T' : 'C'; + char diagChar = ( diag == CblasUnit ) ? 'U' : 'N'; + CBLAS_INT fm = ( order == CblasRowMajor ) ? N : M; + CBLAS_INT fn = ( order == CblasRowMajor ) ? M : N; + ctrsm( &sideChar, &uploChar, &transChar, &diagChar, &fm, &fn, (const void *)&alpha, (const void *)abuf, &strideA1, (void *)bbuf, &strideB1 ); +} diff --git a/lib/node_modules/@stdlib/blas/base/ctrsm/src/ctrsm_ndarray.c b/lib/node_modules/@stdlib/blas/base/ctrsm/src/ctrsm_ndarray.c new file mode 100644 index 000000000000..3e5b5bbc67d0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ctrsm/src/ctrsm_ndarray.c @@ -0,0 +1,344 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/blas/base/ctrsm.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/complex/float32/ctor.h" +#include + +/** +* Returns the real part of complex division: (bRe + i*bIm) / (aRe + i*aIm). +*/ +static float cdivf_re( const float bRe, const float bIm, const float aRe, const float aIm ) { + float denom = ( aRe * aRe ) + ( aIm * aIm ); + return ( ( bRe * aRe ) + ( bIm * aIm ) ) / denom; +} + +/** +* Returns the imaginary part of complex division: (bRe + i*bIm) / (aRe + i*aIm). +*/ +static float cdivf_im( const float bRe, const float bIm, const float aRe, const float aIm ) { + float denom = ( aRe * aRe ) + ( aIm * aIm ); + return ( ( bIm * aRe ) - ( bRe * aIm ) ) / denom; +} + +/** +* Solves one of the matrix equations `op(A)*X = alpha*B` or `X*op(A) = alpha*B` +* using alternative indexing semantics. +* +* @param order storage layout +* @param side specifies whether A appears on the left or right +* @param uplo specifies whether upper or lower triangular part of A is used +* @param transA transpose operation applied to A +* @param diag specifies whether A is unit triangular +* @param M number of rows in B +* @param N number of columns in B +* @param alphaRe real part of scalar constant +* @param alphaIm imaginary part of scalar constant +* @param A input triangular matrix (float32 interleaved re/im) +* @param strideA1 leading dimension stride of A +* @param offsetA starting index for A +* @param B input/output matrix (float32 interleaved re/im) +* @param strideB1 leading dimension stride of B +* @param offsetB starting index for B +*/ +void API_SUFFIX(c_ctrsm_ndarray)( const CBLAS_LAYOUT order, const CBLAS_SIDE side, const CBLAS_UPLO uplo, const CBLAS_TRANSPOSE transA, const CBLAS_DIAG diag, const CBLAS_INT M, const CBLAS_INT N, const float alphaRe, const float alphaIm, const void *A, const CBLAS_INT strideA1, const CBLAS_INT offsetA, void *B, const CBLAS_INT strideB1, const CBLAS_INT offsetB ) { + const float *abuf = (const float *)A; + float *bbuf = (float *)B; + CBLAS_INT isLeft = ( side == CblasLeft ); + CBLAS_INT isUpper = ( uplo == CblasUpper ); + CBLAS_INT isNoTrans = ( transA == CblasNoTrans ); + CBLAS_INT isConjTrans = ( transA == CblasConjTrans ); + CBLAS_INT isUnit = ( diag == CblasUnit ); + CBLAS_INT isRowMajor = ( order == CblasRowMajor ); + CBLAS_INT SA1, SA2, SB1, SB2; + CBLAS_INT i, j, k, iA, iB; + float aRe, aIm, bRe, bIm, kbRe, kbIm, tRe, tIm; + + if ( M == 0 || N == 0 ) { + return; + } + if ( isRowMajor ) { + SA1 = strideA1; + SA2 = 1; + SB1 = strideB1; + SB2 = 1; + } else { + SA1 = 1; + SA2 = strideA1; + SB1 = 1; + SB2 = strideB1; + } + + /* Scale B by alpha */ + if ( alphaRe != 1.0f || alphaIm != 0.0f ) { + for ( i = 0; i < M; i++ ) { + for ( j = 0; j < N; j++ ) { + iB = ( offsetB + ( i * SB1 ) + ( j * SB2 ) ) * 2; + bRe = bbuf[ iB ]; + bIm = bbuf[ iB + 1 ]; + bbuf[ iB ] = ( alphaRe * bRe ) - ( alphaIm * bIm ); + bbuf[ iB + 1 ] = ( alphaRe * bIm ) + ( alphaIm * bRe ); + } + } + } + if ( alphaRe == 0.0f && alphaIm == 0.0f ) { + return; + } + + if ( isLeft ) { + if ( isNoTrans ) { + if ( isUpper ) { + for ( j = 0; j < N; j++ ) { + for ( k = M - 1; k >= 0; k-- ) { + iB = ( offsetB + ( k * SB1 ) + ( j * SB2 ) ) * 2; + bRe = bbuf[ iB ]; + bIm = bbuf[ iB + 1 ]; + if ( bRe != 0.0f || bIm != 0.0f ) { + if ( isUnit == 0 ) { + iA = ( offsetA + ( k * SA1 ) + ( k * SA2 ) ) * 2; + aRe = abuf[ iA ]; + aIm = abuf[ iA + 1 ]; + bbuf[ iB ] = cdivf_re( bRe, bIm, aRe, aIm ); + bbuf[ iB + 1 ] = cdivf_im( bRe, bIm, aRe, aIm ); + bRe = bbuf[ iB ]; + bIm = bbuf[ iB + 1 ]; + } + for ( i = 0; i < k; i++ ) { + iA = ( offsetA + ( i * SA1 ) + ( k * SA2 ) ) * 2; + aRe = abuf[ iA ]; + aIm = abuf[ iA + 1 ]; + iB = ( offsetB + ( i * SB1 ) + ( j * SB2 ) ) * 2; + bbuf[ iB ] -= ( aRe * bRe ) - ( aIm * bIm ); + bbuf[ iB + 1 ] -= ( aRe * bIm ) + ( aIm * bRe ); + } + } + } + } + } else { + for ( j = 0; j < N; j++ ) { + for ( k = 0; k < M; k++ ) { + iB = ( offsetB + ( k * SB1 ) + ( j * SB2 ) ) * 2; + bRe = bbuf[ iB ]; + bIm = bbuf[ iB + 1 ]; + if ( bRe != 0.0f || bIm != 0.0f ) { + if ( isUnit == 0 ) { + iA = ( offsetA + ( k * SA1 ) + ( k * SA2 ) ) * 2; + aRe = abuf[ iA ]; + aIm = abuf[ iA + 1 ]; + bbuf[ iB ] = cdivf_re( bRe, bIm, aRe, aIm ); + bbuf[ iB + 1 ] = cdivf_im( bRe, bIm, aRe, aIm ); + bRe = bbuf[ iB ]; + bIm = bbuf[ iB + 1 ]; + } + for ( i = k + 1; i < M; i++ ) { + iA = ( offsetA + ( i * SA1 ) + ( k * SA2 ) ) * 2; + aRe = abuf[ iA ]; + aIm = abuf[ iA + 1 ]; + iB = ( offsetB + ( i * SB1 ) + ( j * SB2 ) ) * 2; + bbuf[ iB ] -= ( aRe * bRe ) - ( aIm * bIm ); + bbuf[ iB + 1 ] -= ( aRe * bIm ) + ( aIm * bRe ); + } + } + } + } + } + } else { + /* Transpose or conjugate-transpose */ + if ( isUpper ) { + for ( j = 0; j < N; j++ ) { + for ( i = 0; i < M; i++ ) { + iB = ( offsetB + ( i * SB1 ) + ( j * SB2 ) ) * 2; + tRe = bbuf[ iB ]; + tIm = bbuf[ iB + 1 ]; + for ( k = 0; k < i; k++ ) { + iA = ( offsetA + ( k * SA1 ) + ( i * SA2 ) ) * 2; + aRe = abuf[ iA ]; + aIm = ( isConjTrans ) ? -abuf[ iA + 1 ] : abuf[ iA + 1 ]; + iB = ( offsetB + ( k * SB1 ) + ( j * SB2 ) ) * 2; + bRe = bbuf[ iB ]; + bIm = bbuf[ iB + 1 ]; + tRe -= ( aRe * bRe ) - ( aIm * bIm ); + tIm -= ( aRe * bIm ) + ( aIm * bRe ); + } + if ( isUnit == 0 ) { + iA = ( offsetA + ( i * SA1 ) + ( i * SA2 ) ) * 2; + aRe = abuf[ iA ]; + aIm = ( isConjTrans ) ? -abuf[ iA + 1 ] : abuf[ iA + 1 ]; + iB = ( offsetB + ( i * SB1 ) + ( j * SB2 ) ) * 2; + bbuf[ iB ] = cdivf_re( tRe, tIm, aRe, aIm ); + bbuf[ iB + 1 ] = cdivf_im( tRe, tIm, aRe, aIm ); + } else { + iB = ( offsetB + ( i * SB1 ) + ( j * SB2 ) ) * 2; + bbuf[ iB ] = tRe; + bbuf[ iB + 1 ] = tIm; + } + } + } + } else { + for ( j = 0; j < N; j++ ) { + for ( i = M - 1; i >= 0; i-- ) { + iB = ( offsetB + ( i * SB1 ) + ( j * SB2 ) ) * 2; + tRe = bbuf[ iB ]; + tIm = bbuf[ iB + 1 ]; + for ( k = i + 1; k < M; k++ ) { + iA = ( offsetA + ( k * SA1 ) + ( i * SA2 ) ) * 2; + aRe = abuf[ iA ]; + aIm = ( isConjTrans ) ? -abuf[ iA + 1 ] : abuf[ iA + 1 ]; + iB = ( offsetB + ( k * SB1 ) + ( j * SB2 ) ) * 2; + bRe = bbuf[ iB ]; + bIm = bbuf[ iB + 1 ]; + tRe -= ( aRe * bRe ) - ( aIm * bIm ); + tIm -= ( aRe * bIm ) + ( aIm * bRe ); + } + if ( isUnit == 0 ) { + iA = ( offsetA + ( i * SA1 ) + ( i * SA2 ) ) * 2; + aRe = abuf[ iA ]; + aIm = ( isConjTrans ) ? -abuf[ iA + 1 ] : abuf[ iA + 1 ]; + iB = ( offsetB + ( i * SB1 ) + ( j * SB2 ) ) * 2; + bbuf[ iB ] = cdivf_re( tRe, tIm, aRe, aIm ); + bbuf[ iB + 1 ] = cdivf_im( tRe, tIm, aRe, aIm ); + } else { + iB = ( offsetB + ( i * SB1 ) + ( j * SB2 ) ) * 2; + bbuf[ iB ] = tRe; + bbuf[ iB + 1 ] = tIm; + } + } + } + } + } + } else { + /* Right side */ + if ( isNoTrans ) { + if ( isUpper ) { + for ( j = 0; j < N; j++ ) { + for ( i = 0; i < M; i++ ) { + iB = ( offsetB + ( i * SB1 ) + ( j * SB2 ) ) * 2; + bRe = bbuf[ iB ]; + bIm = bbuf[ iB + 1 ]; + for ( k = 0; k < j; k++ ) { + iA = ( offsetA + ( k * SA1 ) + ( j * SA2 ) ) * 2; + aRe = abuf[ iA ]; + aIm = abuf[ iA + 1 ]; + iB = ( offsetB + ( i * SB1 ) + ( k * SB2 ) ) * 2; + kbRe = bbuf[ iB ]; + kbIm = bbuf[ iB + 1 ]; + bRe -= ( aRe * kbRe ) - ( aIm * kbIm ); + bIm -= ( aRe * kbIm ) + ( aIm * kbRe ); + } + if ( isUnit == 0 ) { + iA = ( offsetA + ( j * SA1 ) + ( j * SA2 ) ) * 2; + aRe = abuf[ iA ]; + aIm = abuf[ iA + 1 ]; + iB = ( offsetB + ( i * SB1 ) + ( j * SB2 ) ) * 2; + bbuf[ iB ] = cdivf_re( bRe, bIm, aRe, aIm ); + bbuf[ iB + 1 ] = cdivf_im( bRe, bIm, aRe, aIm ); + } else { + iB = ( offsetB + ( i * SB1 ) + ( j * SB2 ) ) * 2; + bbuf[ iB ] = bRe; + bbuf[ iB + 1 ] = bIm; + } + } + } + } else { + for ( j = N - 1; j >= 0; j-- ) { + for ( i = 0; i < M; i++ ) { + iB = ( offsetB + ( i * SB1 ) + ( j * SB2 ) ) * 2; + bRe = bbuf[ iB ]; + bIm = bbuf[ iB + 1 ]; + for ( k = j + 1; k < N; k++ ) { + iA = ( offsetA + ( k * SA1 ) + ( j * SA2 ) ) * 2; + aRe = abuf[ iA ]; + aIm = abuf[ iA + 1 ]; + iB = ( offsetB + ( i * SB1 ) + ( k * SB2 ) ) * 2; + kbRe = bbuf[ iB ]; + kbIm = bbuf[ iB + 1 ]; + bRe -= ( aRe * kbRe ) - ( aIm * kbIm ); + bIm -= ( aRe * kbIm ) + ( aIm * kbRe ); + } + if ( isUnit == 0 ) { + iA = ( offsetA + ( j * SA1 ) + ( j * SA2 ) ) * 2; + aRe = abuf[ iA ]; + aIm = abuf[ iA + 1 ]; + iB = ( offsetB + ( i * SB1 ) + ( j * SB2 ) ) * 2; + bbuf[ iB ] = cdivf_re( bRe, bIm, aRe, aIm ); + bbuf[ iB + 1 ] = cdivf_im( bRe, bIm, aRe, aIm ); + } else { + iB = ( offsetB + ( i * SB1 ) + ( j * SB2 ) ) * 2; + bbuf[ iB ] = bRe; + bbuf[ iB + 1 ] = bIm; + } + } + } + } + } else { + /* Right, transpose or conjugate-transpose */ + if ( isUpper ) { + for ( k = N - 1; k >= 0; k-- ) { + for ( i = 0; i < M; i++ ) { + iB = ( offsetB + ( i * SB1 ) + ( k * SB2 ) ) * 2; + tRe = bbuf[ iB ]; + tIm = bbuf[ iB + 1 ]; + if ( isUnit == 0 ) { + iA = ( offsetA + ( k * SA1 ) + ( k * SA2 ) ) * 2; + aRe = abuf[ iA ]; + aIm = ( isConjTrans ) ? -abuf[ iA + 1 ] : abuf[ iA + 1 ]; + tRe = cdivf_re( tRe, tIm, aRe, aIm ); + tIm = cdivf_im( bbuf[ iB ], bbuf[ iB + 1 ], aRe, aIm ); + } + bbuf[ iB ] = tRe; + bbuf[ iB + 1 ] = tIm; + for ( j = 0; j < k; j++ ) { + iA = ( offsetA + ( j * SA1 ) + ( k * SA2 ) ) * 2; + aRe = abuf[ iA ]; + aIm = ( isConjTrans ) ? -abuf[ iA + 1 ] : abuf[ iA + 1 ]; + iB = ( offsetB + ( i * SB1 ) + ( j * SB2 ) ) * 2; + bbuf[ iB ] -= ( aRe * tRe ) - ( aIm * tIm ); + bbuf[ iB + 1 ] -= ( aRe * tIm ) + ( aIm * tRe ); + } + } + } + } else { + for ( k = 0; k < N; k++ ) { + for ( i = 0; i < M; i++ ) { + iB = ( offsetB + ( i * SB1 ) + ( k * SB2 ) ) * 2; + tRe = bbuf[ iB ]; + tIm = bbuf[ iB + 1 ]; + if ( isUnit == 0 ) { + iA = ( offsetA + ( k * SA1 ) + ( k * SA2 ) ) * 2; + aRe = abuf[ iA ]; + aIm = ( isConjTrans ) ? -abuf[ iA + 1 ] : abuf[ iA + 1 ]; + tRe = cdivf_re( tRe, tIm, aRe, aIm ); + tIm = cdivf_im( bbuf[ iB ], bbuf[ iB + 1 ], aRe, aIm ); + } + bbuf[ iB ] = tRe; + bbuf[ iB + 1 ] = tIm; + for ( j = k + 1; j < N; j++ ) { + iA = ( offsetA + ( k * SA1 ) + ( j * SA2 ) ) * 2; + aRe = abuf[ iA ]; + aIm = ( isConjTrans ) ? -abuf[ iA + 1 ] : abuf[ iA + 1 ]; + iB = ( offsetB + ( i * SB1 ) + ( j * SB2 ) ) * 2; + bbuf[ iB ] -= ( aRe * tRe ) - ( aIm * tIm ); + bbuf[ iB + 1 ] -= ( aRe * tIm ) + ( aIm * tRe ); + } + } + } + } + } + } +} diff --git a/lib/node_modules/@stdlib/blas/base/ctrsm/test/test.ctrsm.js b/lib/node_modules/@stdlib/blas/base/ctrsm/test/test.ctrsm.js new file mode 100644 index 000000000000..103f5467dc97 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ctrsm/test/test.ctrsm.js @@ -0,0 +1,318 @@ +/** +* @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 Complex64Array = require( '@stdlib/array/complex64' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var Float32Array = require( '@stdlib/array/float32' ); +var EPS = require( '@stdlib/constants/float32/eps' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var ctrsm = require( './../lib/ctrsm.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ctrsm, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 12', function test( t ) { + t.strictEqual( ctrsm.length, 12, 'arity of 12' ); + t.end(); +}); + +tape( 'the function throws an error if provided an invalid first argument', function test( t ) { + var alpha = new Complex64( 1.0, 0.0 ); + var A = new Complex64Array( [ 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 ] ); + var B = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0 ] ); + + t.throws( badValue, TypeError, 'throws an error' ); + t.end(); + + function badValue() { + ctrsm( 'beep', 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, alpha, A, 2, B, 1 ); + } +}); + +tape( 'the function throws an error if provided an invalid second argument', function test( t ) { + var alpha = new Complex64( 1.0, 0.0 ); + var A = new Complex64Array( [ 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 ] ); + var B = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0 ] ); + + t.throws( badValue, TypeError, 'throws an error' ); + t.end(); + + function badValue() { + ctrsm( 'row-major', 'beep', 'upper', 'no-transpose', 'non-unit', 2, 1, alpha, A, 2, B, 1 ); + } +}); + +tape( 'the function solves op(A)*X = alpha*B (row-major, left, upper, no-transpose, non-unit)', function test( t ) { + var expected; + var delta; + var viewB; + var alpha; + var tol; + var A; + var B; + var k; + + // A = [[1+0i, 2+0i], [0+0i, 1+0i]], row-major + A = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 0.0 ] ); + + // B = [[1+0i], [2+0i]] + B = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0 ] ); + alpha = new Complex64( 1.0, 0.0 ); + + ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, alpha, A, 2, B, 1 ); + + viewB = new Float32Array( B.buffer ); + // X = A^{-1} * B: solve [1 2; 0 1]*X = [1; 2] => X = [-3; 2] + expected = new Float32Array( [ -3.0, 0.0, 2.0, 0.0 ] ); + for ( k = 0; k < expected.length; k++ ) { + if ( viewB[ k ] === expected[ k ] ) { + t.strictEqual( viewB[ k ], expected[ k ], 'returns expected value' ); + } else { + delta = abs( viewB[ k ] - expected[ k ] ); + tol = 2.0 * EPS * abs( expected[ k ] ); + t.ok( delta <= tol, 'within tolerance. B: '+viewB[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function returns B unchanged if M is zero (row-major)', function test( t ) { + var expected; + var viewB; + var alpha; + var A; + var B; + + A = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 0.0 ] ); + B = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0 ] ); + alpha = new Complex64( 1.0, 0.0 ); + + viewB = new Float32Array( B.buffer ); + expected = new Float32Array( [ 1.0, 0.0, 2.0, 0.0 ] ); + + ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 0, 1, alpha, A, 2, B, 1 ); + t.deepEqual( viewB, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns B unchanged if N is zero (row-major)', function test( t ) { + var expected; + var viewB; + var alpha; + var A; + var B; + + A = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 0.0 ] ); + B = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0 ] ); + alpha = new Complex64( 1.0, 0.0 ); + + viewB = new Float32Array( B.buffer ); + expected = new Float32Array( [ 1.0, 0.0, 2.0, 0.0 ] ); + + ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, 0, alpha, A, 2, B, 1 ); + t.deepEqual( viewB, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function scales B by alpha before solving (row-major)', function test( t ) { + var expected; + var delta; + var viewB; + var alpha; + var tol; + var A; + var B; + var k; + + A = new Complex64Array( [ 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 ] ); + B = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0 ] ); + alpha = new Complex64( 2.0, 0.0 ); + + ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, alpha, A, 2, B, 1 ); + + viewB = new Float32Array( B.buffer ); + + // A is identity, so X = alpha*B = [2; 4] + expected = new Float32Array( [ 2.0, 0.0, 4.0, 0.0 ] ); + for ( k = 0; k < expected.length; k++ ) { + if ( viewB[ k ] === expected[ k ] ) { + t.strictEqual( viewB[ k ], expected[ k ], 'returns expected value' ); + } else { + delta = abs( viewB[ k ] - expected[ k ] ); + tol = 2.0 * EPS * abs( expected[ k ] ); + t.ok( delta <= tol, 'within tolerance. B: '+viewB[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function returns a reference to B', function test( t ) { + var alpha; + var out; + var A; + var B; + + A = new Complex64Array( [ 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 ] ); + B = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0 ] ); + alpha = new Complex64( 1.0, 0.0 ); + + out = ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, alpha, A, 2, B, 1 ); + t.strictEqual( out, B, 'same reference' ); + t.end(); +}); + +tape( 'the function solves X*op(A) = alpha*B (row-major, right, upper, no-transpose, non-unit, 1x2)', function test( t ) { + var expected; + var delta; + var viewB; + var alpha; + var tol; + var A; + var B; + var k; + + // A = [[1+0i, 2+0i], [0+0i, 1+0i]], row-major 2x2 + A = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 0.0 ] ); + + // B = [[1+0i, 2+0i]] (1x2 matrix) + B = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0 ] ); + alpha = new Complex64( 1.0, 0.0 ); + + // Solve X*A = B where X is 1x2: X = B * A^{-1} + ctrsm( 'row-major', 'right', 'upper', 'no-transpose', 'non-unit', 1, 2, alpha, A, 2, B, 2 ); + + viewB = new Float32Array( B.buffer ); + + // A^{-1} = [[1, -2], [0, 1]], so X = [1, 2]*[[1,-2],[0,1]] = [1, 0] + expected = new Float32Array( [ 1.0, 0.0, 0.0, 0.0 ] ); + for ( k = 0; k < expected.length; k++ ) { + if ( viewB[ k ] === expected[ k ] ) { + t.strictEqual( viewB[ k ], expected[ k ], 'returns expected value' ); + } else { + delta = abs( viewB[ k ] - expected[ k ] ); + tol = 2.0 * EPS * abs( expected[ k ] ); + t.ok( delta <= tol, 'within tolerance. B: '+viewB[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function solves op(A)*X = alpha*B (row-major, left, upper, no-transpose, non-unit, 2x2)', function test( t ) { + var expected; + var delta; + var viewB; + var alpha; + var tol; + var A; + var B; + var k; + + // A = [[2+0i, 1+0i], [0+0i, 3+0i]] + A = new Complex64Array( [ 2.0, 0.0, 1.0, 0.0, 0.0, 0.0, 3.0, 0.0 ] ); + + // B = [[4+0i, 5+0i], [6+0i, 9+0i]] + B = new Complex64Array( [ 4.0, 0.0, 5.0, 0.0, 6.0, 0.0, 9.0, 0.0 ] ); + alpha = new Complex64( 1.0, 0.0 ); + + ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, 2, alpha, A, 2, B, 2 ); + + viewB = new Float32Array( B.buffer ); + + // Solve [2 1; 0 3]*X = B: x21=2,x22=3; x11=(4-1*2)/2=1, x12=(5-1*3)/2=1 + expected = new Float32Array( [ 1.0, 0.0, 1.0, 0.0, 2.0, 0.0, 3.0, 0.0 ] ); + for ( k = 0; k < expected.length; k++ ) { + if ( viewB[ k ] === expected[ k ] ) { + t.strictEqual( viewB[ k ], expected[ k ], 'returns expected value' ); + } else { + delta = abs( viewB[ k ] - expected[ k ] ); + tol = 2.0 * EPS * abs( expected[ k ] ); + t.ok( delta <= tol, 'within tolerance. B: '+viewB[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function solves with complex alpha (row-major)', function test( t ) { + var expected; + var delta; + var viewB; + var alpha; + var tol; + var A; + var B; + var k; + + // A = identity + A = new Complex64Array( [ 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 ] ); + B = new Complex64Array( [ 1.0, 0.0, 0.0, 1.0 ] ); + alpha = new Complex64( 0.0, 1.0 ); // alpha = i + + ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, alpha, A, 2, B, 1 ); + + viewB = new Float32Array( B.buffer ); + + // X = A^{-1}*(i*B) = i*[1+0i, 0+1i] = [0+1i, -1+0i] + expected = new Float32Array( [ 0.0, 1.0, -1.0, 0.0 ] ); + for ( k = 0; k < expected.length; k++ ) { + if ( viewB[ k ] === expected[ k ] ) { + t.strictEqual( viewB[ k ], expected[ k ], 'returns expected value' ); + } else { + delta = abs( viewB[ k ] - expected[ k ] ); + tol = 2.0 * EPS * abs( expected[ k ] ); + t.ok( delta <= tol, 'within tolerance. B: '+viewB[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function throws an error if provided an M less than zero', function test( t ) { + var alpha = new Complex64( 1.0, 0.0 ); + var A = new Complex64Array( [ 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 ] ); + var B = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0 ] ); + + t.throws( badValue, RangeError, 'throws an error' ); + t.end(); + + function badValue() { + ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', -1, 1, alpha, A, 2, B, 1 ); + } +}); + +tape( 'the function throws an error if provided an N less than zero', function test( t ) { + var alpha = new Complex64( 1.0, 0.0 ); + var A = new Complex64Array( [ 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 ] ); + var B = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0 ] ); + + t.throws( badValue, RangeError, 'throws an error' ); + t.end(); + + function badValue() { + ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, -1, alpha, A, 2, B, 1 ); + } +}); diff --git a/lib/node_modules/@stdlib/blas/base/ctrsm/test/test.ctrsm.native.js b/lib/node_modules/@stdlib/blas/base/ctrsm/test/test.ctrsm.native.js new file mode 100644 index 000000000000..89e3ad648dc7 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ctrsm/test/test.ctrsm.native.js @@ -0,0 +1,97 @@ +/** +* @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 Complex64Array = require( '@stdlib/array/complex64' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var Float32Array = require( '@stdlib/array/float32' ); +var EPS = require( '@stdlib/constants/float32/eps' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var ctrsm = tryRequire( resolve( __dirname, './../lib/ctrsm.native.js' ) ); +var opts = { + 'skip': ( ctrsm instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ctrsm, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 12', opts, function test( t ) { + t.strictEqual( ctrsm.length, 12, 'arity of 12' ); + t.end(); +}); + +tape( 'the function solves op(A)*X = alpha*B (row-major, left, upper, no-transpose, non-unit)', opts, function test( t ) { + var expected; + var delta; + var viewB; + var alpha; + var tol; + var A; + var B; + var k; + + A = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 0.0 ] ); + B = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0 ] ); + alpha = new Complex64( 1.0, 0.0 ); + + ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, alpha, A, 2, B, 1 ); + + viewB = new Float32Array( B.buffer ); + expected = new Float32Array( [ -3.0, 0.0, 2.0, 0.0 ] ); + for ( k = 0; k < expected.length; k++ ) { + if ( viewB[ k ] === expected[ k ] ) { + t.strictEqual( viewB[ k ], expected[ k ], 'returns expected value' ); + } else { + delta = abs( viewB[ k ] - expected[ k ] ); + tol = 2.0 * EPS * abs( expected[ k ] ); + t.ok( delta <= tol, 'within tolerance. B: '+viewB[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function returns a reference to B', opts, function test( t ) { + var alpha; + var out; + var A; + var B; + + A = new Complex64Array( [ 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 ] ); + B = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0 ] ); + alpha = new Complex64( 1.0, 0.0 ); + + out = ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, alpha, A, 2, B, 1 ); + t.strictEqual( out, B, 'same reference' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/ctrsm/test/test.js b/lib/node_modules/@stdlib/blas/base/ctrsm/test/test.js new file mode 100644 index 000000000000..df4b265b349e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ctrsm/test/test.js @@ -0,0 +1,431 @@ +/** +* @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 Complex64Array = require( '@stdlib/array/complex64' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var realf = require( '@stdlib/complex/float32/real' ); +var imagf = require( '@stdlib/complex/float32/imag' ); +var EPS = require( '@stdlib/constants/float32/eps' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var ctrsm = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Tests for element-wise approximate equality. +* +* @private +* @param {Object} t - test object +* @param {Complex64Array} actual - actual array +* @param {Complex64Array} expected - expected array +* @param {number} rtol - relative tolerance +*/ +function isApprox( t, actual, expected, rtol ) { + var delta; + var tol; + var i; + + t.strictEqual( actual.length, expected.length, 'has expected length' ); + for ( i = 0; i < actual.length; i++ ) { + if ( realf( actual.get( i ) ) === realf( expected.get( i ) ) && imagf( actual.get( i ) ) === imagf( expected.get( i ) ) ) { + t.pass( 'elements ' + i + ' are equal' ); + } else { + delta = abs( realf( actual.get( i ) ) - realf( expected.get( i ) ) ); + tol = rtol * abs( realf( expected.get( i ) ) ); + t.ok( delta <= tol, 'within tolerance. actual (re): ' + realf( actual.get( i ) ) + '. expected (re): ' + realf( expected.get( i ) ) + '. tol: ' + tol + '. delta: ' + delta + '.' ); + + delta = abs( imagf( actual.get( i ) ) - imagf( expected.get( i ) ) ); + tol = rtol * abs( imagf( expected.get( i ) ) ); + t.ok( delta <= tol, 'within tolerance. actual (im): ' + imagf( actual.get( i ) ) + '. expected (im): ' + imagf( expected.get( i ) ) + '. tol: ' + tol + '. delta: ' + delta + '.' ); + } + } +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ctrsm, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an ndarray method', function test( t ) { + t.strictEqual( typeof ctrsm.ndarray, 'function', 'has ndarray method' ); + t.end(); +}); + +tape( 'the function throws an error if provided an invalid order argument', function test( t ) { + var alpha = new Complex64( 1.0, 0.0 ); + var A = new Complex64Array( [ 1.0, 0.0 ] ); + var B = new Complex64Array( [ 1.0, 0.0 ] ); + t.throws( badValue, TypeError, 'throws an error' ); + t.end(); + + function badValue() { + ctrsm( 'beep', 'left', 'upper', 'no-transpose', 'non-unit', 1, 1, alpha, A, 1, B, 1 ); + } +}); + +tape( 'the function throws an error if provided an invalid side argument', function test( t ) { + var alpha = new Complex64( 1.0, 0.0 ); + var A = new Complex64Array( [ 1.0, 0.0 ] ); + var B = new Complex64Array( [ 1.0, 0.0 ] ); + t.throws( badValue, TypeError, 'throws an error' ); + t.end(); + + function badValue() { + ctrsm( 'row-major', 'beep', 'upper', 'no-transpose', 'non-unit', 1, 1, alpha, A, 1, B, 1 ); + } +}); + +tape( 'the function throws an error if provided an invalid uplo argument', function test( t ) { + var alpha = new Complex64( 1.0, 0.0 ); + var A = new Complex64Array( [ 1.0, 0.0 ] ); + var B = new Complex64Array( [ 1.0, 0.0 ] ); + t.throws( badValue, TypeError, 'throws an error' ); + t.end(); + + function badValue() { + ctrsm( 'row-major', 'left', 'beep', 'no-transpose', 'non-unit', 1, 1, alpha, A, 1, B, 1 ); + } +}); + +tape( 'the function throws an error if provided an invalid trans argument', function test( t ) { + var alpha = new Complex64( 1.0, 0.0 ); + var A = new Complex64Array( [ 1.0, 0.0 ] ); + var B = new Complex64Array( [ 1.0, 0.0 ] ); + t.throws( badValue, TypeError, 'throws an error' ); + t.end(); + + function badValue() { + ctrsm( 'row-major', 'left', 'upper', 'beep', 'non-unit', 1, 1, alpha, A, 1, B, 1 ); + } +}); + +tape( 'the function throws an error if provided an invalid diag argument', function test( t ) { + var alpha = new Complex64( 1.0, 0.0 ); + var A = new Complex64Array( [ 1.0, 0.0 ] ); + var B = new Complex64Array( [ 1.0, 0.0 ] ); + t.throws( badValue, TypeError, 'throws an error' ); + t.end(); + + function badValue() { + ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'beep', 1, 1, alpha, A, 1, B, 1 ); + } +}); + +tape( 'the function throws an error if provided an invalid M argument', function test( t ) { + var alpha = new Complex64( 1.0, 0.0 ); + var A = new Complex64Array( [ 1.0, 0.0 ] ); + var B = new Complex64Array( [ 1.0, 0.0 ] ); + t.throws( badValue, RangeError, 'throws an error' ); + t.end(); + + function badValue() { + ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', -1, 1, alpha, A, 1, B, 1 ); + } +}); + +tape( 'the function throws an error if provided an invalid N argument', function test( t ) { + var alpha = new Complex64( 1.0, 0.0 ); + var A = new Complex64Array( [ 1.0, 0.0 ] ); + var B = new Complex64Array( [ 1.0, 0.0 ] ); + t.throws( badValue, RangeError, 'throws an error' ); + t.end(); + + function badValue() { + ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 1, -1, alpha, A, 1, B, 1 ); + } +}); + +tape( 'the function returns B unchanged if M is zero (row-major)', function test( t ) { + var expected; + var alpha; + var out; + var A; + var B; + + A = new Complex64Array( [] ); + B = new Complex64Array( [] ); + alpha = new Complex64( 1.0, 0.0 ); + expected = new Complex64Array( [] ); + + out = ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 0, 1, alpha, A, 1, B, 1 ); + + t.strictEqual( out, B, 'returns B' ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns B unchanged if N is zero (row-major)', function test( t ) { + var expected; + var alpha; + var out; + var A; + var B; + + A = new Complex64Array( [ 1.0, 0.0 ] ); + B = new Complex64Array( [] ); + alpha = new Complex64( 1.0, 0.0 ); + expected = new Complex64Array( [] ); + + out = ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 1, 0, alpha, A, 1, B, 1 ); + + t.strictEqual( out, B, 'returns B' ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function solves op(A)*X = alpha*B (row-major, left, upper, no-transpose, non-unit, 2x2)', function test( t ) { + var expected; + var alpha; + var out; + var A; + var B; + + /* + * A = | 2+0i 1+0i | + * | 0+0i 2+0i | + * + * B = | 4+0i | + * | 2+0i | + * + * Solve: A * X = B + * Row 1 (backwards): X[1] = B[1]/A[1][1] = 2/2 = 1 + * Row 0: X[0] = (B[0] - A[0][1]*X[1]) / A[0][0] = (4 - 1*1) / 2 = 1.5 + */ + A = new Complex64Array([ + 2.0, + 0.0, // A[0][0] + 1.0, + 0.0, // A[0][1] + 0.0, + 0.0, // A[1][0] (not referenced for upper) + 2.0, + 0.0 // A[1][1] + ]); + B = new Complex64Array([ + 4.0, + 0.0, + 2.0, + 0.0 + ]); + alpha = new Complex64( 1.0, 0.0 ); + expected = new Complex64Array([ + 1.5, + 0.0, + 1.0, + 0.0 + ]); + + out = ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, alpha, A, 2, B, 1 ); + + t.strictEqual( out, B, 'returns B' ); + isApprox( t, out, expected, 2.0 * EPS ); + t.end(); +}); + +tape( 'the function solves X*op(A) = alpha*B (row-major, right, upper, no-transpose, non-unit, 1x2)', function test( t ) { + var expected; + var alpha; + var out; + var A; + var B; + + /* + * A = | 2+0i 1+0i | + * | 0+0i 3+0i | + * + * B = | 6+0i 9+0i | (1x2) + * + * Solve: X * A = B + * X[0][0] = B[0][0] / A[0][0] = 6/2 = 3 + * X[0][1] = (B[0][1] - X[0][0]*A[0][1]) / A[1][1] = (9 - 3*1) / 3 = 2 + */ + A = new Complex64Array([ + 2.0, + 0.0, + 1.0, + 0.0, + 0.0, + 0.0, + 3.0, + 0.0 + ]); + B = new Complex64Array([ + 6.0, + 0.0, + 9.0, + 0.0 + ]); + alpha = new Complex64( 1.0, 0.0 ); + expected = new Complex64Array([ + 3.0, + 0.0, + 2.0, + 0.0 + ]); + + out = ctrsm( 'row-major', 'right', 'upper', 'no-transpose', 'non-unit', 1, 2, alpha, A, 2, B, 2 ); + + t.strictEqual( out, B, 'returns B' ); + isApprox( t, out, expected, 2.0 * EPS ); + t.end(); +}); + +tape( 'the function scales B by alpha before solving (row-major)', function test( t ) { + var expected; + var alpha; + var out; + var A; + var B; + + /* + * A = | 1+0i | (1x1) + * B = | 3+0i | (1x1) + * alpha = 2+0i + * Solve: A * X = alpha * B => X = 2*3/1 = 6 + */ + A = new Complex64Array( [ 1.0, 0.0 ] ); + B = new Complex64Array( [ 3.0, 0.0 ] ); + alpha = new Complex64( 2.0, 0.0 ); + expected = new Complex64Array( [ 6.0, 0.0 ] ); + + out = ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 1, 1, alpha, A, 1, B, 1 ); + + t.strictEqual( out, B, 'returns B' ); + isApprox( t, out, expected, 2.0 * EPS ); + t.end(); +}); + +tape( 'the function solves with complex alpha (row-major)', function test( t ) { + var expected; + var alpha; + var out; + var A; + var B; + + /* + * A = | 1+0i | (1x1, identity) + * B = | 1+0i | (1x1) + * alpha = 0+1i (imaginary unit) + * Solve: A * X = alpha * B => X = (0+i)*1/1 = 0+1i + */ + A = new Complex64Array( [ 1.0, 0.0 ] ); + B = new Complex64Array( [ 1.0, 0.0 ] ); + alpha = new Complex64( 0.0, 1.0 ); + expected = new Complex64Array( [ 0.0, 1.0 ] ); + + out = ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'unit', 1, 1, alpha, A, 1, B, 1 ); + + t.strictEqual( out, B, 'returns B' ); + isApprox( t, out, expected, 2.0 * EPS ); + t.end(); +}); + +tape( 'the function handles unit diagonal (row-major, left, upper, no-transpose)', function test( t ) { + var expected; + var alpha; + var out; + var A; + var B; + + /* + * A = | 99+0i 2+0i | (upper triangular, diag NOT used because unit) + * | 0+0i 99+0i | + * + * B = | 5+0i | + * | 3+0i | + * + * Solve A * X = B with unit diagonal (treat diag as 1): + * X[1] = B[1]/1 = 3 + * X[0] = (B[0] - A[0][1]*X[1])/1 = 5 - 2*3 = -1 + */ + A = new Complex64Array([ + 99.0, + 0.0, + 2.0, + 0.0, + 0.0, + 0.0, + 99.0, + 0.0 + ]); + B = new Complex64Array([ + 5.0, + 0.0, + 3.0, + 0.0 + ]); + alpha = new Complex64( 1.0, 0.0 ); + expected = new Complex64Array([ + -1.0, + 0.0, + 3.0, + 0.0 + ]); + + out = ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'unit', 2, 1, alpha, A, 2, B, 1 ); + + t.strictEqual( out, B, 'returns B' ); + isApprox( t, out, expected, 2.0 * EPS ); + t.end(); +}); + +tape( 'the ndarray method solves op(A)*X = alpha*B (row-major, left, upper, no-transpose, non-unit)', function test( t ) { + var expected; + var out; + var A; + var B; + + A = new Complex64Array([ + 2.0, + 0.0, + 1.0, + 0.0, + 0.0, + 0.0, + 2.0, + 0.0 + ]); + B = new Complex64Array([ + 4.0, + 0.0, + 2.0, + 0.0 + ]); + expected = new Complex64Array([ + 1.5, + 0.0, + 1.0, + 0.0 + ]); + + out = ctrsm.ndarray( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, 1.0, 0.0, A, 2, 0, B, 1, 0 ); + + t.strictEqual( out, B, 'returns B' ); + isApprox( t, out, expected, 2.0 * EPS ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/ctrsm/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/ctrsm/test/test.ndarray.js new file mode 100644 index 000000000000..147bbe8fb919 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ctrsm/test/test.ndarray.js @@ -0,0 +1,132 @@ +/** +* @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 Complex64Array = require( '@stdlib/array/complex64' ); +var Float32Array = require( '@stdlib/array/float32' ); +var EPS = require( '@stdlib/constants/float32/eps' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var ctrsm = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ctrsm, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 15', function test( t ) { + t.strictEqual( ctrsm.length, 15, 'arity of 15' ); + t.end(); +}); + +tape( 'the function solves op(A)*X = alpha*B (row-major, left, upper, no-transpose, non-unit)', function test( t ) { + var expected; + var delta; + var viewB; + var tol; + var A; + var B; + var k; + + A = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 0.0 ] ); + B = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0 ] ); + + ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, 1.0, 0.0, A, 2, 0, B, 1, 0 ); + + viewB = new Float32Array( B.buffer ); + expected = new Float32Array( [ -3.0, 0.0, 2.0, 0.0 ] ); + for ( k = 0; k < expected.length; k++ ) { + if ( viewB[ k ] === expected[ k ] ) { + t.strictEqual( viewB[ k ], expected[ k ], 'returns expected value' ); + } else { + delta = abs( viewB[ k ] - expected[ k ] ); + tol = 2.0 * EPS * abs( expected[ k ] ); + t.ok( delta <= tol, 'within tolerance. B: '+viewB[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function returns B unchanged if M is zero', function test( t ) { + var expected; + var viewB; + var A; + var B; + + A = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 0.0 ] ); + B = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0 ] ); + + viewB = new Float32Array( B.buffer ); + expected = new Float32Array( [ 1.0, 0.0, 2.0, 0.0 ] ); + + ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 0, 1, 1.0, 0.0, A, 2, 0, B, 1, 0 ); + t.deepEqual( viewB, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports offsets', function test( t ) { + var expected; + var delta; + var viewB; + var tol; + var A; + var B; + var k; + + // Prepend a dummy element to both arrays + A = new Complex64Array( [ 0.0, 0.0, 1.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 0.0 ] ); + B = new Complex64Array( [ 0.0, 0.0, 1.0, 0.0, 2.0, 0.0 ] ); + + // Start A at index 1, B at index 1 + ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, 1.0, 0.0, A, 2, 1, B, 1, 1 ); + + viewB = new Float32Array( B.buffer ); + + // B[0] should be unchanged, B[1] and B[2] should be [-3, 2] + expected = new Float32Array( [ 0.0, 0.0, -3.0, 0.0, 2.0, 0.0 ] ); + for ( k = 0; k < expected.length; k++ ) { + if ( viewB[ k ] === expected[ k ] ) { + t.strictEqual( viewB[ k ], expected[ k ], 'returns expected value' ); + } else { + delta = abs( viewB[ k ] - expected[ k ] ); + tol = 2.0 * EPS * abs( expected[ k ] ); + t.ok( delta <= tol, 'within tolerance. B: '+viewB[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function returns a reference to B', function test( t ) { + var out; + var A; + var B; + + A = new Complex64Array( [ 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 ] ); + B = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0 ] ); + + out = ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, 1.0, 0.0, A, 2, 0, B, 1, 0 ); + t.strictEqual( out, B, 'same reference' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/ctrsm/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/base/ctrsm/test/test.ndarray.native.js new file mode 100644 index 000000000000..9f768fcb1e0c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ctrsm/test/test.ndarray.native.js @@ -0,0 +1,92 @@ +/** +* @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 Complex64Array = require( '@stdlib/array/complex64' ); +var Float32Array = require( '@stdlib/array/float32' ); +var EPS = require( '@stdlib/constants/float32/eps' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var ctrsm = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); +var opts = { + 'skip': ( ctrsm instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ctrsm, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 15', opts, function test( t ) { + t.strictEqual( ctrsm.length, 15, 'arity of 15' ); + t.end(); +}); + +tape( 'the function solves op(A)*X = alpha*B (row-major, left, upper, no-transpose, non-unit)', opts, function test( t ) { + var expected; + var delta; + var viewB; + var tol; + var A; + var B; + var k; + + A = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 0.0 ] ); + B = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0 ] ); + + ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, 1.0, 0.0, A, 2, 0, B, 1, 0 ); + + viewB = new Float32Array( B.buffer ); + expected = new Float32Array( [ -3.0, 0.0, 2.0, 0.0 ] ); + for ( k = 0; k < expected.length; k++ ) { + if ( viewB[ k ] === expected[ k ] ) { + t.strictEqual( viewB[ k ], expected[ k ], 'returns expected value' ); + } else { + delta = abs( viewB[ k ] - expected[ k ] ); + tol = 2.0 * EPS * abs( expected[ k ] ); + t.ok( delta <= tol, 'within tolerance. B: '+viewB[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function returns a reference to B', opts, function test( t ) { + var out; + var A; + var B; + + A = new Complex64Array( [ 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 ] ); + B = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0 ] ); + + out = ctrsm( 'row-major', 'left', 'upper', 'no-transpose', 'non-unit', 2, 1, 1.0, 0.0, A, 2, 0, B, 1, 0 ); + t.strictEqual( out, B, 'same reference' ); + t.end(); +});