Skip to content

Commit d54eb2c

Browse files
committed
feat: add C ndarray interface and refactor implementation
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: passed - task: lint_c_benchmarks status: passed - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 5e05d49 commit d54eb2c

File tree

21 files changed

+345
-253
lines changed

21 files changed

+345
-253
lines changed

lib/node_modules/@stdlib/stats/base/dcumin/README.md

Lines changed: 132 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ The function has the following parameters:
5454

5555
- **N**: number of indexed elements.
5656
- **x**: input [`Float64Array`][@stdlib/array/float64].
57-
- **strideX**: index increment for `x`.
57+
- **strideX**: stride length for `x`.
5858
- **y**: output [`Float64Array`][@stdlib/array/float64].
59-
- **strideY**: index increment for `y`.
59+
- **strideY**: stride length for `y`.
6060

61-
The `N` and `stride` parameters determine which elements in `x` and `y` are accessed at runtime. For example, to compute the cumulative minimum of every other element in `x`,
61+
The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to compute the cumulative minimum of every other element in `x`,
6262

6363
```javascript
6464
var Float64Array = require( '@stdlib/array/float64' );
@@ -141,21 +141,15 @@ dcumin.ndarray( 4, x, 2, 1, y, -1, y.length-1 );
141141
<!-- eslint no-undef: "error" -->
142142

143143
```javascript
144-
var randu = require( '@stdlib/random/base/randu' );
145-
var round = require( '@stdlib/math/base/special/round' );
144+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
146145
var Float64Array = require( '@stdlib/array/float64' );
147146
var dcumin = require( '@stdlib/stats/base/dcumin' );
148147

149-
var y;
150-
var x;
151-
var i;
152-
153-
x = new Float64Array( 10 );
154-
y = new Float64Array( x.length );
155-
for ( i = 0; i < x.length; i++ ) {
156-
x[ i ] = round( randu()*100.0 );
157-
}
148+
var x = discreteUniform( 10, -50, 50, {
149+
'dtype': 'float64'
150+
});
158151
console.log( x );
152+
var y = new Float64Array( x.length );
159153
console.log( y );
160154

161155
dcumin( x.length, x, 1, y, -1 );
@@ -166,6 +160,130 @@ console.log( y );
166160

167161
<!-- /.examples -->
168162

163+
<!-- C interface documentation. -->
164+
165+
* * *
166+
167+
<section class="c">
168+
169+
## C APIs
170+
171+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
172+
173+
<section class="intro">
174+
175+
</section>
176+
177+
<!-- /.intro -->
178+
179+
<!-- C usage documentation. -->
180+
181+
<section class="usage">
182+
183+
### Usage
184+
185+
```c
186+
#include "stdlib/stats/base/dcumin.h"
187+
```
188+
189+
#### stdlib_strided_dcumin( N, \*X, strideX, \*Y, strideY )
190+
191+
Calculate the cumulative minimum of double-precision floating-point strided array elements.
192+
193+
```c
194+
const double x[] = { 1.0, 2.0, -3.0, 4.0, -5.0, 6.0, 7.0, 8.0 };
195+
double y[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
196+
stdlib_strided_dcumin( 4, x, 2, y, -2 );
197+
```
198+
199+
The function accepts the following arguments:
200+
201+
- **N**: `[in] CBLAS_INT` number of indexed elements.
202+
- **X**: `[in] double*` input array.
203+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
204+
- **Y**: `[in] double*` output array.
205+
- **strideY**: `[in] CBLAS_INT` stride length for `Y`.
206+
207+
```c
208+
void stdlib_strided_dcumin( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, double *Y, const CBLAS_INT strideY );
209+
```
210+
211+
#### stdlib_strided_dcumin_ndarray(N, \*X, strideX, offsetX, \*Y, strideY, offsetY)
212+
213+
Computes the cumulative minimum of double-precision floating-point strided array elements using alternative indexing semantics.
214+
215+
```c
216+
const double x[] = { 1.0, 2.0, -3.0, 4.0, -5.0, 6.0, 7.0, 8.0 };
217+
double y[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
218+
stdlib_strided_dcumin_ndarray( 4, x, 2, 0, y, -2, 0 );
219+
```
220+
221+
The function accepts the following arguments:
222+
223+
- **N**: `[in] CBLAS_INT` number of indexed elements.
224+
- **X**: `[in] double*` input array.
225+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
226+
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
227+
- **Y**: `[in] double*` output array.
228+
- **strideY**: `[in] CBLAS_INT` stride length for `Y`.
229+
- **offsetY**: `[in] CBLAS_INT` starting index for `Y`.
230+
231+
```c
232+
void stdlib_strided_dcumin_ndarray( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY );
233+
```
234+
235+
</section>
236+
237+
<!-- /.usage -->
238+
239+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
240+
241+
<section class="notes">
242+
243+
</section>
244+
245+
<!-- /.notes -->
246+
247+
<!-- C API usage examples. -->
248+
249+
<section class="examples">
250+
251+
### Examples
252+
253+
```c
254+
#include "stdlib/stats/base/dcumin.h"
255+
#include <stdio.h>
256+
257+
int main( void ) {
258+
// Create strided arrays:
259+
const double x[] = { 1.0, 2.0, -3.0, 4.0, -5.0, 6.0, 7.0, 8.0 };
260+
double y[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
261+
262+
// Specify the number of elements:
263+
const int N = 4;
264+
265+
// Specify stride lengths:
266+
const int strideX = 2;
267+
const int strideY = -2;
268+
269+
// Compute the cumulative minimum:
270+
stdlib_strided_dcumin( N, x, strideX, y, strideY );
271+
272+
// Print the result:
273+
for ( int i = 0; i < 8; i++ ) {
274+
printf( "y[ %d ] = %lf\n", i, y[ i ] );
275+
}
276+
}
277+
```
278+
279+
</section>
280+
281+
<!-- /.examples -->
282+
283+
</section>
284+
285+
<!-- /.c -->
286+
169287
<section class="references">
170288
171289
</section>

