-
-
Notifications
You must be signed in to change notification settings - Fork 825
feat: add C ndarray interface and refactor implementation for stats/base/dvarmpn
#4543
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
87a38be
fa22cd0
dddbaa2
521f17c
61d6511
4cb641f
15b7142
718f26d
06cdd25
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -94,7 +94,7 @@ static double rand_double( 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; | ||||||
double x[ len ]; | ||||||
double v; | ||||||
|
@@ -107,6 +107,7 @@ static double benchmark( int iterations, int len ) { | |||||
v = 0.0; | ||||||
t = tic(); | ||||||
for ( i = 0; i < iterations; i++ ) { | ||||||
// cppcheck-suppress uninitvar | ||||||
v = stdlib_strided_dvarmpn( len, 0.0, 1, x, 1 ); | ||||||
if ( v != v ) { | ||||||
printf( "should not return NaN\n" ); | ||||||
|
@@ -120,6 +121,40 @@ 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; | ||||||
double x[ len ]; | ||||||
float v; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
double t; | ||||||
int i; | ||||||
|
||||||
for ( i = 0; i < len; i++ ) { | ||||||
x[ i ] = i; | ||||||
} | ||||||
DhruvArvindSingh marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
v = 0.0f; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
t = tic(); | ||||||
for ( i = 0; i < iterations; i++ ) { | ||||||
// cppcheck-suppress uninitvar | ||||||
v = stdlib_strided_dvarmpn_ndarray( len, 0.0, 1, x, 1, 1 ); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
just following the convention here |
||||||
if ( v != v ) { | ||||||
printf( "should not return NaN\n" ); | ||||||
break; | ||||||
} | ||||||
} | ||||||
elapsed = tic() - t; | ||||||
if ( v != v ) { | ||||||
printf( "should not return NaN\n" ); | ||||||
} | ||||||
return elapsed; | ||||||
} | ||||||
|
||||||
/** | ||||||
* Main execution sequence. | ||||||
*/ | ||||||
|
@@ -142,7 +177,18 @@ 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 ( i = MIN; i <= MAX - 3; i++ ) { | ||||||
len = pow( 10, i ); | ||||||
iter = ITERATIONS; | ||||||
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 ); | ||||||
} | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -17,21 +17,20 @@ | |||||
*/ | ||||||
|
||||||
#include "stdlib/stats/base/dvarmpn.h" | ||||||
#include <stdint.h> | ||||||
#include <stdio.h> | ||||||
|
||||||
int main( void ) { | ||||||
// Create a strided array: | ||||||
double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }; | ||||||
const double x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
only single precision floating-point values are suffixed with a |
||||||
|
||||||
// Specify the number of elements: | ||||||
int64_t N = 4; | ||||||
const int N = 4; | ||||||
|
||||||
// Specify the stride length: | ||||||
int64_t stride = 2; | ||||||
// Specify the strideX length: | ||||||
DhruvArvindSingh marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
const int strideX = 2; | ||||||
|
||||||
// Compute the variance: | ||||||
double v = stdlib_strided_dvarmpn( N, 4.5, 1, x, stride ); | ||||||
double v = stdlib_strided_dvarmpn( N, 4.5, 1, x, strideX ); | ||||||
|
||||||
// Print the result: | ||||||
printf( "sample variance: %lf\n", v ); | ||||||
|
Uh oh!
There was an error while loading. Please reload this page.