Skip to content

Commit 975097d

Browse files
committed
feat: add C implementation of stats/base/dists/t/cdf
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: missing_dependencies - task: lint_c_examples status: missing_dependencies - task: lint_c_benchmarks status: missing_dependencies - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na ---
1 parent 3246d1a commit 975097d

File tree

16 files changed

+322
-164
lines changed

16 files changed

+322
-164
lines changed

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

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,101 @@ for ( i = 0; i < 10; i++ ) {
132132

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

135+
<!-- C interface documentation. -->
136+
137+
* * *
138+
139+
<section class="c">
140+
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+
153+
<section class="usage">
154+
155+
### Usage
156+
157+
```c
158+
#include "stdlib/stats/base/dists/t/cdf.h"
159+
```
160+
161+
#### stdlib_base_dists_t_cdf( x, v )
162+
163+
Evaluates the cumulative distribution function (CDF) for a Student's t distribution.
164+
165+
```c
166+
double out = stdlib_base_dists_t_cdf( 2.0, 0.1 );
167+
// returns ~0.611
168+
```
169+
170+
The function accepts the following arguments:
171+
172+
- **x**: `[in] double` input value.
173+
- **v**: `[in] double` degrees of freedom.
174+
175+
```c
176+
double stdlib_base_dists_t_cdf( const double x, const double v );
177+
```
178+
179+
</section>
180+
181+
<!-- /.usage -->
182+
183+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
184+
185+
<section class="notes">
186+
187+
</section>
188+
189+
<!-- /.notes -->
190+
191+
<!-- C API usage examples. -->
192+
193+
<section class="examples">
194+
195+
### Examples
196+
197+
```c
198+
#include "stdlib/stats/base/dists/t/cdf.h"
199+
#include <stdlib.h>
200+
#include <stdio.h>
201+
202+
static double random_uniform( const double min, const double max ) {
203+
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
204+
return min + ( v*(max-min) );
205+
}
206+
207+
int main( void ) {
208+
double x;
209+
double v;
210+
double y;
211+
int i;
212+
213+
for ( i = 0; i < 25; i++ ) {
214+
x = random_uniform( -10.0, 10.0 );
215+
v = random_uniform( 1.0, 30.0 );
216+
y = stdlib_base_dists_t_cdf( x, v );
217+
printf( "x: %lf, v: %lf, F(x;v): %lf\n", x, v, y );
218+
}
219+
}
220+
```
221+
222+
</section>
223+
224+
<!-- /.examples -->
225+
226+
</section>
227+
228+
<!-- /.c -->
229+
135230
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
136231

137232
<section class="related">

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2018 The Stdlib Authors.
4+
* Copyright (c) 2024 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -21,8 +21,8 @@
2121
// MODULES //
2222

2323
var bench = require( '@stdlib/bench' );
24-
var ceil = require( '@stdlib/math/base/special/ceil' );
25-
var randu = require( '@stdlib/random/base/randu' );
24+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
25+
var uniform = require( '@stdlib/random/array/uniform' );
2626
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2727
var pkg = require( './../package.json' ).name;
2828
var cdf = require( './../lib' );
@@ -36,11 +36,12 @@ bench( pkg, function benchmark( b ) {
3636
var y;
3737
var i;
3838

39+
x = uniform( 100, -50.0, 50.0 );
40+
v = discreteUniform( 100, 1.0, 100.0 );
41+
3942
b.tic();
4043
for ( i = 0; i < b.iterations; i++ ) {
41-
x = ( randu()*100.0 ) - 100;
42-
v = ceil( randu()*100.0 );
43-
y = cdf( x, v );
44+
y = cdf( x[ i % x.length ], v[ i % v.length ] );
4445
if ( isnan( y ) ) {
4546
b.fail( 'should not return NaN' );
4647
}
@@ -55,18 +56,16 @@ bench( pkg, function benchmark( b ) {
5556

5657
bench( pkg+':factory', function benchmark( b ) {
5758
var mycdf;
58-
var v;
5959
var x;
6060
var y;
6161
var i;
6262

63-
v = 3.0;
64-
mycdf = cdf.factory( v );
63+
x = uniform( 100, -50.0, 50.0 );
64+
mycdf = cdf.factory( 3.0 );
6565

6666
b.tic();
6767
for ( i = 0; i < b.iterations; i++ ) {
68-
x = ( randu()*100.0 ) - 50.0;
69-
y = mycdf( x );
68+
y = mycdf( x[ i % x.length ] );
7069
if ( isnan( y ) ) {
7170
b.fail( 'should not return NaN' );
7271
}

lib/node_modules/@stdlib/stats/base/dists/t/cdf/benchmark/c/Makefile

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
# VARIABLES #
2020

2121
ifndef VERBOSE
22-
QUIET := @
22+
QUIET := @
2323
else
24-
QUIET :=
24+
QUIET :=
2525
endif
2626

2727
# Determine the OS ([1][1], [2][2]).
@@ -30,43 +30,43 @@ endif
3030
# [2]: http://stackoverflow.com/a/27776822/2225624
3131
OS ?= $(shell uname)
3232
ifneq (, $(findstring MINGW,$(OS)))
33-
OS := WINNT
33+
OS := WINNT
3434
else
3535
ifneq (, $(findstring MSYS,$(OS)))
36-
OS := WINNT
36+
OS := WINNT
3737
else
3838
ifneq (, $(findstring CYGWIN,$(OS)))
39-
OS := WINNT
39+
OS := WINNT
4040
else
4141
ifneq (, $(findstring Windows_NT,$(OS)))
42-
OS := WINNT
42+
OS := WINNT
4343
endif
4444
endif
4545
endif
4646
endif
4747

4848
# Define the program used for compiling C source files:
4949
ifdef C_COMPILER
50-
CC := $(C_COMPILER)
50+
CC := $(C_COMPILER)
5151
else
52-
CC := gcc
52+
CC := gcc
5353
endif
5454

5555
# Define the command-line options when compiling C files:
5656
CFLAGS ?= \
57-
-std=c99 \
58-
-O3 \
59-
-Wall \
60-
-pedantic
57+
-std=c99 \
58+
-O3 \
59+
-Wall \
60+
-pedantic
6161

6262
# Determine whether to generate position independent code ([1][1], [2][2]).
6363
#
6464
# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options
6565
# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option
6666
ifeq ($(OS), WINNT)
67-
fPIC ?=
67+
fPIC ?=
6868
else
69-
fPIC ?= -fPIC
69+
fPIC ?= -fPIC
7070
endif
7171

7272
# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`):
@@ -121,7 +121,7 @@ all: $(c_targets)
121121
# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`)
122122
#/
123123
$(c_targets): %.out: %.c
124-
$(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES)
124+
$(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES)
125125

126126
#/
127127
# Runs compiled benchmarks.
@@ -130,7 +130,7 @@ $(c_targets): %.out: %.c
130130
# make run
131131
#/
132132
run: $(c_targets)
133-
$(QUIET) ./$<
133+
$(QUIET) ./$<
134134

135135
.PHONY: run
136136

@@ -141,6 +141,6 @@ run: $(c_targets)
141141
# make clean
142142
#/
143143
clean:
144-
$(QUIET) -rm -f *.o *.out
144+
$(QUIET) -rm -f *.o *.out
145145

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

lib/node_modules/@stdlib/stats/base/dists/t/cdf/benchmark/c/benchmark.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,4 @@ int main( void ) {
136136
printf( "ok %d benchmark finished\n", i+1 );
137137
}
138138
print_summary( REPEATS, REPEATS );
139-
}
139+
}

lib/node_modules/@stdlib/stats/base/dists/t/cdf/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/t/cdf/examples/c/Makefile

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
# VARIABLES #
2020

2121
ifndef VERBOSE
22-
QUIET := @
22+
QUIET := @
2323
else
24-
QUIET :=
24+
QUIET :=
2525
endif
2626

2727
# Determine the OS ([1][1], [2][2]).
@@ -30,43 +30,43 @@ endif
3030
# [2]: http://stackoverflow.com/a/27776822/2225624
3131
OS ?= $(shell uname)
3232
ifneq (, $(findstring MINGW,$(OS)))
33-
OS := WINNT
33+
OS := WINNT
3434
else
3535
ifneq (, $(findstring MSYS,$(OS)))
36-
OS := WINNT
36+
OS := WINNT
3737
else
3838
ifneq (, $(findstring CYGWIN,$(OS)))
39-
OS := WINNT
39+
OS := WINNT
4040
else
4141
ifneq (, $(findstring Windows_NT,$(OS)))
42-
OS := WINNT
42+
OS := WINNT
4343
endif
4444
endif
4545
endif
4646
endif
4747

4848
# Define the program used for compiling C source files:
4949
ifdef C_COMPILER
50-
CC := $(C_COMPILER)
50+
CC := $(C_COMPILER)
5151
else
52-
CC := gcc
52+
CC := gcc
5353
endif
5454

5555
# Define the command-line options when compiling C files:
5656
CFLAGS ?= \
57-
-std=c99 \
58-
-O3 \
59-
-Wall \
60-
-pedantic
57+
-std=c99 \
58+
-O3 \
59+
-Wall \
60+
-pedantic
6161

6262
# Determine whether to generate position independent code ([1][1], [2][2]).
6363
#
6464
# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options
6565
# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option
6666
ifeq ($(OS), WINNT)
67-
fPIC ?=
67+
fPIC ?=
6868
else
69-
fPIC ?= -fPIC
69+
fPIC ?= -fPIC
7070
endif
7171

7272
# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`):
@@ -121,7 +121,7 @@ all: $(c_targets)
121121
# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`)
122122
#/
123123
$(c_targets): %.out: %.c
124-
$(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES)
124+
$(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES)
125125

126126
#/
127127
# Runs compiled examples.
@@ -130,7 +130,7 @@ $(c_targets): %.out: %.c
130130
# make run
131131
#/
132132
run: $(c_targets)
133-
$(QUIET) ./$<
133+
$(QUIET) ./$<
134134

135135
.PHONY: run
136136

@@ -141,6 +141,6 @@ run: $(c_targets)
141141
# make clean
142142
#/
143143
clean:
144-
$(QUIET) -rm -f *.o *.out
144+
$(QUIET) -rm -f *.o *.out
145145

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

lib/node_modules/@stdlib/stats/base/dists/t/cdf/examples/c/example.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,14 @@ static double random_uniform( const double min, const double max ) {
2727

2828
int main( void ) {
2929
double x;
30-
double v; // degrees of freedom
30+
double v;
3131
double y;
3232
int i;
3333

3434
for ( i = 0; i < 25; i++ ) {
35-
// Generate random values for x and degrees of freedom v
3635
x = random_uniform( -10.0, 10.0 );
37-
v = random_uniform( 1.0, 30.0 ); // degrees of freedom should be > 0
38-
// Calculate the CDF for the Student's t-distribution
36+
v = random_uniform( 1.0, 30.0 );
3937
y = stdlib_base_dists_t_cdf( x, v );
40-
// Print the results
4138
printf( "x: %lf, v: %lf, F(x;v): %lf\n", x, v, y );
4239
}
43-
}
40+
}

lib/node_modules/@stdlib/stats/base/dists/t/cdf/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+
}

0 commit comments

Comments
 (0)