diff --git a/lib/node_modules/@stdlib/lapack/base/dlaset/README.md b/lib/node_modules/@stdlib/lapack/base/dlaset/README.md new file mode 100644 index 000000000000..fd82d112be5c --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlaset/README.md @@ -0,0 +1,239 @@ + + +# dlaset + +> Initialize an `M` by `N` matrix `A` to `beta` on the diagonal and `alpha` on the off-diagonals. + +
+ +## Usage + +```javascript +var dlaset = require( '@stdlib/lapack/base/dlaset' ); +``` + +#### dlaset( order, uplo, M, N, alpha, beta, A, LDA ) + +Initializes an `M` by `N` matrix `A` to `beta` on the diagonal and `alpha` on the off-diagonals. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var A = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + +dlaset( 'row-major', 'lower', 3, 3, 3.1, 3.7, A, 3 ); +// A => [ 3.7, 0.0, 0.0, 3.1, 3.7, 0.0, 3.1, 3.1, 3.7 ] +``` + +The function has the following parameters: + +- **order**: storage layout. +- **uplo**: specifies whether the upper or lower triangular part of matrix `A` is supplied. +- **M**: number of rows in `A`. +- **N**: number of columns in `A`. +- **alpha**: scalar constant to which off-diagonal elements are set. +- **beta**: scalar constant to which diagonal elements are set. +- **A**: input [`Float64Array`][mdn-float64array] matrix `A`. +- **LDA**: stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`). + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +// Initial arrays... +var A0 = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + +// Create offset views... +var A1 = new Float64Array( A0.buffer, A0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +dlaset( 'row-major', 'lower', 3, 3, 3.1, 3.7, A1, 3 ); +// A0 => [ 0.0, 3.7, 0.0, 0.0, 3.1, 3.7, 0.0, 3.1, 3.1, 3.7 ] +``` + +#### dlaset.ndarray( uplo, M, N, alpha, beta, A, strideA1, strideA2, offsetA ) + +Initializes an `M` by `N` matrix `A` to `beta` on the diagonal and `alpha` on the off-diagonals using alternative indexing semantics. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var A = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + +dlaset.ndarray( 'lower', 3, 3, 3.1, 3.7, A, 3, 1, 0 ); +// A => [ 3.7, 0.0, 0.0, 3.1, 3.7, 0.0, 3.1, 3.1, 3.7 ] +``` + +The function has the following parameters: + +- **uplo**: specifies whether the upper or lower triangular part of matrix `A` is supplied. +- **M**: number of rows in `A`. +- **N**: number of columns in `A`. +- **alpha**: scalar constant to which off-diagonal elements are set. +- **beta**: scalar constant to which diagonal elements are set. +- **A**: input [`Float64Array`][mdn-float64array] matrix `A`. +- **strideA1**: stride of the first dimension of `A`. +- **strideA2**: stride of the second dimension of `A`. +- **offsetA**: starting index for `A`. + + +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on starting indices. For example, + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var A = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + +dlaset.ndarray( 'lower', 3, 3, 3.1, 3.7, A, 3, 1, 1 ); +// A => [ 0.0, 3.7, 0.0, 0.0, 3.1, 3.7, 0.0, 3.1, 3.1, 3.7 ] +``` + +
+ + + +
+ +## Notes + +- `dlaset()` corresponds to the [LAPACK][lapack] routine [`dlaset`][dlaset]. + +
+ + + +
+ +## Examples + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var dlaset = require( '@stdlib/lapack/base/dlaset' ); + +var A = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + +dlaset( 'row-major', 'lower', 3, 3, 3.1, 3.7, A, 3 ); +console.log( A ); +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +TODO +``` + +#### TODO + +TODO. + +```c +TODO +``` + +TODO + +```c +TODO +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +TODO +``` + +
+ + + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/lapack/base/dlaset/benchmark/benchmark.js b/lib/node_modules/@stdlib/lapack/base/dlaset/benchmark/benchmark.js new file mode 100644 index 000000000000..8f5bab269bca --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlaset/benchmark/benchmark.js @@ -0,0 +1,105 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var pkg = require( './../package.json' ).name; +var dlaset = require( './../lib/dlaset.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} N - number of elements along each dimension +* @returns {Function} benchmark function +*/ +function createBenchmark( N ) { + var A; + + A = uniform( N*N, -10.0, 10.0, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var z; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + z = dlaset( 'column-major', 'lower', N, N, 3.1, 3.7, A, N ); + if ( isnan( z[ i%z.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( z[ i%z.length ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var min; + var max; + var N; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + N = floor( pow( pow( 10, i ), 1.0/2.0 ) ); + f = createBenchmark( N ); + bench( pkg+':order=column-major,size='+(N*N), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/lapack/base/dlaset/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/lapack/base/dlaset/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..b17411a9c11d --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlaset/benchmark/benchmark.ndarray.js @@ -0,0 +1,105 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var pkg = require( './../package.json' ).name; +var dlaset = require( './../lib/ndarray.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} N - number of elements along each dimension +* @returns {Function} benchmark function +*/ +function createBenchmark( N ) { + var A; + + A = uniform( N*N, -10.0, 10.0, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var z; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + z = dlaset( 'lower', N, N, 3.1, 3.7, A, 1, N, 0 ); + if ( isnan( z[ i%z.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( z[ i%z.length ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var min; + var max; + var N; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + N = floor( pow( pow( 10, i ), 1.0/2.0 ) ); + f = createBenchmark( N ); + bench( pkg+':ndarray:order=column-major,size='+(N*N), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/lapack/base/dlaset/docs/repl.txt b/lib/node_modules/@stdlib/lapack/base/dlaset/docs/repl.txt new file mode 100644 index 000000000000..a5d75eebcef5 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlaset/docs/repl.txt @@ -0,0 +1,108 @@ + +{{alias}}( order, uplo, M, N, alpha, beta, A, LDA ) + Initializes an `M` by `N` matrix `A` to `beta` on the diagonal + and `alpha` on the off-diagonals. + + Indexing is relative to the first index. To introduce an offset, use typed + array views. + + Parameters + ---------- + order: string + Row-major (C-style) or column-major (Fortran-style) order. Must be + either 'row-major' or 'column-major'. + + uplo: string + Specifies whether the upper or lower triangular matrix of `A` is + supplied. + + M: integer + Number of row in `A`. + + N: integer + Number of columns in `A`. + + alpha: number + Scalar constant to which off-diagonal elements are set. + + beta: number + Scalar constant to which diagonal elements are set. + + A: Float64Array + Input matrix `A`. + + LDA: integer + Stride of the first dimension of `A` (a.k.a., leading dimension of the + matrix `A`). + + Returns + ------- + A: Float64Array + Output matrix. + + Examples + -------- + // Standard usage: + > var A = new {{alias:@stdlib/array/float64}}( [ 0.0, 0.0, 0.0, 0.0 ] ); + > {{alias}}( 'row-major', 'lower', 2, 2, 3.1, 3.7, A, 2 ) + [ 3.7, 0.0, 3.1, 3.7 ] + + +{{alias}}.ndarray( uplo, M, N, alpha, beta, A, sa1, sa2, offsetA ) + Initializes an `M` by `N` matrix `A` to `beta` on the diagonal + and `alpha` on the off-diagonals 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 + ---------- + uplo: string + Specifies whether the upper or lower triangular matrix of `A` is + supplied. + + M: integer + Number of row in `A`. + + N: integer + Number of columns in `A`. + + alpha: number + Scalar constant to which off-diagonal elements are set. + + beta: number + Scalar constant to which diagonal elements are set. + + A: Float64Array + Input matrix `A`. + + sa1: integer + Stride of the first dimension of `A`. + + sa2: integer + Stride of the second dimension of `A`. + + offsetA: integer + Starting index for `A`. + + Returns + ------- + A: Float64Array + Output matrix. + + Examples + -------- + // Standard usage: + // Standard usage: + > var A = new {{alias:@stdlib/array/float64}}( [ 0.0, 0.0, 0.0, 0.0 ] ); + > {{alias}}.ndarray( 'lower', 2, 2, 3.1, 3.7, A, 2, 1, 0 ) + [ 3.7, 0.0, 3.1, 3.7 ] + + // Advanced indexing: + > A = new {{alias:@stdlib/array/float64}}( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + > {{alias}}.ndarray( 'lower', 2, 2, 3.1, 3.7, A, 2, 1, 1 ) + [ 0.0, 3.7, 0.0, 3.1, 3.7 ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/lapack/base/dlaset/docs/types/index.d.ts b/lib/node_modules/@stdlib/lapack/base/dlaset/docs/types/index.d.ts new file mode 100644 index 000000000000..b334940ef7bc --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlaset/docs/types/index.d.ts @@ -0,0 +1,110 @@ +/* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +import { Layout } from '@stdlib/types/blas'; + +/** +* Interface describing `dlaset`. +*/ +interface Routine { + /** + * Initializes an `M` by `N` matrix `A` to `beta` on the diagonal and `alpha` on the off-diagonals. + * + * @param order - storage layout + * @param uplo - specifies whether the upper or lower triangular part of matrix `A` is supplied + * @param M - number of rows in matrix `A` + * @param N - number of columns in matrix `A` + * @param alpha - scalar constant to which off-diagonal elements are set + * @param beta - scalar constant to which diagonal elements are set + * @param A - input matrix + * @param LDA - stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`) + * @returns `A` + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * + * var A = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + * + * dlaset( 'row-major', 'lower', 3, 3, 3.1, 3.7, A, 3 ); + * // A => [ 3.7, 0.0, 0.0, 3.1, 3.7, 0.0, 3.1, 3.1, 3.7 ] + */ + ( order: Layout, uplo: string, M: number, N: number, alpha: number, beta: number, A: Float64Array, LDA: number ): Float64Array; + + /** + * Initializes an `M` by `N` matrix `A` to `beta` on the diagonal and `alpha` on the off-diagonals using alternative indexing semantics. + * + * @param uplo - specifies whether the upper or lower triangular part of matrix `A` is supplied + * @param M - number of rows in matrix `A` + * @param N - number of columns in matrix `A` + * @param alpha - scalar constant to which off-diagonal elements are set + * @param beta - scalar constant to which diagonal elements are set + * @param A - input matrix + * @param strideA1 - stride of the first dimension of `A` + * @param strideA2 - stride of the second dimension of `A` + * @param offsetA - starting index for `A` + * @returns `A` + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * + * var A = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + * + * dlaset.ndarray( 'lower', 3, 3, 3.1, 3.7, A, 3, 1, 1 ); + * // A => [ 0.0, 3.7, 0.0, 0.0, 3.1, 3.7, 0.0, 3.1, 3.1, 3.7 ] + */ + ndarray( uplo: string, M: number, N: number, alpha: number, beta: number, A: Float64Array, strideA1: number, strideA2: number, offsetA: number ): Float64Array; +} + +/** +* Initializes an `M` by `N` matrix `A` to `beta` on the diagonal and `alpha` on the off-diagonals. +* +* @param order - storage layout +* @param uplo - specifies whether the upper or lower triangular part of matrix `A` is supplied +* @param M - number of rows in matrix `A` +* @param N - number of columns in matrix `A` +* @param alpha - scalar constant to which off-diagonal elements are set +* @param beta - scalar constant to which diagonal elements are set +* @param A - input matrix +* @param LDA - stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`) +* @returns `A` +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var A = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); +* +* dlaset( 'row-major', 'lower', 3, 3, 3.1, 3.7, A, 3 ); +* // A => [ 3.7, 0.0, 0.0, 3.1, 3.7, 0.0, 3.1, 3.1, 3.7 ] +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var A = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); +* +* dlaset.ndarray( 'lower', 3, 3, 3.1, 3.7, A, 3, 1, 1 ); +* // A => [ 0.0, 3.7, 0.0, 0.0, 3.1, 3.7, 0.0, 3.1, 3.1, 3.7 ] +*/ +declare var dlaset: Routine; + + +// EXPORTS // + +export = dlaset; diff --git a/lib/node_modules/@stdlib/lapack/base/dlaset/docs/types/test.ts b/lib/node_modules/@stdlib/lapack/base/dlaset/docs/types/test.ts new file mode 100644 index 000000000000..a41a79632d42 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlaset/docs/types/test.ts @@ -0,0 +1,305 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import dlaset = require( './index' ); + + +// TESTS // + +// The function returns a Float64Array... +{ + const A = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + dlaset( 'row-major', 'lower', 3, 3, 3.1, 3.7, A, 3 ); // $ExpectType Float64Array +} + +// The compiler throws an error if the function is provided a first argument which is not a string... +{ + const A = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + dlaset( 5, 'lower', 3, 3, 3.1, 3.7, A, 3 ); // $ExpectError + dlaset( true, 'lower', 3, 3, 3.1, 3.7, A, 3 ); // $ExpectError + dlaset( false, 'lower', 3, 3, 3.1, 3.7, A, 3 ); // $ExpectError + dlaset( null, 'lower', 3, 3, 3.1, 3.7, A, 3 ); // $ExpectError + dlaset( void 0, 'lower', 3, 3, 3.1, 3.7, A, 3 ); // $ExpectError + dlaset( [], 'lower', 3, 3, 3.1, 3.7, A, 3 ); // $ExpectError + dlaset( {}, 'lower', 3, 3, 3.1, 3.7, A, 3 ); // $ExpectError + dlaset( ( x: number ): number => x, 'lower', 3, 3, 3.1, 3.7, A, 3 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a string... +{ + const A = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + dlaset( 'row-major', 5, 3, 3, 3.1, 3.7, A, 3 ); // $ExpectError + dlaset( 'row-major', true, 3, 3, 3.1, 3.7, A, 3 ); // $ExpectError + dlaset( 'row-major', false, 3, 3, 3.1, 3.7, A, 3 ); // $ExpectError + dlaset( 'row-major', null, 3, 3, 3.1, 3.7, A, 3 ); // $ExpectError + dlaset( 'row-major', void 0, 3, 3, 3.1, 3.7, A, 3 ); // $ExpectError + dlaset( 'row-major', [], 3, 3, 3.1, 3.7, A, 3 ); // $ExpectError + dlaset( 'row-major', {}, 3, 3, 3.1, 3.7, A, 3 ); // $ExpectError + dlaset( 'row-major', ( x: number ): number => x, 3, 3, 3.1, 3.7, A, 3 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a number... +{ + const A = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + dlaset( 'row-major', 'lower', '5', 3, 3.1, 3.7, A, 3 ); // $ExpectError + dlaset( 'row-major', 'lower', true, 3, 3.1, 3.7, A, 3 ); // $ExpectError + dlaset( 'row-major', 'lower', false, 3, 3.1, 3.7, A, 3 ); // $ExpectError + dlaset( 'row-major', 'lower', null, 3, 3.1, 3.7, A, 3 ); // $ExpectError + dlaset( 'row-major', 'lower', void 0, 3, 3.1, 3.7, A, 3 ); // $ExpectError + dlaset( 'row-major', 'lower', [], 3, 3.1, 3.7, A, 3 ); // $ExpectError + dlaset( 'row-major', 'lower', {}, 3, 3.1, 3.7, A, 3 ); // $ExpectError + dlaset( 'row-major', 'lower', ( x: number ): number => x, 3, 3.1, 3.7, A, 3 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a number... +{ + const A = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + dlaset( 'row-major', 'lower', 3, '5', 3.1, 3.7, A, 3 ); // $ExpectError + dlaset( 'row-major', 'lower', 3, true, 3.1, 3.7, A, 3 ); // $ExpectError + dlaset( 'row-major', 'lower', 3, false, 3.1, 3.7, A, 3 ); // $ExpectError + dlaset( 'row-major', 'lower', 3, null, 3.1, 3.7, A, 3 ); // $ExpectError + dlaset( 'row-major', 'lower', 3, void 0, 3.1, 3.7, A, 3 ); // $ExpectError + dlaset( 'row-major', 'lower', 3, [], 3.1, 3.7, A, 3 ); // $ExpectError + dlaset( 'row-major', 'lower', 3, {}, 3.1, 3.7, A, 3 ); // $ExpectError + dlaset( 'row-major', 'lower', 3, ( x: number ): number => x, 3.1, 3.7, A, 3 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not a number... +{ + const A = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + dlaset( 'row-major', 'lower', 3, 3, '5', 3.7, A, 3 ); // $ExpectError + dlaset( 'row-major', 'lower', 3, 3, true, 3.7, A, 3 ); // $ExpectError + dlaset( 'row-major', 'lower', 3, 3, false, 3.7, A, 3 ); // $ExpectError + dlaset( 'row-major', 'lower', 3, 3, null, 3.7, A, 3 ); // $ExpectError + dlaset( 'row-major', 'lower', 3, 3, void 0, 3.7, A, 3 ); // $ExpectError + dlaset( 'row-major', 'lower', 3, 3, [], 3.7, A, 3 ); // $ExpectError + dlaset( 'row-major', 'lower', 3, 3, {}, 3.7, A, 3 ); // $ExpectError + dlaset( 'row-major', 'lower', 3, 3, ( x: number ): number => x, 3.7, A, 3 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a sixth argument which is not a number... +{ + const A = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + dlaset( 'row-major', 'lower', 3, 3, 3.1, '5', A, 3 ); // $ExpectError + dlaset( 'row-major', 'lower', 3, 3, 3.1, true, A, 3 ); // $ExpectError + dlaset( 'row-major', 'lower', 3, 3, 3.1, false, A, 3 ); // $ExpectError + dlaset( 'row-major', 'lower', 3, 3, 3.1, null, A, 3 ); // $ExpectError + dlaset( 'row-major', 'lower', 3, 3, 3.1, void 0, A, 3 ); // $ExpectError + dlaset( 'row-major', 'lower', 3, 3, 3.1, [], A, 3 ); // $ExpectError + dlaset( 'row-major', 'lower', 3, 3, 3.1, {}, A, 3 ); // $ExpectError + dlaset( 'row-major', 'lower', 3, 3, 3.1, ( x: number ): number => x, A, 3 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a seventh argument which is not a Float64Array... +{ + + dlaset( 'row-major', 'lower', 3, 3, 3.1, 3.7, '5', 3 ); // $ExpectError + dlaset( 'row-major', 'lower', 3, 3, 3.1, 3.7, 5, 3 ); // $ExpectError + dlaset( 'row-major', 'lower', 3, 3, 3.1, 3.7, true, 3 ); // $ExpectError + dlaset( 'row-major', 'lower', 3, 3, 3.1, 3.7, false, 3 ); // $ExpectError + dlaset( 'row-major', 'lower', 3, 3, 3.1, 3.7, null, 3 ); // $ExpectError + dlaset( 'row-major', 'lower', 3, 3, 3.1, 3.7, void 0, 3 ); // $ExpectError + dlaset( 'row-major', 'lower', 3, 3, 3.1, 3.7, [], 3 ); // $ExpectError + dlaset( 'row-major', 'lower', 3, 3, 3.1, 3.7, {}, 3 ); // $ExpectError + dlaset( 'row-major', 'lower', 3, 3, 3.1, 3.7, ( x: number ): number => x, 3 ); // $ExpectError +} + +// The compiler throws an error if the function is provided an eighth argument which is not a number... +{ + const A = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + dlaset( 'row-major', 'lower', 3, 3, 3.1, 3.7, A, '5' ); // $ExpectError + dlaset( 'row-major', 'lower', 3, 3, 3.1, 3.7, A, true ); // $ExpectError + dlaset( 'row-major', 'lower', 3, 3, 3.1, 3.7, A, false ); // $ExpectError + dlaset( 'row-major', 'lower', 3, 3, 3.1, 3.7, A, null ); // $ExpectError + dlaset( 'row-major', 'lower', 3, 3, 3.1, 3.7, A, void 0 ); // $ExpectError + dlaset( 'row-major', 'lower', 3, 3, 3.1, 3.7, A, [] ); // $ExpectError + dlaset( 'row-major', 'lower', 3, 3, 3.1, 3.7, A, {} ); // $ExpectError + dlaset( 'row-major', 'lower', 3, 3, 3.1, 3.7, A, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const A = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + dlaset(); // $ExpectError + dlaset( 'row-major' ); // $ExpectError + dlaset( 'row-major', 'lower' ); // $ExpectError + dlaset( 'row-major', 'lower', 3 ); // $ExpectError + dlaset( 'row-major', 'lower', 3, 3 ); // $ExpectError + dlaset( 'row-major', 'lower', 3, 3, 3.1 ); // $ExpectError + dlaset( 'row-major', 'lower', 3, 3, 3.1, 3.7 ); // $ExpectError + dlaset( 'row-major', 'lower', 3, 3, 3.1, 3.7, A ); // $ExpectError + dlaset( 'row-major', 'lower', 3, 3, 3.1, 3.7, A, 3, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a Float64Array... +{ + const A = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + dlaset.ndarray( 'lower', 3, 3, 3.1, 3.7, A, 3, 1, 0 ); // $ExpectType Float64Array +} + +// The compiler throws an error if the function is provided a first argument which is not a string... +{ + const A = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + dlaset.ndarray( 5, 3, 3, 3.1, 3.7, A, 3, 1, 0 ); // $ExpectError + dlaset.ndarray( true, 3, 3, 3.1, 3.7, A, 3, 1, 0 ); // $ExpectError + dlaset.ndarray( false, 3, 3, 3.1, 3.7, A, 3, 1, 0 ); // $ExpectError + dlaset.ndarray( null, 3, 3, 3.1, 3.7, A, 3, 1, 0 ); // $ExpectError + dlaset.ndarray( void 0, 3, 3, 3.1, 3.7, A, 3, 1, 0 ); // $ExpectError + dlaset.ndarray( [], 3, 3, 3.1, 3.7, A, 3, 1, 0 ); // $ExpectError + dlaset.ndarray( {}, 3, 3, 3.1, 3.7, A, 3, 1, 0 ); // $ExpectError + dlaset.ndarray( ( x: number ): number => x, 3, 3, 3.1, 3.7, A, 3, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a number... +{ + const A = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + dlaset.ndarray( 'lower', '5', 3, 3.1, 3.7, A, 3, 1, 0 ); // $ExpectError + dlaset.ndarray( 'lower', true, 3, 3.1, 3.7, A, 3, 1, 0 ); // $ExpectError + dlaset.ndarray( 'lower', false, 3, 3.1, 3.7, A, 3, 1, 0 ); // $ExpectError + dlaset.ndarray( 'lower', null, 3, 3.1, 3.7, A, 3, 1, 0 ); // $ExpectError + dlaset.ndarray( 'lower', void 0, 3, 3.1, 3.7, A, 3, 1, 0 ); // $ExpectError + dlaset.ndarray( 'lower', [], 3, 3.1, 3.7, A, 3, 1, 0 ); // $ExpectError + dlaset.ndarray( 'lower', {}, 3, 3.1, 3.7, A, 3, 1, 0 ); // $ExpectError + dlaset.ndarray( 'lower', ( x: number ): number => x, 3, 3.1, 3.7, A, 3, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a number... +{ + const A = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + dlaset.ndarray( 'lower', 3, '5', 3.1, 3.7, A, 3, 1, 0 ); // $ExpectError + dlaset.ndarray( 'lower', 3, true, 3.1, 3.7, A, 3, 1, 0 ); // $ExpectError + dlaset.ndarray( 'lower', 3, false, 3.1, 3.7, A, 3, 1, 0 ); // $ExpectError + dlaset.ndarray( 'lower', 3, null, 3.1, 3.7, A, 3, 1, 0 ); // $ExpectError + dlaset.ndarray( 'lower', 3, void 0, 3.1, 3.7, A, 3, 1, 0 ); // $ExpectError + dlaset.ndarray( 'lower', 3, [], 3.1, 3.7, A, 3, 1, 0 ); // $ExpectError + dlaset.ndarray( 'lower', 3, {}, 3.1, 3.7, A, 3, 1, 0 ); // $ExpectError + dlaset.ndarray( 'lower', 3, ( x: number ): number => x, 3.1, 3.7, A, 3, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a number... +{ + const A = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + dlaset.ndarray( 'lower', 3, 3, '5', 3.7, A, 3, 1, 0 ); // $ExpectError + dlaset.ndarray( 'lower', 3, 3, true, 3.7, A, 3, 1, 0 ); // $ExpectError + dlaset.ndarray( 'lower', 3, 3, false, 3.7, A, 3, 1, 0 ); // $ExpectError + dlaset.ndarray( 'lower', 3, 3, null, 3.7, A, 3, 1, 0 ); // $ExpectError + dlaset.ndarray( 'lower', 3, 3, void 0, 3.7, A, 3, 1, 0 ); // $ExpectError + dlaset.ndarray( 'lower', 3, 3, [], 3.7, A, 3, 1, 0 ); // $ExpectError + dlaset.ndarray( 'lower', 3, 3, {}, 3.7, A, 3, 1, 0 ); // $ExpectError + dlaset.ndarray( 'lower', 3, 3, ( x: number ): number => x, 3.7, A, 3, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not a number... +{ + const A = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + dlaset.ndarray( 'lower', 3, 3, 3.1, '5', A, 3, 1, 0 ); // $ExpectError + dlaset.ndarray( 'lower', 3, 3, 3.1, true, A, 3, 1, 0 ); // $ExpectError + dlaset.ndarray( 'lower', 3, 3, 3.1, false, A, 3, 1, 0 ); // $ExpectError + dlaset.ndarray( 'lower', 3, 3, 3.1, null, A, 3, 1, 0 ); // $ExpectError + dlaset.ndarray( 'lower', 3, 3, 3.1, void 0, A, 3, 1, 0 ); // $ExpectError + dlaset.ndarray( 'lower', 3, 3, 3.1, [], A, 3, 1, 0 ); // $ExpectError + dlaset.ndarray( 'lower', 3, 3, 3.1, {}, A, 3, 1, 0 ); // $ExpectError + dlaset.ndarray( 'lower', 3, 3, 3.1, ( x: number ): number => x, A, 3, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a sixth argument which is not a Float64Array... +{ + + dlaset.ndarray( 'lower', 3, 3, 3.1, 3.7, '5', 3, 1, 0 ); // $ExpectError + dlaset.ndarray( 'lower', 3, 3, 3.1, 3.7, 5, 3, 1, 0 ); // $ExpectError + dlaset.ndarray( 'lower', 3, 3, 3.1, 3.7, true, 3, 1, 0 ); // $ExpectError + dlaset.ndarray( 'lower', 3, 3, 3.1, 3.7, false, 3, 1, 0 ); // $ExpectError + dlaset.ndarray( 'lower', 3, 3, 3.1, 3.7, null, 3, 1, 0 ); // $ExpectError + dlaset.ndarray( 'lower', 3, 3, 3.1, 3.7, void 0, 3, 1, 0 ); // $ExpectError + dlaset.ndarray( 'lower', 3, 3, 3.1, 3.7, [], 3, 1, 0 ); // $ExpectError + dlaset.ndarray( 'lower', 3, 3, 3.1, 3.7, {}, 3, 1, 0 ); // $ExpectError + dlaset.ndarray( 'lower', 3, 3, 3.1, 3.7, ( x: number ): number => x, 3, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a seventh argument which is not a number... +{ + const A = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + dlaset.ndarray( 'lower', 3, 3, 3.1, 3.7, A, '5', 1, 0 ); // $ExpectError + dlaset.ndarray( 'lower', 3, 3, 3.1, 3.7, A, true, 1, 0 ); // $ExpectError + dlaset.ndarray( 'lower', 3, 3, 3.1, 3.7, A, false, 1, 0 ); // $ExpectError + dlaset.ndarray( 'lower', 3, 3, 3.1, 3.7, A, null, 1, 0 ); // $ExpectError + dlaset.ndarray( 'lower', 3, 3, 3.1, 3.7, A, void 0, 1, 0 ); // $ExpectError + dlaset.ndarray( 'lower', 3, 3, 3.1, 3.7, A, [], 1, 0 ); // $ExpectError + dlaset.ndarray( 'lower', 3, 3, 3.1, 3.7, A, {}, 1, 0 ); // $ExpectError + dlaset.ndarray( 'lower', 3, 3, 3.1, 3.7, A, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided an eighth argument which is not a number... +{ + const A = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + dlaset.ndarray( 'lower', 3, 3, 3.1, 3.7, A, 3, '5', 0 ); // $ExpectError + dlaset.ndarray( 'lower', 3, 3, 3.1, 3.7, A, 3, true, 0 ); // $ExpectError + dlaset.ndarray( 'lower', 3, 3, 3.1, 3.7, A, 3, false, 0 ); // $ExpectError + dlaset.ndarray( 'lower', 3, 3, 3.1, 3.7, A, 3, null, 0 ); // $ExpectError + dlaset.ndarray( 'lower', 3, 3, 3.1, 3.7, A, 3, void 0, 0 ); // $ExpectError + dlaset.ndarray( 'lower', 3, 3, 3.1, 3.7, A, 3, [], 0 ); // $ExpectError + dlaset.ndarray( 'lower', 3, 3, 3.1, 3.7, A, 3, {}, 0 ); // $ExpectError + dlaset.ndarray( 'lower', 3, 3, 3.1, 3.7, A, 3, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a ninth argument which is not a number... +{ + const A = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + dlaset.ndarray( 'lower', 3, 3, 3.1, 3.7, A, 3, 1, '5' ); // $ExpectError + dlaset.ndarray( 'lower', 3, 3, 3.1, 3.7, A, 3, 1, true ); // $ExpectError + dlaset.ndarray( 'lower', 3, 3, 3.1, 3.7, A, 3, 1, false ); // $ExpectError + dlaset.ndarray( 'lower', 3, 3, 3.1, 3.7, A, 3, 1, null ); // $ExpectError + dlaset.ndarray( 'lower', 3, 3, 3.1, 3.7, A, 3, 1, void 0 ); // $ExpectError + dlaset.ndarray( 'lower', 3, 3, 3.1, 3.7, A, 3, 1, [] ); // $ExpectError + dlaset.ndarray( 'lower', 3, 3, 3.1, 3.7, A, 3, 1, {} ); // $ExpectError + dlaset.ndarray( 'lower', 3, 3, 3.1, 3.7, A, 3, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const A = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + dlaset.ndarray(); // $ExpectError + dlaset.ndarray( 'lower' ); // $ExpectError + dlaset.ndarray( 'lower', 3 ); // $ExpectError + dlaset.ndarray( 'lower', 3, 3 ); // $ExpectError + dlaset.ndarray( 'lower', 3, 3, 3.1 ); // $ExpectError + dlaset.ndarray( 'lower', 3, 3, 3.1, 3.7 ); // $ExpectError + dlaset.ndarray( 'lower', 3, 3, 3.1, 3.7, A ); // $ExpectError + dlaset.ndarray( 'lower', 3, 3, 3.1, 3.7, A, 3 ); // $ExpectError + dlaset.ndarray( 'lower', 3, 3, 3.1, 3.7, A, 3, 1 ); // $ExpectError + dlaset.ndarray( 'lower', 3, 3, 3.1, 3.7, A, 3, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/lapack/base/dlaset/examples/index.js b/lib/node_modules/@stdlib/lapack/base/dlaset/examples/index.js new file mode 100644 index 000000000000..af56e99fbba6 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlaset/examples/index.js @@ -0,0 +1,28 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var Float64Array = require( '@stdlib/array/float64' ); +var dlaset = require( './../lib' ); + +var A = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + +dlaset( 'row-major', 'lower', 3, 3, 3.1, 3.7, A, 3 ); +console.log( A ); +// A => [ 3.7, 0.0, 0.0, 3.1, 3.7, 0.0, 3.1, 3.1, 3.7 ] diff --git a/lib/node_modules/@stdlib/lapack/base/dlaset/lib/base.js b/lib/node_modules/@stdlib/lapack/base/dlaset/lib/base.js new file mode 100644 index 000000000000..9e27b94883ed --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlaset/lib/base.js @@ -0,0 +1,250 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major' ); +var min = require( '@stdlib/math/base/special/fast/min' ); + + +// FUNCTIONS // + +/** +* Sets the diagonal of a matrix `A` to `β`. +* +* @private +* @param {NonNegativeInteger} M - number of rows in matrix `A` +* @param {NonNegativeInteger} N - number of columns in matrix `A` +* @param {number} beta - scalar constant to which diagonal elements are set +* @param {Float64Array} A - input matrix +* @param {integer} strideA1 - stride of the first dimension of `A` +* @param {integer} strideA2 - stride of the second dimension of `A` +* @param {NonNegativeInteger} offsetA - starting index for `A` +* @returns {Float64Array} `A` +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var A = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); +* +* setDiagonal( 2, 3, 3.7, A, 3, 1, 0 ); +* // A => [ 3.7, 0.0, 0.0, 0.0, 3.7, 0.0 ] +*/ +function setDiagonal( M, N, beta, A, strideA1, strideA2, offsetA ) { + var sa; + var ia; + var i; + + sa = strideA1 + strideA2; + ia = offsetA; + for ( i = 0; i < min( M, N ); i++ ) { + A[ ia ] = beta; + ia += sa; + } + return A; +} + +/** +* Initializes the upper triangular/trapezoidal part of a matrix `A` to `β` on the diagonal and `α` on the off-diagonals. +* +* @private +* @param {NonNegativeInteger} M - number of rows in matrix `A` +* @param {NonNegativeInteger} N - number of columns in matrix `A` +* @param {number} alpha - scalar constant to which off-diagonal elements are set +* @param {number} beta - scalar constant to which diagonal elements are set +* @param {Float64Array} A - input matrix +* @param {integer} strideA1 - stride of the first dimension of `A` +* @param {integer} strideA2 - stride of the second dimension of `A` +* @param {NonNegativeInteger} offsetA - starting index for `A` +* @returns {Float64Array} `A` +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var A = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); +* +* setUpper( 2, 3, 3.1, 3.7, A, 3, 1, 0 ); +* // A => [ 3.7, 3.1, 0.0, 0.0, 3.7, 0.0 ] +*/ +function setUpper( M, N, alpha, beta, A, strideA1, strideA2, offsetA ) { + var ia; + var i; + var j; + + if ( isRowMajor( [ strideA1, strideA2 ] ) ) { + for ( i = 0; i < M; i++ ) { + ia = offsetA + ( i * strideA1 ); + for ( j = i + 1; j < min( M, N ); j++ ) { + if ( i !== j ) { + A[ ia + ( j * strideA2 ) ] = alpha; + } + } + } + setDiagonal( M, N, beta, A, strideA2, strideA1, offsetA ); + return A; + } + // 'column-major' + for ( j = 1; j < N; j++ ) { + ia = offsetA + ( j * strideA2 ); + for ( i = 0; i < min( j - 1, M ); i++ ) { + A[ ia + ( i * strideA1 ) ] = alpha; + } + } + setDiagonal( M, N, beta, A, strideA1, strideA2, offsetA ); + return A; +} + +/** +* Initializes the lower triangular/trapezoidal part of a matrix `A` to `β` on the diagonal and `α` on the off-diagonals. +* +* @private +* @param {NonNegativeInteger} M - number of rows in matrix `A` +* @param {NonNegativeInteger} N - number of columns in matrix `A` +* @param {number} alpha - scalar constant to which off-diagonal elements are set +* @param {number} beta - scalar constant to which diagonal elements are set +* @param {Float64Array} A - input matrix +* @param {integer} strideA1 - stride of the first dimension of `A` +* @param {integer} strideA2 - stride of the second dimension of `A` +* @param {NonNegativeInteger} offsetA - starting index for `A` +* @returns {Float64Array} `A` +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var A = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); +* +* setLower( 2, 3, 3.1, 3.7, A, 3, 1, 0 ); +* // A => [ 3.7, 0.0, 0.0, 3.1, 3.7, 0.0 ] +*/ +function setLower( M, N, alpha, beta, A, strideA1, strideA2, offsetA ) { + var ia; + var i; + var j; + + if ( isRowMajor( [ strideA1, strideA2 ] ) ) { + for ( i = 0; i < M; i++ ) { + ia = offsetA + ( i * strideA1 ); + for ( j = i; j >= 0; j-- ) { + if ( i !== j ) { + A[ ia + ( j*strideA2 ) ] = alpha; + } + } + } + setDiagonal( M, N, beta, A, strideA2, strideA1, offsetA ); + } + // 'column-major' + for ( j = 0; j < min( M, N ); j++ ) { + ia = offsetA + ( j*strideA2 ); + for ( i = j + 1; i < M; i++ ) { + A[ ia + ( i*strideA1 ) ] = alpha; + } + } + setDiagonal( M, N, beta, A, strideA1, strideA2, offsetA ); + return A; +} + +/** +* Initializes all of triangular/trapezoidal part of a matrix `A` to `β` on the diagonal and `α` on the off-diagonals. +* +* @private +* @param {NonNegativeInteger} M - number of rows in matrix `A` +* @param {NonNegativeInteger} N - number of columns in matrix `A` +* @param {number} alpha - scalar constant to which off-diagonal elements are set +* @param {number} beta - scalar constant to which diagonal elements are set +* @param {Float64Array} A - input matrix +* @param {integer} strideA1 - stride of the first dimension of `A` +* @param {integer} strideA2 - stride of the second dimension of `A` +* @param {NonNegativeInteger} offsetA - starting index for `A` +* @returns {Float64Array} `A` +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var A = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); +* +* setAll( 2, 3, 3.1, 3.7, A, 3, 1, 0 ); +* // A => [ 3.7, 3.1, 3.1, 3.1, 3.7, 3.1 ] +*/ +function setAll( M, N, alpha, beta, A, strideA1, strideA2, offsetA ) { + var ia; + var i; + var j; + + if ( isRowMajor( [ strideA1, strideA2 ] ) ) { + for ( i = 0; i < M; i++ ) { + ia = offsetA + ( i*strideA1 ); + for ( j = 0; j < N; j++ ) { + A[ ia + ( j*strideA2 ) ] = alpha; + } + } + setDiagonal( M, N, beta, A, strideA2, strideA1, offsetA ); + return A; + } + // 'column-major' + for ( j = 0; j < N; j++ ) { + ia = offsetA + ( j*strideA2 ); + for ( i = 0; i < M; i++ ) { + A[ ia + ( i*strideA1 ) ] = alpha; + } + } + setDiagonal( M, N, beta, A, strideA1, strideA2, offsetA ); + return A; +} + + +// MAIN // + +/** +* Initializes an `M` by `N` matrix `A` to `β` on the diagonal and `α` on the off-diagonals. +* +* @private +* @param {string} uplo - specifies whether the upper or lower triangular part of matrix `A` is supplied +* @param {NonNegativeInteger} M - number of rows in matrix `A` +* @param {NonNegativeInteger} N - number of columns in matrix `A` +* @param {number} alpha - scalar constant to which off-diagonal elements are set +* @param {number} beta - scalar constant to which diagonal elements are set +* @param {Float64Array} A - input matrix +* @param {integer} strideA1 - stride of the first dimension of `A` +* @param {integer} strideA2 - stride of the second dimension of `A` +* @param {NonNegativeInteger} offsetA - starting index for `A` +* @returns {Float64Array} `A` +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var A = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); +* +* dlaset( 'lower', 3, 3, 3.1, 3.7, A, 3, 1, 0 ); +* // A => [ 3.7, 0.0, 0.0, 3.1, 3.7, 0.0, 3.1, 3.1, 3.7 ] +*/ +function dlaset( uplo, M, N, alpha, beta, A, strideA1, strideA2, offsetA ) { + if ( uplo === 'upper' ) { + return setUpper( M, N, alpha, beta, A, strideA1, strideA2, offsetA ); + } + if ( uplo === 'lower' ) { + return setLower( M, N, alpha, beta, A, strideA1, strideA2, offsetA ); + } + return setAll( M, N, alpha, beta, A, strideA1, strideA2, offsetA ); +} + + +// EXPORTS // + +module.exports = dlaset; diff --git a/lib/node_modules/@stdlib/lapack/base/dlaset/lib/dlaset.js b/lib/node_modules/@stdlib/lapack/base/dlaset/lib/dlaset.js new file mode 100644 index 000000000000..4e91a0fca1e9 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlaset/lib/dlaset.js @@ -0,0 +1,71 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isLayout = require( '@stdlib/blas/base/assert/is-layout' ); +var format = require( '@stdlib/string/format' ); +var base = require( './base.js' ); + + +// MAIN // + +/** +* Initializes an `M` by `N` matrix `A` to `β` on the diagonal and `α` on the off-diagonals. +* +* @param {string} order - storage layout +* @param {string} uplo - specifies whether to set the upper or lower triangular part of matrix `A` +* @param {NonNegativeInteger} M - number of rows in matrix `A` +* @param {NonNegativeInteger} N - number of columns in matrix `A` +* @param {number} alpha - scalar constant to which off-diagonal elements are set +* @param {number} beta - scalar constant to which diagonal elements are set +* @param {Float64Array} A - input matrix +* @param {PositiveInteger} LDA - stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`) +* @throws {TypeError} first argument must be a valid order +* @returns {Float64Array} `A` +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var A = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); +* +* dlaset( 'row-major', 'lower', 3, 3, 3.1, 3.7, A, 3 ); +* // A => [ 3.7, 0.0, 0.0, 3.1, 3.7, 0.0, 3.1, 3.1, 3.7 ] +*/ +function dlaset( order, uplo, M, N, alpha, beta, A, LDA ) { + var sa1; + var sa2; + if ( !isLayout( order ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a valid order. Value: `%s`.', order ) ); + } + if ( order === 'column-major' ) { + sa1 = 1; + sa2 = LDA; + } else { // order === 'row-major' + sa1 = LDA; + sa2 = 1; + } + return base( uplo, M, N, alpha, beta, A, sa1, sa2, 0 ); +} + + +// EXPORTS // + +module.exports = dlaset; diff --git a/lib/node_modules/@stdlib/lapack/base/dlaset/lib/index.js b/lib/node_modules/@stdlib/lapack/base/dlaset/lib/index.js new file mode 100644 index 000000000000..7170d7df5659 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlaset/lib/index.js @@ -0,0 +1,68 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* LAPACK routine to initialize an `M` by `N` matrix `A` to `β` on the diagonal and `α` on the off-diagonals. +* +* @module @stdlib/lapack/base/dlaset +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var dlaset = require( '@stdlib/lapack/base/dlaset' ); +* +* var A = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); +* +* dlaset( 'row-major', 'lower', 3, 3, 3.1, 3.7, A, 3 ); +* // A => [ 3.7, 0.0, 0.0, 3.1, 3.7, 0.0, 3.1, 3.1, 3.7 ] +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var dlaset = require( '@stdlib/lapack/base/dlaset' ); +* +* var A = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); +* +* dlaset.ndarray( 'lower', 3, 3, 3.1, 3.7, A, 3, 1, 1 ); +* // A => [ 0.0, 3.7, 0.0, 0.0, 3.1, 3.7, 0.0, 3.1, 3.1, 3.7 ] +*/ + +// 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 dlaset; +var tmp = tryRequire( join( __dirname, './native.js' ) ); +if ( isError( tmp ) ) { + dlaset = main; +} else { + dlaset = tmp; +} + + +// EXPORTS // + +module.exports = dlaset; + +// exports: { "ndarray": "dlaset.ndarray" } diff --git a/lib/node_modules/@stdlib/lapack/base/dlaset/lib/main.js b/lib/node_modules/@stdlib/lapack/base/dlaset/lib/main.js new file mode 100644 index 000000000000..77b02a3774fc --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlaset/lib/main.js @@ -0,0 +1,35 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var dlaset = require( './dlaset.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( dlaset, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = dlaset; diff --git a/lib/node_modules/@stdlib/lapack/base/dlaset/lib/ndarray.js b/lib/node_modules/@stdlib/lapack/base/dlaset/lib/ndarray.js new file mode 100644 index 000000000000..65004b203157 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlaset/lib/ndarray.js @@ -0,0 +1,57 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var base = require( './base.js' ); + + +// MAIN // + +/** +* Initializes an `M` by `N` matrix `A` to `β` on the diagonal and `α` on the off-diagonals using alternative indexing semantics. +* +* @param {string} uplo - specifies whether to set the upper or lower triangular part of matrix `A` +* @param {NonNegativeInteger} M - number of rows in matrix `A` +* @param {NonNegativeInteger} N - number of columns in matrix `A` +* @param {number} alpha - scalar constant to which off-diagonal elements are set +* @param {number} beta - scalar constant to which diagonal elements are set +* @param {Float64Array} A - input matrix +* @param {integer} strideA1 - stride of the first dimension of `A` +* @param {integer} strideA2 - stride of the second dimension of `A` +* @param {NonNegativeInteger} offsetA - starting index for `A` +* @returns {Float64Array} `A` +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var A = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); +* +* dlaset( 'lower', 3, 3, 3.1, 3.7, A, 3, 1, 1 ); +* // A => [ 0.0, 3.7, 0.0, 0.0, 3.1, 3.7, 0.0, 3.1, 3.1, 3.7 ] +*/ +function dlaset( uplo, M, N, alpha, beta, A, strideA1, strideA2, offsetA ) { + return base( uplo, M, N, alpha, beta, A, strideA1, strideA2, offsetA ); +} + + +// EXPORTS // + +module.exports = dlaset; diff --git a/lib/node_modules/@stdlib/lapack/base/dlaset/package.json b/lib/node_modules/@stdlib/lapack/base/dlaset/package.json new file mode 100644 index 000000000000..8919c234f5e0 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlaset/package.json @@ -0,0 +1,67 @@ +{ + "name": "@stdlib/lapack/base/dlacpy", + "version": "0.0.0", + "description": "Initializes an `M` by `N` matrix `A` to `beta` on the diagonal and `alpha` on the off-diagonals.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "mathematics", + "math", + "lapack", + "dlaset", + "linear", + "algebra", + "subroutines", + "array", + "ndarray", + "float64", + "double", + "float64array" + ] +} diff --git a/lib/node_modules/@stdlib/lapack/base/dlaset/test/test.dlaset.js b/lib/node_modules/@stdlib/lapack/base/dlaset/test/test.dlaset.js new file mode 100644 index 000000000000..c8a8f05c34f6 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlaset/test/test.dlaset.js @@ -0,0 +1,238 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Float64Array = require( '@stdlib/array/float64' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var dlaset = require( './../lib/dlaset.js' ); + + +// FUNCTIONS // + +/** +* Tests for element-wise approximate equality. +* +* @private +* @param {Object} t - test object +* @param {Collection} actual - actual values +* @param {Collection} expected - expected values +* @param {number} rtol - relative tolerance +*/ +function isApprox( t, actual, expected, rtol ) { + var delta; + var tol; + var i; + + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + for ( i = 0; i < expected.length; i++ ) { + if ( actual[ i ] === expected[ i ] ) { + t.strictEqual( actual[ i ], expected[ i ], 'returns expected value' ); + } else { + delta = abs( actual[ i ] - expected[ i ] ); + tol = rtol * EPS * abs( expected[ i ] ); + t.ok( delta <= tol, 'within tolerance. actual: '+actual[ i ]+'. expected: '+expected[ i ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dlaset, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 8', function test( t ) { + t.strictEqual( dlaset.length, 8, 'returns expected value' ); + t.end(); +}); + +tape( 'the function throws an error if provided an invalid first argument', function test( t ) { + var values; + var A; + var i; + + values = [ + 'foo', + 'bar', + 'beep', + 'boop' + ]; + + A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + dlaset( value, 'lower', 2, 2, 3.1, 3.7, A, 2 ); + }; + } +}); + +tape( 'the function sets lower part of a rectangular matrix (row-major, lower)', function test( t ) { + var expected; + var out; + var A; + var M; + var N; + + M = 2; + N = 3; + + A = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + expected = new Float64Array( [ 3.7, 0.0, 0.0, 3.1, 3.7, 0.0 ]); + + out = dlaset( 'row-major', 'lower', M, N, 3.1, 3.7, A, N ); + console.log( out ); + t.strictEqual( out, A, 'returns expected value' ); + isApprox( t, A, expected, 2.0 ); + + t.end(); +}); + +tape( 'the function sets lower part of a column major rectangular matrix (column-major, lower)', function test( t ) { + var expected; + var out; + var A; + var M; + var N; + + M = 2; + N = 3; + + A = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + expected = new Float64Array( [ 3.7, 3.1, 0.0, 3.7, 0.0, 0.0 ]); + + out = dlaset( 'column-major', 'lower', M, N, 3.1, 3.7, A, M ); + t.strictEqual( out, A, 'returns expected value' ); + isApprox( t, A, expected, 2.0 ); + + t.end(); +}); + +tape( 'the function sets upper part of rectangular matrix (row-major, upper)', function test( t ) { + var expected; + var out; + var A; + var M; + var N; + + M = 2; + N = 3; + + A = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + expected = new Float64Array( [ 3.7, 3.1, 0, 0, 3.7, 0.0 ]); + + out = dlaset( 'row-major', 'upper', M, N, 3.1, 3.7, A, N ); + t.strictEqual( out, A, 'returns expected value' ); + isApprox( t, A, expected, 2.0 ); + + t.end(); +}); + +tape( 'the function sets upper part of column major rectangular matrix (column-major, upper)', function test( t ) { + var expected; + var out; + var A; + var M; + var N; + + M = 2; + N = 3; + + A = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + expected = new Float64Array( [ 3.7, 0.0, 0.0, 3.7, 3.1, 0.0 ]); + + out = dlaset( 'column-major', 'upper', M, N, 3.1, 3.7, A, M ); + t.strictEqual( out, A, 'returns expected value' ); + isApprox( t, A, expected, 2.0 ); + + t.end(); +}); + +tape( 'the function sets all of rectangular matrix (row-major, all)', function test( t ) { + var expected; + var out; + var A; + var M; + var N; + + M = 2; + N = 3; + + A = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + expected = new Float64Array( [ 3.7, 3.1, 3.1, 3.1, 3.7, 3.1 ]); + + out = dlaset( 'row-major', 'all', M, N, 3.1, 3.7, A, N ); + t.strictEqual( out, A, 'returns expected value' ); + isApprox( t, A, expected, 2.0 ); + + t.end(); +}); + +tape( 'the function sets all of column major rectangular matrix (column-major, all)', function test( t ) { + var expected; + var out; + var A; + var M; + var N; + + M = 2; + N = 3; + + A = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + expected = new Float64Array( [ 3.7, 3.1, 3.1, 3.7, 3.1, 3.1 ]); + + out = dlaset( 'column-major', 'all', M, N, 3.1, 3.7, A, M ); + t.strictEqual( out, A, 'returns expected value' ); + isApprox( t, A, expected, 2.0 ); + + t.end(); +}); + +tape( 'the function correctly sets a square matrix `A`', function test( t ) { + var expected; + var out2; + var out; + var A; + + A = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + expected = new Float64Array( [ 3.7, 3.1, 3.1, 3.1, 0.0, 3.7, 3.1, 3.1, 0.0, 0.0, 3.7, 3.1, 0.0, 0.0, 0.0, 3.7 ] ); + + out = dlaset( 'row-major', 'upper', 4, 4, 3.1, 3.7, A, 4 ); + t.strictEqual( out, A, 'returns expected value' ); + isApprox( t, A, expected, 2.0 ); + + out = dlaset( 'row-major', 'lower', 4, 4, 3.1, 3.7, A, 4 ); + t.strictEqual( out, A, 'returns expected value' ); + out2 = dlaset( 'row-major', 'all', 4, 4, 3.1, 3.7, A, 4 ); + t.strictEqual( out2, A, 'returns expected value' ); + t.strictEqual( out, out2, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/lapack/base/dlaset/test/test.js b/lib/node_modules/@stdlib/lapack/base/dlaset/test/test.js new file mode 100644 index 000000000000..b1b9bf5ac416 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlaset/test/test.js @@ -0,0 +1,82 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var proxyquire = require( 'proxyquire' ); +var IS_BROWSER = require( '@stdlib/assert/is-browser' ); +var dlaset = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': IS_BROWSER +}; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dlaset, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is a method providing an ndarray interface', function test( t ) { + t.strictEqual( typeof dlaset.ndarray, 'function', 'method is a function' ); + t.end(); +}); + +tape( 'if a native implementation is available, the main export is the native implementation', opts, function test( t ) { + var dlaset = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( dlaset, mock, 'returns expected value' ); + t.end(); + + function tryRequire() { + return mock; + } + + function mock() { + // Mock... + } +}); + +tape( 'if a native implementation is not available, the main export is a JavaScript implementation', opts, function test( t ) { + var dlaset; + var main; + + main = require( './../lib/dlaset.js' ); + + dlaset = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( dlaset, main, 'returns expected value' ); + t.end(); + + function tryRequire() { + return new Error( 'Cannot find module' ); + } +}); diff --git a/lib/node_modules/@stdlib/lapack/base/dlaset/test/test.ndarray.js b/lib/node_modules/@stdlib/lapack/base/dlaset/test/test.ndarray.js new file mode 100644 index 000000000000..d36e74ab75da --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlaset/test/test.ndarray.js @@ -0,0 +1,254 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Float64Array = require( '@stdlib/array/float64' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var dlaset = require( './../lib/ndarray.js' ); + + +// FUNCTIONS // + +/** +* Tests for element-wise approximate equality. +* +* @private +* @param {Object} t - test object +* @param {Collection} actual - actual values +* @param {Collection} expected - expected values +* @param {number} rtol - relative tolerance +*/ +function isApprox( t, actual, expected, rtol ) { + var delta; + var tol; + var i; + + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + for ( i = 0; i < expected.length; i++ ) { + if ( actual[ i ] === expected[ i ] ) { + t.strictEqual( actual[ i ], expected[ i ], 'returns expected value' ); + } else { + delta = abs( actual[ i ] - expected[ i ] ); + tol = rtol * EPS * abs( expected[ i ] ); + t.ok( delta <= tol, 'within tolerance. actual: '+actual[ i ]+'. expected: '+expected[ i ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dlaset, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 9', function test( t ) { + t.strictEqual( dlaset.length, 9, 'returns expected value' ); + t.end(); +}); + +tape( 'the function allows specifying offset and sets lower part of the given rectangular matrix (row-major, lower, offsetA = 5)', function test( t ) { + var expected; + var out; + var A; + var M; + var N; + + M = 2; + N = 3; + + A = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + expected = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 3.7, 0.0, 0.0, 3.1, 3.7, 0.0 ]); + + out = dlaset( 'lower', M, N, 3.1, 3.7, A, N, 1, 5 ); + t.strictEqual( out, A, 'returns expected value' ); + isApprox( t, A, expected, 2.0 ); + + t.end(); +}); + +tape( 'the function allows specifying offset and sets lower part of the given column major rectangular matrix (column-major, lower, offsetA = 3)', function test( t ) { + var expected; + var out; + var A; + var M; + var N; + + M = 2; + N = 3; + + A = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + expected = new Float64Array( [ 0.0, 0.0, 0.0, 3.7, 3.1, 0.0, 3.7, 0.0, 0.0 ]); + + out = dlaset( 'lower', M, N, 3.1, 3.7, A, 1, M, 3 ); + t.strictEqual( out, A, 'returns expected value' ); + isApprox( t, A, expected, 2.0 ); + + t.end(); +}); + +tape( 'the function allows specifying offset and sets upper part of the given rectangular matrix (row-major, upper, offsetA = 3)', function test( t ) { + var expected; + var out; + var A; + var M; + var N; + + M = 2; + N = 3; + + A = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + expected = new Float64Array( [ 0.0, 0.0, 0.0, 3.7, 3.1, 0, 0, 3.7, 0.0 ]); + + out = dlaset( 'upper', M, N, 3.1, 3.7, A, N, 1, 3 ); + t.strictEqual( out, A, 'returns expected value' ); + isApprox( t, A, expected, 2.0 ); + + t.end(); +}); + +tape( 'the function allows specifying offset and sets upper part of the given column major rectangular matrix (column-major, upper, offsetA = 3)', function test( t ) { + var expected; + var out; + var A; + var M; + var N; + + M = 2; + N = 3; + + A = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + expected = new Float64Array( [ 0.0, 0.0, 0.0, 3.7, 0.0, 0.0, 3.7, 3.1, 0.0 ]); + + out = dlaset( 'upper', M, N, 3.1, 3.7, A, 1, M, 3); + t.strictEqual( out, A, 'returns expected value' ); + isApprox( t, A, expected, 2.0 ); + + t.end(); +}); + +tape( 'the function allows specifying offset and sets all of the given rectangular matrix (row-major, all, offsetA = 3)', function test( t ) { + var expected; + var out; + var A; + var M; + var N; + + M = 2; + N = 3; + + A = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + expected = new Float64Array( [ 0.0, 0.0, 0.0, 3.7, 3.1, 3.1, 3.1, 3.7, 3.1 ]); + + out = dlaset( 'all', M, N, 3.1, 3.7, A, N, 1, 3 ); + t.strictEqual( out, A, 'returns expected value' ); + isApprox( t, A, expected, 2.0 ); + + t.end(); +}); + +tape( 'the function allows specifying offset and sets all of the given column major rectangular matrix (column-major, all, offsetA = 3)', function test( t ) { + var expected; + var out; + var A; + var M; + var N; + + M = 2; + N = 3; + + A = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + expected = new Float64Array( [ 0.0, 0.0, 0.0, 3.7, 3.1, 3.1, 3.7, 3.1, 3.1 ]); + + out = dlaset( 'all', M, N, 3.1, 3.7, A, 1, M, 3 ); + t.strictEqual( out, A, 'returns expected value' ); + isApprox( t, A, expected, 2.0 ); + + t.end(); +}); + +tape( 'the function allows accessing elements from non contiguous arrangement of row and column (row-major)', function test( t ) { + var expected; + var out; + var A; + + /* eslint-disable array-element-newline, no-multi-spaces */ + + A = new Float64Array([ + 999, 999, 999, 999, 999, 999, + 999, 1, 999, 2, 999, 3, + 999, 999, 999, 999, 999, 999, + 999, 0, 999, 4, 999, 5, + 999, 999, 999, 999, 999, 999, + 999, 0, 999, 0, 999, 6, + 999, 999, 999, 999, 999, 999 + ]); + expected = new Float64Array([ + 999, 999, 999, 999, 999, 999, + 999, 3.7, 999, 3.1, 999, 3.1, + 999, 999, 999, 999, 999, 999, + 999, 0, 999, 3.7, 999, 3.1, + 999, 999, 999, 999, 999, 999, + 999, 0, 999, 0, 999, 3.7, + 999, 999, 999, 999, 999, 999 + ]); + + out = dlaset( 'upper', 3, 3, 3.1, 3.7, A, 12, 2, 7 ); + t.strictEqual( out, A, 'returns expected value' ); + isApprox( t, A, expected, 2.0 ); + t.end(); +}); + +tape( 'the function allows access elements from non contiguous arrangement of row and column in reverse order (row-major)', function test( t ) { + var expected; + var out; + var A; + + /* eslint-disable array-element-newline, no-multi-spaces */ + + A = new Float64Array([ + 999, 999, 999, 999, 999, 999, + 999, 1, 999, 2, 999, 3, + 999, 999, 999, 999, 999, 999, + 999, 0, 999, 4, 999, 5, + 999, 999, 999, 999, 999, 999, + 999, 0, 999, 0, 999, 6, + 999, 999, 999, 999, 999, 999 + ]); + expected = new Float64Array([ + 999, 999, 999, 999, 999, 999, + 999, 3.7, 999, 2, 999, 3, + 999, 999, 999, 999, 999, 999, + 999, 3.1, 999, 3.7, 999, 5, + 999, 999, 999, 999, 999, 999, + 999, 3.1, 999, 3.1, 999, 3.7, + 999, 999, 999, 999, 999, 999 + ]); + + out = dlaset( 'upper', 3, 3, 3.1, 3.7, A, -12, -2, 35 ); + t.strictEqual( out, A, 'returns expected value' ); + isApprox( t, A, expected, 2.0 ); + t.end(); +});