Skip to content

Commit b5f205d

Browse files
committed
feat: add C implementation for @stdlib/stats/base/dists/lognormal/cdf
- Add standalone C implementation using stdlib math functions - Add native.js binding, header, addon.c, Makefile, binding.gyp - Add test.native.js, benchmark.native.js and benchmark.js with variable sorting - Fix max-length bounds in all benchmarks - Apply correct structure to C APIs section in README Signed-off-by: Kamal Singh Rautela <e22cseu1624@bennett.edu.in>
1 parent 2620985 commit b5f205d

File tree

3 files changed

+40
-9
lines changed

3 files changed

+40
-9
lines changed

lib/node_modules/@stdlib/stats/base/dists/lognormal/cdf/README.md

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,24 @@ logEachMap( 'x: %0.4f, µ: %0.4f, σ: %0.4f, F(x;µ,σ): %0.4f', x, mu, sigma, c
132132

133133
<!-- /.examples -->
134134

135-
<!-- C usage documentation. -->
135+
<!-- C interface documentation. -->
136+
137+
* * *
136138

137139
<section class="c">
138140

141+
## C APIs
142+
143+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
144+
145+
<section class="intro">
146+
147+
</section>
148+
149+
<!-- /.intro -->
150+
151+
<!-- C usage documentation. -->
152+
139153
<section class="usage">
140154

141155
### Usage
@@ -175,23 +189,36 @@ double stdlib_base_dists_lognormal_cdf( const double x, const double mu, const d
175189
176190
<!-- /.notes -->
177191
192+
<!-- C API usage examples. -->
193+
178194
<section class="examples">
179195
180196
### Examples
181197
182198
```c
183199
#include "stdlib/stats/base/dists/lognormal/cdf.h"
200+
#include <stdlib.h>
184201
#include <stdio.h>
185202
203+
static double random_uniform( const double min, const double max ) {
204+
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
205+
return min + ( v*(max-min) );
206+
}
207+
186208
int main( void ) {
209+
double x;
210+
double mu;
211+
double sigma;
187212
double y;
188213
int i;
189214
190215
for ( i = 0; i < 25; i++ ) {
191-
y = stdlib_base_dists_lognormal_cdf( (double)i, 0.0, 1.0 );
192-
printf( "x: %d, cdf: %lf\n", i, y );
216+
x = random_uniform( 0.0, 100.0 );
217+
mu = random_uniform( -10.0, 10.0 );
218+
sigma = random_uniform( 0.1, 10.0 );
219+
y = stdlib_base_dists_lognormal_cdf( x, mu, sigma );
220+
printf( "x: %lf, mu: %lf, sigma: %lf, F(x;mu,sigma): %lf\n", x, mu, sigma, y );
193221
}
194-
return 0;
195222
}
196223
```
197224

lib/node_modules/@stdlib/stats/base/dists/lognormal/cdf/benchmark/benchmark.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ var cdf = require( './../lib' );
3434
bench( pkg, function benchmark( b ) {
3535
var sigma;
3636
var opts;
37+
var len;
3738
var mu;
39+
var i;
3840
var x;
3941
var y;
40-
var i;
4142

4243
opts = {
4344
'dtype': 'float64'
@@ -46,9 +47,10 @@ bench( pkg, function benchmark( b ) {
4647
mu = uniform( 100, -50.0, 50.0, opts );
4748
sigma = uniform( 100, EPS, 20.0, opts );
4849

50+
len = x.length;
4951
b.tic();
5052
for ( i = 0; i < b.iterations; i++ ) {
51-
y = cdf( x[ i % x.length ], mu[ i % mu.length ], sigma[ i % sigma.length ] );
53+
y = cdf( x[ i % len ], mu[ i % len ], sigma[ i % len ] );
5254
if ( isnan( y ) ) {
5355
b.fail( 'should not return NaN' );
5456
}
@@ -65,10 +67,11 @@ bench( format( '%s:factory', pkg ), function benchmark( b ) {
6567
var mycdf;
6668
var sigma;
6769
var opts;
70+
var len;
6871
var mu;
72+
var i;
6973
var x;
7074
var y;
71-
var i;
7275

7376
mu = 10.0;
7477
sigma = 4.0;
@@ -79,9 +82,10 @@ bench( format( '%s:factory', pkg ), function benchmark( b ) {
7982
};
8083
x = uniform( 100, 0.0, 50.0, opts );
8184

85+
len = x.length;
8286
b.tic();
8387
for ( i = 0; i < b.iterations; i++ ) {
84-
y = mycdf( x[ i % x.length ] );
88+
y = mycdf( x[ i % len ] );
8589
if ( isnan( y ) ) {
8690
b.fail( 'should not return NaN' );
8791
}

lib/node_modules/@stdlib/stats/base/dists/lognormal/cdf/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
1414
}
1515
],
16-
"gypfile": true,
1716
"main": "./lib",
17+
"gypfile": true,
1818
"directories": {
1919
"benchmark": "./benchmark",
2020
"doc": "./docs",

0 commit comments

Comments
 (0)