Skip to content

Commit f44e0b1

Browse files
committed
fix:refactor c implementation
--- 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 320feda commit f44e0b1

File tree

5 files changed

+39
-26
lines changed

5 files changed

+39
-26
lines changed

lib/node_modules/@stdlib/stats/base/dists/signrank/quantile/examples/c/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ CFLAGS ?= \
5757
-std=c99 \
5858
-O3 \
5959
-Wall \
60-
-pedantic
60+
-pedantic \
61+
-v
6162

6263
# Determine whether to generate position independent code ([1][1], [2][2]).
6364
#
@@ -84,7 +85,6 @@ LIBPATH := -L$(PWD)/lib/node_modules/@stdlib/stats/base/dists/signrank/quantile/
8485
# List of C targets:
8586
c_targets := example.out
8687

87-
8888
# RULES #
8989

9090
#/

lib/node_modules/@stdlib/stats/base/dists/signrank/quantile/include/stdlib/stats/base/dists/signrank/quantile.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
* limitations under the License.
1717
*/
1818

19-
#ifndef STDLIB_BASES_DISTS_SIGNRANK_QUANTILE_H
20-
#define STDLIB_BASES_DISTS_SIGNRANK_QUANTILE_H
19+
#ifndef STDLIB_STATS_BASE_DISTS_SIGNRANK_QUANTILE_H
20+
#define STDLIB_STATS_BASE_DISTS_SIGNRANK_QUANTILE_H
2121

2222
/**
2323
* Evaluates the quantile function for the Wilcoxon signed rank test statistic.
@@ -28,4 +28,4 @@
2828
*/
2929
double stdlib_base_dists_signrank_quantile(double p, int n);
3030

31-
#endif // !STDLIB_BASES_DISTS_SIGNRANK_QUANTILE_H
31+
#endif // !STDLIB_STATS_BASE_DISTS_SIGNRANK_QUANTILE_H

lib/node_modules/@stdlib/stats/base/dists/signrank/quantile/lib/native.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020

2121
// MODULES //
2222

23-
var addon = require( './../src/addon.node' );
24-
console.log(addon);
25-
23+
var addon = require( './../src/addon' );
2624

2725

2826
// MAIN //
@@ -48,7 +46,10 @@ console.log(addon);
4846
* // returns NaN
4947
*/
5048
function quantile( p, n ) {
51-
return addon( p, n );
49+
if (typeof p !== 'number' || typeof n !== 'number' || n <= 0 || p < 0 || p > 1) {
50+
return NaN;
51+
}
52+
return addon(p, n);
5253
}
5354

5455

lib/node_modules/@stdlib/stats/base/dists/signrank/quantile/src/Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,19 @@ endif
4545
endif
4646
endif
4747

48+
# Compiler and flags
49+
CC = gcc
50+
CFLAGS = -fPIC -shared
51+
52+
# Source files
53+
SRC = addon.c
54+
55+
# Target shared object
56+
TARGET = addon.node
57+
58+
# Build rule
59+
$(TARGET): $(SRC)
60+
$(CC) $(CFLAGS) -o $@ $^ -I/path/to/stdlib/include -L/path/to/stdlib/lib -lstdc++
4861

4962
# RULES #
5063

lib/node_modules/@stdlib/stats/base/dists/signrank/quantile/src/main.c

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,34 @@
1717
*/
1818

1919
#include "stdlib/stats/base/dists/signrank/quantile.h"
20-
#include <stdio.h>
20+
#include <math.h>
2121

2222
/**
23-
* Evaluates the quantile function for the Wilcoxon signed rank test statistic with `n` observations.
23+
* Evaluates the quantile function for the Wilcoxon signed-rank test statistic with `n` observations.
2424
*
2525
* @param p input probability
2626
* @param n number of observations
27-
* @return evaluated quantile
27+
* @return evaluated quantile or NaN if inputs are invalid
2828
*
2929
* @example
3030
* double y = stdlib_base_dists_signrank_quantile( 0.5, 5 );
3131
* // returns 11
3232
*/
33-
int main() {
34-
double probabilities[] = {0.1, 0.25, 0.5, 0.75, 0.9};
35-
int sample_sizes[] = {3, 5, 7, 10};
36-
37-
printf("Quantile Function for Wilcoxon Signed Rank Test\n");
38-
printf("------------------------------------------------\n");
33+
double stdlib_base_dists_signrank_quantile(double p, int n) {
34+
if (isnan(p) || p < 0.0 || p > 1.0 || n <= 0) {
35+
return NAN;
36+
}
3937

40-
for (int i = 0; i < sizeof(sample_sizes) / sizeof(sample_sizes[0]); i++) {
41-
int n = sample_sizes[i];
42-
printf("\nSample size (n): %d\n", n);
43-
for (int j = 0; j < sizeof(probabilities) / sizeof(probabilities[0]); j++) {
44-
double p = probabilities[j];
45-
double result = stdlib_base_dists_signrank_quantile(p, n);
46-
printf("P: %.2f -> Quantile: %.4f\n", p, result);
38+
int max_rank_sum = (n * (n + 1)) / 2;
39+
double cumulative_prob = 0.0;
40+
for (int rank_sum = 0; rank_sum <= max_rank_sum; rank_sum++) {
41+
double pmf = 0.0;
42+
cumulative_prob += pmf;
43+
if (cumulative_prob >= p) {
44+
return (double)rank_sum;
4745
}
4846
}
4947

50-
return 0;
48+
49+
return NAN;
5150
}

0 commit comments

Comments
 (0)