Skip to content

feat: add c implementation for blas/base/dgemv #7013

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

Merged
merged 56 commits into from
Jun 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
26fc04d
feat: add c implementation for blas/base/dgemv
ShabiShett07 May 16, 2025
2d93fce
chore: update examples
ShabiShett07 May 16, 2025
f668d26
chore: update manifest.json
ShabiShett07 May 16, 2025
c3bcf01
chore: update header file
ShabiShett07 May 16, 2025
4be825f
chore: update packagae
ShabiShett07 May 16, 2025
4f8c591
chore: rename benchmark.ndarray.native.js
ShabiShett07 May 16, 2025
b612864
chore: minor clean-up
ShabiShett07 May 16, 2025
04df633
chore: minor clean-up
ShabiShett07 May 16, 2025
4d25c0a
chore: minor clean-up
ShabiShett07 May 16, 2025
2f68589
chore: remove whitespace
ShabiShett07 May 16, 2025
3bbc9a9
chore: minor clean-up
ShabiShett07 May 16, 2025
99586e8
chore: minor clean-up
ShabiShett07 May 16, 2025
6bd1361
chore: minor clean-up
ShabiShett07 May 16, 2025
27f075f
chore: function name
ShabiShett07 May 16, 2025
df9d395
chore: update function name
ShabiShett07 May 16, 2025
0620efe
chore: update parameter naming
ShabiShett07 May 16, 2025
3e84f80
chore: update parameter naming
ShabiShett07 May 16, 2025
138b53c
chore: update example
ShabiShett07 May 16, 2025
9e88a43
chore: update implementation
ShabiShett07 May 31, 2025
c9b4c4a
chore: minor clean-up
ShabiShett07 May 31, 2025
5d43034
chore: minor clean-up
ShabiShett07 May 31, 2025
4612b0e
chore: minor clean-up
ShabiShett07 May 31, 2025
7ba0869
chore: minor clean-up
ShabiShett07 May 31, 2025
e2f8320
chore: update implementation
ShabiShett07 Jun 27, 2025
f34d2f7
chore: update implementation
ShabiShett07 Jun 27, 2025
d91164a
chore: update implementation
ShabiShett07 Jun 27, 2025
bc7227e
chore: clean-up
ShabiShett07 Jun 27, 2025
a2ee0c5
chore: clean-up
ShabiShett07 Jun 27, 2025
703782f
chore: minor clean-up
ShabiShett07 Jun 28, 2025
c2eaf9e
chore: minor clean-up
ShabiShett07 Jun 28, 2025
1750255
chore: minor clean-up
ShabiShett07 Jun 28, 2025
a0fb7e0
chore: minor clean-up
ShabiShett07 Jun 28, 2025
e6032e9
chore: minor clean-up
ShabiShett07 Jun 28, 2025
d71215a
chore: minor clean-up
ShabiShett07 Jun 28, 2025
ff513b9
chore: minor clean-up
ShabiShett07 Jun 28, 2025
229c7bc
chore: minor clean-up
ShabiShett07 Jun 28, 2025
daf7633
chore: minor clean-up
ShabiShett07 Jun 28, 2025
0d98567
chore: minor clean-up
ShabiShett07 Jun 28, 2025
d4574d9
chore: minor clean-up
ShabiShett07 Jun 28, 2025
40e55f5
chore: add checks
ShabiShett07 Jun 28, 2025
e62310c
chore: minor clean-up
ShabiShett07 Jun 28, 2025
02979c0
refactor: eliminate multiplications
kgryte Jun 29, 2025
e729b32
chore: clean-up
kgryte Jun 29, 2025
9bc72e9
fix: use correct return value
kgryte Jun 29, 2025
abf1ac5
fix: add missing commas
kgryte Jun 29, 2025
30d7b4b
test: add argument validation tests
kgryte Jun 29, 2025
844b8ce
fix: update variable name
kgryte Jun 29, 2025
e26ad21
refactor: rename parameter
kgryte Jun 29, 2025
b0f076e
Merge remote-tracking branch 'upstream/develop' into feature/c/dgemv
stdlib-bot Jun 29, 2025
579ea3f
fix: remove duplicate import
kgryte Jun 29, 2025
14e8744
fix: remove duplicate check
kgryte Jun 29, 2025
b9d086e
chore: add test cases
ShabiShett07 Jun 29, 2025
67a1f53
chore: add test cases
ShabiShett07 Jun 29, 2025
4dfca99
chore: add test cases
ShabiShett07 Jun 29, 2025
90db3ae
chore: clean-up
ShabiShett07 Jun 29, 2025
9471d77
test: update tests and add fixtures
kgryte Jun 30, 2025
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
112 changes: 102 additions & 10 deletions lib/node_modules/@stdlib/blas/base/dgemv/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ limitations under the License.
var dgemv = require( '@stdlib/blas/base/dgemv' );
```

#### dgemv( ord, trans, M, N, α, A, LDA, x, sx, β, y, sy )
#### dgemv( 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.

Expand All @@ -47,18 +47,18 @@ dgemv( '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 [`Float64Array`][mdn-float64array].
- **lda**: stride of the first dimension of `A` (leading dimension of `A`).
- **x**: input [`Float64Array`][mdn-float64array].
- **sx**: index increment for `x`.
- **sx**: stride length for `x`.
- **β**: scalar constant.
- **y**: output [`Float64Array`][mdn-float64array].
- **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,6 +93,8 @@ dgemv( 'row-major', 'no-transpose', 2, 2, 1.0, A, 2, x1, -1, 1.0, y1, -1 );
// y0 => <Float64Array>[ 0.0, 8.0, 4.0 ]
```

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

