Skip to content

Commit

Permalink
feat: add support for specifying integer size
Browse files Browse the repository at this point in the history
  • Loading branch information
kgryte committed Apr 27, 2024
1 parent 0d7489e commit 34a206e
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 23 deletions.
95 changes: 95 additions & 0 deletions lib/node_modules/@stdlib/blas/base/dnrm2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,101 @@ console.log( out );

<!-- /.examples -->

<!-- C interface documentation. -->

* * *

<section class="c">

## C APIs

<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

<section class="intro">

</section>

<!-- /.intro -->

<!-- C usage documentation. -->

<section class="usage">

### Usage

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

#### c_dnrm2( N, X, stride )

Computes the L2-norm of a double-precision floating-point vector.

```c
const double x[] = { 1.0, -2.0, 2.0 };

double v = c_dnrm2( 3, x, 1 );
// returns 3.0
```
The function accepts the following arguments:
- **N**: `[in] CBLAS_INT` number of indexed elements.
- **X**: `[in] double*` input array.
- **stride**: `[in] CBLAS_INT` index increment for `X`.
```c
double c_dnrm2( const CBLAS_INT N, const double *X, const CBLAS_INT stride );
```

</section>

<!-- /.usage -->

<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="notes">

</section>

<!-- /.notes -->

<!-- C API usage examples. -->

<section class="examples">

### Examples

```c
#include "stdlib/blas/base/dnrm2.h"
#include <stdio.h>

int main( void ) {
// Create a strided array:
const double x[] = { 1.0, -2.0, 3.0, -4.0, 5.0, -6.0, 7.0, -8.0 };

// Specify the number of elements:
const int N = 8;

// Specify a stride:
const int strideX = 1;

// Compute the L2-norm:
double l2 = c_dnrm2( N, x, strideX );

// Print the result:
printf( "L2-norm: %lf\n", l2 );
}
```
</section>
<!-- /.examples -->
</section>
<!-- /.c -->
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
<section class="related">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#ifndef DNRM2_H
#define DNRM2_H

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

/*
* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
*/
Expand All @@ -32,7 +34,7 @@ extern "C" {
/**
* Computes the L2-norm of a double-precision floating-point vector.
*/
double c_dnrm2( const int N, const double *X, const int stride );
double c_dnrm2( const CBLAS_INT N, const double *X, const CBLAS_INT stride );

#ifdef __cplusplus
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#ifndef DNRM2_CBLAS_H
#define DNRM2_CBLAS_H

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

/*
* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
*/
Expand All @@ -32,7 +34,7 @@ extern "C" {
/**
* Computes the L2-norm of a double-precision floating-point vector.
*/
double cblas_dnrm2( const int N, const double *X, const int stride );
double cblas_dnrm2( const CBLAS_INT N, const double *X, const CBLAS_INT stride );

#ifdef __cplusplus
}
Expand Down
76 changes: 62 additions & 14 deletions lib/node_modules/@stdlib/blas/base/dnrm2/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"libraries": [],
"libpath": [],
"dependencies": [
"@stdlib/blas/base/shared",
"@stdlib/napi/export",
"@stdlib/napi/argv",
"@stdlib/napi/argv-int64",
Expand All @@ -66,7 +67,11 @@
"-lm"
],
"libpath": [],
"dependencies": []
"dependencies": [
"@stdlib/blas/base/shared",
"@stdlib/math/base/special/abs",
"@stdlib/math/base/special/sqrt"
]
},
{
"task": "examples",
Expand All @@ -83,7 +88,11 @@
"-lm"
],
"libpath": [],
"dependencies": []
"dependencies": [
"@stdlib/blas/base/shared",
"@stdlib/math/base/special/abs",
"@stdlib/math/base/special/sqrt"
]
},

{
Expand All @@ -103,6 +112,7 @@
],
"libpath": [],
"dependencies": [
"@stdlib/blas/base/shared",
"@stdlib/napi/export",
"@stdlib/napi/argv",
"@stdlib/napi/argv-int64",
Expand All @@ -126,7 +136,9 @@
"-lpthread"
],
"libpath": [],
"dependencies": []
"dependencies": [
"@stdlib/blas/base/shared"
]
},
{
"task": "examples",
Expand All @@ -144,7 +156,9 @@
"-lpthread"
],
"libpath": [],
"dependencies": []
"dependencies": [
"@stdlib/blas/base/shared"
]
},

{
Expand All @@ -163,6 +177,7 @@
"libraries": [],
"libpath": [],
"dependencies": [
"@stdlib/blas/base/shared",
"@stdlib/napi/export",
"@stdlib/napi/argv",
"@stdlib/napi/argv-int64",
Expand All @@ -185,7 +200,11 @@
"-lm"
],
"libpath": [],
"dependencies": []
"dependencies": [
"@stdlib/blas/base/shared",
"@stdlib/math/base/special/abs",
"@stdlib/math/base/special/sqrt"
]
},
{
"task": "examples",
Expand All @@ -202,7 +221,11 @@
"-lm"
],
"libpath": [],
"dependencies": []
"dependencies": [
"@stdlib/blas/base/shared",
"@stdlib/math/base/special/abs",
"@stdlib/math/base/special/sqrt"
]
},

