diff --git a/lib/node_modules/@stdlib/lapack/base/dlassq/README.md b/lib/node_modules/@stdlib/lapack/base/dlassq/README.md new file mode 100644 index 000000000000..049bf474e341 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlassq/README.md @@ -0,0 +1,257 @@ + + +# dlassq + +> Return an updated sum of squares represented in scaled form. + +
+ +This routine returns the values $s_{textrm{out}}$ and $\textrm{ss}_{\textrm{out}}$ such that + + + +
+ Sum of squares represented in scaled form +
+
+ + + +where $x_i = X_{(i-1) \cdot \textrm{sx}}$ and $\textrm{sx}$ is the stride of `X`. The value of $\textrm{ss}_{\textrm{in}}$ is assumed to be nonnegative. + +
+ + + +
+ +## Usage + +```javascript +var dlassq = require( '@stdlib/lapack/base/dlassq' ); +``` + +#### dlassq( N, X, strideX, scale, sumsq ) + +Returns an updated sum of squares represented in scaled form. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var X = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + +var out = dlassq( 4, X, 1, 1.0, 0.0 ); +// returns [ 1.0, 30.0 ] +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **X**: input [`Float64Array`][mdn-float64array]. +- **strideX**: stride length for `X`. +- **scale**: scaling factor. +- **sumsq**: basic sum of squares from which output is factored out. + +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 array: +var X0 = new Float64Array( [ 0.0, 1.0, 2.0, 3.0, 4.0 ] ); + +// Create an offset view: +var X1 = new Float64Array( X0.buffer, X0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +// Compute the sum of squares: +var out = dlassq( X1.length, X1, 1, 1.0, 0.0 ); +// returns [ 1.0, 30.0 ] +``` + +The returned [`Float64Array`][mdn-float64array] contains an updated scale factor and an updated sum of squares, respectively. + +#### dlassq.ndarray( N, X, sx, ox, scale, sumsq, out, so, oo ) + +Returns an updated sum of squares represented in scaled form using alternative indexing semantics. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var X = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +var out = new Float64Array( [ 0.0, 0.0 ] ); + +dlassq.ndarray( 4, X, 1, 0, 1.0, 0.0, out, 1, 0 ); +// out => [ 1.0, 30.0 ] +``` + +The function has the following additional parameters: + +- **ox**: starting index for `X`. +- **out**: output [`Float64Array`][mdn-float64array] +- **so**: stride length for `out`. +- **oo**: starting index for `out`. + +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 X = new Float64Array( [ 1.0, 0.0, 2.0, 0.0, 3.0, 0.0, 4.0 ] ); +var out = new Float64Array( [ 0.0, 0.0, 999.9, 0.0, 999.9 ] ); + +dlassq.ndarray( 4, X, 2, 0, 1.0, 0.0, out, 2, 1 ); +// out => [ 0.0, 1.0, 999.9, 30.0, 999.9 ] +``` + +
+ + + +
+ +## Notes + +- `dlassq()` corresponds to the [LAPACK][LAPACK] function [`dlassq`][lapack-dlassq]. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var dlassq = require( '@stdlib/lapack/base/dlassq' ); + +var X = discreteUniform( 10, -10, 10, { + 'dtype': 'float64' +}); +console.log( X ); + +var out = dlassq( X.length, X, 1, 1.0, 0.0 ); +console.log( out ); +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +TODO +``` + +#### TODO + +TODO. + +```c +TODO +``` + +TODO + +```c +TODO +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +TODO +``` + +
+ + + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/lapack/base/dlassq/benchmark/benchmark.js b/lib/node_modules/@stdlib/lapack/base/dlassq/benchmark/benchmark.js new file mode 100644 index 000000000000..edf6ed0d798b --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlassq/benchmark/benchmark.js @@ -0,0 +1,96 @@ +/** +* @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 pkg = require( './../package.json' ).name; +var dlassq = require( './../lib/dlassq.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -100.0, 100.0, options ); + return benchmark; + + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = dlassq( x.length, x, 1, 1.0, 0.0 ); + if ( isnan( out[ 0 ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( out[ 1 ] ) ) { + 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 = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/lapack/base/dlassq/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/lapack/base/dlassq/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..1136c479d3a2 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlassq/benchmark/benchmark.ndarray.js @@ -0,0 +1,99 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var pkg = require( '@stdlib/lapack/base/dlassq/package.json' ).name; +var dlassq = require( './../lib/ndarray.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -100.0, 100.0, options ); + return benchmark; + + function benchmark( b ) { + var out; + var i; + + out = new Float64Array( 2 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = dlassq( x.length, x, 1, 0, 1.0, 0.0, out, 1, 0 ); + if ( isnan( out[ 0 ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( out[ 1 ] ) ) { + 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 = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':ndarray:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/lapack/base/dlassq/docs/repl.txt b/lib/node_modules/@stdlib/lapack/base/dlassq/docs/repl.txt new file mode 100644 index 000000000000..19044a7e7e33 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlassq/docs/repl.txt @@ -0,0 +1,98 @@ + +{{alias}}( N, X, strideX, scale, sumsq ) + Returns an updated sum of squares represented in scaled form. + + s_o^2*ss_o = X_0^2 + ... + X_(N-1)^2 + s_i^2*ss_i + + where s_o is the output scale factor, ss_o is the output sum of squares, s_i + is the input scale factor, and ss_i is the input sum of squares. + + Indexing is relative to the first index. To introduce an offset, use typed + array views. + + Parameters + ---------- + N: integer + Number of indexed elements. + + X: Float64Array + Input array. + + strideX: integer + Stride length for `X`. + + scale: number + Scaling factor. + + sumsq: number + Basic sum of squares from which output is factored out. + + Returns + ------- + out: Float64Array + Two-element array containing the updated scale factor and updated sum of + squares, respectively. + + Examples + -------- + > var X = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0 ] ); + > {{alias}}( 4, X, 1, 1.0, 0.0 ) + [ 1.0, 30.0 ] + + +{{alias}}.ndarray( N, X, sx, ox, scale, sumsq, out, so, oo ) + Returns an updated sum of squares represented in scaled form using + alternative indexing semantics. + + s_o^2*ss_o = X_0^2 + ... + X_(N-1)^2 + s_i^2*ss_i + + where s_o is the output scale factor, ss_o is the output sum of squares, s_i + is the input scale factor, and ss_i is the input sum of squares. + + While typed array views mandate a view offset based on the underlying + buffer, the offset parameters support indexing semantics based on starting + indices. + + Parameters + ---------- + N: integer + Number of indexed elements. + + X: Float64Array + Input array. + + sx: integer + Stride length for `X`. + + ox: integer + Starting index for `X`. + + scale: number + Scaling factor. + + sumsq: number + Basic sum of squares from which output is factored out. + + out: Float64Array + Output array. + + so: integer + Stride length for `out`. + + oo: integer + Starting index for `out`. + + Returns + ------- + out: Float64Array + Output array. + + Examples + -------- + > var X = new {{alias:@stdlib/array/float64}}( [ 0.0, 1.0, 2.0, 3.0, 4.0 ] ); + > var out = new {{alias:@stdlib/array/float64}}( [ 0.0, 0.0, 0.0 ] ); + > {{alias}}.ndarray( 4, X, 1, 1, 1.0, 0.0, out, 1, 1 ) + [ 0.0, 1.0, 30.0 ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/lapack/base/dlassq/docs/types/index.d.ts b/lib/node_modules/@stdlib/lapack/base/dlassq/docs/types/index.d.ts new file mode 100644 index 000000000000..2fed1cc5e80f --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlassq/docs/types/index.d.ts @@ -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. +*/ + +// TypeScript Version: 4.1 + +/// + +/** +* Interface describing `dlassq`. +*/ +interface Routine { + /** + * Returns an updated sum of squares represented in scaled form. + * + * @param N - number of indexed elements + * @param X - input array + * @param strideX - stride length for `X` + * @param scale - scaling factor + * @param sumsq - basic sum of squares from which output is factored out + * @returns output array + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * + * var X = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + * + * var out = dlassq( 4, X, 1, 1.0, 0.0 ); + * // returns [ 1.0, 30.0 ] + */ + ( N: number, X: Float64Array, strideX: number, scale: number, sumsq: number ): Float64Array; + + /** + * Returns an updated sum of squares represented in scaled form using alternative indexing semantics. + * + * @param N - number of indexed elements + * @param X - input array + * @param strideX - stride length for `X` + * @param offsetX - starting index for `X` + * @param scale - scaling factor + * @param sumsq - basic sum of squares from which output is factored out + * @param out - output array + * @param strideOut - stride length for `out` + * @param offsetOut - starting index for `out` + * @returns output array + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * + * var X = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + * var out = new Float64Array( [ 0.0, 0.0 ] ); + * + * dlassq.ndarray( 4, X, 1, 0, 1.0, 0.0, out, 1, 0 ); + * // out => [ 1.0, 30.0 ] + */ + ndarray( N: number, X: Float64Array, strideX: number, offsetX: number, scale: number, sumsq: number, out: Float64Array, strideOut: number, offsetOut: number ): Float64Array; +} + +/** +* Returns an updated sum of squares represented in scaled form. +* +* @param N - number of indexed elements +* @param X - input array +* @param strideX - stride length for `X` +* @param scale - scaling factor +* @param sumsq - basic sum of squares from which output is factored out +* @returns output array +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var X = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +* +* var out = dlassq( 4, X, 1, 1.0, 0.0, out ); +* // returns [ 1.0, 30.0 ] +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var X = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +* var out = new Float64Array( [ 0.0, 0.0 ] ); +* +* dlassq.ndarray( 4, X, 1, 0, 1.0, 0.0, out, 1, 0 ); +* // out => [ 1.0, 30.0 ] +*/ +declare var dlassq: Routine; + + +// EXPORTS // + +export = dlassq; diff --git a/lib/node_modules/@stdlib/lapack/base/dlassq/docs/types/test.ts b/lib/node_modules/@stdlib/lapack/base/dlassq/docs/types/test.ts new file mode 100644 index 000000000000..a17b7a55d7e2 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlassq/docs/types/test.ts @@ -0,0 +1,270 @@ +/* +* @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 dlassq = require( './index' ); + + +// TESTS // + +// The function returns a Float64Array... +{ + const X = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + + dlassq( 4, X, 1, 1.0, 0.0 ); // $ExpectType Float64Array +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + const X = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + + dlassq( '5', X, 1, 1.0, 0.0 ); // $ExpectError + dlassq( true, X, 1, 1.0, 0.0 ); // $ExpectError + dlassq( false, X, 1, 1.0, 0.0 ); // $ExpectError + dlassq( null, X, 1, 1.0, 0.0 ); // $ExpectError + dlassq( void 0, X, 1, 1.0, 0.0 ); // $ExpectError + dlassq( [], X, 1, 1.0, 0.0 ); // $ExpectError + dlassq( {}, X, 1, 1.0, 0.0 ); // $ExpectError + dlassq( ( x: number ): number => x, X, 1, 1.0, 0.0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a Float64Array... +{ + dlassq( 4, '5', 1, 1.0, 0.0 ); // $ExpectError + dlassq( 4, 5, 1, 1.0, 0.0 ); // $ExpectError + dlassq( 4, true, 1, 1.0, 0.0 ); // $ExpectError + dlassq( 4, false, 1, 1.0, 0.0 ); // $ExpectError + dlassq( 4, null, 1, 1.0, 0.0 ); // $ExpectError + dlassq( 4, void 0, 1, 1.0, 0.0 ); // $ExpectError + dlassq( 4, [], 1, 1.0, 0.0 ); // $ExpectError + dlassq( 4, {}, 1, 1.0, 0.0 ); // $ExpectError + dlassq( 4, ( x: number ): number => x, 1, 1.0, 0.0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a number... +{ + const X = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + + dlassq( 4, X, '5', 1.0, 0.0 ); // $ExpectError + dlassq( 4, X, true, 1.0, 0.0 ); // $ExpectError + dlassq( 4, X, false, 1.0, 0.0 ); // $ExpectError + dlassq( 4, X, null, 1.0, 0.0 ); // $ExpectError + dlassq( 4, X, void 0, 1.0, 0.0 ); // $ExpectError + dlassq( 4, X, [], 1.0, 0.0 ); // $ExpectError + dlassq( 4, X, {}, 1.0, 0.0 ); // $ExpectError + dlassq( 4, X, ( x: number ): number => x, 1.0, 0.0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a number... +{ + const X = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + + dlassq( 4, X, 1, '5', 0.0 ); // $ExpectError + dlassq( 4, X, 1, true, 0.0 ); // $ExpectError + dlassq( 4, X, 1, false, 0.0 ); // $ExpectError + dlassq( 4, X, 1, null, 0.0 ); // $ExpectError + dlassq( 4, X, 1, void 0, 0.0 ); // $ExpectError + dlassq( 4, X, 1, [], 0.0 ); // $ExpectError + dlassq( 4, X, 1, {}, 0.0 ); // $ExpectError + dlassq( 4, X, 1, ( x: number ): number => x, 0.0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not a number... +{ + const X = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + + dlassq( 4, X, 1, 1.0, '5' ); // $ExpectError + dlassq( 4, X, 1, 1.0, true ); // $ExpectError + dlassq( 4, X, 1, 1.0, false ); // $ExpectError + dlassq( 4, X, 1, 1.0, null ); // $ExpectError + dlassq( 4, X, 1, 1.0, void 0 ); // $ExpectError + dlassq( 4, X, 1, 1.0, [] ); // $ExpectError + dlassq( 4, X, 1, 1.0, {} ); // $ExpectError + dlassq( 4, X, 1, 1.0, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const X = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + + dlassq(); // $ExpectError + dlassq( 4 ); // $ExpectError + dlassq( 4, X ); // $ExpectError + dlassq( 4, X, 1 ); // $ExpectError + dlassq( 4, X, 1, 1.0 ); // $ExpectError + dlassq( 4, X, 1, 1.0, 0.0, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a Float64Array... +{ + const out = new Float64Array( [ 0.0, 0.0 ] ); + const X = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + + dlassq.ndarray( 4, X, 1, 0, 1.0, 0.0, out, 1, 0 ); // $ExpectType Float64Array +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + const out = new Float64Array( [ 0.0, 0.0 ] ); + const X = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + + dlassq.ndarray( '5', X, 1, 0, 1.0, 0.0, out, 1, 0 ); // $ExpectError + dlassq.ndarray( true, X, 1, 0, 1.0, 0.0, out, 1, 0 ); // $ExpectError + dlassq.ndarray( false, X, 1, 0, 1.0, 0.0, out, 1, 0 ); // $ExpectError + dlassq.ndarray( null, X, 1, 0, 1.0, 0.0, out, 1, 0 ); // $ExpectError + dlassq.ndarray( void 0, X, 1, 0, 1.0, 0.0, out, 1, 0 ); // $ExpectError + dlassq.ndarray( [], X, 1, 0, 1.0, 0.0, out, 1, 0 ); // $ExpectError + dlassq.ndarray( {}, X, 1, 0, 1.0, 0.0, out, 1, 0 ); // $ExpectError + dlassq.ndarray( ( x: number ): number => x, X, 1, 0, 1.0, 0.0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a Float64Array... +{ + const out = new Float64Array( [ 0.0, 0.0 ] ); + + dlassq.ndarray( 4, '5', 1, 0, 1.0, 0.0, out, 1, 0 ); // $ExpectError + dlassq.ndarray( 4, 5, 1, 0, 1.0, 0.0, out, 1, 0 ); // $ExpectError + dlassq.ndarray( 4, true, 1, 0, 1.0, 0.0, out, 1, 0 ); // $ExpectError + dlassq.ndarray( 4, false, 1, 0, 1.0, 0.0, out, 1, 0 ); // $ExpectError + dlassq.ndarray( 4, null, 1, 0, 1.0, 0.0, out, 1, 0 ); // $ExpectError + dlassq.ndarray( 4, void 0, 1, 0, 1.0, 0.0, out, 1, 0 ); // $ExpectError + dlassq.ndarray( 4, [], 1, 0, 1.0, 0.0, out, 1, 0 ); // $ExpectError + dlassq.ndarray( 4, {}, 1, 0, 1.0, 0.0, out, 1, 0 ); // $ExpectError + dlassq.ndarray( 4, ( x: number ): number => x, 1, 0, 1.0, 0.0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a number... +{ + const out = new Float64Array( [ 0.0, 0.0 ] ); + const X = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + + dlassq.ndarray( 4, X, '5', 0, 1.0, 0.0, out, 1, 0 ); // $ExpectError + dlassq.ndarray( 4, X, true, 0, 1.0, 0.0, out, 1, 0 ); // $ExpectError + dlassq.ndarray( 4, X, false, 0, 1.0, 0.0, out, 1, 0 ); // $ExpectError + dlassq.ndarray( 4, X, null, 0, 1.0, 0.0, out, 1, 0 ); // $ExpectError + dlassq.ndarray( 4, X, void 0, 0, 1.0, 0.0, out, 1, 0 ); // $ExpectError + dlassq.ndarray( 4, X, [], 0, 1.0, 0.0, out, 1, 0 ); // $ExpectError + dlassq.ndarray( 4, X, {}, 0, 1.0, 0.0, out, 1, 0 ); // $ExpectError + dlassq.ndarray( 4, X, ( x: number ): number => x, 0, 1.0, 0.0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a number... +{ + const out = new Float64Array( [ 0.0, 0.0 ] ); + const X = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + + dlassq.ndarray( 4, X, 1, '5', 1.0, 0.0, out, 1, 0 ); // $ExpectError + dlassq.ndarray( 4, X, 1, true, 1.0, 0.0, out, 1, 0 ); // $ExpectError + dlassq.ndarray( 4, X, 1, false, 1.0, 0.0, out, 1, 0 ); // $ExpectError + dlassq.ndarray( 4, X, 1, null, 1.0, 0.0, out, 1, 0 ); // $ExpectError + dlassq.ndarray( 4, X, 1, void 0, 1.0, 0.0, out, 1, 0 ); // $ExpectError + dlassq.ndarray( 4, X, 1, [], 1.0, 0.0, out, 1, 0 ); // $ExpectError + dlassq.ndarray( 4, X, 1, {}, 1.0, 0.0, out, 1, 0 ); // $ExpectError + dlassq.ndarray( 4, X, 1, ( x: number ): number => x, 1.0, 0.0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not a number... +{ + const out = new Float64Array( [ 0.0, 0.0 ] ); + const X = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + + dlassq.ndarray( 4, X, 1, 0, '5', 0.0, out, 1, 0 ); // $ExpectError + dlassq.ndarray( 4, X, 1, 0, true, 0.0, out, 1, 0 ); // $ExpectError + dlassq.ndarray( 4, X, 1, 0, false, 0.0, out, 1, 0 ); // $ExpectError + dlassq.ndarray( 4, X, 1, 0, null, 0.0, out, 1, 0 ); // $ExpectError + dlassq.ndarray( 4, X, 1, 0, void 0, 0.0, out, 1, 0 ); // $ExpectError + dlassq.ndarray( 4, X, 1, 0, [], 0.0, out, 1, 0 ); // $ExpectError + dlassq.ndarray( 4, X, 1, 0, {}, 0.0, out, 1, 0 ); // $ExpectError + dlassq.ndarray( 4, X, 1, 0, ( x: number ): number => x, 0.0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a sixth argument which is not a number... +{ + const out = new Float64Array( [ 0.0, 0.0 ] ); + const X = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + + dlassq.ndarray( 4, X, 1, 0, 1.0, '5', out, 1, 0 ); // $ExpectError + dlassq.ndarray( 4, X, 1, 0, 1.0, true, out, 1, 0 ); // $ExpectError + dlassq.ndarray( 4, X, 1, 0, 1.0, false, out, 1, 0 ); // $ExpectError + dlassq.ndarray( 4, X, 1, 0, 1.0, null, out, 1, 0 ); // $ExpectError + dlassq.ndarray( 4, X, 1, 0, 1.0, void 0, out, 1, 0 ); // $ExpectError + dlassq.ndarray( 4, X, 1, 0, 1.0, [], out, 1, 0 ); // $ExpectError + dlassq.ndarray( 4, X, 1, 0, 1.0, {}, out, 1, 0 ); // $ExpectError + dlassq.ndarray( 4, X, 1, 0, 1.0, ( x: number ): number => x, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a seventh argument which is not a Float64Array... +{ + const X = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + + dlassq.ndarray( 4, X, 1, 0, 1.0, 0.0, '5', 1, 0 ); // $ExpectError + dlassq.ndarray( 4, X, 1, 0, 1.0, 0.0, 5, 1, 0 ); // $ExpectError + dlassq.ndarray( 4, X, 1, 0, 1.0, 0.0, true, 1, 0 ); // $ExpectError + dlassq.ndarray( 4, X, 1, 0, 1.0, 0.0, false, 1, 0 ); // $ExpectError + dlassq.ndarray( 4, X, 1, 0, 1.0, 0.0, null, 1, 0 ); // $ExpectError + dlassq.ndarray( 4, X, 1, 0, 1.0, 0.0, void 0, 1, 0 ); // $ExpectError + dlassq.ndarray( 4, X, 1, 0, 1.0, 0.0, [], 1, 0 ); // $ExpectError + dlassq.ndarray( 4, X, 1, 0, 1.0, 0.0, {}, 1, 0 ); // $ExpectError + dlassq.ndarray( 4, X, 1, 0, 1.0, 0.0, ( 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 out = new Float64Array( [ 0.0, 0.0 ] ); + const X = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + + dlassq.ndarray( 4, X, 1, 0, 1.0, 0.0, out, '5', 0 ); // $ExpectError + dlassq.ndarray( 4, X, 1, 0, 1.0, 0.0, out, true, 0 ); // $ExpectError + dlassq.ndarray( 4, X, 1, 0, 1.0, 0.0, out, false, 0 ); // $ExpectError + dlassq.ndarray( 4, X, 1, 0, 1.0, 0.0, out, null, 0 ); // $ExpectError + dlassq.ndarray( 4, X, 1, 0, 1.0, 0.0, out, void 0, 0 ); // $ExpectError + dlassq.ndarray( 4, X, 1, 0, 1.0, 0.0, out, [], 0 ); // $ExpectError + dlassq.ndarray( 4, X, 1, 0, 1.0, 0.0, out, {}, 0 ); // $ExpectError + dlassq.ndarray( 4, X, 1, 0, 1.0, 0.0, out, ( 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 out = new Float64Array( [ 0.0, 0.0 ] ); + const X = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + + dlassq.ndarray( 4, X, 1, 0, 1.0, 0.0, out, 1, '5' ); // $ExpectError + dlassq.ndarray( 4, X, 1, 0, 1.0, 0.0, out, 1, true ); // $ExpectError + dlassq.ndarray( 4, X, 1, 0, 1.0, 0.0, out, 1, false ); // $ExpectError + dlassq.ndarray( 4, X, 1, 0, 1.0, 0.0, out, 1, null ); // $ExpectError + dlassq.ndarray( 4, X, 1, 0, 1.0, 0.0, out, 1, void 0 ); // $ExpectError + dlassq.ndarray( 4, X, 1, 0, 1.0, 0.0, out, 1, [] ); // $ExpectError + dlassq.ndarray( 4, X, 1, 0, 1.0, 0.0, out, 1, {} ); // $ExpectError + dlassq.ndarray( 4, X, 1, 0, 1.0, 0.0, out, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const out = new Float64Array( [ 0.0, 0.0 ] ); + const X = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + + dlassq.ndarray(); // $ExpectError + dlassq.ndarray( 4 ); // $ExpectError + dlassq.ndarray( 4, X ); // $ExpectError + dlassq.ndarray( 4, X, 1 ); // $ExpectError + dlassq.ndarray( 4, X, 1, 0 ); // $ExpectError + dlassq.ndarray( 4, X, 1, 0, 1.0 ); // $ExpectError + dlassq.ndarray( 4, X, 1, 0, 1.0, 0.0 ); // $ExpectError + dlassq.ndarray( 4, X, 1, 0, 1.0, 0.0, out ); // $ExpectError + dlassq.ndarray( 4, X, 1, 0, 1.0, 0.0, out, 1 ); // $ExpectError + dlassq.ndarray( 4, X, 1, 0, 1.0, 0.0, out, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/lapack/base/dlassq/examples/index.js b/lib/node_modules/@stdlib/lapack/base/dlassq/examples/index.js new file mode 100644 index 000000000000..c5b4ac81ba97 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlassq/examples/index.js @@ -0,0 +1,30 @@ +/** +* @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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var dlassq = require( './../lib' ); + +var X = discreteUniform( 10, -10, 10, { + 'dtype': 'float64' +}); +console.log( X ); + +var out = dlassq( X.length, X, 1, 1.0, 0.0 ); +console.log( out ); diff --git a/lib/node_modules/@stdlib/lapack/base/dlassq/lib/base.js b/lib/node_modules/@stdlib/lapack/base/dlassq/lib/base.js new file mode 100644 index 000000000000..e177b36b47db --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlassq/lib/base.js @@ -0,0 +1,186 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var abs2 = require( '@stdlib/math/base/special/abs2' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var sqrt = require( '@stdlib/math/base/special/sqrt' ); + + +// VARIABLES // + +var SBIG = 1.11137937474253874e-162; +var SSML = 4.49891379454319638e+161; +var TBIG = 1.99791907220223503e+146; +var TSML = 1.49166814624004135e-154; + + +// MAIN // + +/** +* Returns an updated sum of squares represented in scaled form. +* +* @private +* @param {NonNegativeInteger} N - number of indexed elements +* @param {Float64Array} X - input array +* @param {integer} strideX - stride length for `X` +* @param {NonNegativeInteger} offsetX - starting index for `X` +* @param {number} scale - scaling factor +* @param {number} sumsq - basic sum of squares from which output is factored out +* @param {Float64Array} out - output array +* @param {integer} strideOut - stride length for `out` +* @param {NonNegativeInteger} offsetOut - starting index for `out` +* @returns {Float64Array} output array +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var X = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +* var out = new Float64Array( [ 0.0, 0.0 ] ); +* +* dlassq( 4, X, 1, 0, 1.0, 0.0, out, 1, 0 ); +* // out => [ 1.0, 30.0 ] +*/ +function dlassq( N, X, strideX, offsetX, scale, sumsq, out, strideOut, offsetOut ) { // eslint-disable-line max-len + var notbig; + var abig; + var asml; + var amed; + var ymin; + var ymax; + var ax; + var ox; + var i; + + if ( isnan( scale ) || isnan( sumsq ) ) { + return out; + } + if ( sumsq === 0.0 ) { + scale = 1.0; + } + if ( scale === 0.0 ) { + scale = 1.0; + sumsq = 0.0; + } + if ( N <= 0 ) { + out[ offsetOut ] = scale; + out[ offsetOut + strideOut ] = sumsq; + return out; + } + /* + * Compute the sum of squares in 3 accumulators: + * + * - `abig`: sums of squares scaled down to avoid overflow + * - `asml`: sums of squares scaled up to avoid underflow + * - `amed`: sums of squares that do not require scaling + * + * The thresholds and multipliers are + * + * - `tbig`: values bigger than this are scaled down by `sbig` + * - `tsml`: values smaller than this are scaled up by `ssml` + */ + notbig = true; + asml = 0.0; + amed = 0.0; + abig = 0.0; + ox = offsetX; + for ( i = 0; i < N; i++ ) { + ax = abs( X[ ox ] ); + if ( ax > TBIG ) { + abig += abs2( ax*SBIG ); + notbig = false; + } else if ( ax < TSML ) { + if ( notbig ) { + asml += abs2( ax*SSML ); + } + } else { + amed += abs2( ax ); + } + ox += strideX; + } + // Put the existing sum of squares into one of the accumulators... + if ( sumsq > 0.0 ) { + ax = scale * sqrt( sumsq ); + if ( ax > TBIG ) { + if ( scale > 1.0 ) { + scale *= SBIG; + abig += scale * ( scale * sumsq ); + } else { + // `sumsq > tbig^2` => `(sbig * (sbig * sumsq))` is representable + abig += scale * ( scale * ( SBIG * ( SBIG*sumsq ) ) ); + } + } else if ( ax < TSML ) { + if ( notbig ) { + if ( scale < 1.0 ) { + scale *= SSML; + asml += scale * ( scale*sumsq ); + } else { + // `sumsq < tsml^2` => `(ssml * (ssml * sumsq))` is representable + asml += scale * ( scale * ( SSML * ( SSML*sumsq ) ) ); + } + } + } else { + amed += scale * ( scale*sumsq ); + } + } + // Combine `abig` and `amed` or `amed` and `asml` if more than one accumulator was used... + if ( abig > 0.0 ) { + // Combine `abig` and `amed` if `abig > 0`... + if ( amed > 0.0 || isnan( amed ) ) { + abig += ( amed*SBIG ) * SBIG; + } + out[ offsetOut ] = 1.0 / SBIG; + out[ offsetOut + strideOut ] = abig; + return out; + } + if ( asml > 0.0 ) { + // Combine `amed` and `asml` if `asml > 0`... + if ( amed > 0.0 || isnan( amed ) ) { + amed = sqrt( amed ); + asml = sqrt( asml ) / SSML; + if ( asml > amed ) { + ymin = amed; + ymax = asml; + } else { + ymin = asml; + ymax = amed; + } + scale = 1.0; + sumsq = abs2( ymax ) * ( 1.0 + abs2( ymin/ymax ) ); + } else { + scale = 1.0 / SSML; + sumsq = asml; + } + out[ offsetOut ] = scale; + out[ offsetOut + strideOut ] = sumsq; + return out; + } + // Otherwise all values are mid-range or zero... + out[ offsetOut ] = 1.0; + out[ offsetOut + strideOut ] = amed; + return out; +} + + +// EXPORTS // + +module.exports = dlassq; diff --git a/lib/node_modules/@stdlib/lapack/base/dlassq/lib/dlassq.js b/lib/node_modules/@stdlib/lapack/base/dlassq/lib/dlassq.js new file mode 100644 index 000000000000..bfccec29bf12 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlassq/lib/dlassq.js @@ -0,0 +1,60 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var base = require( './base.js' ); + + +// MAIN // + +/** +* Returns an updated sum of squares represented in scaled form. +* +* @param {NonNegativeInteger} N - number of indexed elements +* @param {Float64Array} X - input array +* @param {integer} strideX - stride length for `X` +* @param {number} scale - scaling factor +* @param {number} sumsq - basic sum of squares from which output is factored out +* @returns {Float64Array} output array +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var X = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +* +* var out = dlassq( 4, X, 1, 1.0, 0.0 ); +* // returns [ 1.0, 30.0 ] +*/ +function dlassq( N, X, strideX, scale, sumsq ) { + var out; + var ox; + + ox = stride2offset( N, strideX ); + out = new Float64Array( 2 ); + return base( N, X, strideX, ox, scale, sumsq, out, 1, 0 ); +} + + +// EXPORTS // + +module.exports = dlassq; diff --git a/lib/node_modules/@stdlib/lapack/base/dlassq/lib/index.js b/lib/node_modules/@stdlib/lapack/base/dlassq/lib/index.js new file mode 100644 index 000000000000..97a45fa76f89 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlassq/lib/index.js @@ -0,0 +1,67 @@ +/** +* @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 return an updated sum of squares represented in scaled form. +* +* @module @stdlib/lapack/base/dlassq +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var dlassq = require( '@stdlib/lapack/base/dlassq' ); +* +* var X = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +* +* var out = dlassq( X.length, X, 1, 1.0, 0.0 ); +* // returns [ 1.0, 30.0 ] +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var dlassq = require( '@stdlib/lapack/base/dlassq' ); +* +* var X = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +* var out = new Float64Array( [ 0.0, 0.0 ] ); +* +* dlassq.ndarray( X.length, X, 1, 0, 1.0, 0.0, out, 1, 0 ); +* // out => [ 1.0, 30.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 dlassq; +var tmp = tryRequire( join( __dirname, './native.js' ) ); +if ( isError( tmp ) ) { + dlassq = main; +} else { + dlassq = tmp; +} + + +// EXPORTS // + +module.exports = dlassq; diff --git a/lib/node_modules/@stdlib/lapack/base/dlassq/lib/main.js b/lib/node_modules/@stdlib/lapack/base/dlassq/lib/main.js new file mode 100644 index 000000000000..35485b0c330c --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlassq/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 dlassq = require( './dlassq.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( dlassq, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = dlassq; diff --git a/lib/node_modules/@stdlib/lapack/base/dlassq/lib/ndarray.js b/lib/node_modules/@stdlib/lapack/base/dlassq/lib/ndarray.js new file mode 100644 index 000000000000..5aefdec5104f --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlassq/lib/ndarray.js @@ -0,0 +1,60 @@ +/** +* @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. +*/ + +/* eslint-disable max-len */ + +'use strict'; + +// MODULES // + +var base = require( './base.js' ); + + +// MAIN // + +/** +* Returns an updated sum of squares represented in scaled form using alternative indexing semantics. +* +* @param {NonNegativeInteger} N - number of indexed elements +* @param {Float64Array} X - input array +* @param {integer} strideX - stride length for `X` +* @param {NonNegativeInteger} offsetX - starting index for `X` +* @param {number} scale - scaling factor +* @param {number} sumsq - basic sum of squares from which output is factored out +* @param {Float64Array} out - output array +* @param {integer} strideOut - stride length for `out` +* @param {NonNegativeInteger} offsetOut - starting index for `out` +* @returns {Float64Array} output array +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var X = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +* var out = new Float64Array( [ 0.0, 0.0 ] ); +* +* dlassq( 4, X, 1, 0, 1.0, 0.0, out, 1, 0 ); +* // out => [ 1.0, 30.0 ] +*/ +function dlassq( N, X, strideX, offsetX, scale, sumsq, out, strideOut, offsetOut ) { + return base( N, X, strideX, offsetX, scale, sumsq, out, strideOut, offsetOut ); +} + + +// EXPORTS // + +module.exports = dlassq; diff --git a/lib/node_modules/@stdlib/lapack/base/dlassq/package.json b/lib/node_modules/@stdlib/lapack/base/dlassq/package.json new file mode 100644 index 000000000000..074d20812a4a --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlassq/package.json @@ -0,0 +1,71 @@ +{ + "name": "@stdlib/lapack/base/dlassq", + "version": "0.0.0", + "description": "Return an updated sum of squares represented in scaled form.", + "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", + "dlassq", + "squares", + "sum", + "norm", + "euclidean", + "linear", + "algebra", + "subroutines", + "array", + "ndarray", + "float64", + "double", + "float64array" + ] +} diff --git a/lib/node_modules/@stdlib/lapack/base/dlassq/test/test.dlassq.js b/lib/node_modules/@stdlib/lapack/base/dlassq/test/test.dlassq.js new file mode 100644 index 000000000000..91c0d9699313 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlassq/test/test.dlassq.js @@ -0,0 +1,227 @@ +/** +* @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. +*/ + +/* eslint-disable max-len */ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Float64Array = require( '@stdlib/array/float64' ); +var isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); +var dlassq = require( './../lib/dlassq.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dlassq, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 5', function test( t ) { + t.strictEqual( dlassq.length, 5, 'returns expected value' ); + t.end(); +}); + +tape( 'the function computes an updated sum of squares represented in scaled form', function test( t ) { + var expected; + var out; + var X; + + X = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + expected = new Float64Array( [ 1.0, 30.0 ] ); + + out = dlassq( 4, X, 1, 1.0, 0.0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes an updated sum of squares represented in scaled form (NaNs)', function test( t ) { + var expected; + var out; + var X; + + X = new Float64Array( [ 1.0, NaN, 3.0, 4.0 ] ); + expected = new Float64Array( [ 1.0, NaN ] ); + + out = dlassq( 4, X, 1, 1.0, 0.0 ); + t.strictEqual( isSameFloat64Array( out, expected ), true, 'returns expected value' ); + + X = new Float64Array( [ 1.0e-160, 1.0e-160, NaN, 1.0e-160 ] ); + expected = new Float64Array( [ 1.0, NaN ] ); + + out = dlassq( 4, X, 1, 1.0, 0.0 ); + t.strictEqual( isSameFloat64Array( out, expected ), true, 'returns expected value' ); + + // Checked on Wolfram Alpha: + X = new Float64Array( [ 1.0e150, 1.0e150, NaN, 1.0e150 ] ); + expected = new Float64Array( [ 8.997827589086393e+161, NaN ] ); + + out = dlassq( 4, X, 1, 1.0, 0.0 ); + t.strictEqual( isSameFloat64Array( out, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes an updated sum of squares represented in scaled form (large values)', function test( t ) { + var expected; + var out; + var X; + + // Checked on Wolfram Alpha: + X = new Float64Array( [ 1.0e150, 1.0e150, 1.0e150, 1.0e150 ] ); + expected = new Float64Array( [ 8.997827589086393e+161, 4.940656458412465e-24 ] ); // => 4.0e300 + + out = dlassq( 4, X, 1, 1.0, 0.0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Checked on Wolfram Alpha: + X = new Float64Array( [ 1.0e150, 1.0e150, 1.0e150, 1.0e150 ] ); + expected = new Float64Array( [ 8.997827589086393e+161, 9.881312916824931e-24 ] ); // => 8.0e300 + + out = dlassq( 4, X, 1, 2.0, 1.0e300 ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Checked on Wolfram Alpha: + X = new Float64Array( [ 1.0e150, 1.0e150, 1.0e150, 1.0e150 ] ); + expected = new Float64Array( [ 8.997827589086393e+161, 6.1758205730155814e-24 ] ); // => 5.0e300 + + out = dlassq( 4, X, 1, 1.0, 1.0e300 ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Checked on Wolfram Alpha: + X = new Float64Array( [ 1.0e308, 1.0e308, 1.0e308, 1.0e308 ] ); + expected = new Float64Array( [ 8.997827589086393e+161, 1.0/0.0 ] ); + + out = dlassq( 4, X, 1, 1.0e308, 1.0e308 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes an updated sum of squares represented in scaled form (small values)', function test( t ) { + var expected; + var out; + var X; + + // Checked on Wolfram Alpha: + X = new Float64Array( [ 1.0e-160, 1.0e-160, 1.0e-160, 1.0e-160 ] ); + expected = new Float64Array( [ 2.2227587494850775e-162, 8096.090132292425 ] ); // => ~4.0e-320 + + out = dlassq( 4, X, 1, 1.0, 0.0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Checked on Wolfram Alpha: + X = new Float64Array( [ 1.0e-160, 1.0e-160, 1.0e-160, 1.0e-160 ] ); + expected = new Float64Array( [ 2.2227587494850775e-162, 8602.090132292426 ] ); // => ~4.24e-320 + + out = dlassq( 4, X, 1, 0.5, 1.0e-320 ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Checked on Wolfram Alpha: + X = new Float64Array( [ 1.0e-160, 1.0e-160, 1.0e-160, 1.0e-160 ] ); + expected = new Float64Array( [ 2.2227587494850775e-162, 10120.090132292426 ] ); // => ~5.0e-320 + + out = dlassq( 4, X, 1, 1.0, 1.0e-320 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes an updated sum of squares represented in scaled form (sumsq > 0)', function test( t ) { + var expected; + var out; + var X; + + X = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + expected = new Float64Array( [ 1.0, 31.0 ] ); + + out = dlassq( 4, X, 1, 1.0, 1.0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports negative strides', function test( t ) { + var expected; + var out; + var X; + + X = new Float64Array( [ 4.0, 3.0, 2.0, 1.0 ] ); + expected = new Float64Array( [ 1.0, 31.0 ] ); + + out = dlassq( 4, X, -1, 1.0, 1.0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns initialized values if provided an `N` argument less than or equal to `0`', function test( t ) { + var expected; + var out; + var X; + + X = new Float64Array( [ 4.0, 3.0, 2.0, 1.0 ] ); + expected = new Float64Array( [ 1.0, 1.0 ] ); + + out = dlassq( 0, X, -1, 1.0, 1.0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + out = dlassq( -5, X, -1, 1.0, 1.0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + X = new Float64Array( [ 4.0, 3.0, 2.0, 1.0 ] ); + expected = new Float64Array( [ 1.0, 0.0 ] ); + + out = dlassq( 0, X, 1, 0.0, 999.0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function does not compute an updated sum of squares if the scale factor is `NaN`', function test( t ) { + var expected; + var out; + var X; + + X = new Float64Array( [ 4.0, 3.0, 2.0, 1.0 ] ); + expected = new Float64Array( [ 0.0, 0.0 ] ); + + out = dlassq( 4, X, -1, NaN, 1.0 ); + t.strictEqual( isSameFloat64Array( out, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function does not compute an updated sum of squares if the sum of squares is `NaN`', function test( t ) { + var expected; + var out; + var X; + + X = new Float64Array( [ 4.0, 3.0, 2.0, 1.0 ] ); + expected = new Float64Array( [ 0.0, 0.0 ] ); + + out = dlassq( 4, X, -1, 1.0, NaN ); + t.strictEqual( isSameFloat64Array( out, expected ), true, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/lapack/base/dlassq/test/test.js b/lib/node_modules/@stdlib/lapack/base/dlassq/test/test.js new file mode 100644 index 000000000000..5bad04c11320 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlassq/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 dlassq = 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 dlassq, '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 dlassq.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 dlassq = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( dlassq, 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 dlassq; + var main; + + main = require( './../lib/dlassq.js' ); + + dlassq = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( dlassq, main, 'returns expected value' ); + t.end(); + + function tryRequire() { + return new Error( 'Cannot find module' ); + } +}); diff --git a/lib/node_modules/@stdlib/lapack/base/dlassq/test/test.ndarray.js b/lib/node_modules/@stdlib/lapack/base/dlassq/test/test.ndarray.js new file mode 100644 index 000000000000..4cb2e12533dc --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlassq/test/test.ndarray.js @@ -0,0 +1,180 @@ +/** +* @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 isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); +var dlassq = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dlassq, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 9', function test( t ) { + t.strictEqual( dlassq.length, 9, 'returns expected value' ); + t.end(); +}); + +tape( 'the function computes an updated sum of squares represented in scaled form', function test( t ) { + var expected; + var actual; + var out; + var X; + + X = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + out = new Float64Array( [ 0.0, 0.0 ] ); + expected = new Float64Array( [ 1.0, 30.0 ] ); + + actual = dlassq( 4, X, 1, 0, 1.0, 0.0, out, 1, 0 ); + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes an updated sum of squares represented in scaled form (sumsq > 0)', function test( t ) { + var expected; + var actual; + var out; + var X; + + X = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + out = new Float64Array( [ 0.0, 0.0 ] ); + expected = new Float64Array( [ 1.0, 31.0 ] ); + + actual = dlassq( 4, X, 1, 0, 1.0, 1.0, out, 1, 0 ); + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports negative strides', function test( t ) { + var expected; + var actual; + var out; + var X; + + X = new Float64Array( [ 4.0, 3.0, 2.0, 1.0 ] ); + out = new Float64Array( [ 0.0, 0.0 ] ); + expected = new Float64Array( [ 1.0, 31.0 ] ); + + actual = dlassq( 4, X, -1, 3, 1.0, 1.0, out, 1, 0 ); + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + X = new Float64Array( [ 4.0, 3.0, 2.0, 1.0 ] ); + out = new Float64Array( [ 0.0, 0.0 ] ); + expected = new Float64Array( [ 31.0, 1.0 ] ); + + actual = dlassq( 4, X, 1, 0, 1.0, 1.0, out, -1, 1 ); + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns initialized values if provided an `N` argument less than or equal to `0`', function test( t ) { + var expected; + var actual; + var out; + var X; + + X = new Float64Array( [ 4.0, 3.0, 2.0, 1.0 ] ); + out = new Float64Array( [ 0.0, 0.0 ] ); + expected = new Float64Array( [ 1.0, 1.0 ] ); + + actual = dlassq( 0, X, 1, 0, 1.0, 1.0, out, 1, 0 ); + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + actual = dlassq( -5, X, 1, 0, 1.0, 1.0, out, 1, 0 ); + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + X = new Float64Array( [ 4.0, 3.0, 2.0, 1.0 ] ); + out = new Float64Array( [ 0.0, 0.0 ] ); + expected = new Float64Array( [ 1.0, 0.0 ] ); + + actual = dlassq( 0, X, 1, 0, 0.0, 999.0, out, 1, 0 ); + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function does not compute an updated sum of squares if the scale factor is `NaN`', function test( t ) { + var expected; + var actual; + var out; + var X; + + X = new Float64Array( [ 4.0, 3.0, 2.0, 1.0 ] ); + out = new Float64Array( [ 0.0, 0.0 ] ); + expected = new Float64Array( [ 0.0, 0.0 ] ); + + actual = dlassq( 4, X, 1, 0, NaN, 1.0, out, 1, 0 ); + t.strictEqual( actual, out, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( out, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function does not compute an updated sum of squares if the sum of squares is `NaN`', function test( t ) { + var expected; + var actual; + var out; + var X; + + X = new Float64Array( [ 4.0, 3.0, 2.0, 1.0 ] ); + out = new Float64Array( [ 0.0, 0.0 ] ); + expected = new Float64Array( [ 0.0, 0.0 ] ); + + actual = dlassq( 4, X, 1, 0, 1.0, NaN, out, 1, 0 ); + t.strictEqual( actual, out, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( out, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports complex access patterns', function test( t ) { + var expected; + var actual; + var out; + var X; + + X = new Float64Array( [ 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0 ] ); // eslint-disable-line max-len + out = new Float64Array( [ 0.0, 0.0, 0.0, 999.9, 0.0, 0.0, 999.9 ] ); + + expected = new Float64Array( [ 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 30.0 ] ); + + actual = dlassq( 4, X, -4, 14, 1.0, 0.0, out, 3, 3 ); + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +});