Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: update implementation for blas/base/sspmv #2839

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions lib/node_modules/@stdlib/blas/base/sspmv/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ limitations under the License.

# sspmv

> 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 supplied in packed form.
> Perform the matrix-vector operation `y = α*A*x + β*y`.

<section class = "usage">

Expand Down Expand Up @@ -91,7 +91,7 @@ sspmv( 'row-major', 'upper', 2, 1.0, AP, x1, -1, 1.0, y1, -1 );
// y0 => <Float32Array>[ 0.0, 6.0, 4.0 ]
```

#### sspmv.ndarray( order, uplo, N, α, AP, x, sx, ox, β, y, sy, oy )
#### sspmv.ndarray( order, uplo, N, α, AP, sap, oap 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 supplied in packed form `AP`.

Expand All @@ -102,12 +102,14 @@ var AP = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
var x = new Float32Array( [ 1.0, 1.0, 1.0 ] );
var y = new Float32Array( [ 1.0, 1.0, 1.0 ] );

sspmv.ndarray( 'column-major', 'lower', 3, 1.0, AP, x, 1, 0, 1.0, y, 1, 0 );
sspmv.ndarray( 'column-major', 'lower', 3, 1.0, AP, 1, 0, x, 1, 0, 1.0, y, 1, 0 );
// y => <Float32Array>[ 7.0, 12.0, 15.0 ]
```

The function has the following additional parameters:

- **sap**: `AP` stride length.
- **oap**: starting index for `AP`.
- **ox**: starting index for `x`.
- **oy**: starting index for `y`.

Expand All @@ -120,7 +122,7 @@ var AP = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
var x = new Float32Array( [ 1.0, 1.0, 1.0 ] );
var y = new Float32Array( [ 1.0, 1.0, 1.0 ] );

sspmv.ndarray( 'column-major', 'lower', 3, 1.0, AP, x, 1, 0, 1.0, y, -1, 2 );
sspmv.ndarray( 'column-major', 'lower', 3, 1.0, AP, 1, 0, x, 1, 0, 1.0, y, -1, 2 );
// y => <Float32Array>[ 15.0, 12.0, 7.0 ]
```

Expand Down Expand Up @@ -152,13 +154,16 @@ var opts = {
'dtype': 'float32'
};

var N = 3;
var N = 5;
var AP = discreteUniform( N * ( N + 1 ) / 2, -10, 10, opts );

var x = discreteUniform( N, -10, 10, opts );
var y = discreteUniform( N, -10, 10, opts );

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

sspmv.ndarray( 'row-major', 'upper', N, 1.0, AP, 1, 0, x, 1, 0, 1.0, y, 1, 0 );
console.log( y );
```

