Skip to content

Commit 307f740

Browse files
committed
refactoring C implementation
--- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: passed - task: run_c_examples status: failed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: passed - task: run_c_examples status: failed ---
1 parent 8c49027 commit 307f740

File tree

8 files changed

+75
-69
lines changed

8 files changed

+75
-69
lines changed

lib/node_modules/@stdlib/stats/base/dists/chisquare/mgf/examples/c/example.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
/**
2-
* @license Apache-2.0
3-
*
4-
* Copyright (c) 2025 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-
*/
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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+
*/
1818

1919
#include "stdlib/stats/base/dists/chisquare/mgf.h"
2020
#include <stdio.h>

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#/
22
# @license Apache-2.0
33
#
4-
# Copyright (c) 2024 The Stdlib Authors.
4+
# Copyright (c) 2025 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.
@@ -70,19 +70,19 @@ else
7070
endif
7171

7272
# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`):
73-
INCLUDE ?=
73+
INCLUDE := -I$(PWD)/lib/node_modules/@stdlib/stats/base/dists/signrank/quantile/include
7474

7575
# List of source files:
7676
SOURCE_FILES ?=
7777

7878
# List of libraries (e.g., `-lopenblas -lpthread`):
79-
LIBRARIES ?=
79+
LIBRARIES := -lstdlib_base_dists_signrank_quantile -lm
8080

8181
# List of library paths (e.g., `-L /foo/bar -L /beep/boop`):
82-
LIBPATH ?=
82+
LIBPATH := -L$(PWD)/lib/node_modules/@stdlib/stats/base/dists/signrank/quantile/lib
8383

8484
# List of C targets:
85-
c_targets := benchmark.out
85+
c_targets := example.out
8686

8787

