Skip to content
Merged
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
120 changes: 106 additions & 14 deletions lib/node_modules/@stdlib/blas/base/sgemv/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ limitations under the License.

# sgemv

> Perform one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y`.
> Perform one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A**T*x + β*y`.

<section class="usage">

Expand All @@ -30,9 +30,9 @@ limitations under the License.
var sgemv = require( '@stdlib/blas/base/sgemv' );
```

#### sgemv( ord, trans, M, N, α, A, LDA, x, sx, β, y, sy )
#### sgemv( order, trans, M, N, α, A, LDA, x, sx, β, y, sy )

Performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y`, where `α` and `β` are scalars, `x` and `y` are vectors, and `A` is an `M` by `N` matrix.
Performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A**T*x + β*y`, where `α` and `β` are scalars, `x` and `y` are vectors, and `A` is an `M` by `N` matrix.

```javascript
var Float32Array = require( '@stdlib/array/float32' );
Expand All @@ -47,18 +47,18 @@ sgemv( 'row-major', 'no-transpose', 2, 3, 1.0, A, 3, x, 1, 1.0, y, 1 );

The function has the following parameters:

- **ord**: storage layout.
- **order**: storage layout.
- **trans**: specifies whether `A` should be transposed, conjugate-transposed, or not transposed.
- **M**: number of rows in the matrix `A`.
- **N**: number of columns in the matrix `A`.
- **α**: scalar constant.
- **A**: input matrix stored in linear memory as a [`Float32Array`][mdn-float32array].
- **lda**: stride of the first dimension of `A` (leading dimension of `A`).
- **x**: input [`Float32Array`][mdn-float32array].
- **sx**: index increment for `x`.
- **sx**: stride length for `x`.
- **β**: scalar constant.
- **y**: output [`Float32Array`][mdn-float32array].
- **sy**: index increment for `y`.
- **sy**: stride length for `y`.

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

Expand Down Expand Up @@ -93,9 +93,11 @@ sgemv( 'row-major', 'no-transpose', 2, 2, 1.0, A, 2, x1, -1, 1.0, y1, -1 );
// y0 => <Float32Array>[ 0.0, 8.0, 4.0 ]
```

<!-- lint disable maximum-heading-length -->

#### sgemv.ndarray( trans, M, N, α, A, sa1, sa2, oa, x, sx, ox, β, y, sy, oy )

Performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y`, using alternative indexing semantics and where `α` and `β` are scalars, `x` and `y` are vectors, and `A` is an `M` by `N` matrix.
Performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A**T*x + β*y`, using alternative indexing semantics and where `α` and `β` are scalars, `x` and `y` are vectors, and `A` is an `M` by `N` matrix.

```javascript
var Float32Array = require( '@stdlib/array/float32' );
Expand Down Expand Up @@ -199,18 +201,73 @@ console.log( y );
#include "stdlib/blas/base/sgemv.h"
```

#### TODO
#### c_sgemv( layout, trans, M, N, alpha, \*A, LDA, \*X, strideX, beta, \*Y, strideY )

TODO.
Performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y`, where `α` and `β` are scalars, `x` and `y` are vectors, and `A` is an `M` by `N` matrix.

```c
TODO
#include "stdlib/blas/base/shared.h"

const float A[] = { 1.0f, 0.0f, 0.0f, 2.0f, 1.0f, 0.0f, 3.0f, 2.0f, 1.0f };
const float x[] = { 1.0f, 2.0f, 3.0f };
float y[] = { 1.0f, 2.0f, 3.0f };

c_sgemv( CblasColMajor, CblasNoTrans, 3, 3, 1.0f, A, 3, x, 1, 1.0f, y, 1 );
```

TODO
The function accepts the following arguments:

