Skip to content

Commit

Permalink
Auto-generated commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stdlib-bot committed Sep 18, 2024
1 parent e65e142 commit d4c94d2
Show file tree
Hide file tree
Showing 13 changed files with 459 additions and 88 deletions.
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,28 @@

<!-- /.package -->

<section class="package" id="blas-base-sdot-unreleased">

#### [@stdlib/blas/base/sdot](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/base/sdot)

<details>

<section class="features">

##### Features

- [`2bedae9`](https://github.com/stdlib-js/stdlib/commit/2bedae91dbdd0080b38ae0413f5e8f26b88db95b) - add C `ndarray` implementation for `blas/base/sdot` [(#2919)](https://github.com/stdlib-js/stdlib/pull/2919)

</section>

<!-- /.features -->

</details>

</section>

<!-- /.package -->

<section class="package" id="blas-base-sspr-unreleased">

#### [@stdlib/blas/base/sspr](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/base/sspr)
Expand Down Expand Up @@ -471,6 +493,7 @@ A total of 6 people contributed to this release. Thank you to the following cont

<details>

- [`2bedae9`](https://github.com/stdlib-js/stdlib/commit/2bedae91dbdd0080b38ae0413f5e8f26b88db95b) - **feat:** add C `ndarray` implementation for `blas/base/sdot` [(#2919)](https://github.com/stdlib-js/stdlib/pull/2919) _(by Aman Bhansali, Athan Reines)_
- [`e85f394`](https://github.com/stdlib-js/stdlib/commit/e85f3947aaca3cbbd6ab4f84e41577928e0a10a4) - **feat:** add C `ndarray` implementation for `blas/base/saxpy` [(#2918)](https://github.com/stdlib-js/stdlib/pull/2918) _(by Aman Bhansali)_
- [`6ae1c10`](https://github.com/stdlib-js/stdlib/commit/6ae1c10d70d86520a0c915864440ef6e8d255a21) - **docs:** rename parameter _(by Athan Reines)_
- [`7eb1266`](https://github.com/stdlib-js/stdlib/commit/7eb12667e2052db9fc1e678bf0cc2082e2993aec) - **docs:** rename parameters _(by Athan Reines)_
Expand Down
132 changes: 132 additions & 0 deletions base/sdot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,138 @@ 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/sdot.h"
```

#### c_sdot( N, \*X, strideX, \*Y, strideY )

Computes the dot product of two single-precision floating-point vectors.

```c
const float x[] = { 4.0f, 2.0f, -3.0f, 5.0f, -1.0f };
const float y[] = { 2.0f, 6.0f, -1.0f, -4.0f, 8.0f };

float d = c_sdot( 5, x, 1, y, 1 );
// returns -5.0f
```
The function accepts the following arguments:
- **N**: `[in] CBLAS_INT` number of indexed elements.
- **X**: `[in] float*` first input array.
- **strideX**: `[in] CBLAS_INT` index increment for `X`.
- **Y**: `[in] float*` second input array.
- **strideY**: `[in] CBLAS_INT` index increment for `Y`.
```c
float c_sdot( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const float *Y, const CBLAS_INT strideY );
```

#### c_sdot_ndarray( N, \*X, strideX, offsetX, \*Y, strideY, offsetY )

Computes the dot product of two single-precision floating-point vectors using alternative indexing semantics.

```c
const float x[] = { 4.0f, 2.0f, -3.0f, 5.0f, -1.0f };
const float y[] = { 2.0f, 6.0f, -1.0f, -4.0f, 8.0f };

float d = c_sdot_ndarray( 3, x, 1, 2, y, 1, 2 );
// returns -25.0f
```
The function accepts the following arguments:
- **N**: `[in] CBLAS_INT` number of indexed elements.
- **X**: `[in] float*` first input array.
- **strideX**: `[in] CBLAS_INT` index increment for `X`.
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
- **Y**: `[in] float*` second input array.
- **strideY**: `[in] CBLAS_INT` index increment for `Y`.
- **offsetY**: `[in] CBLAS_INT` starting index for `Y`.
```c
float c_sdot_ndarray( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const float *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY );
```

</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/sdot.h"
#include <stdio.h>

int main( void ) {
// Create strided arrays:
const float x[] = { 1.0f, -2.0f, 3.0f, -4.0f, 5.0f, -6.0f, 7.0f, -8.0f };
const float y[] = { 1.0f, -2.0f, 3.0f, -4.0f, 5.0f, -6.0f, 7.0f, -8.0f };

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

// Specify strides:
const int strideX = 1;
const int strideY = -1;

// Compute the dot product:
float d = c_sdot( N, x, strideX, y, strideY );

// Print the result:
printf( "dot product: %f\n", d );

// Compute the dot product:
d = c_sdot_ndarray( N, x, strideX, 0, y, strideY, 7 );

// Print the result:
printf( "dot product: %f\n", d );
}
```
</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
46 changes: 44 additions & 2 deletions base/sdot/benchmark/c/benchmark.length.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ static float rand_float( void ) {
* @param len array length
* @return elapsed time in seconds
*/
static double benchmark( int iterations, int len ) {
static double benchmark1( int iterations, int len ) {
double elapsed;
float x[ len ];
float y[ len ];
Expand Down Expand Up @@ -122,6 +122,41 @@ static double benchmark( int iterations, int len ) {
return elapsed;
}

/**
* Runs a benchmark.
*
* @param iterations number of iterations
* @param len array length
* @return elapsed time in seconds
*/
static double benchmark2( int iterations, int len ) {
double elapsed;
float x[ len ];
float y[ len ];
float z;
double t;
int i;

for ( i = 0; i < len; i++ ) {
x[ i ] = ( rand_float()*20000.0f ) - 10000.0f;
y[ i ] = ( rand_float()*20000.0f ) - 10000.0f;
}
z = 0.0f;
t = tic();
for ( i = 0; i < iterations; i++ ) {
z = c_sdot_ndarray( len, x, 1, 0, y, 1, 0 );
if ( z != z ) {
printf( "should not return NaN\n" );
break;
}
}
elapsed = tic() - t;
if ( z != z ) {
printf( "should not return NaN\n" );
}
return elapsed;
}

/**
* Main execution sequence.
*/
Expand All @@ -144,7 +179,14 @@ int main( void ) {
for ( j = 0; j < REPEATS; j++ ) {
count += 1;
printf( "# c::%s:len=%d\n", NAME, len );
elapsed = benchmark( iter, len );
elapsed = benchmark1( iter, len );
print_results( iter, elapsed );
printf( "ok %d benchmark finished\n", count );
}
for ( j = 0; j < REPEATS; j++ ) {
count += 1;
printf( "# c::%s:ndarray:len=%d\n", NAME, len );
elapsed = benchmark2( iter, len );
print_results( iter, elapsed );
printf( "ok %d benchmark finished\n", count );
}
Expand Down
6 changes: 6 additions & 0 deletions base/sdot/examples/c/example.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,10 @@ int main( void ) {

// Print the result:
printf( "dot product: %f\n", d );

// Compute the dot product:
d = c_sdot_ndarray( N, x, strideX, 0, y, strideY, 7 );

// Print the result:
printf( "dot product: %f\n", d );
}
9 changes: 8 additions & 1 deletion base/sdot/include/stdlib/blas/base/sdot.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#ifndef SDOT_H
#define SDOT_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,12 @@ extern "C" {
/**
* Computes the dot product of two single-precision floating-point vectors.
*/
float c_sdot( const int N, const float *X, const int strideX, const float *Y, const int strideY );
float API_SUFFIX(c_sdot)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const float *Y, const CBLAS_INT strideY );

/**
* Computes the dot product of two single-precision floating-point vectors using alternative indexing semantics.
*/
float API_SUFFIX(c_sdot_ndarray)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const float *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY );

#ifdef __cplusplus
}
Expand Down
4 changes: 3 additions & 1 deletion base/sdot/include/stdlib/blas/base/sdot_cblas.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#ifndef SDOT_CBLAS_H
#define SDOT_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 dot product of two single-precision floating-point vectors.
*/
float cblas_sdot( const int N, const float *X, const int strideX, const float *Y, const int strideY );
float API_SUFFIX(cblas_sdot)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const float *Y, const CBLAS_INT strideY );

#ifdef __cplusplus
}
Expand Down
15 changes: 2 additions & 13 deletions base/sdot/lib/ndarray.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@

// MODULES //

var minViewBufferIndex = require( '@stdlib/strided/base/min-view-buffer-index' );
var offsetView = require( '@stdlib/strided/base/offset-view' );
var addon = require( './sdot.native.js' );
var addon = require( './../src/addon.node' );


// MAIN //
Expand All @@ -49,16 +47,7 @@ var addon = require( './sdot.native.js' );
* // returns -5.0
*/
function sdot( N, x, strideX, offsetX, y, strideY, offsetY ) {
var viewX;
var viewY;

offsetX = minViewBufferIndex( N, strideX, offsetX );
offsetY = minViewBufferIndex( N, strideY, offsetY );

viewX = offsetView( x, offsetX );
viewY = offsetView( y, offsetY );

return addon( N, viewX, strideX, viewY, strideY );
return addon.ndarray( N, x, strideX, offsetX, y, strideY, offsetY );
}


Expand Down
Loading

0 comments on commit d4c94d2

Please sign in to comment.