Skip to content

Commit d9dfc21

Browse files
committed
refactor: use common implementation and document C API
1 parent 3efb708 commit d9dfc21

File tree

3 files changed

+123
-16
lines changed

3 files changed

+123
-16
lines changed

lib/node_modules/@stdlib/blas/base/srot/README.md

+107
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,113 @@ console.log( y );
179179

180180
<!-- /.examples -->
181181

182+
<!-- C interface documentation. -->
183+
184+
* * *
185+
186+
<section class="c">
187+
188+
## C APIs
189+
190+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
191+
192+
<section class="intro">
193+
194+
</section>
195+
196+
<!-- /.intro -->
197+
198+
<!-- C usage documentation. -->
199+
200+
<section class="usage">
201+
202+
### Usage
203+
204+
```c
205+
#include "stdlib/blas/base/srot.h"
206+
```
207+
208+
#### c_srot( N, \*X, strideX, \*Y, strideY, c, s )
209+
210+
Applies a plane rotation.
211+
212+
```c
213+
float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f };
214+
float y[] = { 6.0f, 7.0f, 8.0f, 9.0f, 10.0f };
215+
216+
c_drot( 5, x, 1, y, 1, 0.8f, 0.6f );
217+
```
218+
219+
The function accepts the following arguments:
220+
221+
- **N**: `[in] CBLAS_INT` number of indexed elements.
222+
- **X**: `[inout] float*` first input array.
223+
- **strideX**: `[in] CBLAS_INT` index increment for `X`.
224+
- **Y**: `[inout] float*` second input array.
225+
- **strideY**: `[in] CBLAS_INT` index increment for `Y`.
226+
- **c**: `[in] float` cosine of the angle of rotation.
227+
- **s**: `[in] float` sine of the angle of rotation.
228+
229+
```c
230+
void c_drot( const CBLAS_INT N, float *X, const CBLAS_INT strideX, float *Y, const CBLAS_INT strideY, const float c, const float s );
231+
```
232+
233+
</section>
234+
235+
<!-- /.usage -->
236+
237+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
238+
239+
<section class="notes">
240+
241+
</section>
242+
243+
<!-- /.notes -->
244+
245+
<!-- C API usage examples. -->
246+
247+
<section class="examples">
248+
249+
### Examples
250+
251+
```c
252+
#include "stdlib/blas/base/drot.h"
253+
#include <stdio.h>
254+
255+
int main( void ) {
256+
// Create strided arrays:
257+
float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f };
258+
float y[] = { 6.0f, 7.0f, 8.0f, 9.0f, 10.0f };
259+
260+
// Specify the number of elements:
261+
const int N = 5;
262+
263+
// Specify stride lengths:
264+
const int strideX = 1;
265+
const int strideY = 1;
266+
267+
// Specify angle of rotation:
268+
const float c = 0.8f;
269+
const float s = 0.6f;
270+
271+
// Apply plane rotation:
272+
c_drot( N, x, strideX, y, strideY, c, s );
273+
274+
// Print the result:
275+
for ( int i = 0; i < 5; i++ ) {
276+
printf( "x[ %i ] = %f, y[ %i ] = %f\n", i, x[ i ], i, y[ i ] );
277+
}
278+
}
279+
```
280+
281+
</section>
282+
283+
<!-- /.examples -->
284+
285+
</section>
286+
287+
<!-- /.c -->
288+
182289
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
183290
184291
<section class="related">

lib/node_modules/@stdlib/blas/base/srot/lib/ndarray.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818

1919
'use strict';
2020

21+
// MODULES //
22+
23+
var f32 = require( '@stdlib/number/float64/base/to-float32' );
24+
25+
2126
// MAIN //
2227

2328
/**
@@ -53,12 +58,13 @@ function srot( N, x, strideX, offsetX, y, strideY, offsetY, c, s ) {
5358
if ( N <= 0 ) {
5459
return y;
5560
}
61+
c = f32( c );
62+
s = f32( s );
5663
ix = offsetX;
5764
iy = offsetY;
58-
5965
for ( i = 0; i < N; i++ ) {
60-
tmp = ( c * x[ ix ] ) + ( s * y[ iy ] );
61-
y[ iy ] = ( c * y[ iy ] ) - ( s * x[ ix ] );
66+
tmp = f32( c * x[ ix ] ) + f32( s * y[ iy ] );
67+
y[ iy ] = f32( c * y[ iy ] ) - f32( s * x[ ix ] );
6268
x[ ix ] = tmp;
6369
ix += strideX;
6470
iy += strideY;

lib/node_modules/@stdlib/blas/base/srot/lib/srot.js

+7-13
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,16 @@ var ndarray = require( './ndarray.js' );
4141
* @example
4242
* var Float32Array = require( '@stdlib/array/float32' );
4343
*
44-
* var x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
45-
* var y = new Float32Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
44+
* var x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
45+
* var y = new Float32Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] );
4646
*
47-
* srot( 3, x, 2, y, 2, 0.8, 0.6 );
48-
* // x => <Float32Array>[ 5.0, 2.0, ~7.8, 4.0, ~10.6, 6.0 ]
49-
* // y => <Float32Array>[ 5.0, 8.0, ~5.4, 10.0, ~5.8, 12.0 ]
47+
* srot( x.length, x, 1, y, 1, 0.8, 0.6 );
48+
* // x => <Float32Array>[ ~4.4, ~5.8, ~7.2, ~8.6, 10.0 ]
49+
* // y => <Float32Array>[ ~4.2, 4.4, 4.6, 4.8, 5.0 ]
5050
*/
5151
function srot( N, x, strideX, y, strideY, c, s ) {
52-
var ix;
53-
var iy;
54-
55-
if ( N <= 0 ) {
56-
return y;
57-
}
58-
ix = stride2offset( N, strideX );
59-
iy = stride2offset( N, strideY );
52+
var ix = stride2offset( N, strideX );
53+
var iy = stride2offset( N, strideY );
6054
return ndarray( N, x, strideX, ix, y, strideY, iy, c, s );
6155
}
6256

0 commit comments

Comments
 (0)