Skip to content

Latest commit

 

History

History
350 lines (232 loc) · 11.1 KB

File metadata and controls

350 lines (232 loc) · 11.1 KB

dsymv

Perform the matrix-vector operation y = α*A*x + β*y where α and β are scalars, x and y are N element vectors, and A is an N by N symmetric matrix.

Usage

var dsymv = require( '@stdlib/blas/base/dsymv' );

dsymv( order, uplo, N, α, A, LDA, x, sx, β, y, sy )

Performs the matrix-vector operation y = α*A*x + β*y where α and β are scalars, x and y are N element vectors, and A is an N by N symmetric matrix.

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

var A = new Float64Array( [ 1.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 3.0 ] );
var x = new Float64Array( [ 1.0, 1.0, 1.0 ] );
var y = new Float64Array( [ 0.0, 0.0, 0.0 ] );

dsymv( 'row-major', 'lower', 3, 1.0, A, 3, x, 1, 0.0, y, 1 );
// y => <Float64Array>[ 1.0, 2.0, 3.0 ]

The function has the following parameters:

  • order: storage layout.
  • uplo: specifies whether the upper or lower triangular part of the symmetric matrix A should be referenced.
  • N: number of elements along each dimension of A.
  • α: scalar constant.
  • A: input matrix stored in linear memory as a Float64Array.
  • lda: stride of the first dimension of A (a.k.a., leading dimension of the matrix A).
  • x: input Float64Array.
  • sx: index increment for x.
  • β: scalar constant.
  • y: output Float64Array.
  • sy: index increment for y.

The stride parameters determine how elements in the input arrays are accessed at runtime. For example, to iterate over the elements of x in reverse order,

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

var A = new Float64Array( [ 1.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 3.0 ] );
var x = new Float64Array( [ 1.0, 2.0, 3.0 ] );
var y = new Float64Array( [ 1.0, 2.0, 3.0 ] );

dsymv( 'row-major', 'upper', 3, 2.0, A, 3, x, -1, 1.0, y, 1 );
// y => <Float64Array>[ 7.0, 10.0, 9.0 ]

Note that indexing is relative to the first index. To introduce an offset, use typed array views.

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

// Initial arrays...
var x0 = new Float64Array( [ 1.0, 1.0, 1.0, 1.0 ] );
var y0 = new Float64Array( [ 1.0, 1.0, 1.0, 1.0 ] );
var A = new Float64Array( [ 1.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 3.0 ] );

// Create offset views...
var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
var y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*1 ); // start at 2nd element

dsymv( 'row-major', 'upper', 3, 1.0, A, 3, x1, -1, 1.0, y1, -1 );
// y0 => <Float64Array>[ 1.0, 4.0, 3.0, 2.0 ]

dsymv.ndarray( order, uplo, N, α, A, LDA, x, sx, ox, β, y, sy, oy )

Performs the matrix-vector operation y = α*A*x + β*y using alternative indexing semantics and where α and β are scalars, x and y are N element vectors, and A is an N by N symmetric matrix.

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

var A = new Float64Array( [ 1.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 3.0 ] );
var x = new Float64Array( [ 1.0, 2.0, 3.0 ] );
var y = new Float64Array( [ 1.0, 2.0, 3.0 ] );

dsymv.ndarray( 'row-major', 'upper', 3, 2.0, A, 3, x, -1, 2, 1.0, y, 1, 0 );
// y => <Float64Array>[ 7.0, 10.0, 9.0 ]

The function has the following additional parameters:

  • ox: starting index for x.
  • oy: starting index for y.

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 A = new Float64Array( [ 1.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 3.0 ] );
var x = new Float64Array( [ 1.0, 1.0, 1.0 ] );
var y = new Float64Array( [ 1.0, 1.0, 1.0 ] );

dsymv.ndarray( 'row-major', 'lower', 3, 1.0, A, 3, x, -1, 2, 1.0, y, -1, 2 );
// y => <Float64Array>[ 4.0, 3.0, 2.0 ]

Notes

  • dsymv() corresponds to the BLAS level 2 function dsymv.

Examples

var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var ones = require( '@stdlib/array/ones' );
var dsymv = require( '@stdlib/blas/base/dsymv' );

var opts = {
    'dtype': 'float64'
};

var N = 3;
var A = ones( N*N, opts.dtype );

var x = discreteUniform( N, 0, 255, opts );
var y = discreteUniform( N, 0, 255, opts );

dsymv.ndarray( 'row-major', 'upper', N, 1.0, A, N, x, 1, 0, 1.0, y, 1, 0 );
console.log( y );

C APIs

Usage

#include "stdlib/blas/base/dsymv.h"

