Perform the matrix-vector operation
y = α*A*x + β*ywhereαandβare scalars,xandyareNelement vectors and,Ais anNbyNsymmetric matrix supplied in packed form.
var dspmv = require( '@stdlib/blas/base/dspmv' );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 supplied in packed form AP.
var Float64Array = require( '@stdlib/array/float64' );
var AP = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
var x = new Float64Array( [ 1.0, 1.0, 1.0 ] );
var y = new Float64Array( [ 1.0, 1.0, 1.0 ] );
dspmv( 'column-major', 'lower', 3, 1.0, AP, x, 1, 1.0, y, 1 );
// y => <Float64Array>[ 7.0, 12.0, 15.0 ]The function has the following parameters:
- order: storage layout.
- uplo: specifies whether the upper or lower triangular part of the symmetric matrix
Ais supplied. - N: specifies the order of the matrix
A. - α: scalar constant.
- AP: packed form of a symmetric matrix
Astored in linear memory as aFloat64Array. - 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 y in reverse order,
var Float64Array = require( '@stdlib/array/float64' );
var AP = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
var x = new Float64Array( [ 1.0, 1.0, 1.0 ] );
var y = new Float64Array( [ 1.0, 1.0, 1.0 ] );
dspmv( 'column-major', 'lower', 3, 1.0, AP, x, 1, 1.0, y, -1 );
// y => <Float64Array>[ 15.0, 12.0, 7.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( [ 0.0, 1.0, 1.0 ] );
var y0 = new Float64Array( [ 0.0, 1.0, 1.0 ] );
var AP = new Float64Array( [ 1.0, 2.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
dspmv( 'row-major', 'upper', 2, 1.0, AP, x1, -1, 1.0, y1, -1 );
// y0 => <Float64Array>[ 0.0, 6.0, 4.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 supplied in packed form AP.
var Float64Array = require( '@stdlib/array/float64' );
var AP = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
var x = new Float64Array( [ 1.0, 1.0, 1.0 ] );
var y = new Float64Array( [ 1.0, 1.0, 1.0 ] );
dspmv.ndarray( 'column-major', 'lower', 3, 1.0, AP, 0, x, 1, 0, 1.0, y, 1, 0 );
// y => <Float64Array>[ 7.0, 12.0, 15.0 ]The function has the following additional parameters:
- oa: starting index for
AP. - 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 AP = new Float64Array( [ 0.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
var x = new Float64Array( [ 1.0, 1.0, 1.0 ] );
var y = new Float64Array( [ 1.0, 1.0, 1.0 ] );
dspmv.ndarray( 'column-major', 'lower', 3, 1.0, AP, 2, x, 1, 0, 1.0, y, -1, 2 );
// y => <Float64Array>[ 15.0, 12.0, 7.0 ]var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var dspmv = require( '@stdlib/blas/base/dspmv' );
var opts = {
'dtype': 'float64'
};
var N = 3;
var AP = discreteUniform( N * ( N + 1 ) / 2, -10, 10, opts );
var x = discreteUniform( N, -10, 10, opts );
var y = discreteUniform( N, -10, 10, opts );
dspmv.ndarray( 'row-major', 'upper', N, 1.0, AP, 0, x, 1, 0, 1.0, y, 1, 0 );
console.log( y );#include "stdlib/blas/base/dspmv.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 supplied in packed form AP.
#include "stdlib/blas/base/shared.h"
const double AP[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 };
const double x[] = { 1.0, 1.0, 1.0 };
double y[] = { 1.0, 1.0, 1.0 };
c_dspmv( CblasColMajor, CblasLower, 3, 1.0, AP, x, 1, 1.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 matrixAis supplied. - N:
[in] CBLAS_INTnumber of elements along each dimension ofA. - alpha:
[in] doublescalar constant. - AP:
[in] double*packed form of a symmetric 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_dspmv( const CBLAS_LAYOUT order, const CBLAS_UPLO uplo, const CBLAS_INT N, const double alpha, const double *AP, 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 supplied in packed form AP.
#include "stdlib/blas/base/shared.h"
const double AP[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 };
const double x[] = { 1.0, 1.0, 1.0 };
double y[] = { 1.0, 1.0, 1.0 };
c_dspmv_ndarray( CblasColMajor, CblasLower, 3, 1.0, AP, 0, x, 1, 0, 1.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. - AP:
[in] double*packed form of a symmetric matrixA. - oap:
[in] CBLAS_INTstarting index forAP. - 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_dspmv_ndarray( const CBLAS_LAYOUT order, const CBLAS_UPLO uplo, const CBLAS_INT N, const double alpha, const double *AP, const CBLAS_INT offsetAP, 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/dspmv.h"
#include "stdlib/blas/base/shared.h"
#include <stdio.h>
int main( void ) {
// Define `AP`, a packed form of a symmetric matrix `A`:
const double AP[ 3*(3+1)/2 ] = {
1.0, 2.0, 3.0, 4.0, 5.0, 6.0
};
// Define `x` and `y` vectors:
const double x[ 3 ] = { 1.0, 1.0, 1.0 };
double y[ 3 ] = { 1.0, 1.0, 1.0 };
// Specify the number of elements along each dimension of `A`:
const int N = 3;
// Perform the matrix-vector operation `y = α*A*x + β*y`:
c_dspmv( CblasColMajor, CblasLower, N, 1.0, AP, x, 1, 1.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_dspmv_ndarray( CblasColMajor, CblasLower, N, 1.0, AP, 0, 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 ] );
}
}