{
Expand All @@ -221,6 +244,7 @@
],
"libpath": [],
"dependencies": [
"@stdlib/blas/base/shared",
"@stdlib/napi/export",
"@stdlib/napi/argv",
"@stdlib/napi/argv-int64",
Expand All @@ -243,7 +267,9 @@
"-lblas"
],
"libpath": [],
"dependencies": []
"dependencies": [
"@stdlib/blas/base/shared"
]
},
{
"task": "examples",
Expand All @@ -260,7 +286,9 @@
"-lblas"
],
"libpath": [],
"dependencies": []
"dependencies": [
"@stdlib/blas/base/shared"
]
},

{
Expand All @@ -280,6 +308,7 @@
],
"libpath": [],
"dependencies": [
"@stdlib/blas/base/shared",
"@stdlib/napi/export",
"@stdlib/napi/argv",
"@stdlib/napi/argv-int64",
Expand All @@ -303,7 +332,9 @@
"-lpthread"
],
"libpath": [],
"dependencies": []
"dependencies": [
"@stdlib/blas/base/shared"
]
},
{
"task": "examples",
Expand All @@ -321,7 +352,9 @@
"-lpthread"
],
"libpath": [],
"dependencies": []
"dependencies": [
"@stdlib/blas/base/shared"
]
},

{
Expand All @@ -340,11 +373,14 @@
],
"libpath": [],
"dependencies": [
"@stdlib/blas/base/shared",
"@stdlib/napi/export",
"@stdlib/napi/argv",
"@stdlib/napi/argv-int64",
"@stdlib/napi/argv-strided-float64array",
"@stdlib/napi/create-double"
"@stdlib/napi/create-double",
"@stdlib/math/base/special/abs",
"@stdlib/math/base/special/sqrt"
]
},
{
Expand All @@ -362,7 +398,11 @@
"-lm"
],
"libpath": [],
"dependencies": []
"dependencies": [
"@stdlib/blas/base/shared",
"@stdlib/math/base/special/abs",
"@stdlib/math/base/special/sqrt"
]
},
{
"task": "examples",
Expand All @@ -379,7 +419,11 @@
"-lm"
],
"libpath": [],
"dependencies": []
"dependencies": [
"@stdlib/blas/base/shared",
"@stdlib/math/base/special/abs",
"@stdlib/math/base/special/sqrt"
]
},

{
Expand All @@ -397,7 +441,11 @@
"-lm"
],
"libpath": [],
"dependencies": []
"dependencies": [
"@stdlib/blas/base/shared",
"@stdlib/math/base/special/abs",
"@stdlib/math/base/special/sqrt"
]
}
]
}
13 changes: 8 additions & 5 deletions lib/node_modules/@stdlib/blas/base/dnrm2/src/dnrm2.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
*/

#include "stdlib/blas/base/dnrm2.h"
#include "stdlib/blas/base/shared.h"
#include "stdlib/math/base/special/abs.h"
#include "stdlib/math/base/special/sqrt.h"
#include <math.h>

/**
Expand All @@ -27,23 +30,23 @@
* @param stride stride length
* @return L2-norm
*/
double c_dnrm2( const int N, const double *X, const int stride ) {
double c_dnrm2( const CBLAS_INT N, const double *X, const CBLAS_INT stride ) {
double scale;
double ssq;
double ax;
int i;
CBLAS_INT i;

if ( N <= 0 || stride <= 0 ) {
return 0.0;
}
if ( N == 1 ) {
return fabs( X[ 0 ] );
return stdlib_base_abs( X[ 0 ] );
}
scale = 0.0;
ssq = 1.0;
for ( i = 0; i < N*stride; i += stride ) {
if ( X[ i ] != 0.0 ) {
ax = fabs( X[ i ] );
ax = stdlib_base_abs( X[ i ] );
if ( scale < ax ) {
ssq = 1.0 + ( ssq * pow( scale/ax, 2 ) );
scale = ax;
Expand All @@ -52,5 +55,5 @@ double c_dnrm2( const int N, const double *X, const int stride ) {
}
}
}
return scale * sqrt( ssq );
return scale * stdlib_base_sqrt( ssq );
}
Loading

1 comment on commit 34a206e

@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/ddot $\color{green}454/454$
$\color{green}+100.00\%$
$\color{green}45/45$
$\color{green}+100.00\%$
$\color{green}4/4$
$\color{green}+100.00\%$
$\color{green}454/454$
$\color{green}+100.00\%$
blas/base/dnrm2 $\color{green}408/408$
$\color{green}+100.00\%$
$\color{green}32/32$
$\color{green}+100.00\%$
$\color{green}4/4$
$\color{green}+100.00\%$
$\color{green}408/408$
$\color{green}+100.00\%$

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

Please sign in to comment.