8888
# RULES #
@@ -120,11 +120,13 @@ all: $(c_targets)
120120
# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`)
121121
# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`)
122122
#/
123+
123124
$(c_targets): %.out: %.c
124-
$(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES)
125+
$(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $< $(LIBPATH) -lm $(LIBRARIES)
126+
125127

126128
#/
127-
# Runs compiled benchmarks.
129+
# Runs compiled examples.
128130
#
129131
# @example
130132
# make run
@@ -143,3 +145,5 @@ run: $(c_targets)
143145
clean:
144146
$(QUIET) -rm -f *.o *.out
145147

148+
.PHONY: clean
149+

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ static void benchmark_quantile(int n) {
2828
double result;
2929
clock_t start, end;
3030
double elapsed;
31+
double sum = 0.0;
3132

3233
printf("Benchmarking signrank_quantile with %d iterations for n=%d...\n", NUM_ITERATIONS, n);
3334

@@ -36,7 +37,8 @@ static void benchmark_quantile(int n) {
3637

3738
for (int i = 0; i < NUM_ITERATIONS; i++) {
3839
p = (double)(i % 101) / 100.0; // Generate p values in [0, 1]
39-
result = signrank_quantile(p, n);
40+
result = stdlib_base_dists_signrank_quantile(p, n);
41+
sum += result;
4042
}
4143

4244
// End timer
@@ -48,6 +50,7 @@ static void benchmark_quantile(int n) {
4850
// Print benchmark results
4951
printf("Elapsed time: %.6f seconds\n", elapsed);
5052
printf("Average time per call: %.6f microseconds\n", (elapsed / NUM_ITERATIONS) * 1e6);
53+
printf("Sum of results: %.6f\n", sum);
5154
}
5255

5356
int main() {

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#/
22
# @license Apache-2.0
33
#
4-
# Copyright (c) 2024 The Stdlib Authors.
4+
# Copyright (c) 2025 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.
@@ -70,16 +70,16 @@ else
7070
endif
7171

7272
# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`):
73-
INCLUDE ?=
73+
INCLUDE := -I$(PWD)/lib/node_modules/@stdlib/stats/base/dists/signrank/quantile/include
7474

7575
# List of source files:
7676
SOURCE_FILES ?=
7777

7878
# List of libraries (e.g., `-lopenblas -lpthread`):
79-
LIBRARIES ?=
79+
LIBRARIES := -lstdlib_base_dists_signrank_quantile -lm
8080

8181
# List of library paths (e.g., `-L /foo/bar -L /beep/boop`):
82-
LIBPATH ?=
82+
LIBPATH := -L$(PWD)/lib/node_modules/@stdlib/stats/base/dists/signrank/quantile/lib
8383

8484
# List of C targets:
8585
c_targets := example.out
@@ -120,8 +120,10 @@ all: $(c_targets)
120120
# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`)
121121
# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`)
122122
#/
123+
123124
$(c_targets): %.out: %.c
124-
$(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES)
125+
$(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $< $(LIBPATH) -lm $(LIBRARIES)
126+
125127

126128
#/
127129
# Runs compiled examples.
@@ -144,3 +146,4 @@ clean:
144146
$(QUIET) -rm -f *.o *.out
145147

146148
.PHONY: clean
149+

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

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

19+
#include "stdlib/stats/base/dists/signrank/quantile.h"
1920
#include <stdio.h>
2021
#include <stdlib.h>
21-
#include <time.h>
22-
#include "stdlib/stats/base/dists/signrank/quantile.h"
2322

24-
// Function to generate a random integer between min and max (inclusive)
2523
int randint(int min, int max) {
2624
return min + rand() % (max - min + 1);
2725
}
2826

29-
// Function to generate a random double in the range [0, 1)
3027
double randu() {
3128
return (double)rand() / (double)RAND_MAX;
3229
}
3330

34-
int main() {
31+
int main() {
3532
int n;
3633
double p;
3734
double y;
3835

39-
// Seed the random number generator
40-
srand((unsigned int)time(NULL));
41-
4236
for (int i = 0; i < 10; i++) {
4337
p = randu();
4438
n = randint(1, 20);
45-
y = signrank_quantile(p, n);
39+
y = stdlib_base_dists_signrank_quantile(p, n);
4640
printf("p: %.4f, n: %d, Q(p;n): %.4f\n", p, n, y);
4741
}
4842

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@
2828
*/
2929
double stdlib_base_dists_signrank_quantile(double p, int n);
3030

31-
#endif // QUANTILE_H
31+
#endif // !QUANTILE_H

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

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

2323
var addon = require( './../src/addon.node' );
24+
console.log(addon);
25+
2426

2527

2628
// MAIN //

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

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,58 +20,58 @@
2020

2121
// MODULES //
2222

23-
// Include the function to be tested
23+
var resolve = require('path').resolve;
2424
var tape = require('tape');
25+
var path = require('path');
2526

26-
// Replace `addon` with your actual function, for example:
27-
var quantileFunction = require('./../lib/native.js'); // Adjust the path accordingly
27+
// VARIABLES //
28+
var quantile = require(resolve(__dirname, './../lib/native.js'));
29+
var opts = {
30+
'skip': ( quantile instanceof Error )
31+
};
32+
33+
// FIXTURES //
34+
35+
var data = require('./fixtures/r/data.json');
2836

2937
// TESTS //
3038

31-
// Check that the main export is a function
32-
tape('main export is a function', function test(t) {
39+
tape('main export is a function',opts, function test(t) {
3340
t.ok(true, __filename);
34-
t.strictEqual(typeof quantileFunction, 'function', 'main export is a function');
41+
t.strictEqual(typeof quantile, 'function', 'main export is a function');
3542
t.end();
3643
});
3744

3845
// Test that the function returns expected quantiles for valid inputs
39-
tape('the function returns expected quantiles for valid inputs', function test(t) {
40-
var probabilities = [0.1, 0.25, 0.5, 0.75, 0.9];
41-
var sampleSizes = [3, 5, 7, 10];
42-
var expected;
43-
var actual;
44-
var p;
45-
var n;
46-
var i;
47-
var j;
46+
tape('the function returns expected quantiles for valid inputs',opts, function test(t) {
47+
var probabilities = data.p;
48+
var sampleSizes = data.n;
49+
var expectedValues = data.expected;
50+
var actual, p, n;
51+
52+
t.plan(probabilities.length);
4853

49-
for (i = 0; i < sampleSizes.length; i++) {
54+
for (var i = 0; i < probabilities.length; i++) {
55+
p = probabilities[i];
5056
n = sampleSizes[i];
51-
for (j = 0; j < probabilities.length; j++) {
52-
p = probabilities[j];
53-
actual = quantileFunction(p, n);
57+
actual = quantile(p, n);
5458

55-
// Compute expected value based on known results or formula (placeholder logic here):
56-
expected /* Insert logic or precomputed values */;
57-
t.strictEqual(actual, expected, 'returns ' + expected + ' for p: ' + p + ', n: ' + n);
58-
}
59+
t.strictEqual(actual, expectedValues[i], 'returns ' + expectedValues[i] + ' for p: ' + p + ', n: ' + n);
5960
}
6061
t.end();
6162
});
6263

6364
// Test that the function returns NaN for invalid inputs
64-
tape('the function returns NaN for invalid inputs', function test(t) {
65+
tape('the function returns NaN for invalid inputs',opts, function test(t) {
6566
var invalidProbabilities = [-0.1, 1.1, NaN];
6667
var invalidSampleSizes = [-5, 0, 3.5, NaN];
67-
var i;
6868

69-
for (i = 0; i < invalidProbabilities.length; i++) {
70-
t.ok(isNaN(quantileFunction(invalidProbabilities[i], 5)), 'returns NaN for invalid probability: ' + invalidProbabilities[i]);
69+
for (var i = 0; i < invalidProbabilities.length; i++) {
70+
t.ok(isNaN(quantile(invalidProbabilities[i], 5)), 'returns NaN for invalid probability: ' + invalidProbabilities[i]);
7171
}
7272

73-
for (i = 0; i < invalidSampleSizes.length; i++) {
74-
t.ok(isNaN(quantileFunction(0.5, invalidSampleSizes[i])), 'returns NaN for invalid sample size: ' + invalidSampleSizes[i]);
73+
for (var j = 0; j < invalidSampleSizes.length; j++) {
74+
t.ok(isNaN(quantile(0.5, invalidSampleSizes[j])), 'returns NaN for invalid sample size: ' + invalidSampleSizes[j]);
7575
}
7676
t.end();
7777
});

0 commit comments

Comments
 (0)