Perform the matrix-vector operation
y = α*A*x + β*ywhereαandβare scalars,xandyareNelement vectors, andAis anNbyNsymmetric matrix.
var dsymv = require( '@stdlib/blas/base/dsymv' );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
Ashould 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 matrixA). - 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 ]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 ]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 );#include "stdlib/blas/base/dsymv.h"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_LAYOUTstorage layout. - uplo:
[in] CBLAS_UPLOspecifies whether the upper or lower triangular part of the symmetric matrixAshould be referenced. - N:
[in] CBLAS_INTnumber of elements along each dimension ofA. - alpha:
[in] doublescalar 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 matrixA). - X:
[in] double*first input vector. - strideX:
[in] CBLAS_INTstride length forX. - beta:
[in] doublescalar constant. - Y:
[inout] double*second input vector. - strideY:
[in] CBLAS_INTstride length forY.
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 )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_LAYOUTstorage layout. - uplo:
[in] CBLAS_UPLOspecifies whether the upper or lower triangular part of the symmetric matrixAis supplied. - N:
[in] CBLAS_INTnumber of elements along each dimension ofA. - alpha:
[in] doublescalar. - 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 matrixA). - X:
[in] double*first input vector. - sx:
[in] CBLAS_INTstride length forX. - ox:
[in] CBLAS_INTstarting index forX. - beta:
[in] doublescalar. - Y:
[inout] double*second input vector. - sy:
[in] CBLAS_INTstride length forY. - oy:
[in] CBLAS_INTstarting index forY.
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 )#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 ] );
}
}