Skip to content

Latest commit

 

History

History
306 lines (195 loc) · 8.69 KB

File metadata and controls

306 lines (195 loc) · 8.69 KB

chpmv

Performs the matrix-vector operation y = α*A*x + β*y.

Usage

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

chpmv( order, uplo, N, α, AP, 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 Hermitian matrix supplied in packed form.

var Complex64Array = require( '@stdlib/array/complex64' );
var Complex64 = require( '@stdlib/complex/float32/ctor' );

var AP = new Complex64Array( [ 1.0, 0.0, 2.0, -2.0, 4.0, 0.0, 3.0, -3.0, 5.0, -5.0, 6.0, 0.0 ] );
var x = new Complex64Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ] );
var y = new Complex64Array( [ 3.0, 3.0, 2.0, 2.0, 1.0, 1.0 ] );
var alpha = new Complex64( 0.5, 0.5 );
var beta = new Complex64( 0.5, -0.5 );

chpmv( 'row-major', 'lower', 3, alpha, AP, x, 1, beta, y, 1 );
// y => <Complex64Array>[ -10.0, 14.0, -11.0, 25.0, 14.0, 31.0 ]

The function has the following parameters:

  • order: storage layout.
  • uplo: specifies whether the upper or lower triangular part of the matrix A is supplied.
  • N: specifies number of elements along each dimension of A.
  • α: scalar constant.
  • AP: input matrix in packed form stored in linear memory as a Complex64Array.
  • x: input vector Complex64Array.
  • sx: stride length for x.
  • β: scalar constant.
  • y: output Complex64Array.
  • sy: stride length for y.

The stride parameters determine how elements are accessed. For example, to iterate over every other element in x and y,

var Complex64Array = require( '@stdlib/array/complex64' );
var Complex64 = require( '@stdlib/complex/float32/ctor' );

var AP = new Complex64Array( [ 1.0, 0.0, 2.0, -2.0, 4.0, 0.0, 3.0, -3.0, 5.0, -5.0, 6.0, 0.0 ] );
var x = new Complex64Array( [ 1.0, 1.0, 0.0, 0.0, 2.0, 2.0, 0.0, 0.0, 3.0, 3.0 ] );
var y = new Complex64Array( [ 3.0, 3.0, 0.0, 0.0, 2.0, 2.0, 0.0, 0.0, 1.0, 1.0 ] );
var alpha = new Complex64( 0.5, 0.5 );
var beta = new Complex64( 0.5, -0.5 );

chpmv( 'row-major', 'lower', 3, alpha, AP, x, 2, beta, y, 2 );
// y => <Complex64Array>[ -10.0, 14.0, 0.0, 0.0, -11.0, 25.0, 0.0, 0.0, 14.0, 31.0 ]

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

var Complex64Array = require( '@stdlib/array/complex64' );
var Complex64 = require( '@stdlib/complex/float32/ctor' );

// Initial arrays...
var x0 = new Complex64Array( [ 0.0, 0.0, 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ] );
var y0 = new Complex64Array( [ 0.0, 0.0, 3.0, 3.0, 2.0, 2.0, 1.0, 1.0 ] );
var AP = new Complex64Array( [ 1.0, 0.0, 2.0, -2.0, 4.0, 0.0, 3.0, -3.0, 5.0, -5.0, 6.0, 0.0 ] );
var alpha = new Complex64( 0.5, 0.5 );
var beta = new Complex64( 0.5, -0.5 );

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

chpmv( 'row-major', 'lower', 3, alpha, AP, x1, 1, beta, y1, 1 );
// y1 => <Complex64Array>[ -10.0, 14.0, -11.0, 25.0, 14.0, 31.0 ]

chpmv.ndarray( order, uplo, N, α, A, sap, oap, x, sx, ox, β, y, sy, oy )

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

var Complex64Array = require( '@stdlib/array/complex64' );
var Complex64 = require( '@stdlib/complex/float32/ctor' );

var AP = new Complex64Array( [ 1.0, 0.0, 2.0, -2.0, 4.0, 0.0, 3.0, -3.0, 5.0, -5.0, 6.0, 0.0 ] );
var x = new Complex64Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ] );
var y = new Complex64Array( [ 3.0, 3.0, 2.0, 2.0, 1.0, 1.0 ] );
var alpha = new Complex64( 0.5, 0.5 );
var beta = new Complex64( 0.5, -0.5 );

chpmv.ndarray( 'row-major', 'lower', 3, alpha, AP, 1, 0, x, 1, 0, beta, y, 1, 0 );
// y => <Complex64Array>[ -10.0, 14.0, -11.0, 25.0, 14.0, 31.0 ]

The function has the following additional parameters:

  • sap: stride of AP..
  • oap: 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 Complex64Array = require( '@stdlib/array/complex64' );
var Complex64 = require( '@stdlib/complex/float32/ctor' );

var AP = new Complex64Array( [ 1.0, 0.0, 2.0, -2.0, 4.0, 0.0, 3.0, -3.0, 5.0, -5.0, 6.0, 0.0 ] );
var x = new Complex64Array( [ 0.0, 0.0, 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ] );
var y = new Complex64Array( [ 1.0, 1.0, 0.0, 0.0, 2.0, 2.0, 0.0, 0.0, 3.0, 3.0 ] );

var alpha = new Complex64( 0.5, 0.5 );
var beta = new Complex64( 0.5, -0.5 );

chpmv.ndarray( 'row-major', 'lower', 3, alpha, AP, 1, 0, x, 1, 1, beta, y, -2, 4 );
// y => <Complex64Array>[ 14.0, 31.0, 0.0, 0.0, -11.0, 25.0, 0.0, 0.0, -10.0, 14.0 ]

Notes

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

Examples

var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
var Complex64 = require( '@stdlib/complex/float32/ctor' );
var filledarrayBy = require( '@stdlib/array/filled-by' );
var logEach = require( '@stdlib/console/log-each' );
var chpmv = require( '@stdlib/blas/base/chpmv' );

function rand() {
    return new Complex64( discreteUniform( 0, 255 ), discreteUniform( -128, 127 ) );
}

var N = 5;

var AP = filledarrayBy( N*(N+1)/2, 'complex64', rand );
var x = filledarrayBy( N, 'complex64', rand );
var y = filledarrayBy( N, 'complex64', rand );

var alpha = new Complex64( 0.5, 0.5 );
var beta = new Complex64( 0.5, -0.5 );

chpmv( 'row-major', 'lower', N, alpha, AP, x, 1, beta, y, 1 );

// Print the results:
logEach( '%s', x );

chpmv.ndarray( 'row-major', 'lower', N, alpha, AP, 1, 0, x, 1, 0, beta, y, 1, 0 );

// Print the results:
logEach( '%s', x );

C APIs

Usage

TODO

TODO

TODO.

TODO

TODO

TODO

Examples

TODO