Skip to content
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

Fix JavaScript lint errors #5934 #6205

Closed
wants to merge 11 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2022 The Stdlib Authors.
* Copyright (c) 2024 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,6 +26,7 @@
* @example
* var plugin = require( '@stdlib/_tools/makie/plugins/makie-list-pkgs-names' );
* var makie = require( '@stdlib/_tools/makie' );
*
* var opts = {
* 'plugins': {
* 'benchmark': plugin
@@ -40,7 +41,6 @@

var main = require( './main.js' );


// EXPORTS //

module.exports = main;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2018 The Stdlib Authors.
* Copyright (c) 2023 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,16 +16,26 @@
* limitations under the License.
*/

#include "stdlib/math/base/special/ccis.h"
#include "stdlib/complex/float64/ctor.h"
#include "stdlib/complex/float64/reim.h"
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <complex.h>
#include <time.h>
#include <sys/time.h>

#define NAME "cis"
/**
* Constants
*/
#define NAME "ccis"
#define ITERATIONS 1000000
#define REPEATS 3

#define RAND_MIN -500.0
#define RAND_MAX 500.0
#define RAND_RANGE (RAND_MAX - RAND_MIN)

/**
* Prints the TAP version.
*/
@@ -70,17 +80,17 @@ static void print_results( double elapsed ) {
static double tic( void ) {
struct timeval now;
gettimeofday( &now, NULL );
return (double)now.tv_sec + (double)now.tv_usec/1.0e6;
return (double)now.tv_sec + (double)now.tv_usec / 1.0e6;
}

/**
* Generates a random number on the interval [0,1).
* Generates a random number on the interval [RAND_MIN, RAND_MAX).
*
* @return random number
*/
static double rand_double( void ) {
int r = rand();
return (double)r / ( (double)RAND_MAX + 1.0 );
return ( RAND_RANGE * ( (double)r / ( (double)RAND_MAX + 1.0 ) ) ) + RAND_MIN;
}

/**
@@ -95,23 +105,32 @@ static double benchmark( void ) {
double t;
int i;

double complex z;
stdlib_complex128_t z1;
stdlib_complex128_t z2;

t = tic();

for ( i = 0; i < ITERATIONS; i++ ) {
re = ( 100.0*rand_double() ) - 50.0;
im = ( 100.0*rand_double() ) - 50.0;
// Generate random real and imaginary parts for each iteration:
re = rand_double();
im = rand_double();
z1 = stdlib_complex128( re, im );

z = ( cos( re ) + I * sin( re ) ) / exp( im );
if ( z != z ) {
printf( "should not return NaN\n" );
z2 = stdlib_base_ccis( z1 );
stdlib_complex128_reim( z2, &re, &im );

if ( isnan( re ) ) {
printf( "should not return NaN for real part\n" );
break;
}
if ( isnan( im ) ) {
printf( "should not return NaN for imaginary part\n" );
break;
}
}

elapsed = tic() - t;
if ( z != z ) {
printf( "should not return NaN\n" );
}

return elapsed;
}

@@ -126,11 +145,15 @@ int main( void ) {
srand( time( NULL ) );

print_version();

for ( i = 0; i < REPEATS; i++ ) {
printf( "# c::%s\n", NAME );
printf( "# c::native::%s\n", NAME );
elapsed = benchmark();
print_results( elapsed );
printf( "ok %d benchmark finished\n", i+1 );
printf( "ok %d benchmark finished\n", i + 1 );
}

print_summary( REPEATS, REPEATS );

return 0;
}
Original file line number Diff line number Diff line change
@@ -28,6 +28,7 @@
#define NAME "ccis"
#define ITERATIONS 1000000
#define REPEATS 3
#define ARRAY_SIZE 100 // For our re/im arrays

/**
* Prints the TAP version.
@@ -73,7 +74,7 @@ static void print_results( double elapsed ) {
static double tic( void ) {
struct timeval now;
gettimeofday( &now, NULL );
return (double)now.tv_sec + (double)now.tv_usec/1.0e6;
return (double)now.tv_sec + (double)now.tv_usec / 1.0e6;
}

/**
@@ -93,31 +94,42 @@ static double rand_double( void ) {
*/
static double benchmark( void ) {
double elapsed;
double re;
double im;
double t;
int i;

// Arrays to store 100 random real and imaginary values:
double re_array[ ARRAY_SIZE ];
double im_array[ ARRAY_SIZE ];

// Initialize re and im arrays with random values:
for ( i = 0; i < ARRAY_SIZE; i++ ) {
re_array[ i ] = ( 1000.0 * rand_double() ) - 500.0;
im_array[ i ] = ( 1000.0 * rand_double() ) - 500.0;
}

stdlib_complex128_t z1;
stdlib_complex128_t z2;

t = tic();

for ( i = 0; i < ITERATIONS; i++ ) {
re = ( 1000.0*rand_double() ) - 500.0;
im = ( 1000.0*rand_double() ) - 500.0;
z1 = stdlib_complex128( re, im );
// Get real and imaginary values from the arrays using i % 100:
z1 = stdlib_complex128( re_array[ i % ARRAY_SIZE ], im_array[ i % ARRAY_SIZE ] );

z2 = stdlib_base_ccis( z1 );
stdlib_complex128_reim( z2, &re, &im );
if ( re != re ) {
printf( "should not return NaN\n" );

// Overwrite the original arrays with the result:
stdlib_complex128_reim( z2, &re_array[ i % ARRAY_SIZE ], &im_array[ i % ARRAY_SIZE ] );

// Check if the real part becomes NaN:
if ( isnan( re_array[ i % ARRAY_SIZE ] ) ) {
printf( "should not return NaN at index %d\n", i % ARRAY_SIZE );
break;
}
}

elapsed = tic() - t;
if ( im != im ) {
printf( "should not return NaN\n" );
}

return elapsed;
}

@@ -132,11 +144,13 @@ int main( void ) {
srand( time( NULL ) );

print_version();

for ( i = 0; i < REPEATS; i++ ) {
printf( "# c::native::%s\n", NAME );
elapsed = benchmark();
print_results( elapsed );
printf( "ok %d benchmark finished\n", i+1 );
printf( "ok %d benchmark finished\n", i + 1 );
}

print_summary( REPEATS, REPEATS );
}
Loading
Oops, something went wrong.
Loading
Oops, something went wrong.