Skip to content

Commit 2d6c6a4

Browse files
feat(add c implementation): add stats/base/dists/arcsine/logcdf
1 parent 4206f90 commit 2d6c6a4

File tree

16 files changed

+144
-48
lines changed

16 files changed

+144
-48
lines changed

lib/node_modules/@stdlib/stats/base/dists/arcsine/logcdf/README.md

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ for ( i = 0; i < 25; i++ ) {
173173
#include "stdlib/stats/base/dists/arcsine/logcdf.h"
174174
```
175175

176-
#### stdlib_base_dists_arcsine_logcdf( a, b )
176+
#### stdlib_base_dists_arcsine_logcdf( x, a, b )
177177

178178
Evaluates the logarithm of the [cumulative distribution function][cdf] (CDF) for an [arcsine][arcsine-distribution] distribution with parameters `a` (minimum support) and `b` (maximum support).
179179

@@ -184,13 +184,14 @@ double out = stdlib_base_dists_arcsine_logcdf( 9.0, 0.0, 10.0 );
184184

185185
The function accepts the following arguments:
186186

187-
- **x**: `[in] double` minimum support
188-
- **a**: `[in] double` minimum support
189-
- **b**: `[in] double` maximum support
187+
- **x**: `[in] double` input value.
188+
- **a**: `[in] double` minimum support.
189+
- **b**: `[in] double` maximum support.
190190

191191
```c
192192
double stdlib_base_dists_arcsine_logcdf( const double x, const double a, const double b );
193193
```
194+
194195
</section>
195196
196197
<!-- /.usage -->
@@ -213,6 +214,12 @@ double stdlib_base_dists_arcsine_logcdf( const double x, const double a, const d
213214
#include "stdlib/stats/base/dists/arcsine/logcdf.h"
214215
#include <stdlib.h>
215216
#include <stdio.h>
217+
218+
static double random_uniform( const double min, const double max ) {
219+
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
220+
return min + ( v*(max-min) );
221+
}
222+
216223
int main( void ) {
217224
double x;
218225
double a;
@@ -221,12 +228,12 @@ int main( void ) {
221228
int i;
222229
223230
for ( i = 0; i < 25; i++ ) {
224-
x = ( (double)rand() / (double)RAND_MAX ) * 20.0 - 10.0;
225-
a = ( (double)rand() / (double)RAND_MAX ) * 20.0 - 20.0;
226-
b = a + ( (double)rand() / (double)RAND_MAX ) * 40.0;
227-
y = stdlib_base_dists_arcsine_logcdf( x, a, b );
228-
printf( "x: %lf ,a: %lf, b: %lf, ln(F;x,a,b): %lf\n", x, a, b, y );
229-
}
231+
x = random_uniform( -10.0, 10.0 );
232+
a = random_uniform( -20.0, 0.0 );
233+
b = random_uniform( a, a+40.0 );
234+
y = stdlib_base_dists_arcsine_logcdf( x, a, b );
235+
printf( "x: %lf, a: %lf, b: %lf, F(x;a,b): %lf\n", x, a, b, y );
236+
}
230237
}
231238
```
232239

lib/node_modules/@stdlib/stats/base/dists/arcsine/logcdf/benchmark/benchmark.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
// MODULES //
2222

2323
var bench = require( '@stdlib/bench' );
24+
var Float64Array = require( '@stdlib/array/float64' );
25+
var uniform = require( '@stdlib/random/array/uniform' );
2426
var randu = require( '@stdlib/random/base/randu' );
2527
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2628
var pkg = require( './../package.json' ).name;
@@ -32,16 +34,24 @@ var logcdf = require( './../lib' );
3234
bench( pkg, function benchmark( b ) {
3335
var min;
3436
var max;
37+
var len;
3538
var x;
3639
var y;
3740
var i;
3841

42+
len = 100;
43+
x = new Float64Array( len );
44+
min = new Float64Array( len );
45+
max = new Float64Array( len );
46+
for ( i = 0; i < len; i++ ) {
47+
x[ i ] = ( randu() * 20.0 ) - 10.0;
48+
min[ i ] = ( randu() * 20.0 ) - 20.0;
49+
max[ i ] = min[ i ] + ( randu() * 40.0 );
50+
}
51+
3952
b.tic();
4053
for ( i = 0; i < b.iterations; i++ ) {
41-
x = ( randu() * 20.0 ) - 10.0;
42-
min = ( randu() * 20.0 ) - 20.0;
43-
max = min + ( randu() * 40.0 );
44-
y = logcdf( x, min, max );
54+
y = logcdf( x[ i % len ], min[ i % len ], max[ i % len ] );
4555
if ( isnan( y ) ) {
4656
b.fail( 'should not return NaN' );
4757
}
@@ -65,11 +75,11 @@ bench( pkg+':factory', function benchmark( b ) {
6575
min = -1.5;
6676
max = 1.5;
6777
mylogcdf = logcdf.factory( min, max );
78+
x = uniform( 100, -2.0, 2.0 );
6879

6980
b.tic();
7081
for ( i = 0; i < b.iterations; i++ ) {
71-
x = ( randu()*2.0 ) - 2.0;
72-
y = mylogcdf( x );
82+
y = mylogcdf( x[ i % x.length ] );
7383
if ( isnan( y ) ) {
7484
b.fail( 'should not return NaN' );
7585
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var resolve = require( 'path' ).resolve;
24+
var bench = require( '@stdlib/bench' );
25+
var Float64Array = require( '@stdlib/array/float64' );
26+
var randu = require( '@stdlib/random/base/randu' );
27+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
28+
var tryRequire = require( '@stdlib/utils/try-require' );
29+
var pkg = require( './../package.json' ).name;
30+
31+
32+
// VARIABLES //
33+
34+
var logcdf = tryRequire( resolve( __dirname, './../lib/native.js' ) );
35+
var opts = {
36+
'skip': ( logcdf instanceof Error )
37+
};
38+
39+
40+
// MAIN //
41+
42+
bench( pkg+'::native', opts, function benchmark( b ) {
43+
var len;
44+
var min;
45+
var max;
46+
var x;
47+
var y;
48+
var i;
49+
50+
len = 100;
51+
x = new Float64Array( len );
52+
min = new Float64Array( len );
53+
max = new Float64Array( len );
54+
for ( i = 0; i < len; i++ ) {
55+
x[ i ] = ( randu() * 20.0 ) - 10.0;
56+
min[ i ] = ( randu() * 20.0 ) - 20.0;
57+
max[ i ] = min[ i ] + ( randu() * 40.0 );
58+
}
59+
60+
b.tic();
61+
for ( i = 0; i < b.iterations; i++ ) {
62+
y = logcdf( x[ i % len ], min[ i % len ], max[ i % len ] );
63+
if ( isnan( y ) ) {
64+
b.fail( 'should not return NaN' );
65+
}
66+
}
67+
b.toc();
68+
if ( isnan( y ) ) {
69+
b.fail( 'should not return NaN' );
70+
}
71+
b.pass( 'benchmark finished' );
72+
b.end();
73+
});

lib/node_modules/@stdlib/stats/base/dists/arcsine/logcdf/benchmark/c/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,4 @@ run: $(c_targets)
143143
clean:
144144
$(QUIET) -rm -f *.o *.out
145145

146-
.PHONY: clean
146+
.PHONY: clean

lib/node_modules/@stdlib/stats/base/dists/arcsine/logcdf/benchmark/c/benchmark.c

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,15 @@ static double tic( void ) {
7575
}
7676

7777
/**
78-
* Generates a random number on the interval [0,1).
78+
* Generates a random number on the interval [min,max).
7979
*
80-
* @return random number
80+
* @param min minimum value (inclusive)
81+
* @param max maximum value (exclusive)
82+
* @return random number
8183
*/
82-
static double rand_double( void ) {
83-
int r = rand();
84-
return (double)r / ( (double)RAND_MAX + 1.0 );
84+
static double random_uniform( const double min, const double max ) {
85+
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
86+
return min + ( v*(max-min) );
8587
}
8688

8789
/**
@@ -91,19 +93,22 @@ static double rand_double( void ) {
9193
*/
9294
static double benchmark( void ) {
9395
double elapsed;
94-
double x;
95-
double a;
96-
double b;
96+
double x[ 100 ];
97+
double a[ 100 ];
98+
double b[ 100 ];
9799
double y;
98100
double t;
99101
int i;
100102

103+
for ( i = 0; i < 100; i++ ) {
104+
x[ i ] = random_uniform( -10.0, 10.0 );
105+
a[ i ] = random_uniform( -20.0, 0.0 );
106+
b[ i ] = random_uniform( a[ i ], a[ i ]+40.0 );
107+
}
108+
101109
t = tic();
102110
for ( i = 0; i < ITERATIONS; i++ ) {
103-
x = ( 20.0 * rand_double() ) - 10.0;
104-
a = ( 20.0 * rand_double() ) - 20.0;
105-
b = a + ( 40.0 * rand_double() );
106-
y = stdlib_base_dists_arcsine_logcdf( x, a, b );
111+
y = stdlib_base_dists_arcsine_logcdf( x[ i%100 ], a[ i%100 ], b[ i%100 ] );
107112
if ( y != y ) {
108113
printf( "should not return NaN\n" );
109114
break;
@@ -134,4 +139,4 @@ int main( void ) {
134139
printf( "ok %d benchmark finished\n", i+1 );
135140
}
136141
print_summary( REPEATS, REPEATS );
137-
}
142+
}

lib/node_modules/@stdlib/stats/base/dists/arcsine/logcdf/binding.gyp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,4 @@
167167
], # end actions
168168
}, # end target copy_addon
169169
], # end targets
170-
}
170+
}

lib/node_modules/@stdlib/stats/base/dists/arcsine/logcdf/examples/c/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,4 @@ run: $(c_targets)
143143
clean:
144144
$(QUIET) -rm -f *.o *.out
145145

146-
.PHONY: clean
146+
.PHONY: clean

lib/node_modules/@stdlib/stats/base/dists/arcsine/logcdf/examples/c/example.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ int main( void ) {
3434
y = stdlib_base_dists_arcsine_logcdf( x, a, b );
3535
printf( "x: %lf ,a: %lf, b: %lf, ln(F;x,a,b): %lf\n", x, a, b, y );
3636
}
37-
}
37+
}

lib/node_modules/@stdlib/stats/base/dists/arcsine/logcdf/include.gypi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@
5050
'<!@(node -e "var arr = require(\'@stdlib/utils/library-manifest\')(\'./manifest.json\',{},{\'basedir\':process.cwd(),\'paths\':\'posix\'}).libpath; for ( var i = 0; i < arr.length; i++ ) { console.log( arr[ i ] ); }")',
5151
],
5252
}, # end variables
53-
}
53+
}

lib/node_modules/@stdlib/stats/base/dists/arcsine/logcdf/include/stdlib/stats/base/dists/arcsine/logcdf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ double stdlib_base_dists_arcsine_logcdf( const double x, const double a, const d
3535
}
3636
#endif
3737

38-
#endif // !STDLIB_STATS_BASE_DISTS_ARCSINE_LOGCDF_H
38+
#endif // !STDLIB_STATS_BASE_DISTS_ARCSINE_LOGCDF_H

0 commit comments

Comments
 (0)