Skip to content

Commit

Permalink
feat!: add support for specifying the index offset for AP
Browse files Browse the repository at this point in the history
BREAKING CHANGE: add offset parameter to `ndarray` method

To migrate, users should set the `offsetAP` parameter. For most cases,
this parameter will be zero, but supporting this parameter allows
users to specify alternative starting indices, such as needed when
working with ndarray views.
  • Loading branch information
kgryte committed Jul 1, 2024
1 parent 43b84f7 commit bc23559
Show file tree
Hide file tree
Showing 22 changed files with 210 additions and 176 deletions.
11 changes: 6 additions & 5 deletions lib/node_modules/@stdlib/blas/base/dspmv/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ dspmv( 'row-major', 'upper', 2, 1.0, AP, x1, -1, 1.0, y1, -1 );
// y0 => <Float64Array>[ 6.0, 4.0 ]
```

#### dspmv.ndarray( order, uplo, N, α, AP, x, sx, ox, β, y, sy, oy )
#### dspmv.ndarray( order, uplo, N, α, AP, oa, 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,13 @@ 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, x, 1, 0, 1.0, y, 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`.

Expand All @@ -116,11 +117,11 @@ While [`typed array`][mdn-typed-array] views mandate a view offset based on the
```javascript
var Float64Array = require( '@stdlib/array/float64' );

var AP = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
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, x, 1, 0, 1.0, y, -1, 2 );
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 ]
```

Expand Down Expand Up @@ -158,7 +159,7 @@ 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, x, 1, 0, 1.0, y, 1, 0 );
dspmv.ndarray( 'row-major', 'upper', N, 1.0, AP, 0, x, 1, 0, 1.0, y, 1, 0 );
console.log( y );
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function createBenchmark( len ) {

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
z = dspmv( 'row-major', 'upper', len, 1.0, AP, x, 1, 0, 1.0, y, 1, 0 );
z = dspmv( 'row-major', 'upper', len, 1.0, AP, 0, x, 1, 0, 1.0, y, 1, 0 );
if ( isnan( z[ i%z.length ] ) ) {
b.fail( 'should not return NaN' );
}
Expand Down
9 changes: 6 additions & 3 deletions lib/node_modules/@stdlib/blas/base/dspmv/docs/repl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
<Float64Array>[ ~6.0, ~4.0 ]


{{alias}}.ndarray( ord, uplo, N, α, AP, x, sx, ox, β, y, sy, oy )
{{alias}}.ndarray( ord, uplo, N, α, AP, oa, 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,9 @@
AP: Float64Array
Matrix in packed form.

oa: integer
Starting index for `AP`.

x: Float64Array
Input vector `x`.

Expand Down Expand Up @@ -140,14 +143,14 @@
> var AP = new {{alias:@stdlib/array/float64}}( [ 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, 0, x, 1, 0, 1.0, y, 1, 0 )
<Float64Array>[ ~4.0, ~6.0 ]

// Advanced indexing:
> x = new {{alias:@stdlib/array/float64}}( [ 1.0, 1.0 ] );
> y = new {{alias:@stdlib/array/float64}}( [ 1.0, 1.0 ] );
> AP = new {{alias:@stdlib/array/float64}}( [ 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, 0, x, -1, 1, 1.0, y, -1, 1 )
<Float64Array>[ ~6.0, ~4.0 ]

See Also
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ interface Routine {
* @param N - number of columns in the matrix `A`
* @param alpha - scalar constant
* @param AP - packed form of a symmetric matrix `A`
* @param offsetAP - starting `AP` index
* @param x - first input array
* @param strideX - `x` stride length
* @param offsetX - starting `x` index
Expand All @@ -77,10 +78,10 @@ interface Routine {
* 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, x, 1, 0, 1.0, y, 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 ]
*/
ndarray( order: Layout, uplo: MatrixTriangle, N: number, alpha: number, AP: Float64Array, x: Float64Array, strideX: number, offsetX: number, beta: number, y: Float64Array, strideY: number, offsetY: number ): Float64Array;
ndarray( order: Layout, uplo: MatrixTriangle, N: number, alpha: number, AP: Float64Array, offsetAP: number, x: Float64Array, strideX: number, offsetX: number, beta: number, y: Float64Array, strideY: number, offsetY: number ): Float64Array;
}

/**
Expand Down Expand Up @@ -115,7 +116,7 @@ interface Routine {
* 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, x, 1, 0, 1.0, y, -1, 2 );
* dspmv.ndarray( 'column-major', 'lower', 3, 1.0, AP, 0, x, 1, 0, 1.0, y, -1, 2 );
* // y => <Float64Array>[ 15.0, 12.0, 7.0 ]
*/
declare var dspmv: Routine;
Expand Down
Loading

1 comment on commit bc23559

@stdlib-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage Report

Package Statements Branches Functions Lines
blas/base/dspmv $\color{green}421/421$
$\color{green}+100.00\%$
$\color{green}47/47$
$\color{green}+100.00\%$
$\color{green}3/3$
$\color{green}+100.00\%$
$\color{green}421/421$
$\color{green}+100.00\%$

The above coverage report was generated for the changes in this push.

Please sign in to comment.