- **layout**: `[in] CBLAS_LAYOUT` storage layout.
- **trans**: `[in] CBLAS_TRANSPOSE` specifies whether `A` should be transposed, conjugate-transposed, or not transposed.
- **M**: `[in] CBLAS_INT` number of rows in the matrix `A`.
- **N**: `[in] CBLAS_INT` number of columns in the matrix `A`.
- **alpha**: `[in] float` scalar constant.
- **A**: `[in] float*` input matrix.
- **LDA**: `[in] CBLAS_INT` stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`).
- **X**: `[in] float*` first input vector.
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
- **beta**: `[in] float` scalar constant.
- **Y**: `[inout] float*` second input vector.
- **strideY**: `[in] CBLAS_INT` stride length for `Y`.

```c
TODO
void c_sgemv( const CBLAS_LAYOUT layout, const CBLAS_TRANSPOSE trans, const CBLAS_INT M, const CBLAS_INT N, const float alpha, const float *A, const CBLAS_INT LDA, const float *X, const CBLAS_INT strideX, const float beta, float *Y, const CBLAS_INT strideY )
```

#### c_sgemv_ndarray( trans, M, N, alpha, \*A, sa1, sa2, oa, \*X, sx, ox, beta, \*Y, sy, oy )

Performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y`, using indexing alternative semantics and where `α` and `β` are scalars, `x` and `y` are vectors, and `A` is an `M` by `N` matrix.

```c
#include "stdlib/blas/base/shared.h"

const float A[] = { 1.0f, 0.0f, 0.0f, 2.0f, 1.0f, 0.0f, 3.0f, 2.0f, 1.0f };
const float x[] = { 1.0f, 2.0f, 3.0f };
float y[] = { 1.0f, 2.0f, 3.0f };

c_sgemv_ndarray( CblasNoTrans, 3, 3, 1.0f, A, 1, 3, 0, x, 1, 0, 1.0f, y, 1, 0 );
```

The function accepts the following arguments:

- **trans**: `[in] CBLAS_TRANSPOSE` specifies whether `A` should be transposed, conjugate-transposed, or not transposed.
- **M**: `[in] CBLAS_INT` number of rows in the matrix `A`.
- **N**: `[in] CBLAS_INT` number of columns in the matrix `A`.
- **alpha**: `[in] float` scalar constant.
- **A**: `[in] float*` input matrix.
- **sa1**: `[in] CBLAS_INT` stride of the first dimension of `A`.
- **sa2**: `[in] CBLAS_INT` stride of the second dimension of `A`.
- **oa**: `[in] CBLAS_INT` starting index for `A`.
- **X**: `[in] float*` first input vector.
- **sx**: `[in] CBLAS_INT` stride length for `X`.
- **ox**: `[in] CBLAS_INT` starting index for `X`.
- **beta**: `[in] float` scalar constant.
- **Y**: `[inout] float*` second input vector.
- **sy**: `[in] CBLAS_INT` stride length for `Y`.
- **oy**: `[in] CBLAS_INT` starting index for `Y`.

```c
void c_sgemv_ndarray( const CBLAS_TRANSPOSE trans, const CBLAS_INT M, const CBLAS_INT N, const float alpha, const float *A, const CBLAS_INT strideA1, const CBLAS_INT strideA2, const CBLAS_INT offsetA, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const float beta, float *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY )
```

</section>
Expand All @@ -232,7 +289,42 @@ TODO
### Examples

```c
TODO
#include "stdlib/blas/base/sgemv.h"
#include "stdlib/blas/base/shared.h"
#include <stdio.h>

int main( void ) {
// Define a 3x3 matrix stored in row-major order:
const float A[ 3*3 ] = {
1.0f, 2.0f, 3.0f,
4.0f, 5.0f, 6.0f,
7.0f, 8.0f, 9.0f
};

// Define `x` and `y` vectors:
const float x[ 3 ] = { 1.0f, 2.0f, 3.0f };
float y[ 3 ] = { 1.0f, 2.0f, 3.0f };

// Specify the number of elements along each dimension of `A`:
const int M = 3;
const int N = 3;

// Perform the matrix-vector operation `y = α*A*x + β*y`:
c_sgemv( CblasRowMajor, CblasNoTrans, M, N, 1.0f, A, M, x, 1, 1.0f, y, 1 );

// Print the result:
for ( int i = 0; i < N; i++ ) {
printf( "y[ %i ] = %f\n", i, y[ i ] );
}

// Perform the matrix-vector operation `y = α*A*x + β*y` using alternative indexing semantics:
c_sgemv_ndarray( CblasNoTrans, M, N, 1.0f, A, N, 1, 0, x, 1, 0, 1.0f, y, 1, 0 );

// Print the result:
for ( int i = 0; i < N; i++ ) {
printf( "y[ %i ] = %f\n", i, y[ i ] );
}
}
```

