Skip to content

feat: add c implementation for blas/base/strmv #7017

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

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
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
89 changes: 82 additions & 7 deletions lib/node_modules/@stdlib/blas/base/strmv/README.md
Original file line number Diff line number Diff line change
@@ -86,6 +86,8 @@ strmv( 'row-major', 'upper', 'no-transpose', 'unit', 3, A, 3, x1, 1 );
// x0 => <Float32Array>[ 1.0, 6.0, 3.0, 1.0 ]
```

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

#### strmv.ndarray( uplo, trans, diag, N, A, sa1, sa2, oa, x, sx, ox )

Performs one of the matrix-vector operations `x = A*x` or `x = A^T*x`, using alternative indexing semantics and where `x` is an `N` element vector and `A` is an `N` by `N` unit, or non-unit, upper or lower triangular matrix.
@@ -186,21 +188,67 @@ console.log( x );
### Usage

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

#### c_strmv( order, uplo, trans, diag, N, \*A, LDA, \*X, strideX )

Performs one of the matrix-vector operations `x = A*x` or `x = A^T*x`, where `x` is an `N` element vector and `A` is an `N` by `N` unit, or non-unit, upper or lower triangular matrix.

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

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

c_strmv( CblasRowMajor, CblasUpper, CblasNoTrans, CblasUnit, 3, A, 3, x, 1 );
```

#### TODO
The function accepts the following arguments:

TODO.
- **order**: `[in] CBLAS_LAYOUT` storage layout.
- **uplo**: `[in] CBLAS_UPLO` specifies whether `A` is an upper or lower triangular matrix.
- **trans**: `[in] CBLAS_TRANSPOSE` specifies whether `A` should be transposed, conjugate-transposed, or not transposed.
- **diag**: `[in] CBLAS_DIAG` specifies whether `A` has a unit diagonal.
- **N**: `[in] CBLAS_INT` number of elements along each dimension of `A`.
- **A**: `[inout] 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*` input vector.
- **strideX**: `[in] CBLAS_INT` index increment for `X`.

```c
TODO
void c_strmv( const CBLAS_LAYOUT order, const CBLAS_UPLO uplo, const CBLAS_TRANSPOSE trans, const CBLAS_DIAG diag, const CBLAS_INT N, const float *A, const CBLAS_INT LDA, float *x, const CBLAS_INT strideX )
```

TODO
#### c_strmv_ndarray( uplo, trans, diag, N, \*A, strideA1, strideA2, offsetA, \*X, strideX, offsetA )

Performs one of the matrix-vector operations `x = A*x` or `x = A^T*x` using alternative indexing semantics, where `x` is an `N` element vector and `A` is an `N` by `N` unit, or non-unit, upper or lower triangular matrix.

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

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

