Skip to content

feat: add c implementation for blas/base/dtrmv #7016

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 24 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4cdad25
feat: add c implementation for blas/base/dtrmv
ShabiShett07 May 16, 2025
54a5c4e
chore: update implementation
ShabiShett07 May 31, 2025
af2a38e
chore: minor clean-up
ShabiShett07 Jun 30, 2025
243b10a
chore: remove unused package
ShabiShett07 Jun 30, 2025
9d8bc50
chore: update copyright years
stdlib-bot Jun 30, 2025
f94d43c
chore: minor clean-up
ShabiShett07 Jun 30, 2025
4c46c37
chore: minor clean-up
ShabiShett07 Jun 30, 2025
b793780
Merge remote-tracking branch 'upstream/develop' into feature/c/dtrmv
stdlib-bot Jun 30, 2025
fe6deb9
chore: remove unused package
ShabiShett07 Jun 30, 2025
5ca0392
chore: minor clean-up
ShabiShett07 Jun 30, 2025
dc4574a
chore: add correct variable
ShabiShett07 Jun 30, 2025
9e3723b
chore: minor clean-up
ShabiShett07 Jun 30, 2025
602fae7
chore: minor clean-up
ShabiShett07 Jun 30, 2025
4e8ace2
chore: update markdown
ShabiShett07 Jun 30, 2025
01de8bc
chore: update implementation
ShabiShett07 Jun 30, 2025
ee87bad
chore: update implementation
ShabiShett07 Jun 30, 2025
a40d428
chore: minor clean-up
ShabiShett07 Jun 30, 2025
45d1c4e
chore: clean-up
ShabiShett07 Jun 30, 2025
613dc97
chore: minor clean-up
ShabiShett07 Jun 30, 2025
8587b9e
chore: update variable name
ShabiShett07 Jun 30, 2025
d17b829
chore: add appropriate comments for example
ShabiShett07 Jul 4, 2025
dfd24f4
chore: change comment
ShabiShett07 Jul 4, 2025
573b3c8
chore: add proper indentation
ShabiShett07 Jul 4, 2025
f98b52b
fix: add appropriate package name
ShabiShett07 Jul 4, 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
92 changes: 85 additions & 7 deletions lib/node_modules/@stdlib/blas/base/dtrmv/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,21 +186,67 @@ console.log( x );
### Usage

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

#### TODO
#### c_dtrmv( order, uplo, trans, diag, N, \*A, LDA, \*X, sx )

TODO.
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"

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

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

The function accepts the following arguments:

- **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**: `[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**: `[inout] double*` input vector.
- **sx**: `[in] CBLAS_INT` stride length for `X`.

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

TODO
#### c_dtrmv_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, 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"

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

c_dtrmv_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**: `[in] double*` 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**: `[inout] double*` input vector.
- **sx**: `[in] CBLAS_INT` stride length for `X`.
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.

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

</section>
Expand All @@ -222,7 +268,39 @@ TODO
### Examples

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

int main( void ) {
// Define a 3x3 triangular matrix stored in row-major order:
const double A[ 3*3 ] = {
1.0, 0.0, 0.0,
2.0, 1.0, 0.0,
3.0, 2.0, 1.0
};
// Define `x` vector:
double x[ 3 ] = { 1.0, 2.0, 3.0 };

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

// Perform the matrix-vector operations `x = A*x`:
c_dtrmv( 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 matrix-vector operations `x = A*x` using alternative indexing semantics:
c_dtrmv_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>
Expand Down
103 changes: 103 additions & 0 deletions lib/node_modules/@stdlib/blas/base/dtrmv/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 isnan = require( '@stdlib/math/base/assert/is-nan' );
var ones = require( '@stdlib/array/ones' );
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 dtrmv = tryRequire( resolve( __dirname, './../lib/dtrmv.native.js' ) );
var opts = {
'skip': ( dtrmv 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 = ones( N, options.dtype );
var A = ones( N*N, options.dtype );
return benchmark;

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

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
z = dtrmv( 'row-major', 'upper', 'transpose', 'non-unit', N, A, N, x, 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
@@ -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 isnan = require( '@stdlib/math/base/assert/is-nan' );
var ones = require( '@stdlib/array/ones' );
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/ndarray.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 = ones( N, options.dtype );
var A = ones( N*N, options.dtype );
return benchmark;

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

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
z = dgemv( 'upper', 'transpose', 'non-unit', N, A, N, 1, 0, x, 1, 0 );
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:ndarray:size='+(N*N), opts, f );
}
}

main();
Loading