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 cebb352 commit 3fe9721
Show file tree
Hide file tree
Showing 16 changed files with 471 additions and 99 deletions.
1 change: 0 additions & 1 deletion .github/.keepalive

This file was deleted.

16 changes: 14 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,25 @@
<section class="release" id="unreleased">

## Unreleased (2024-09-01)
## Unreleased (2024-09-18)

<section class="features">

### Features

- [`f7edbe0`](https://github.com/stdlib-js/stdlib/commit/f7edbe044289b877586d0140467cb43cdfd18c19) - add C `ndarray` implementation for `blas/base/sdsdot` [(#2921)](https://github.com/stdlib-js/stdlib/pull/2921)

</section>

<!-- /.features -->

<section class="commits">

### Commits

<details>

- [`f7edbe0`](https://github.com/stdlib-js/stdlib/commit/f7edbe044289b877586d0140467cb43cdfd18c19) - **feat:** add C `ndarray` implementation for `blas/base/sdsdot` [(#2921)](https://github.com/stdlib-js/stdlib/pull/2921) _(by Aman Bhansali, Athan Reines)_
- [`2777e4b`](https://github.com/stdlib-js/stdlib/commit/2777e4be161869d09406e3b17947d24c64b47af2) - **bench:** resolve lint errors in benchmarks _(by Athan Reines)_

</details>
Expand All @@ -24,8 +35,9 @@

### Contributors

A total of 1 person contributed to this release. Thank you to this contributor:
A total of 2 people contributed to this release. Thank you to the following contributors:

- Aman Bhansali
- Athan Reines

</section>
Expand Down
7 changes: 7 additions & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#
# Contributors listed in alphabetical order.

Aayush Khanna <96649223+aayush0325@users.noreply.github.com>
Adarsh Palaskar <adarshpalaskar99@gmail.com>
Aditya Sapra <adityaework@gmail.com>
AgPriyanshu18 <113460573+AgPriyanshu18@users.noreply.github.com>
Expand All @@ -26,17 +27,20 @@ EuniceSim142 <77243938+EuniceSim142@users.noreply.github.com>
Frank Kovacs <fran70kk@gmail.com>
Golden Kumar <103646877+AuenKr@users.noreply.github.com>
Gunj Joshi <gunjjoshi8372@gmail.com>
HarshaNP <96897754+GittyHarsha@users.noreply.github.com>
Harshita Kalani <harshitakalani02@gmail.com>
Hridyanshu <124202756+HRIDYANSHU054@users.noreply.github.com>
Jaimin Godhani <112328542+Jai0401@users.noreply.github.com>
James Gelok <jdgelok@gmail.com>
Jaysukh Makvana <jaysukhmakvana2004@gmail.com>
Jenish Thapa <141203631+jenish-thapa@users.noreply.github.com>
Jithin KS <jithinks112@gmail.com>
Joel Mathew Koshy <joelmathewkoshy@gmail.com>
Joey Reed <joeyrreed@gmail.com>
Jordan Gallivan <115050475+Jordan-Gallivan@users.noreply.github.com>
Joris Labie <joris.labie1@gmail.com>
Justin Dennison <justin1dennison@gmail.com>
Kaif Mohd <mdkaifprofession@gmail.com>
Karthik Prakash <116057817+skoriop@users.noreply.github.com>
Khaldon <kahmd1444@gmail.com>
Krishnendu Das <86651039+itskdhere@users.noreply.github.com>
Expand Down Expand Up @@ -86,8 +90,10 @@ Stephannie Jiménez Gacha <steff456@hotmail.com>
Suraj kumar <125961509+kumarsuraj212003@users.noreply.github.com>
Tirtadwipa Manunggal <tirtadwipa.manunggal@gmail.com>
Tudor Pagu <104032457+tudor-pagu@users.noreply.github.com>
Tufailahmed Bargir <142114244+Tufailahmed-Bargir@users.noreply.github.com>
Utkarsh <http://utkarsh11105@gmail.com>
Utkarsh Raj <rajutkarsh2505@gmail.com>
Vaibhav Patel <98279986+noobCoderVP@users.noreply.github.com>
Varad Gupta <varadgupta21@gmail.com>
Xiaochuan Ye <tap91624@gmail.com>
Yernar Yergaziyev <yernar.yergaziyev@erg.kz>
Expand All @@ -96,3 +102,4 @@ nishant-s7 <97207366+nishant-s7@users.noreply.github.com>
orimiles5 <97595296+orimiles5@users.noreply.github.com>
rainn <88160429+AmCodesLame@users.noreply.github.com>
rei2hu <reimu@reimu.ws>
yaswanth <116426380+yaswanthkosuru@users.noreply.github.com>
134 changes: 134 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,140 @@ 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/sdsdot.h"
```

#### c_sdsdot( N, scalar, \*X, strideX, \*Y, strideY )

Calculates the dot product of vectors `x` and `y` with extended accumulation.

```c
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 };

float v = c_sdsdot( 5, 0.0f, x, 1, y, -1 );
// returns -120.0f
```
The function accepts the following arguments:
- **N**: `[in] CBLAS_INT` number of indexed elements.
- **scalar**: `[in] float` scalar constant to add to dot product.
- **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_sdsdot( const CBLAS_INT N, const float scalar, const float *X, const CBLAS_INT strideX, const float *Y, const CBLAS_INT strideY );
```

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

Calculates the dot product of vectors `x` and `y` with extended accumulation using alternative indexing semantics.

```c
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 };

float v = c_sdsdot_ndarray( 5, 0.0f, x, 1, 0, y, -1, 7 );
// returns -80.0f
```
The function accepts the following arguments:
- **N**: `[in] CBLAS_INT` number of indexed elements.
- **scalar**: `[in] float` scalar constant to add to dot product.
- **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_sdsdot_ndarray( const CBLAS_INT N, const float scalar, 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/sdsdot.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_sdsdot( N, 0.0f, x, strideX, y, strideY );

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

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

// Print the result:
printf( "dot product: %f\n", d );
}
```
</section>
<!-- /.examples -->
</section>
<!-- /.c -->
* * *
<section class="references">
Expand Down
46 changes: 44 additions & 2 deletions 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_sdsdot_ndarray( len, 0.0f, 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 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_sdsdot_ndarray( N, 0.0f, x, strideX, 0, y, strideY, 7 );

// Print the result:
printf( "dot product: %f\n", d );
}
9 changes: 8 additions & 1 deletion include/stdlib/blas/base/sdsdot.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#ifndef SDSDOT_H
#define SDSDOT_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 with extended accumulation.
*/
float c_sdsdot( const int N, const float scalar, const float *X, const int strideX, const float *Y, const int strideY );
float API_SUFFIX(c_sdsdot)( const CBLAS_INT N, const float scalar, 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 with extended accumulation using alternative indexing semantics.
*/
float API_SUFFIX(c_sdsdot_ndarray)( const CBLAS_INT N, const float scalar, 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 include/stdlib/blas/base/sdsdot_cblas.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#ifndef SDSDOT_CBLAS_H
#define SDSDOT_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 with extended accumulation.
*/
float cblas_sdsdot( const int N, const float scalar, const float *X, const int strideX, const float *Y, const int strideY );
float API_SUFFIX(cblas_sdsdot)( const CBLAS_INT N, const float scalar, const float *X, const CBLAS_INT strideX, const float *Y, const CBLAS_INT strideY );

#ifdef __cplusplus
}
Expand Down
15 changes: 2 additions & 13 deletions 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( './sdsdot.native.js' );
var addon = require( './../src/addon.node' );


// MAIN //
Expand Down Expand Up @@ -50,16 +48,7 @@ var addon = require( './sdsdot.native.js' );
* // returns -5.0
*/
function sdsdot( N, scalar, 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, scalar, viewX, strideX, viewY, strideY );
return addon.ndarray( N, scalar, x, strideX, offsetX, y, strideY, offsetY );
}


Expand Down
Loading

0 comments on commit 3fe9721

Please sign in to comment.