c_strmv_ndarray( CblasUpper, CblasNoTrans, CblasUnit, 3, A, 3, 1, 0, x, 1, 0 );
```

The function accepts the following arguments:

- **uplo**: `[in] CBLAS_UPLO` specifies whether `A` is an upper or lower triangular matrix.
- **trans**: `[in] CBLAS_TRANSPOSE` specifies whether `A` should be transposed, conjugate-transposed, or not transposed.
- **diag**: `[in] CBLAS_DIAG` specifies whether `A` has a unit diagonal.
- **N**: `[in] CBLAS_INT` number of elements along each dimension of `A`.
- **A**: `[inout] float*` input matrix.
- **strideA1**: `[in] CBLAS_INT` stride of the first dimension of `A`.
- **strideA2**: `[in] CBLAS_INT` stride of the second dimension of `A`.
- **offsetA**: `[in] CBLAS_INT` starting index for `A`.
- **X**: `[in] float*` input vector.
- **strideX**: `[in] CBLAS_INT` index increment for `X`.
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.

```c
TODO
void c_strmv_ndarray( const CBLAS_UPLO uplo, const CBLAS_TRANSPOSE trans, const CBLAS_DIAG diag, const CBLAS_INT N, const float *A, const CBLAS_INT strideA1, const CBLAS_INT strideA2, const CBLAS_INT offsetA, float *x, const CBLAS_INT strideX, const CBLAS_INT offsetX )
```

</section>
@@ -222,7 +270,34 @@ TODO
### Examples

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

int main( void ) {
// Create a strided array:
const float A[] = { 1.0f, 2.0f, 3.0f, 0.0f, 1.0f, 2.0f, 0.0f, 0.0f, 1.0f };
float x[] = { 1.0f, 2.0f, 3.0f };

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

// Perform the matrix-vector operations `y = α*A*x + β*y`:
c_strmv( CblasRowMajor, CblasUpper, CblasNoTrans, CblasUnit, N, A, N, x, 1 );

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

// Perform the symmetric rank 2 operation `A = α*x*y^T + α*y*x^T + A`:
c_strmv_ndarray( CblasUpper, CblasNoTrans, CblasUnit, 3, A, 3, 1, 0, x, 1, 0 );

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

</section>
103 changes: 103 additions & 0 deletions lib/node_modules/@stdlib/blas/base/strmv/benchmark/benchmark.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/**
* @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 isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var ones = require( '@stdlib/array/ones' );
var pow = require( '@stdlib/math/base/special/pow' );
var floorf = require( '@stdlib/math/base/special/floorf' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;


// VARIABLES //

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


// FUNCTIONS //

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

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

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
z = strmv( 'row-major', 'upper', 'transpose', 'non-unit', len, A, len, x, 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 len;
var f;
var i;

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

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

main();
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/**
* @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 isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var ones = require( '@stdlib/array/ones' );
var pow = require( '@stdlib/math/base/special/pow' );
var floorf = require( '@stdlib/math/base/special/floorf' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;


// VARIABLES //

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


// FUNCTIONS //

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

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

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
z = strmv( 'upper', 'transpose', 'non-unit', len, A, len, 1, 0, x, 1, 0 );
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 len;
var f;
var i;

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

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

main();
147 changes: 147 additions & 0 deletions lib/node_modules/@stdlib/blas/base/strmv/benchmark/c/Makefile
265 changes: 265 additions & 0 deletions lib/node_modules/@stdlib/blas/base/strmv/binding.gyp
146 changes: 146 additions & 0 deletions lib/node_modules/@stdlib/blas/base/strmv/examples/c/Makefile
46 changes: 46 additions & 0 deletions lib/node_modules/@stdlib/blas/base/strmv/examples/c/example.c
70 changes: 70 additions & 0 deletions lib/node_modules/@stdlib/blas/base/strmv/include.gypi
35 changes: 35 additions & 0 deletions lib/node_modules/@stdlib/blas/base/strmv/lib/native.js
64 changes: 64 additions & 0 deletions lib/node_modules/@stdlib/blas/base/strmv/lib/ndarray.native.js
63 changes: 63 additions & 0 deletions lib/node_modules/@stdlib/blas/base/strmv/lib/strmv.native.js
487 changes: 487 additions & 0 deletions lib/node_modules/@stdlib/blas/base/strmv/manifest.json

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions lib/node_modules/@stdlib/blas/base/strmv/package.json
70 changes: 70 additions & 0 deletions lib/node_modules/@stdlib/blas/base/strmv/src/Makefile
96 changes: 96 additions & 0 deletions lib/node_modules/@stdlib/blas/base/strmv/src/addon.c
52 changes: 52 additions & 0 deletions lib/node_modules/@stdlib/blas/base/strmv/src/strmv.c
74 changes: 74 additions & 0 deletions lib/node_modules/@stdlib/blas/base/strmv/src/strmv_cblas.c
153 changes: 153 additions & 0 deletions lib/node_modules/@stdlib/blas/base/strmv/src/strmv_ndarray.c
818 changes: 818 additions & 0 deletions lib/node_modules/@stdlib/blas/base/strmv/test/test.ndarray.native.js

Large diffs are not rendered by default.

555 changes: 555 additions & 0 deletions lib/node_modules/@stdlib/blas/base/strmv/test/test.strmv.native.js

Large diffs are not rendered by default.