#### dgemv.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.
Expand Down Expand Up @@ -199,18 +201,73 @@ console.log( y );
#include "stdlib/blas/base/dgemv.h"
```

#### TODO
#### c_dgemv( 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 double A[] = { 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 3.0, 2.0, 1.0 };
const double x[] = { 1.0, 2.0, 3.0 };
double y[] = { 1.0, 2.0, 3.0 };

c_dgemv( CblasColMajor, CblasNoTrans, 3, 3, 1.0, A, 3, x, 1, 1.0, 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] double` scalar constant.
- **A**: `[in] double*` input matrix.
- **LDA**: `[in] CBLAS_INT` stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`).
- **X**: `[in] double*` first input vector.
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
- **beta**: `[in] double` scalar constant.
- **Y**: `[inout] double*` second input vector.
- **strideY**: `[in] CBLAS_INT` stride length for `Y`.

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

#### c_dgemv_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 double A[] = { 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 3.0, 2.0, 1.0 };
const double x[] = { 1.0, 2.0, 3.0 };
double y[] = { 1.0, 2.0, 3.0 };

c_dgemv_ndarray( CblasNoTrans, 3, 3, 1.0, A, 1, 3, 0, x, 1, 0, 1.0, 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] double` scalar.
- **A**: `[in] double*` 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] double*` first input vector.
- **sx**: `[in] CBLAS_INT` stride length for `X`.
- **ox**: `[in] CBLAS_INT` starting index for `X`.
- **beta**: `[in] double` scalar.
- **Y**: `[inout] double*` second input vector.
- **sy**: `[in] CBLAS_INT` stride length for `Y`.
- **oy**: `[in] CBLAS_INT` starting index for `Y`.

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

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

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

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

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

// 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_dgemv( CblasRowMajor, CblasNoTrans, M, N, 1.0, A, M, 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_dgemv_ndarray( CblasNoTrans, M, N, 1.0, A, N, 1, 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 ] );
}
}
```

</section>
Expand Down
Original file line number Diff line number Diff line change
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/dgemv/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 isnan = require( '@stdlib/math/base/assert/is-nan' );
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 dgemv = tryRequire( resolve( __dirname, './../lib/dgemv.native.js' ) );
var opts = {
'skip': ( dgemv instanceof Error )
};
var options = {
'dtype': 'float64'
};


// 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 = dgemv( 'row-major', 'no-transpose', N, N, 1.0, A, N, x, 1, 1.0, y, 1 );
if ( isnan( z ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( 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
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+':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