lib/node_modules/@stdlib/stats/base/dcumin/benchmark/benchmark.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,21 @@
2121
// MODULES //
2222

2323
var bench = require( '@stdlib/bench' );
24-
var randu = require( '@stdlib/random/base/randu' );
24+
var uniform = require( '@stdlib/random/array/uniform' );
2525
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2626
var pow = require( '@stdlib/math/base/special/pow' );
2727
var Float64Array = require( '@stdlib/array/float64' );
2828
var pkg = require( './../package.json' ).name;
2929
var dcumin = require( './../lib/dcumin.js' );
3030

3131

32+
// VARIABLES //
33+
34+
var options = {
35+
'dtype': 'float64'
36+
};
37+
38+
3239
// FUNCTIONS //
3340

3441
/**
@@ -39,15 +46,8 @@ var dcumin = require( './../lib/dcumin.js' );
3946
* @returns {Function} benchmark function
4047
*/
4148
function createBenchmark( len ) {
42-
var y;
43-
var x;
44-
var i;
45-
46-
x = new Float64Array( len );
47-
y = new Float64Array( len );
48-
for ( i = 0; i < x.length; i++ ) {
49-
x[ i ] = ( randu()*20.0 ) - 10.0;
50-
}
49+
var x = uniform( len, -10.0, 10.0, options );
50+
var y = new Float64Array( len );
5151
return benchmark;
5252

5353
function benchmark( b ) {

lib/node_modules/@stdlib/stats/base/dcumin/benchmark/benchmark.native.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
25-
var randu = require( '@stdlib/random/base/randu' );
25+
var uniform = require( '@stdlib/random/array/uniform' );
2626
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2727
var pow = require( '@stdlib/math/base/special/pow' );
2828
var Float64Array = require( '@stdlib/array/float64' );
@@ -36,6 +36,9 @@ var dcumin = tryRequire( resolve( __dirname, './../lib/dcumin.native.js' ) );
3636
var opts = {
3737
'skip': ( dcumin instanceof Error )
3838
};
39+
var options = {
40+
'dtype': 'float64'
41+
};
3942

4043

4144
// FUNCTIONS //
@@ -48,15 +51,8 @@ var opts = {
4851
* @returns {Function} benchmark function
4952
*/
5053
function createBenchmark( len ) {
51-
var x;
52-
var y;
53-
var i;
54-
55-
x = new Float64Array( len );
56-
y = new Float64Array( len );
57-
for ( i = 0; i < x.length; i++ ) {
58-
x[ i ] = ( randu()*20.0 ) - 10.0;
59-
}
54+
var x = uniform( len, -10.0, 10.0, options );
55+
var y = new Float64Array( len );
6056
return benchmark;
6157

6258
function benchmark( b ) {

lib/node_modules/@stdlib/stats/base/dcumin/benchmark/benchmark.ndarray.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,21 @@
2121
// MODULES //
2222

2323
var bench = require( '@stdlib/bench' );
24-
var randu = require( '@stdlib/random/base/randu' );
24+
var uniform = require( '@stdlib/random/array/uniform' );
2525
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2626
var pow = require( '@stdlib/math/base/special/pow' );
2727
var Float64Array = require( '@stdlib/array/float64' );
2828
var pkg = require( './../package.json' ).name;
2929
var dcumin = require( './../lib/ndarray.js' );
3030

3131

32+
// VARIABLES //
33+
34+
var options = {
35+
'dtype': 'float64'
36+
};
37+
38+
3239
// FUNCTIONS //
3340

3441
/**
@@ -39,15 +46,8 @@ var dcumin = require( './../lib/ndarray.js' );
3946
* @returns {Function} benchmark function
4047
*/
4148
function createBenchmark( len ) {
42-
var x;
43-
var y;
44-
var i;
45-
46-
x = new Float64Array( len );
47-
y = new Float64Array( len );
48-
for ( i = 0; i < x.length; i++ ) {
49-
x[ i ] = ( randu()*20.0 ) - 10.0;
50-
}
49+
var x = uniform( len, -10.0, 10.0, options );
50+
var y = new Float64Array( len );
5151
return benchmark;
5252

5353
function benchmark( b ) {

lib/node_modules/@stdlib/stats/base/dcumin/benchmark/benchmark.ndarray.native.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
25-
var randu = require( '@stdlib/random/base/randu' );
25+
var uniform = require( '@stdlib/random/array/uniform' );
2626
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2727
var pow = require( '@stdlib/math/base/special/pow' );
2828
var Float64Array = require( '@stdlib/array/float64' );
@@ -36,6 +36,9 @@ var dcumin = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) );
3636
var opts = {
3737
'skip': ( dcumin instanceof Error )
3838
};
39+
var options = {
40+
'dtype': 'float64'
41+
};
3942

4043

4144
// FUNCTIONS //
@@ -48,15 +51,8 @@ var opts = {
4851
* @returns {Function} benchmark function
4952
*/
5053
function createBenchmark( len ) {
51-
var x;
52-
var y;
53-
var i;
54-
55-
x = new Float64Array( len );
56-
y = new Float64Array( len );
57-
for ( i = 0; i < x.length; i++ ) {
58-
x[ i ] = ( randu()*20.0 ) - 10.0;
59-
}
54+
var x = uniform( len, -10.0, 10.0, options );
55+
var y = new Float64Array( len );
6056
return benchmark;
6157

6258
function benchmark( b ) {

lib/node_modules/@stdlib/stats/base/dcumin/benchmark/c/benchmark.length.c

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ static double rand_double( void ) {
9494
* @param len array length
9595
* @return elapsed time in seconds
9696
*/
97-
static double benchmark( int iterations, int len ) {
97+
static double benchmark1( int iterations, int len ) {
9898
double elapsed;
9999
double x[ len ];
100100
double y[ len ];
@@ -121,6 +121,40 @@ static double benchmark( int iterations, int len ) {
121121
return elapsed;
122122
}
123123

124+
/**
125+
* Runs a benchmark.
126+
*
127+
* @param iterations number of iterations
128+
* @param len array length
129+
* @return elapsed time in seconds
130+
*/
131+
static double benchmark2( int iterations, int len ) {
132+
double elapsed;
133+
double x[ len ];
134+
double y[ len ];
135+
double t;
136+
int i;
137+
138+
for ( i = 0; i < len; i++ ) {
139+
x[ i ] = ( rand_double() * 20000.0 ) - 10000.0;
140+
y[ i ] = 0.0;
141+
}
142+
t = tic();
143+
for ( i = 0; i < iterations; i++ ) {
144+
x[ 0 ] += 1.0;
145+
stdlib_strided_dcumin_ndarray( len, x, 1, 0, y, 1, 0 );
146+
if ( y[ 0 ] != y[ 0 ] ) {
147+
printf( "should not return NaN\n" );
148+
break;
149+
}
150+
}
151+
elapsed = tic() - t;
152+
if ( y[ len-1 ] != y[ len-1 ] ) {
153+
printf( "should not return NaN\n" );
154+
}
155+
return elapsed;
156+
}
157+
124158
/**
125159
* Main execution sequence.
126160
*/
@@ -143,7 +177,18 @@ int main( void ) {
143177
for ( j = 0; j < REPEATS; j++ ) {
144178
count += 1;
145179
printf( "# c::%s:len=%d\n", NAME, len );
146-
elapsed = benchmark( iter, len );
180+
elapsed = benchmark1( iter, len );
181+
print_results( iter, elapsed );
182+
printf( "ok %d benchmark finished\n", count );
183+
}
184+
}
185+
for ( i = MIN; i <= MAX; i++ ) {
186+
len = pow( 10, i );
187+
iter = ITERATIONS / pow( 10, i-1 );
188+
for ( j = 0; j < REPEATS; j++ ) {
189+
count += 1;
190+
printf( "# c::%s:ndarray:len=%d\n", NAME, len );
191+
elapsed = benchmark2( iter, len );
147192
print_results( iter, elapsed );
148193
printf( "ok %d benchmark finished\n", count );
149194
}

0 commit comments

Comments
 (0)