Skip to content

Latest commit

 

History

History
330 lines (205 loc) · 8.68 KB

File metadata and controls

330 lines (205 loc) · 8.68 KB

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

var dlassq = require( '@stdlib/lapack/base/dlassq' );

dlassq( N, X, strideX, scale, sumsq )

Returns an updated sum of squares represented in scaled form.

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 <Float64Array>[ 1.0, 30.0 ]

The function has the following parameters:

  • N: number of indexed elements.
  • X: input 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 views.

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 <Float64Array>[ 1.0, 30.0 ]

The returned 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.

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 => <Float64Array>[ 1.0, 30.0 ]

The function has the following additional parameters:

  • ox: starting index for X.
  • out: output Float64Array.
  • so: stride length for out.
  • oo: starting index for out.

While typed array views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on starting indices. For example,

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 => <Float64Array>[ 0.0, 1.0, 999.9, 30.0, 999.9 ]

Notes

Examples

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

#include "stdlib/lapack/base/dlassq.h"

c_dlassq( N, *X, incX, *scale, *sumsq )

Returns an updated sum of squares represented in scaled form.

double X[] = { 1.0, 2.0, 3.0, 4.0 };
double scale = 1.0;
double sumsq = 0.0;

c_dlassq( 4, X, 1, &scale, &sumsq );
// scale => 1.0
// sumsq => 30.0

The function has the following parameters:

  • N: [in] LAPACK_INT number of indexed elements.
  • X: [in] double* input array.
  • incX: [in] LAPACK_INT stride length for X.
  • scale: [in,out] double* pointer to scaling factor.
  • sumsq: [in,out] double* pointer to sum of squares.

c_dlassq_ndarray( N, *X, strideX, offsetX, *scale, *sumsq )

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

double X[] = { 0.0, 1.0, 2.0, 3.0, 4.0 };
double scale = 1.0;
double sumsq = 0.0;

c_dlassq_ndarray( 4, X, 1, 1, &scale, &sumsq );
// scale => 1.0
// sumsq => 30.0

The function has the following parameters:

  • N: [in] LAPACK_INT number of indexed elements.
  • X: [in] double* input array.
  • strideX: [in] LAPACK_INT stride length for X.
  • offsetX: [in] LAPACK_INT starting index for X.
  • scale: [in,out] double* pointer to scaling factor.
  • sumsq: [in,out] double* pointer to sum of squares.

Examples

#include "stdlib/lapack/base/dlassq.h"
#include <stdio.h>

int main( void ) {
    // Create a strided array:
    double X[] = { 1.0, 2.0, 3.0, 4.0 };

    // Specify the number of elements:
    const int N = 4;

    // Specify the stride length:
    const int strideX = 1;

    // Initialize scaling factor and sum of squares:
    double scale = 1.0;
    double sumsq = 0.0;

    // Compute the updated sum of squares in scaled form:
    c_dlassq( N, X, strideX, &scale, &sumsq );

    // Print the results:
    printf( "scale: %f\n", scale );
    printf( "sumsq: %f\n", sumsq );

    return 0;
}

References

  • Blue, James L. 1978. "A Portable Fortran Program to Find the Euclidean Norm of a Vector." ACM Transactions on Mathematical Software 4 (1). New York, NY, USA: Association for Computing Machinery: 15–23. doi:10.1145/355769.355771.
  • Anderson, Edward. 2017. "Algorithm 978: Safe Scaling in the Level 1 BLAS." ACM Transactions on Mathematical Software 44 (1). New York, NY, USA: Association for Computing Machinery: 1–28. doi:10.1145/3061665.