Expand Down
12 changes: 6 additions & 6 deletions lib/node_modules/@stdlib/blas/base/sspmv/benchmark/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ var options = {
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} len - array length
* @param {PositiveInteger} N - array length
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var AP = uniform( len * ( len + 1 ) / 2, -10.0, 10.0, options );
var x = uniform( len, -10.0, 10.0, options );
var y = uniform( len, -10.0, 10.0, options );
function createBenchmark( N ) {
var AP = uniform( N*(N+1)/2, -10.0, 10.0, options );
var x = uniform( N, -10.0, 10.0, options );
var y = uniform( N, -10.0, 10.0, options );
return benchmark;

/**
Expand All @@ -63,7 +63,7 @@ function createBenchmark( len ) {

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
z = sspmv( 'row-major', 'upper', len, 1.0, AP, x, 1, 1.0, y, 1 );
z = sspmv( 'row-major', 'upper', N, 1.0, AP, x, 1, 1.0, y, 1 );
if ( isnanf( z[ i%z.length ] ) ) {
b.fail( 'should not return NaN' );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ var options = {
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} len - array length
* @param {PositiveInteger} N - array length
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var AP = uniform( len * ( len + 1 ) / 2, -10.0, 10.0, options );
var x = uniform( len, -10.0, 10.0, options );
var y = uniform( len, -10.0, 10.0, options );
function createBenchmark( N ) {
var AP = uniform( N * ( N + 1 ) / 2, -10.0, 10.0, options );
var x = uniform( N, -10.0, 10.0, options );
var y = uniform( N, -10.0, 10.0, options );
return benchmark;

/**
Expand All @@ -63,7 +63,7 @@ function createBenchmark( len ) {

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
z = sspmv( 'row-major', 'upper', len, 1.0, AP, x, 1, 0, 1.0, y, 1, 0 );
z = sspmv( 'row-major', 'upper', N, 1.0, AP, 1, 0, x, 1, 0, 1.0, y, 1, 0 );
if ( isnanf( z[ i%z.length ] ) ) {
b.fail( 'should not return NaN' );
}
Expand Down
14 changes: 10 additions & 4 deletions lib/node_modules/@stdlib/blas/base/sspmv/docs/repl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@
> AP = new {{alias:@stdlib/array/float32}}( [ 1.0, 2.0, 3.0 ] );
> var x1 = new {{alias:@stdlib/array/float32}}( x0.buffer, x0.BYTES_PER_ELEMENT*0 );
> var y1 = new {{alias:@stdlib/array/float32}}( y0.buffer, y0.BYTES_PER_ELEMENT*0 );
> {{alias}}( 'row-major', 'upper', 2, 1.0, AP, x1, -1, 1.0, y1, -1 )
> {{alias}}( 'row-major', 'upper', 2, 1.0, AP, x1, -1, 1.0, y1, -1 );
> y0
<Float32Array>[ ~6.0, ~4.0 ]


{{alias}}.ndarray( ord, uplo, N, α, AP, x, sx, ox, β, y, sy, oy )
{{alias}}.ndarray( ord, uplo, N, α, AP, sap, oap, 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 supplied in
Expand Down Expand Up @@ -106,6 +106,12 @@
AP: Float32Array
Matrix in packed form.

sap: integer
Index increment for `AP`.

oap: integer
Starting index for `AP`.

x: Float32Array
Input vector `x`.

Expand Down Expand Up @@ -140,14 +146,14 @@
> var AP = new {{alias:@stdlib/array/float32}}( [ 1.0, 2.0, 3.0, 4.0 ] );
> var ord = 'row-major';
> var uplo = 'upper';
> {{alias}}.ndarray( ord, uplo, 2, 1.0, AP, x, 1, 0, 1.0, y, 1, 0 )
> {{alias}}.ndarray( ord, uplo, 2, 1.0, AP, 1, 0, x, 1, 0, 1.0, y, 1, 0 )
<Float32Array>[ ~4.0, ~6.0 ]

// Advanced indexing:
> x = new {{alias:@stdlib/array/float32}}( [ 1.0, 1.0 ] );
> y = new {{alias:@stdlib/array/float32}}( [ 1.0, 1.0 ] );
> AP = new {{alias:@stdlib/array/float32}}( [ 1.0, 2.0, 3.0, 4.0 ] );
> {{alias}}.ndarray( ord, uplo, 2, 1.0, AP, x, -1, 1, 1.0, y, -1, 1 )
> {{alias}}.ndarray( ord, uplo, 2, 1.0, AP, 1, 0, x, -1, 1, 1.0, y, -1, 1 )
<Float32Array>[ ~6.0, ~4.0 ]

See Also
Expand Down
18 changes: 10 additions & 8 deletions lib/node_modules/@stdlib/blas/base/sspmv/docs/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { Layout, MatrixTriangle } from '@stdlib/types/blas';
*/
interface Routine {
/**
* Performs the matrix-vector operation `y = alpha*A*x + beta*y` where `alpha` and `beta` are scalars, `x` and `y` are `N` element vectors, and `A` is an `N` by `N` symmetric matrix supplied in packed form.
* 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.
*
* @param order - storage layout
* @param uplo - specifies whether the upper or lower triangular part of the symmetric matrix `A` is being supplied
Expand All @@ -54,20 +54,22 @@ interface Routine {
( order: Layout, uplo: MatrixTriangle, N: number, alpha: number, AP: Float32Array, x: Float32Array, strideX: number, beta: number, y: Float32Array, strideY: number ): Float32Array;

/**
* Performs the matrix-vector operation `y = alpha*A*x + beta*y` using alternative indexing semantics and where `alpha` and `beta` are scalars, `x` and `y` are `N` element vectors, and `A` is an `N` by `N` symmetric matrix supplied in packed form.
* 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.
*
* @param order - storage layout
* @param uplo - specifies whether the upper or lower triangular part of the symmetric matrix `A` is being supplied
* @param N - number of columns in the matrix `A`
* @param alpha - scalar constant
* @param AP - packed form of a symmetric matrix `A`
* @param sap - `AP` stride length
* @param oap - starting index for `AP`
* @param x - first input array
* @param strideX - `x` stride length
* @param offsetX - starting `x` index
* @param offsetX - starting index for `x`
* @param beta - scalar constant
* @param y - second input array
* @param strideY - `y` stride length
* @param offsetY - starting `y` index
* @param offsetY - starting index for `y`
* @returns `y`
*
* @example
Expand All @@ -77,14 +79,14 @@ interface Routine {
* var x = new Float32Array( [ 1.0, 1.0, 1.0 ] );
* var y = new Float32Array( [ 1.0, 1.0, 1.0 ] );
*
* sspmv.ndarray( 'column-major', 'lower', 3, 1.0, AP, x, 1, 0, 1.0, y, 1, 0 );
* sspmv.ndarray( 'column-major', 'lower', 3, 1.0, AP, 1, 0, x, 1, 0, 1.0, y, 1, 0 );
* // y => <Float32Array>[ 7.0, 12.0, 15.0 ]
*/
ndarray( order: Layout, uplo: MatrixTriangle, N: number, alpha: number, AP: Float32Array, x: Float32Array, strideX: number, offsetX: number, beta: number, y: Float32Array, strideY: number, offsetY: number ): Float32Array;
ndarray( order: Layout, uplo: MatrixTriangle, N: number, alpha: number, AP: Float32Array, strideAP: number, offsetAP: number, x: Float32Array, strideX: number, offsetX: number, beta: number, y: Float32Array, strideY: number, offsetY: number ): Float32Array;
}

/**
* Performs the matrix-vector operation `y = alpha*A*x + beta*y` where `alpha` and `beta` are scalars, `x` and `y` are `N` element vectors, and `A` is an `N` by `N` symmetric matrix supplied in packed form.
* 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.
*
* @param order - storage layout
* @param uplo - specifies whether the upper or lower triangular part of the symmetric matrix `A` is being supplied
Expand Down Expand Up @@ -115,7 +117,7 @@ interface Routine {
* var x = new Float32Array( [ 1.0, 1.0, 1.0 ] );
* var y = new Float32Array( [ 1.0, 1.0, 1.0 ] );
*
* sspmv.ndarray( 'column-major', 'lower', 3, 1.0, AP, x, 1, 0, 1.0, y, -1, 2 );
* sspmv.ndarray( 'column-major', 'lower', 3, 1.0, AP, 1, 0, x, 1, 0, 1.0, y, -1, 2 );
* // y => <Float32Array>[ 15.0, 12.0, 7.0 ]
*/
declare var sspmv: Routine;
Expand Down
Loading
Loading