</section>
Expand All @@ -257,7 +349,7 @@ TODO

[blas]: http://www.netlib.org/blas

[blas-sgemv]: https://www.netlib.org/lapack/explore-html/d7/dda/group__gemv_ga0d35d880b663ad18204bb23bd186e380.html#ga0d35d880b663ad18204bb23bd186e380
[blas-sgemv]: https://www.netlib.org/lapack/explore-html-3.6.1/d6/d30/group__single__blas__level2_gafc92361b74c6d41c7e5afa0aa5d13ec9.html

[mdn-float32array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array

Expand Down
10 changes: 5 additions & 5 deletions lib/node_modules/@stdlib/blas/base/sgemv/benchmark/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var options = {
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} N - array dimension size
* @param {PositiveInteger} N - array length
* @returns {Function} benchmark function
*/
function createBenchmark( N ) {
Expand Down Expand Up @@ -86,19 +86,19 @@ function createBenchmark( N ) {
* @private
*/
function main() {
var len;
var min;
var max;
var N;
var f;
var i;

min = 1; // 10^min
max = 6; // 10^max

for ( i = min; i <= max; i++ ) {
len = floor( pow( pow( 10, i ), 1.0/2.0 ) );
f = createBenchmark( len );
bench( pkg+':size='+(len*len), f );
N = floor( pow( pow( 10, i ), 1.0/2.0 ) );
f = createBenchmark( N );
bench( pkg+':size='+(N*N), f );
}
}

Expand Down
104 changes: 104 additions & 0 deletions lib/node_modules/@stdlib/blas/base/sgemv/benchmark/benchmark.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2025 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var uniform = require( '@stdlib/random/array/uniform' );
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var pow = require( '@stdlib/math/base/special/pow' );
var floor = require( '@stdlib/math/base/special/floor' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;


// VARIABLES //

var sgemv = tryRequire( resolve( __dirname, './../lib/sgemv.native.js' ) );
var opts = {
'skip': ( sgemv instanceof Error )
};
var options = {
'dtype': 'float32'
};


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} N - array length
* @returns {Function} benchmark function
*/
function createBenchmark( N ) {
var x = uniform( N, -10.0, 10.0, options );
var y = uniform( N, -10.0, 10.0, options );
var A = uniform( N*N, -10.0, 10.0, options );
return benchmark;

function benchmark( b ) {
var z;
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
z = sgemv( 'row-major', 'no-transpose', N, N, 1.0, A, N, x, 1, 1.0, y, 1 );
if ( isnanf( z ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnanf( z ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
}
}


// MAIN //

/**
* Main execution sequence.
*
* @private
*/
function main() {
var min;
var max;
var N;
var f;
var i;

min = 1; // 10^min
max = 6; // 10^max

for ( i = min; i <= max; i++ ) {
N = floor( pow( pow( 10, i ), 1.0/2.0 ) );
f = createBenchmark( N );
bench( pkg+'::native:size='+(N*N), opts, f );
}
}

main();
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

/**
* @license Apache-2.0
*
Expand Down Expand Up @@ -42,7 +43,7 @@ var options = {
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} N - array dimension size
* @param {PositiveInteger} N - array length
* @returns {Function} benchmark function
*/
function createBenchmark( N ) {
Expand Down Expand Up @@ -86,19 +87,19 @@ function createBenchmark( N ) {
* @private
*/
function main() {
var len;
var min;
var max;
var N;
var f;
var i;

min = 1; // 10^min
max = 6; // 10^max

for ( i = min; i <= max; i++ ) {
len = floor( pow( pow( 10, i ), 1.0/2.0 ) );
f = createBenchmark( len );
bench( pkg+':ndarray:size='+(len*len), f );
N = floor( pow( pow( 10, i ), 1.0/2.0 ) );
f = createBenchmark( N );
bench( pkg+':ndarray:size='+(N*N), f );
}
}

Expand Down
Loading