Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 41 additions & 21 deletions lib/node_modules/@stdlib/lapack/base/dlassq/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,26 +57,31 @@ var dlassq = require( '@stdlib/lapack/base/dlassq' );

Returns an updated sum of squares represented in scaled form.

<!-- eslint-disable @cspell/spellchecker -->

```javascript
var Float64Array = require( '@stdlib/array/float64' );

var X = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] );
var scale = new Float64Array( [ 1.0 ] );
var sumsq = new Float64Array( [ 0.0 ] );

var out = dlassq( 4, X, 1, 1.0, 0.0 );
// returns <Float64Array>[ 1.0, 30.0 ]
dlassq( 4, X, 1, scale, sumsq );
// scale => <Float64Array>[ 1.0 ]
// sumsq => <Float64Array>[ 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.
- **scale**: [`Float64Array`][mdn-float64array] containing a single element which specifies the scaling factor and is overwritten by the updated scaling factor.
- **sumsq**: [`Float64Array`][mdn-float64array] containing a single element which specifies the basic sum of squares from which output is factored out and is overwritten by the updated sum of squares.

Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views.

<!-- eslint-disable stdlib/capitalized-comments -->
<!-- eslint-disable stdlib/capitalized-comments, @cspell/spellchecker -->

```javascript
var Float64Array = require( '@stdlib/array/float64' );
Expand All @@ -87,44 +92,54 @@ 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

// Create single-element arrays for the scaling factor and the sum of squares:
var scale = new Float64Array( [ 1.0 ] );
var sumsq = new Float64Array( [ 0.0 ] );

// Compute the sum of squares:
var out = dlassq( X1.length, X1, 1, 1.0, 0.0 );
// returns <Float64Array>[ 1.0, 30.0 ]
dlassq( X1.length, X1, 1, scale, sumsq );
// scale => <Float64Array>[ 1.0 ]
// sumsq => <Float64Array>[ 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 )
#### dlassq.ndarray( N, X, sx, ox, scale, offsetScale, sumsq, offsetSumsq )

Returns an updated sum of squares represented in scaled form using alternative indexing semantics.

<!-- eslint-disable @cspell/spellchecker -->

```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 ] );
var scale = new Float64Array( [ 1.0 ] );
var sumsq = new Float64Array( [ 0.0 ] );

dlassq.ndarray( 4, X, 1, 0, 1.0, 0.0, out, 1, 0 );
// out => <Float64Array>[ 1.0, 30.0 ]
dlassq.ndarray( 4, X, 1, 0, scale, 0, sumsq, 0 );
// scale => <Float64Array>[ 1.0 ]
// sumsq => <Float64Array>[ 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`.
- **offsetScale**: index of the element in `scale`.
- **offsetSumsq**: index of the element in `sumsq`.

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,

<!-- eslint-disable @cspell/spellchecker -->

```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 ] );
var scale = new Float64Array( [ 0.0, 1.0 ] );
var sumsq = new Float64Array( [ 0.0, 0.0, 0.0 ] );

dlassq.ndarray( 4, X, 2, 0, 1.0, 0.0, out, 2, 1 );
// out => <Float64Array>[ 0.0, 1.0, 999.9, 30.0, 999.9 ]
dlassq.ndarray( 4, X, 2, 0, scale, 1, sumsq, 2 );
// scale => <Float64Array>[ 0.0, 1.0 ]
// sumsq => <Float64Array>[ 0.0, 0.0, 30.0 ]
```

</section>
Expand All @@ -149,15 +164,20 @@ dlassq.ndarray( 4, X, 2, 0, 1.0, 0.0, out, 2, 1 );

```javascript
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var Float64Array = require( '@stdlib/array/float64' );
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 );
var scale = new Float64Array( [ 1.0 ] );
var sumsq = new Float64Array( [ 0.0 ] );

dlassq( X.length, X, 1, scale, sumsq );
console.log( scale );
console.log( sumsq );
```

