|
1 | 1 | /**
|
2 | 2 | * @license Apache-2.0
|
3 | 3 | *
|
4 |
| -* Copyright (c) 2024 The Stdlib Authors. |
| 4 | +* Copyright (c) 2025 The Stdlib Authors. |
5 | 5 | *
|
6 | 6 | * Licensed under the Apache License, Version 2.0 (the "License");
|
7 | 7 | * you may not use this file except in compliance with the License.
|
|
17 | 17 | */
|
18 | 18 |
|
19 | 19 | #include "stdlib/stats/base/dists/weibull/skewness.h"
|
20 |
| -#include "stdlib/math/base/special/ceil.h" |
21 | 20 | #include <stdlib.h>
|
22 | 21 | #include <stdio.h>
|
23 | 22 | #include <math.h>
|
@@ -94,29 +93,31 @@ static double random_uniform( const double min, const double max ) {
|
94 | 93 | */
|
95 | 94 | static double benchmark( void ) {
|
96 | 95 | double elapsed;
|
97 |
| - double x[ 100 ]; |
98 |
| - double n[ 100 ]; |
99 |
| - double skewness; |
| 96 | + double k[ 100 ]; |
| 97 | + double lambda[ 100 ]; |
100 | 98 | double y;
|
101 | 99 | double t;
|
102 | 100 | int i;
|
103 | 101 |
|
104 |
| - // Generate random values for x, n, and skewness |
| 102 | + // Generate random values for k (shape) and lambda (scale) |
105 | 103 | for ( i = 0; i < 100; i++ ) {
|
106 |
| - x[ i ] = random_uniform( 0, 30.0 ); |
107 |
| - n[ i ] = stdlib_base_ceil(random_uniform( 1, 30.0 )); |
108 |
| - skewness = random_uniform( -1.0, 1.0 ); |
| 104 | + k[ i ] = random_uniform( 0.1, 10.0 ); // k > 0 to avoid NaN result |
| 105 | + lambda[ i ] = random_uniform( 0.1, 10.0 ); // lambda > 0 to avoid NaN result |
109 | 106 | }
|
110 | 107 |
|
111 | 108 | t = tic();
|
| 109 | + // Benchmark loop |
112 | 110 | for ( i = 0; i < ITERATIONS; i++ ) {
|
113 |
| - y = stdlib_base_dists_weibull_skewness( x[ i%100 ], n[ i%100 ], skewness ); |
114 |
| - if ( y != y ) { // Check if the result is NaN |
| 111 | + // Calculate skewness for the Weibull distribution |
| 112 | + y = stdlib_base_dists_weibull_skewness( k[ i % 100 ], lambda[ i % 100 ] ); |
| 113 | + if ( y != y ) { // Check for NaN |
115 | 114 | printf( "should not return NaN\n" );
|
116 | 115 | break;
|
117 | 116 | }
|
118 | 117 | }
|
119 | 118 | elapsed = tic() - t;
|
| 119 | + |
| 120 | + // Final NaN check |
120 | 121 | if ( y != y ) {
|
121 | 122 | printf( "should not return NaN\n" );
|
122 | 123 | }
|
|
0 commit comments