From 1408bdd5f75707a2ab5c0ec7a302dda255ee8f5d Mon Sep 17 00:00:00 2001 From: sahilk45 Date: Tue, 1 Apr 2025 15:17:42 +0530 Subject: [PATCH 1/2] Clint error --- .../base/dmap/benchmark/c/benchmark.length.c | 65 ++++++++++++------- 1 file changed, 41 insertions(+), 24 deletions(-) diff --git a/lib/node_modules/@stdlib/strided/base/dmap/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/strided/base/dmap/benchmark/c/benchmark.length.c index 58c6e2c22fc2..b0123f4e74dc 100644 --- a/lib/node_modules/@stdlib/strided/base/dmap/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/strided/base/dmap/benchmark/c/benchmark.length.c @@ -104,30 +104,47 @@ static double identity( const double x ) { * @param len array length * @return elapsed time in seconds */ -static double benchmark( int iterations, int len ) { - double elapsed; - double x[ len ]; - double y[ len ]; - double t; - int i; - - for ( i = 0; i < len; i++ ) { - x[ i ] = ( rand_double()*200.0 ) - 100.0; - y[ i ] = 0.0; - } - t = tic(); - for ( i = 0; i < iterations; i++ ) { - stdlib_strided_dmap( len, x, 1, y, 1, identity ); - if ( y[ i%len ] != y[ i%len ] ) { - printf( "should not return NaN\n" ); - break; - } - } - elapsed = tic() - t; - if ( y[ i%len ] != y[ i%len ] ) { - printf( "should not return NaN\n" ); - } - return elapsed; +static double benchmark(int iterations, int len) { + // Initialize all variables at declaration + double elapsed = 0.0; + double *x = malloc(len * sizeof(double)); // Use dynamic allocation instead of VLA + double *y = malloc(len * sizeof(double)); + double t = 0.0; + int i = 0; + + // Check if memory allocation was successful + if (x == NULL || y == NULL) { + // Handle allocation failure + free(x); + free(y); + return -1.0; + } + + // Initialize arrays + for (i = 0; i < len; i++) { + x[i] = (rand_double() * 200.0) - 100.0; + y[i] = 0.0; + } + + t = tic(); + for (i = 0; i < iterations; i++) { + stdlib_strided_dmap(len, x, 1, y, 1, identity); + if (y[i % len] != y[i % len]) { + printf("should not return NaN\n"); + break; + } + } + elapsed = tic() - t; + + if (y[i % len] != y[i % len]) { + printf("should not return NaN\n"); + } + + // Free allocated memory + free(x); + free(y); + + return elapsed; } /** From 2cfa533886ff5c4533228d3ae1acf1d9674f1a27 Mon Sep 17 00:00:00 2001 From: SAHIL KUMAR <168997976+sahilk45@users.noreply.github.com> Date: Tue, 1 Apr 2025 17:49:27 +0530 Subject: [PATCH 2/2] Update benchmark.length.c following the same codebase Signed-off-by: SAHIL KUMAR <168997976+sahilk45@users.noreply.github.com> --- .../base/dmap/benchmark/c/benchmark.length.c | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/lib/node_modules/@stdlib/strided/base/dmap/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/strided/base/dmap/benchmark/c/benchmark.length.c index b0123f4e74dc..b9b331caf084 100644 --- a/lib/node_modules/@stdlib/strided/base/dmap/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/strided/base/dmap/benchmark/c/benchmark.length.c @@ -105,21 +105,27 @@ static double identity( const double x ) { * @return elapsed time in seconds */ static double benchmark(int iterations, int len) { - // Initialize all variables at declaration - double elapsed = 0.0; - double *x = malloc(len * sizeof(double)); // Use dynamic allocation instead of VLA - double *y = malloc(len * sizeof(double)); - double t = 0.0; - int i = 0; + double elapsed; + double *x; + double *y; + double t; + int i; + + // Allocate input array: + x = (double*) malloc(len * sizeof(double)); + if (x == NULL) { + printf("Error allocating memory.\n"); + exit(1); + } - // Check if memory allocation was successful - if (x == NULL || y == NULL) { - // Handle allocation failure + // Allocate output array: + y = (double*) malloc(len * sizeof(double)); + if (y == NULL) { free(x); - free(y); - return -1.0; + printf("Error allocating memory.\n"); + exit(1); } - + // Initialize arrays for (i = 0; i < len; i++) { x[i] = (rand_double() * 200.0) - 100.0; @@ -140,13 +146,12 @@ static double benchmark(int iterations, int len) { printf("should not return NaN\n"); } - // Free allocated memory + // Free allocated memory: free(x); free(y); return elapsed; } - /** * Main execution sequence. */