</section>
Expand Down
15 changes: 11 additions & 4 deletions lib/node_modules/@stdlib/lapack/base/dlassq/benchmark/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ 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 format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var dlassq = require( './../lib/dlassq.js' );
Expand Down Expand Up @@ -56,18 +57,24 @@ function createBenchmark( len ) {
* @param {Benchmark} b - benchmark instance
*/
function benchmark( b ) {
var out;
var scale;
var sumsq;
var i;

scale = new Float64Array( 1 );
sumsq = new Float64Array( 1 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
out = dlassq( x.length, x, 1, 1.0, 0.0 );
if ( isnan( out[ 0 ] ) ) {
scale[ 0 ] = 1.0;
sumsq[ 0 ] = 0.0;
dlassq( x.length, x, 1, scale, sumsq );
if ( isnan( scale[ 0 ] ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( out[ 1 ] ) ) {
if ( isnan( sumsq[ 0 ] ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,24 @@ function createBenchmark( len ) {
* @param {Benchmark} b - benchmark instance
*/
function benchmark( b ) {
var out;
var scale;
var sumsq;
var i;

out = new Float64Array( 2 );
scale = new Float64Array( 1 );
sumsq = new Float64Array( 1 );

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 ] ) ) {
scale[ 0 ] = 1.0;
sumsq[ 0 ] = 0.0;
dlassq( x.length, x, 1, 0, scale, 0, sumsq, 0 );
if ( isnan( scale[ 0 ] ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( out[ 1 ] ) ) {
if ( isnan( sumsq[ 0 ] ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
Expand Down
69 changes: 35 additions & 34 deletions lib/node_modules/@stdlib/lapack/base/dlassq/docs/repl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{{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
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.
Expand All @@ -21,30 +21,32 @@
strideX: integer
Stride length for `X`.

scale: number
Scaling factor.
scale: Float64Array
Array containing a single element which specifies the scaling factor
and is overwritten by the updated 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.
sumsq: Float64Array
Array containing a single element which specifies the basic sum of
squares from which output is factored out and is overwritten by the
updated sum of squares.

Examples
--------
> var X = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0 ] );
> {{alias}}( 4, X, 1, 1.0, 0.0 )
<Float64Array>[ 1.0, 30.0 ]
> var scale = new {{alias:@stdlib/array/float64}}( [ 1.0 ] );
> var sumsq = new {{alias:@stdlib/array/float64}}( [ 0.0 ] );
> {{alias}}( 4, X, 1, scale, sumsq );
> scale
<Float64Array>[ 1.0 ]
> sumsq
<Float64Array>[ 30.0 ]


{{alias}}.ndarray( N, X, sx, ox, scale, sumsq, out, so, oo )
{{alias}}.ndarray( N, X, sx, ox, scale, offsetScale, sumsq, offsetSumsq )
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
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.
Expand All @@ -67,32 +69,31 @@
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.
scale: Float64Array
Array containing an element which specifies the scaling factor and is
overwritten by the updated scaling factor.

so: integer
Stride length for `out`.
offsetScale: integer
Index of the element in `scale`.

oo: integer
Starting index for `out`.
sumsq: Float64Array
Array containing an element which specifies the basic sum of squares
from which output is factored out and is overwritten by the updated sum
of squares.

Returns
-------
out: Float64Array
Output array.
offsetSumsq: integer
Index of the element in `sumsq`.

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 )
<Float64Array>[ 0.0, 1.0, 30.0 ]
> var scale = new {{alias:@stdlib/array/float64}}( [ 0.0, 1.0 ] );
> var sumsq = new {{alias:@stdlib/array/float64}}( [ 0.0, 0.0, 0.0 ] );
> {{alias}}.ndarray( 4, X, 1, 1, scale, 1, sumsq, 2 );
> scale
<Float64Array>[ 0.0, 1.0 ]
> sumsq
<Float64Array>[ 0.0, 0.0, 30.0 ]

See Also
--------
Loading
Loading