Skip to content

Commit 4c644e9

Browse files
committed
feat: add C implementation for chi/skewness
1 parent 748ab37 commit 4c644e9

14 files changed

Lines changed: 73 additions & 221 deletions

File tree

lib/node_modules/@stdlib/stats/base/dists/chi/skewness/benchmark/benchmark.native.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2025 The Stdlib Authors.
4+
* Copyright (c) 2026 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.
@@ -23,8 +23,8 @@
2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
2525
var uniform = require( '@stdlib/random/array/uniform' );
26-
var format = require( '@stdlib/string/format' );
2726
var isnan = require( '@stdlib/math/base/assert/is-nan' );
27+
var EPS = require( '@stdlib/constants/float64/eps' );
2828
var tryRequire = require( '@stdlib/utils/try-require' );
2929
var pkg = require( './../package.json' ).name;
3030

@@ -39,16 +39,16 @@ var opts = {
3939

4040
// MAIN //
4141

42-
bench( format( '%s::native', pkg ), opts, function benchmark( b ) {
43-
var opts;
42+
bench( pkg+'::native', opts, function benchmark( b ) {
43+
var kopts;
4444
var k;
4545
var y;
4646
var i;
4747

48-
opts = {
48+
kopts = {
4949
'dtype': 'float64'
5050
};
51-
k = uniform( 100, 1.0, 10.0, opts );
51+
k = uniform( 100, EPS, 20.0, kopts );
5252

5353
b.tic();
5454
for ( i = 0; i < b.iterations; i++ ) {

lib/node_modules/@stdlib/stats/base/dists/chi/skewness/benchmark/c/Makefile

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#/
22
# @license Apache-2.0
33
#
4-
# Copyright (c) 2025 The Stdlib Authors.
4+
# Copyright (c) 2026 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.
@@ -24,10 +24,6 @@ else
2424
QUIET :=
2525
endif
2626

27-
# Determine the OS ([1][1], [2][2]).
28-
#
29-
# [1]: https://en.wikipedia.org/wiki/Uname#Examples
30-
# [2]: http://stackoverflow.com/a/27776822/2225624
3127
OS ?= $(shell uname)
3228
ifneq (, $(findstring MINGW,$(OS)))
3329
OS := WINNT
@@ -45,101 +41,46 @@ endif
4541
endif
4642
endif
4743

48-
# Define the program used for compiling C source files:
4944
ifdef C_COMPILER
5045
CC := $(C_COMPILER)
5146
else
5247
CC := gcc
5348
endif
5449

55-
# Define the command-line options when compiling C files:
5650
CFLAGS ?= \
5751
-std=c99 \
5852
-O3 \
5953
-Wall \
6054
-pedantic
6155

62-
# Determine whether to generate position independent code ([1][1], [2][2]).
63-
#
64-
# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options
65-
# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option
6656
ifeq ($(OS), WINNT)
6757
fPIC ?=
6858
else
6959
fPIC ?= -fPIC
7060
endif
7161

72-
# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`):
7362
INCLUDE ?=
74-
75-
# List of source files:
7663
SOURCE_FILES ?=
77-
78-
# List of libraries (e.g., `-lopenblas -lpthread`):
7964
LIBRARIES ?=
80-
81-
# List of library paths (e.g., `-L /foo/bar -L /beep/boop`):
8265
LIBPATH ?=
8366

84-
# List of C targets:
8567
c_targets := benchmark.out
8668

8769

8870
# RULES #
8971

90-
#/
91-
# Compiles source files.
92-
#
93-
# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`)
94-
# @param {string} [CFLAGS] - C compiler options
95-
# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`)
96-
# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`)
97-
# @param {string} [SOURCE_FILES] - list of source files
98-
# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`)
99-
# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`)
100-
#
101-
# @example
102-
# make
103-
#
104-
# @example
105-
# make all
106-
#/
10772
all: $(c_targets)
10873

10974
.PHONY: all
11075

111-
#/
112-
# Compiles C source files.
113-
#
114-
# @private
115-
# @param {string} CC - C compiler (e.g., `gcc`)
116-
# @param {string} CFLAGS - C compiler options
117-
# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`)
118-
# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`)
119-
# @param {string} SOURCE_FILES - list of source files
120-
# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`)
121-
# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`)
122-
#/
12376
$(c_targets): %.out: %.c
12477
$(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES)
12578

126-
#/
127-
# Runs compiled benchmarks.
128-
#
129-
# @example
130-
# make run
131-
#/
13279
run: $(c_targets)
13380
$(QUIET) ./$<
13481

13582
.PHONY: run
13683

137-
#/
138-
# Removes generated files.
139-
#
140-
# @example
141-
# make clean
142-
#/
14384
clean:
14485
$(QUIET) -rm -f *.o *.out
14586

lib/node_modules/@stdlib/stats/base/dists/chi/skewness/benchmark/c/benchmark.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2025 The Stdlib Authors.
4+
* Copyright (c) 2026 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.

lib/node_modules/@stdlib/stats/base/dists/chi/skewness/binding.gyp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# @license Apache-2.0
22
#
3-
# Copyright (c) 2025 The Stdlib Authors.
3+
# Copyright (c) 2026 The Stdlib Authors.
44
#
55
# Licensed under the Apache License, Version 2.0 (the "License");
66
# you may not use this file except in compliance with the License.

lib/node_modules/@stdlib/stats/base/dists/chi/skewness/examples/c/Makefile

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#/
22
# @license Apache-2.0
33
#
4-
# Copyright (c) 2025 The Stdlib Authors.
4+
# Copyright (c) 2026 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.
@@ -24,10 +24,6 @@ else
2424
QUIET :=
2525
endif
2626

27-
# Determine the OS ([1][1], [2][2]).
28-
#
29-
# [1]: https://en.wikipedia.org/wiki/Uname#Examples
30-
# [2]: http://stackoverflow.com/a/27776822/2225624
3127
OS ?= $(shell uname)
3228
ifneq (, $(findstring MINGW,$(OS)))
3329
OS := WINNT
@@ -45,101 +41,46 @@ endif
4541
endif
4642
endif
4743

48-
# Define the program used for compiling C source files:
4944
ifdef C_COMPILER
5045
CC := $(C_COMPILER)
5146
else
5247
CC := gcc
5348
endif
5449

55-
# Define the command-line options when compiling C files:
5650
CFLAGS ?= \
5751
-std=c99 \
5852
-O3 \
5953
-Wall \
6054
-pedantic
6155

62-
# Determine whether to generate position independent code ([1][1], [2][2]).
63-
#
64-
# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options
65-
# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option
6656
ifeq ($(OS), WINNT)
6757
fPIC ?=
6858
else
6959
fPIC ?= -fPIC
7060
endif
7161

72-
# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`):
7362
INCLUDE ?=
74-
75-
# List of source files:
7663
SOURCE_FILES ?=
77-
78-
# List of libraries (e.g., `-lopenblas -lpthread`):
7964
LIBRARIES ?=
80-
81-
# List of library paths (e.g., `-L /foo/bar -L /beep/boop`):
8265
LIBPATH ?=
8366

84-
# List of C targets:
8567
c_targets := example.out
8668

8769

8870
# RULES #
8971

90-
#/
91-
# Compiles source files.
92-
#
93-
# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`)
94-
# @param {string} [CFLAGS] - C compiler options
95-
# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`)
96-
# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`)
97-
# @param {string} [SOURCE_FILES] - list of source files
98-
# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`)
99-
# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`)
100-
#
101-
# @example
102-
# make
103-
#
104-
# @example
105-
# make all
106-
#/
10772
all: $(c_targets)
10873

10974
.PHONY: all
11075

111-
#/
112-
# Compiles C source files.
113-
#
114-
# @private
115-
# @param {string} CC - C compiler (e.g., `gcc`)
116-
# @param {string} CFLAGS - C compiler options
117-
# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`)
118-
# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`)
119-
# @param {string} SOURCE_FILES - list of source files
120-
# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`)
121-
# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`)
122-
#/
12376
$(c_targets): %.out: %.c
12477
$(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES)
12578

126-
#/
127-
# Runs compiled examples.
128-
#
129-
# @example
130-
# make run
131-
#/
13279
run: $(c_targets)
13380
$(QUIET) ./$<
13481

13582
.PHONY: run
13683

137-
#/
138-
# Removes generated files.
139-
#
140-
# @example
141-
# make clean
142-
#/
14384
clean:
14485
$(QUIET) -rm -f *.o *.out
14586

lib/node_modules/@stdlib/stats/base/dists/chi/skewness/examples/c/example.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2025 The Stdlib Authors.
4+
* Copyright (c) 2026 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.
@@ -33,6 +33,6 @@ int main( void ) {
3333
for ( i = 0; i < 25; i++ ) {
3434
k = random_uniform( 1.0, 10.0 );
3535
y = stdlib_base_dists_chi_skewness( k );
36-
printf( "k: %lf, skew(X,k): %lf\n", k, y );
36+
printf( "k: %lf, skewness(X,k): %lf\n", k, y );
3737
}
3838
}

lib/node_modules/@stdlib/stats/base/dists/chi/skewness/include.gypi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# @license Apache-2.0
22
#
3-
# Copyright (c) 2025 The Stdlib Authors.
3+
# Copyright (c) 2026 The Stdlib Authors.
44
#
55
# Licensed under the Apache License, Version 2.0 (the "License");
66
# you may not use this file except in compliance with the License.

lib/node_modules/@stdlib/stats/base/dists/chi/skewness/include/stdlib/stats/base/dists/chi/skewness.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2025 The Stdlib Authors.
4+
* Copyright (c) 2026 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.
@@ -28,6 +28,9 @@ extern "C" {
2828

2929
/**
3030
* Returns the skewness of a chi distribution.
31+
*
32+
* @param k degrees of freedom
33+
* @return skewness
3134
*/
3235
double stdlib_base_dists_chi_skewness( const double k );
3336

lib/node_modules/@stdlib/stats/base/dists/chi/skewness/lib/index.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,22 @@
3535

3636
// MODULES //
3737

38+
var setReadOnly = require( '@stdlib/utils/define-read-only-property' );
3839
var main = require( './main.js' );
3940

4041

42+
// MAIN //
43+
44+
var skewness;
45+
var tmp = require( './native.js' );
46+
if ( tmp instanceof Error ) {
47+
skewness = main;
48+
} else {
49+
skewness = tmp;
50+
setReadOnly( skewness, 'main', main );
51+
}
52+
53+
4154
// EXPORTS //
4255

43-
module.exports = main;
56+
module.exports = skewness;

0 commit comments

Comments
 (0)