From 64585e7279d877a6396e9a2a89222c88df6a989f Mon Sep 17 00:00:00 2001 From: Vivek Maurya Date: Tue, 10 Dec 2024 14:13:24 +0530 Subject: [PATCH] feat(add C implementation): add stats/base/dists/arcsine/cdf --- .../stdlib/stats/base/dists/arcsine/cdf.h | 38 ++++++++ .../base/dists/arcsine/cdf/lib/native.js | 71 ++++++++++++++ .../base/dists/arcsine/cdf/manifest.json | 94 +++++++++++++++++++ .../stats/base/dists/arcsine/cdf/package.json | 3 + .../stats/base/dists/arcsine/cdf/src/Makefile | 70 ++++++++++++++ .../stats/base/dists/arcsine/cdf/src/addon.c | 23 +++++ .../stats/base/dists/arcsine/cdf/src/main.c | 57 +++++++++++ 7 files changed, 356 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/base/dists/arcsine/cdf/include/stdlib/stats/base/dists/arcsine/cdf.h create mode 100644 lib/node_modules/@stdlib/stats/base/dists/arcsine/cdf/lib/native.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/arcsine/cdf/manifest.json create mode 100644 lib/node_modules/@stdlib/stats/base/dists/arcsine/cdf/src/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/arcsine/cdf/src/addon.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/arcsine/cdf/src/main.c diff --git a/lib/node_modules/@stdlib/stats/base/dists/arcsine/cdf/include/stdlib/stats/base/dists/arcsine/cdf.h b/lib/node_modules/@stdlib/stats/base/dists/arcsine/cdf/include/stdlib/stats/base/dists/arcsine/cdf.h new file mode 100644 index 000000000000..0bfad1403387 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/arcsine/cdf/include/stdlib/stats/base/dists/arcsine/cdf.h @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* 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. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef STDLIB_STATS_BASE_DISTS_ARCSINE_CDF_H +#define STDLIB_STATS_BASE_DISTS_ARCSINE_CDF_H + +/* +* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. +*/ +#ifdef __cplusplus +extern "C" { +#endif + +/** +* Evaluates the cumulative distribution function (CDF) for an arcsine distribution with minimum support `a` and maximum support `b` at a value `x`. +*/ +double stdlib_base_dists_arcsine_cdf( const double a, const double b ); + +#ifdef __cplusplus +} +#endif + +#endif // !STDLIB_STATS_BASE_DISTS_ARCSINE_CDF_H \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/dists/arcsine/cdf/lib/native.js b/lib/node_modules/@stdlib/stats/base/dists/arcsine/cdf/lib/native.js new file mode 100644 index 000000000000..8c013336f928 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/arcsine/cdf/lib/native.js @@ -0,0 +1,71 @@ +/** +* @license Apache-2.0 +* +* 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. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var addon = require( './../src/addon.node' ); + + +// MAIN // + +/** +* Evaluates the cumulative distribution function (CDF) for an arcsine distribution with minimum support `a` and maximum support `b` at a value `x`. +* +* @param {number} x - input value +* @param {number} a - minimum support +* @param {number} b - maximum support +* @returns {Probability} evaluated CDF +* +* @example +* var y = cdf( 9.0, 0.0, 10.0 ); +* // returns ~0.795 +* +* @example +* var y = cdf( 0.5, 0.0, 2.0 ); +* // returns ~0.333 +* +* @example +* var y = cdf( +Infinity, 2.0, 4.0 ); +* // returns 1.0 +* +* @example +* var y = cdf( -Infinity, 2.0, 4.0 ); +* // returns 0.0 +* +* @example +* var y = cdf( NaN, 0.0, 1.0 ); +* // returns NaN +* +* @example +* var y = cdf( 0.0, NaN, 1.0 ); +* // returns NaN +* +* @example +* var y = cdf( 0.0, 0.0, NaN ); +* // returns NaN +*/ +function cdf( x, a, b ) { + return addon( x, a, b ); +} + + +// EXPORTS // + +module.exports = cdf; \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/dists/arcsine/cdf/manifest.json b/lib/node_modules/@stdlib/stats/base/dists/arcsine/cdf/manifest.json new file mode 100644 index 000000000000..c9fcf2cfb747 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/arcsine/cdf/manifest.json @@ -0,0 +1,94 @@ +{ + "options": { + "task": "build", + "wasm": false + }, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "task": "build", + "wasm": false, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/napi/ternary", + "@stdlib/math/base/assert/is-nan", + "@stdlib/math/base/special/ln", + "@stdlib/constants/float64/ln-pi", + "@stdlib/constants/float64/ln-two", + "@stdlib/constants/float64/ninf", + "@stdlib/math/base/special/asin", + "@stdlib/math/base/special/sqrt" + ] + }, + { + "task": "benchmark", + "wasm": false, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/assert/is-nan", + "@stdlib/math/base/special/ln", + "@stdlib/constants/float64/ln-pi", + "@stdlib/constants/float64/ln-two", + "@stdlib/constants/float64/ninf", + "@stdlib/math/base/special/asin", + "@stdlib/math/base/special/sqrt" + ] + }, + { + "task": "examples", + "wasm": false, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/assert/is-nan", + "@stdlib/math/base/special/ln", + "@stdlib/constants/float64/ln-pi", + "@stdlib/constants/float64/ln-two", + "@stdlib/constants/float64/ninf", + "@stdlib/math/base/special/asin", + "@stdlib/math/base/special/sqrt" + ] + } + ] + } \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/dists/arcsine/cdf/package.json b/lib/node_modules/@stdlib/stats/base/dists/arcsine/cdf/package.json index d2d7450f46f4..ad1f28f1a531 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/arcsine/cdf/package.json +++ b/lib/node_modules/@stdlib/stats/base/dists/arcsine/cdf/package.json @@ -14,11 +14,14 @@ } ], "main": "./lib", + "gypfile": true, "directories": { "benchmark": "./benchmark", "doc": "./docs", "example": "./examples", + "include": "./include", "lib": "./lib", + "src": "./src", "test": "./test" }, "types": "./docs/types", diff --git a/lib/node_modules/@stdlib/stats/base/dists/arcsine/cdf/src/Makefile b/lib/node_modules/@stdlib/stats/base/dists/arcsine/cdf/src/Makefile new file mode 100644 index 000000000000..81bb164286c3 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/arcsine/cdf/src/Makefile @@ -0,0 +1,70 @@ +#/ +# @license Apache-2.0 +# +# 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. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + + +# RULES # + +#/ +# Removes generated files for building an add-on. +# +# @example +# make clean-addon +#/ +clean-addon: + $(QUIET) -rm -f *.o *.node + +.PHONY: clean-addon + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: clean-addon + +.PHONY: clean \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/dists/arcsine/cdf/src/addon.c b/lib/node_modules/@stdlib/stats/base/dists/arcsine/cdf/src/addon.c new file mode 100644 index 000000000000..4dc7878ab144 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/arcsine/cdf/src/addon.c @@ -0,0 +1,23 @@ +/** +* @license Apache-2.0 +* +* 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. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/stats/base/dists/arcsine/cdf.h" +#include "stdlib/math/base/napi/ternary.h" + +// cppcheck-suppress shadowFunction +STDLIB_MATH_BASE_NAPI_MODULE_DDD_D( stdlib_base_dists_arcsine_cdf ) \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/dists/arcsine/cdf/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/arcsine/cdf/src/main.c new file mode 100644 index 000000000000..e45a1a88cd9c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/arcsine/cdf/src/main.c @@ -0,0 +1,57 @@ +/** +* @license Apache-2.0 +* +* 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. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/stats/base/dists/arcsine/cdf.h" +#include "stdlib/math/base/assert/is_nan.h" +#include "stdlib/math/base/special/ln.h" +#include "stdlib/constants/float64/pi.h" +#include "stdlib/constants/float64/ln_two.h" +#include "stdlib/constants/float64/ninf.h" +#include "stdlib/math/base/special/asin.h" +#include "stdlib/math/base/special/sqrt.h" + +/** +* Evaluates the cumulative distribution function (CDF) for an arcsine distribution with minimum support `a` and maximum support `b` at a value `x`. +* +* @param {number} x - input value +* @param {number} a - minimum support +* @param {number} b - maximum support +* @returns {Probability} evaluated CDF +* +* @example +* double y = stdlib_base_arcsine_kurtosis( 0.0, 1.0 ); +* // returns 1.5 +*/ +double stdlib_base_dists_arcsine_cdf( const double x, const double a, const double b ) { + double TWO_OVER_PI = 2.0 / STDLIB_CONSTANT_FLOAT64_PI; + if ( + stdlib_base_is_nan( x ) || + stdlib_base_is_nan( a ) || + stdlib_base_is_nan( b ) || + a >= b + ) { + return 0.0/0.0; + } + if ( x < a ) { + return 0.0; + } + if ( x >= b ) { + return 1.0; + } + return TWO_OVER_PI * stdlib_base_asin( stdlib_base_sqrt( ( x-a ) / ( b-a ) ) ); +} \ No newline at end of file