c_dsymv( order, uplo, N, alpha, *A, LDA, *X, strideX, beta, *Y, strideY )

Performs the matrix-vector operation y = α*A*x + β*y where α and β are scalars, x and y are N element vectors, and A is an N by N symmetric matrix.

#include "stdlib/blas/base/shared.h"

const double A[] = { 1.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 3.0 };
const double x[] = { 1.0, 1.0, 1.0 };
double y[] = { 0.0, 0.0, 0.0 };

c_dsymv( CblasRowMajor, CblasLower, 3, 1.0, A, 3, x, 1, 0.0, y, 1 );

The function accepts the following arguments:

  • order: [in] CBLAS_LAYOUT storage layout.
  • uplo: [in] CBLAS_UPLO specifies whether the upper or lower triangular part of the symmetric matrix A should be referenced.
  • N: [in] CBLAS_INT number of elements along each dimension of A.
  • alpha: [in] double scalar constant.
  • A: input matrix stored in linear memory as a Float64Array.
  • lda: stride of the first dimension of A (a.k.a., leading dimension of the matrix A).
  • X: [in] double* first input vector.
  • strideX: [in] CBLAS_INT stride length for X.
  • beta: [in] double scalar constant.
  • Y: [inout] double* second input vector.
  • strideY: [in] CBLAS_INT stride length for Y.
void c_dsymv( const CBLAS_LAYOUT order, const CBLAS_UPLO uplo, const CBLAS_INT N, const double alpha, const double *A, const CBLAS_INT LDA, const double *X, const CBLAS_INT strideX, const double beta, double *Y, const CBLAS_INT strideY )

c_dsymv_ndarray( order,uplo,N,alpha,*A,lda,oap,*X,sx,ox,beta,*Y,sy,oy )

Performs the matrix-vector operation y = α*A*x + β*y using alternative indexing semantics and where α and β are scalars, x and y are N element vectors, and A is an N by N symmetric matrix.

#include "stdlib/blas/base/shared.h"

const double A[] = { 1.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 3.0 };
const double x[] = { 1.0, 1.0, 1.0 };
double y[] = { 0.0, 0.0, 0.0 };

c_dsymv_ndarray( CblasRowMajor, CblasLower, 3, 1.0, A, 3, x, 1, 0, 0.0, y, 1, 0 );

The function accepts the following arguments:

  • order: [in] CBLAS_LAYOUT storage layout.
  • uplo: [in] CBLAS_UPLO specifies whether the upper or lower triangular part of the symmetric matrix A is supplied.
  • N: [in] CBLAS_INT number of elements along each dimension of A.
  • alpha: [in] double scalar.
  • A: input matrix stored in linear memory as a Float64Array.
  • lda: stride of the first dimension of A (a.k.a., leading dimension of the matrix A).
  • X: [in] double* first input vector.
  • sx: [in] CBLAS_INT stride length for X.
  • ox: [in] CBLAS_INT starting index for X.
  • beta: [in] double scalar.
  • Y: [inout] double* second input vector.
  • sy: [in] CBLAS_INT stride length for Y.
  • oy: [in] CBLAS_INT starting index for Y.
void c_dsymv_ndarray( const CBLAS_LAYOUT order, const CBLAS_UPLO uplo, const CBLAS_INT N, const double alpha, const double *A, const CBLAS_INT LDA, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const double beta, double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY )

Examples

#include "stdlib/blas/base/dsymv.h"
#include "stdlib/blas/base/shared.h"
#include <stdio.h>

int main( void ) {
    // symmetric matrix `A`:
    const double A[ 3*3 ] = {
        1.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 3.0
    };

    // Define `x` and `y` vectors:
    const double x[ 3 ] = { 1.0, 1.0, 1.0 };
    double y[ 3 ] = { 0.0, 0.0, 0.0 };

    // Specify the number of elements along each dimension of `A`:
    const int N = 3;

    // Specify the stride of the first dimension of `A`:
    const int LDA = 3;

    // Perform the matrix-vector operation `y = α*A*x + β*y`:
    c_dsymv( CblasRowMajor, CblasLower, N, 1.0, A, LDA, x, 1, 0.0, y, 1 );

    // Print the result:
    for ( int i = 0; i < N; i++ ) {
        printf( "y[ %i ] = %lf\n", i, y[ i ] );
    }

    // Perform the matrix-vector operation `y = α*A*x + β*y` using alternative indexing semantics:
    c_dsymv_ndarray( CblasRowMajor, CblasLower, N, 1.0, A, LDA, x, 1, 0, 1.0, y, 1, 0 );

    // Print the result:
    for ( int i = 0; i < N; i++ ) {
        printf( "y[ %i ] = %lf\n", i, y[ i ] );
    }
}