@stdlib/stats-base-dists-wald-pdf 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/addon.c ADDED
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2026 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
+ #include "stdlib/stats/base/dists/wald/pdf.h"
20
+ #include "stdlib/math/base/napi/ternary.h"
21
+
22
+ STDLIB_MATH_BASE_NAPI_MODULE_DDD_D( stdlib_base_dists_wald_pdf )
package/src/main.c ADDED
@@ -0,0 +1,62 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2026 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
+ #include "stdlib/stats/base/dists/wald/pdf.h"
20
+ #include "stdlib/math/base/assert/is_nan.h"
21
+ #include "stdlib/math/base/assert/is_infinite.h"
22
+ #include "stdlib/math/base/special/sqrt.h"
23
+ #include "stdlib/math/base/special/exp.h"
24
+ #include "stdlib/constants/float64/two_pi.h"
25
+ #include "stdlib/constants/float64/pinf.h"
26
+
27
+ /**
28
+ * Evaluates the probability density function (PDF) for a Wald distribution with mean `mu` and shape parameter `lambda` at a value `x`.
29
+ *
30
+ * @param x input value
31
+ * @param mu mean of the distribution
32
+ * @param lambda shape parameter of the distribution
33
+ * @return evaluated probability density function
34
+ *
35
+ * @example
36
+ * double y = stdlib_base_dists_wald_pdf( 2.0, 1.0, 1.0 );
37
+ * // returns ~0.110
38
+ */
39
+ double stdlib_base_dists_wald_pdf( const double x, const double mu, const double lambda ) {
40
+ double A;
41
+ double B;
42
+ double v;
43
+ if (
44
+ stdlib_base_is_nan( x ) ||
45
+ stdlib_base_is_nan( mu ) ||
46
+ stdlib_base_is_nan( lambda ) ||
47
+ mu <= 0.0 ||
48
+ lambda < 0.0
49
+ ) {
50
+ return 0.0/0.0; // NaN
51
+ }
52
+ if ( lambda == 0.0 ) {
53
+ return ( x == mu ) ? STDLIB_CONSTANT_FLOAT64_PINF : 0.0;
54
+ }
55
+ if ( x <= 0.0 || stdlib_base_is_infinite( x ) ) {
56
+ return 0.0;
57
+ }
58
+ A = stdlib_base_sqrt( lambda / STDLIB_CONSTANT_FLOAT64_TWO_PI );
59
+ B = -lambda / ( 2.0 * mu * mu );
60
+ v = x - mu;
61
+ return A / ( x * stdlib_base_sqrt( x ) ) * stdlib_base_exp( B * v * v / x );
62
+ }