diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b2e1686..585582e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,21 +14,24 @@ jobs: name: 'Tests' strategy: matrix: - php: ['8.1.12'] + php: ['8.1.13'] runs-on: 'ubuntu-20.04' env: PHP_VERSION: ${{ matrix.php }} steps: - name: 'Check out repository' - uses: 'actions/checkout@v2' + uses: 'actions/checkout@v3' with: path: 'php-ext-gsl' - - uses: actions/cache@v2 + - uses: actions/cache@v3 + if: ${{ always() }} with: path: ~/build-cache/php key: ${{ runner.os }}-${{ matrix.php }} + restore-keys: | + ${{ runner.os }}-${{ matrix.php }} - name: 'Build PHP' run: './php-ext-gsl/.github/workflows/test/build-php.sh' @@ -37,4 +40,15 @@ jobs: run: './php-ext-gsl/.github/workflows/test/build-php-ext-gsl.sh' - name: 'Run tests' - run: './php-ext-gsl/.github/workflows/test/tests.sh' \ No newline at end of file + run: './php-ext-gsl/.github/workflows/test/tests.sh' + + - name: Archive test errors + if: ${{ failure() }} + uses: actions/upload-artifact@v3 + with: + name: test-errors + path: php-ext-gsl/tests/*.diff + retention-days: 5 + - name: Download all workflow run artifacts + if: ${{ failure() }} + uses: actions/download-artifact@v3 \ No newline at end of file diff --git a/.github/workflows/test/build-php-ext-gsl.sh b/.github/workflows/test/build-php-ext-gsl.sh index de2995c..2e22150 100755 --- a/.github/workflows/test/build-php-ext-gsl.sh +++ b/.github/workflows/test/build-php-ext-gsl.sh @@ -8,7 +8,7 @@ php --version cd php-ext-gsl phpize -./configure +./configure --with-gsl CFLAGS="$CFLAGS -Wno-implicit-function-declaration" php -dmemory_limit=-1 build/gen_stub.php --force-regeneration sed -i 's/$user_input = fgets($fp, 10);/$user_input = "s";/g' run-tests.php make \ No newline at end of file diff --git a/CMakeList.txt b/CMakeList.txt new file mode 100644 index 0000000..e90e368 --- /dev/null +++ b/CMakeList.txt @@ -0,0 +1,25 @@ +cmake_minimum_required(VERSION 3.8) +project(gslext C) + +set(SOURCE_FILES gslext gslext.c) + +execute_process ( + COMMAND php-config --include-dir + OUTPUT_VARIABLE PHP_SOURCE +) +string(REGEX REPLACE "\n$" "" PHP_SOURCE "${PHP_SOURCE}") + +message("Using source directory: ${PHP_SOURCE}") + +include_directories(${PHP_SOURCE}) +include_directories(${PHP_SOURCE}/main) +include_directories(${PHP_SOURCE}/Zend) +include_directories(${PHP_SOURCE}/TSRM) +include_directories(${PROJECT_SOURCE_DIR}) + +add_custom_target(configure + COMMAND phpize && ./configure + DEPENDS ${SOURCE_FILES} + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}) + +add_library(___ EXCLUDE_FROM_ALL ${SOURCE_FILES}) \ No newline at end of file diff --git a/README.md b/README.md index 7089b79..db628b5 100644 --- a/README.md +++ b/README.md @@ -1 +1,25 @@ # PHP Extension for GNU Scientific Library (GSL) + +## TODO +* refactor all functions from GSL_ to gsl_ +* refactor to use helper instead converting in each function + +## GSL coverage +* [Mathematical Constants](https://www.gnu.org/software/gsl/doc/html/math.html#mathematical-constants) +* [Elementary Functions](https://www.gnu.org/software/gsl/doc/html/math.html#elementary-functions) +* [Small integer powers](https://www.gnu.org/software/gsl/doc/html/math.html#small-integer-powers) +* [Testing for Odd and Even Numbers](https://www.gnu.org/software/gsl/doc/html/math.html#testing-for-odd-and-even-numbers) +* [Maximum and Minimum functions](https://www.gnu.org/software/gsl/doc/html/math.html#maximum-and-minimum-functions) +* [Approximate Comparison of Floating Point Numbers](https://www.gnu.org/software/gsl/doc/html/math.html#approximate-comparison-of-floating-point-numbers) +* []() +* []() +* []() +* []() +* []() +* [Statistics](https://www.gnu.org/software/gsl/doc/html/statistics.html) +* [Running Statistics](https://www.gnu.org/software/gsl/doc/html/rstat.html) + +Full list of functions in [PHP stub file](gslext.stub.php) + +## Tests +* tests in this extension are only to check if functions are working. Correctness of calculations relays on library diff --git a/build.sh b/build.sh index 5bbf423..8e03bbd 100755 --- a/build.sh +++ b/build.sh @@ -1,6 +1,6 @@ make distclean phpize -./configure --with-gsl +./configure --with-gsl CFLAGS="$CFLAGS -Wno-implicit-function-declaration" php -dmemory_limit=-1 build/gen_stub.php --force-regeneration sed -i 's/$user_input = fgets($fp, 10);/$user_input = "s";/g' run-tests.php make && make test diff --git a/gslext.c b/gslext.c index c24a3a1..a398bf3 100644 --- a/gslext.c +++ b/gslext.c @@ -7,10 +7,14 @@ #endif #include "php.h" +#include "php_ini.h" +#include "zend_exceptions.h" #include "ext/standard/info.h" #include "php_gslext.h" #include "gslext_arginfo.h" +#include "gslext_helpers.c" + #include "inc/_functions.inc" /* For compatibility with older PHP versions */ diff --git a/gslext.stub.php b/gslext.stub.php index fd83048..9e698db 100644 --- a/gslext.stub.php +++ b/gslext.stub.php @@ -38,3 +38,71 @@ function GSL_max_float(float $a, float $b): float {} // fcmp function GSL_fcmp(float $x, float $y, float $epsilon): int {} + +// Statistics +function gsl_stats_mean(array $data, int $stride): float {} +function gsl_stats_variance(array $data, int $stride): float {} +function gsl_stats_variance_m(array $data, int $stride, float $mean): float {} +function gsl_stats_sd(array $data, int $stride): float {} +function gsl_stats_tss(array $data, int $stride): float {} +function gsl_stats_tss_m(array $data, int $stride, float $mean): float {} +function gsl_stats_variance_with_fixed_mean(array $data, int $stride, float $mean): float {} +function gsl_stats_sd_with_fixed_mean(array $data, int $stride, float $mean): float {} +function gsl_stats_absdev(array $data, int $stride): float {} +function gsl_stats_absdev_m(array $data, int $stride, float $mean): float {} +function gsl_stats_skew(array $data, int $stride): float {} +function gsl_stats_skew_m_sd(array $data, int $stride, float $mean, float $sd): float {} +function gsl_stats_kurtosis(array $data, int $stride): float {} +function gsl_stats_kurtosis_m_sd(array $data, int $stride, float $mean, float $sd): float {} +function gsl_stats_lag1_autocorrelation(array $data, int $stride): float {} +function gsl_stats_lag1_autocorrelation_m(array $data, int $stride, float $mean): float {} +function gsl_stats_covariance(array $data1, int $stride1, array $data2, int $stride2): float {} +function gsl_stats_covariance_m(array $data1, int $stride1, array $data2, int $stride2, float $mean1, float $mean2): float {} +function gsl_stats_correlation(array $data1, int $stride1, array $data2, int $stride2): float {} +function gsl_stats_spearman(array $data1, int $stride1, array $data2, int $stride2, array $work): float {} +function gsl_stats_wmean(array $w, int $wstride, array $data, int $stride): float {} +function gsl_stats_wvariance(array $w, int $wstride, array $data, int $stride): float {} +function gsl_stats_wvariance_m(array $w, int $wstride, array $data, int $stride, float $wmean): float {} +function gsl_stats_wsd(array $w, int $wstride, array $data, int $stride): float {} +function gsl_stats_wsd_m(array $w, int $wstride, array $data, int $stride, float $wmean): float {} +function gsl_stats_wvariance_with_fixed_mean(array $w, int $wstride, array $data, int $stride, float $mean): float {} +function gsl_stats_wsd_with_fixed_mean(array $w, int $wstride, array $data, int $stride, float $mean): float {} +function gsl_stats_wtss(array $w, int $wstride, array $data, int $stride): float {} +function gsl_stats_wtss_m(array $w, int $wstride, array $data, int $stride, float $mean): float {} +function gsl_stats_wabsdev(array $w, int $wstride, array $data, int $stride): float {} +function gsl_stats_wabsdev_m(array $w, int $wstride, array $data, int $stride, float $mean): float {} +function gsl_stats_wskew(array $w, int $wstride, array $data, int $stride): float {} +function gsl_stats_wskew_m_sd(array $w, int $wstride, array $data, int $stride, float $wmean, float $wds): float {} +function gsl_stats_wkurtosis(array $w, int $wstride, array $data, int $stride): float {} +function gsl_stats_wkurtosis_m_sd(array $w, int $wstride, array $data, int $stride, float $wmean, float $wds): float {} +function gsl_stats_max(array $data, int $stride): float {} +function gsl_stats_min(array $data, int $stride): float {} +function gsl_stats_minmax(float &$min, float &$max, array $data, int $stride): void {} +function gsl_stats_min_index(array $data, int $stride): int {} +function gsl_stats_max_index(array $data, int $stride): int {} +function gsl_stats_minmax_index(int &$min_index, int &$max_index, array $data, int $stride): void {} +function gsl_stats_median_from_sorted_data(array $sorted_data, int $stride): float {} +function gsl_stats_median(array $data, int $stride): float {} +function gsl_stats_quantile_from_sorted_data(array $sorted_data, int $stride, float $f): float {} +function gsl_stats_select(array $data, int $stride, int $k): float {} +function gsl_stats_trmean_from_sorted_data(float $alpha, array $sorted_data, int $stride): float {} +function gsl_stats_gastwirth_from_sorted_data(array $sorted_data, int $stride): float {} +function gsl_stats_mad0(array $data, int $stride): float {} +function gsl_stats_mad(array $data, int $stride): float {} +function gsl_stats_Sn0_from_sorted_data(array $sorted_data, int $stride): float {} +function gsl_stats_Sn_from_sorted_data(array $sorted_data, int $stride): float {} +function gsl_stats_Qn0_from_sorted_data(array $sorted_data, int $stride): float {} +function gsl_stats_Qn_from_sorted_data(array $sorted_data, int $stride): float {} + +// Running Statistics +function gsl_rstat_min(array $data): float {} +function gsl_rstat_max(array $data): float {} +function gsl_rstat_mean(array $data): float {} +function gsl_rstat_variance(array $data): float {} +function gsl_rstat_sd(array $data): float {} +function gsl_rstat_sd_mean(array $data): float {} +function gsl_rstat_rms(array $data): float {} +function gsl_rstat_skew(array $data): float {} +function gsl_rstat_kurtosis(array $data): float {} +function gsl_rstat_median(array $data): float {} +function gsl_rstat_quantile_get(array $data, float $factor): float {} \ No newline at end of file diff --git a/gslext_arginfo.h b/gslext_arginfo.h index 7e1e38d..97b55bb 100644 --- a/gslext_arginfo.h +++ b/gslext_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 477cd8e284da0ba23e4bc326471fc7aeb77e7d8a */ + * Stub hash: d927c9345a6b29cd62bd9dbb4a3856ee6ff03cac */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_GSL_log1p, 0, 1, IS_DOUBLE, 0) ZEND_ARG_TYPE_INFO(0, x, IS_DOUBLE, 0) @@ -88,6 +88,221 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_GSL_fcmp, 0, 3, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, epsilon, IS_DOUBLE, 0) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_gsl_stats_mean, 0, 2, IS_DOUBLE, 0) + ZEND_ARG_TYPE_INFO(0, data, IS_ARRAY, 0) + ZEND_ARG_TYPE_INFO(0, stride, IS_LONG, 0) +ZEND_END_ARG_INFO() + +#define arginfo_gsl_stats_variance arginfo_gsl_stats_mean + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_gsl_stats_variance_m, 0, 3, IS_DOUBLE, 0) + ZEND_ARG_TYPE_INFO(0, data, IS_ARRAY, 0) + ZEND_ARG_TYPE_INFO(0, stride, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, mean, IS_DOUBLE, 0) +ZEND_END_ARG_INFO() + +#define arginfo_gsl_stats_sd arginfo_gsl_stats_mean + +#define arginfo_gsl_stats_tss arginfo_gsl_stats_mean + +#define arginfo_gsl_stats_tss_m arginfo_gsl_stats_variance_m + +#define arginfo_gsl_stats_variance_with_fixed_mean arginfo_gsl_stats_variance_m + +#define arginfo_gsl_stats_sd_with_fixed_mean arginfo_gsl_stats_variance_m + +#define arginfo_gsl_stats_absdev arginfo_gsl_stats_mean + +#define arginfo_gsl_stats_absdev_m arginfo_gsl_stats_variance_m + +#define arginfo_gsl_stats_skew arginfo_gsl_stats_mean + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_gsl_stats_skew_m_sd, 0, 4, IS_DOUBLE, 0) + ZEND_ARG_TYPE_INFO(0, data, IS_ARRAY, 0) + ZEND_ARG_TYPE_INFO(0, stride, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, mean, IS_DOUBLE, 0) + ZEND_ARG_TYPE_INFO(0, sd, IS_DOUBLE, 0) +ZEND_END_ARG_INFO() + +#define arginfo_gsl_stats_kurtosis arginfo_gsl_stats_mean + +#define arginfo_gsl_stats_kurtosis_m_sd arginfo_gsl_stats_skew_m_sd + +#define arginfo_gsl_stats_lag1_autocorrelation arginfo_gsl_stats_mean + +#define arginfo_gsl_stats_lag1_autocorrelation_m arginfo_gsl_stats_variance_m + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_gsl_stats_covariance, 0, 4, IS_DOUBLE, 0) + ZEND_ARG_TYPE_INFO(0, data1, IS_ARRAY, 0) + ZEND_ARG_TYPE_INFO(0, stride1, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, data2, IS_ARRAY, 0) + ZEND_ARG_TYPE_INFO(0, stride2, IS_LONG, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_gsl_stats_covariance_m, 0, 6, IS_DOUBLE, 0) + ZEND_ARG_TYPE_INFO(0, data1, IS_ARRAY, 0) + ZEND_ARG_TYPE_INFO(0, stride1, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, data2, IS_ARRAY, 0) + ZEND_ARG_TYPE_INFO(0, stride2, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, mean1, IS_DOUBLE, 0) + ZEND_ARG_TYPE_INFO(0, mean2, IS_DOUBLE, 0) +ZEND_END_ARG_INFO() + +#define arginfo_gsl_stats_correlation arginfo_gsl_stats_covariance + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_gsl_stats_spearman, 0, 5, IS_DOUBLE, 0) + ZEND_ARG_TYPE_INFO(0, data1, IS_ARRAY, 0) + ZEND_ARG_TYPE_INFO(0, stride1, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, data2, IS_ARRAY, 0) + ZEND_ARG_TYPE_INFO(0, stride2, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, work, IS_ARRAY, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_gsl_stats_wmean, 0, 4, IS_DOUBLE, 0) + ZEND_ARG_TYPE_INFO(0, w, IS_ARRAY, 0) + ZEND_ARG_TYPE_INFO(0, wstride, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, data, IS_ARRAY, 0) + ZEND_ARG_TYPE_INFO(0, stride, IS_LONG, 0) +ZEND_END_ARG_INFO() + +#define arginfo_gsl_stats_wvariance arginfo_gsl_stats_wmean + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_gsl_stats_wvariance_m, 0, 5, IS_DOUBLE, 0) + ZEND_ARG_TYPE_INFO(0, w, IS_ARRAY, 0) + ZEND_ARG_TYPE_INFO(0, wstride, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, data, IS_ARRAY, 0) + ZEND_ARG_TYPE_INFO(0, stride, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, wmean, IS_DOUBLE, 0) +ZEND_END_ARG_INFO() + +#define arginfo_gsl_stats_wsd arginfo_gsl_stats_wmean + +#define arginfo_gsl_stats_wsd_m arginfo_gsl_stats_wvariance_m + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_gsl_stats_wvariance_with_fixed_mean, 0, 5, IS_DOUBLE, 0) + ZEND_ARG_TYPE_INFO(0, w, IS_ARRAY, 0) + ZEND_ARG_TYPE_INFO(0, wstride, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, data, IS_ARRAY, 0) + ZEND_ARG_TYPE_INFO(0, stride, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, mean, IS_DOUBLE, 0) +ZEND_END_ARG_INFO() + +#define arginfo_gsl_stats_wsd_with_fixed_mean arginfo_gsl_stats_wvariance_with_fixed_mean + +#define arginfo_gsl_stats_wtss arginfo_gsl_stats_wmean + +#define arginfo_gsl_stats_wtss_m arginfo_gsl_stats_wvariance_with_fixed_mean + +#define arginfo_gsl_stats_wabsdev arginfo_gsl_stats_wmean + +#define arginfo_gsl_stats_wabsdev_m arginfo_gsl_stats_wvariance_with_fixed_mean + +#define arginfo_gsl_stats_wskew arginfo_gsl_stats_wmean + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_gsl_stats_wskew_m_sd, 0, 6, IS_DOUBLE, 0) + ZEND_ARG_TYPE_INFO(0, w, IS_ARRAY, 0) + ZEND_ARG_TYPE_INFO(0, wstride, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, data, IS_ARRAY, 0) + ZEND_ARG_TYPE_INFO(0, stride, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, wmean, IS_DOUBLE, 0) + ZEND_ARG_TYPE_INFO(0, wds, IS_DOUBLE, 0) +ZEND_END_ARG_INFO() + +#define arginfo_gsl_stats_wkurtosis arginfo_gsl_stats_wmean + +#define arginfo_gsl_stats_wkurtosis_m_sd arginfo_gsl_stats_wskew_m_sd + +#define arginfo_gsl_stats_max arginfo_gsl_stats_mean + +#define arginfo_gsl_stats_min arginfo_gsl_stats_mean + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_gsl_stats_minmax, 0, 4, IS_VOID, 0) + ZEND_ARG_TYPE_INFO(1, min, IS_DOUBLE, 0) + ZEND_ARG_TYPE_INFO(1, max, IS_DOUBLE, 0) + ZEND_ARG_TYPE_INFO(0, data, IS_ARRAY, 0) + ZEND_ARG_TYPE_INFO(0, stride, IS_LONG, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_gsl_stats_min_index, 0, 2, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, data, IS_ARRAY, 0) + ZEND_ARG_TYPE_INFO(0, stride, IS_LONG, 0) +ZEND_END_ARG_INFO() + +#define arginfo_gsl_stats_max_index arginfo_gsl_stats_min_index + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_gsl_stats_minmax_index, 0, 4, IS_VOID, 0) + ZEND_ARG_TYPE_INFO(1, min_index, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(1, max_index, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, data, IS_ARRAY, 0) + ZEND_ARG_TYPE_INFO(0, stride, IS_LONG, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_gsl_stats_median_from_sorted_data, 0, 2, IS_DOUBLE, 0) + ZEND_ARG_TYPE_INFO(0, sorted_data, IS_ARRAY, 0) + ZEND_ARG_TYPE_INFO(0, stride, IS_LONG, 0) +ZEND_END_ARG_INFO() + +#define arginfo_gsl_stats_median arginfo_gsl_stats_mean + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_gsl_stats_quantile_from_sorted_data, 0, 3, IS_DOUBLE, 0) + ZEND_ARG_TYPE_INFO(0, sorted_data, IS_ARRAY, 0) + ZEND_ARG_TYPE_INFO(0, stride, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, f, IS_DOUBLE, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_gsl_stats_select, 0, 3, IS_DOUBLE, 0) + ZEND_ARG_TYPE_INFO(0, data, IS_ARRAY, 0) + ZEND_ARG_TYPE_INFO(0, stride, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, k, IS_LONG, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_gsl_stats_trmean_from_sorted_data, 0, 3, IS_DOUBLE, 0) + ZEND_ARG_TYPE_INFO(0, alpha, IS_DOUBLE, 0) + ZEND_ARG_TYPE_INFO(0, sorted_data, IS_ARRAY, 0) + ZEND_ARG_TYPE_INFO(0, stride, IS_LONG, 0) +ZEND_END_ARG_INFO() + +#define arginfo_gsl_stats_gastwirth_from_sorted_data arginfo_gsl_stats_median_from_sorted_data + +#define arginfo_gsl_stats_mad0 arginfo_gsl_stats_mean + +#define arginfo_gsl_stats_mad arginfo_gsl_stats_mean + +#define arginfo_gsl_stats_Sn0_from_sorted_data arginfo_gsl_stats_median_from_sorted_data + +#define arginfo_gsl_stats_Sn_from_sorted_data arginfo_gsl_stats_median_from_sorted_data + +#define arginfo_gsl_stats_Qn0_from_sorted_data arginfo_gsl_stats_median_from_sorted_data + +#define arginfo_gsl_stats_Qn_from_sorted_data arginfo_gsl_stats_median_from_sorted_data + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_gsl_rstat_min, 0, 1, IS_DOUBLE, 0) + ZEND_ARG_TYPE_INFO(0, data, IS_ARRAY, 0) +ZEND_END_ARG_INFO() + +#define arginfo_gsl_rstat_max arginfo_gsl_rstat_min + +#define arginfo_gsl_rstat_mean arginfo_gsl_rstat_min + +#define arginfo_gsl_rstat_variance arginfo_gsl_rstat_min + +#define arginfo_gsl_rstat_sd arginfo_gsl_rstat_min + +#define arginfo_gsl_rstat_sd_mean arginfo_gsl_rstat_min + +#define arginfo_gsl_rstat_rms arginfo_gsl_rstat_min + +#define arginfo_gsl_rstat_skew arginfo_gsl_rstat_min + +#define arginfo_gsl_rstat_kurtosis arginfo_gsl_rstat_min + +#define arginfo_gsl_rstat_median arginfo_gsl_rstat_min + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_gsl_rstat_quantile_get, 0, 2, IS_DOUBLE, 0) + ZEND_ARG_TYPE_INFO(0, data, IS_ARRAY, 0) + ZEND_ARG_TYPE_INFO(0, factor, IS_DOUBLE, 0) +ZEND_END_ARG_INFO() + ZEND_FUNCTION(GSL_log1p); ZEND_FUNCTION(GSL_expm1); @@ -116,6 +331,70 @@ ZEND_FUNCTION(GSL_max_int); ZEND_FUNCTION(GSL_min_float); ZEND_FUNCTION(GSL_max_float); ZEND_FUNCTION(GSL_fcmp); +ZEND_FUNCTION(gsl_stats_mean); +ZEND_FUNCTION(gsl_stats_variance); +ZEND_FUNCTION(gsl_stats_variance_m); +ZEND_FUNCTION(gsl_stats_sd); +ZEND_FUNCTION(gsl_stats_tss); +ZEND_FUNCTION(gsl_stats_tss_m); +ZEND_FUNCTION(gsl_stats_variance_with_fixed_mean); +ZEND_FUNCTION(gsl_stats_sd_with_fixed_mean); +ZEND_FUNCTION(gsl_stats_absdev); +ZEND_FUNCTION(gsl_stats_absdev_m); +ZEND_FUNCTION(gsl_stats_skew); +ZEND_FUNCTION(gsl_stats_skew_m_sd); +ZEND_FUNCTION(gsl_stats_kurtosis); +ZEND_FUNCTION(gsl_stats_kurtosis_m_sd); +ZEND_FUNCTION(gsl_stats_lag1_autocorrelation); +ZEND_FUNCTION(gsl_stats_lag1_autocorrelation_m); +ZEND_FUNCTION(gsl_stats_covariance); +ZEND_FUNCTION(gsl_stats_covariance_m); +ZEND_FUNCTION(gsl_stats_correlation); +ZEND_FUNCTION(gsl_stats_spearman); +ZEND_FUNCTION(gsl_stats_wmean); +ZEND_FUNCTION(gsl_stats_wvariance); +ZEND_FUNCTION(gsl_stats_wvariance_m); +ZEND_FUNCTION(gsl_stats_wsd); +ZEND_FUNCTION(gsl_stats_wsd_m); +ZEND_FUNCTION(gsl_stats_wvariance_with_fixed_mean); +ZEND_FUNCTION(gsl_stats_wsd_with_fixed_mean); +ZEND_FUNCTION(gsl_stats_wtss); +ZEND_FUNCTION(gsl_stats_wtss_m); +ZEND_FUNCTION(gsl_stats_wabsdev); +ZEND_FUNCTION(gsl_stats_wabsdev_m); +ZEND_FUNCTION(gsl_stats_wskew); +ZEND_FUNCTION(gsl_stats_wskew_m_sd); +ZEND_FUNCTION(gsl_stats_wkurtosis); +ZEND_FUNCTION(gsl_stats_wkurtosis_m_sd); +ZEND_FUNCTION(gsl_stats_max); +ZEND_FUNCTION(gsl_stats_min); +ZEND_FUNCTION(gsl_stats_minmax); +ZEND_FUNCTION(gsl_stats_min_index); +ZEND_FUNCTION(gsl_stats_max_index); +ZEND_FUNCTION(gsl_stats_minmax_index); +ZEND_FUNCTION(gsl_stats_median_from_sorted_data); +ZEND_FUNCTION(gsl_stats_median); +ZEND_FUNCTION(gsl_stats_quantile_from_sorted_data); +ZEND_FUNCTION(gsl_stats_select); +ZEND_FUNCTION(gsl_stats_trmean_from_sorted_data); +ZEND_FUNCTION(gsl_stats_gastwirth_from_sorted_data); +ZEND_FUNCTION(gsl_stats_mad0); +ZEND_FUNCTION(gsl_stats_mad); +ZEND_FUNCTION(gsl_stats_Sn0_from_sorted_data); +ZEND_FUNCTION(gsl_stats_Sn_from_sorted_data); +ZEND_FUNCTION(gsl_stats_Qn0_from_sorted_data); +ZEND_FUNCTION(gsl_stats_Qn_from_sorted_data); +ZEND_FUNCTION(gsl_rstat_min); +ZEND_FUNCTION(gsl_rstat_max); +ZEND_FUNCTION(gsl_rstat_mean); +ZEND_FUNCTION(gsl_rstat_variance); +ZEND_FUNCTION(gsl_rstat_sd); +ZEND_FUNCTION(gsl_rstat_sd_mean); +ZEND_FUNCTION(gsl_rstat_rms); +ZEND_FUNCTION(gsl_rstat_skew); +ZEND_FUNCTION(gsl_rstat_kurtosis); +ZEND_FUNCTION(gsl_rstat_median); +ZEND_FUNCTION(gsl_rstat_quantile_get); static const zend_function_entry ext_functions[] = { @@ -146,5 +425,69 @@ static const zend_function_entry ext_functions[] = { ZEND_FE(GSL_min_float, arginfo_GSL_min_float) ZEND_FE(GSL_max_float, arginfo_GSL_max_float) ZEND_FE(GSL_fcmp, arginfo_GSL_fcmp) + ZEND_FE(gsl_stats_mean, arginfo_gsl_stats_mean) + ZEND_FE(gsl_stats_variance, arginfo_gsl_stats_variance) + ZEND_FE(gsl_stats_variance_m, arginfo_gsl_stats_variance_m) + ZEND_FE(gsl_stats_sd, arginfo_gsl_stats_sd) + ZEND_FE(gsl_stats_tss, arginfo_gsl_stats_tss) + ZEND_FE(gsl_stats_tss_m, arginfo_gsl_stats_tss_m) + ZEND_FE(gsl_stats_variance_with_fixed_mean, arginfo_gsl_stats_variance_with_fixed_mean) + ZEND_FE(gsl_stats_sd_with_fixed_mean, arginfo_gsl_stats_sd_with_fixed_mean) + ZEND_FE(gsl_stats_absdev, arginfo_gsl_stats_absdev) + ZEND_FE(gsl_stats_absdev_m, arginfo_gsl_stats_absdev_m) + ZEND_FE(gsl_stats_skew, arginfo_gsl_stats_skew) + ZEND_FE(gsl_stats_skew_m_sd, arginfo_gsl_stats_skew_m_sd) + ZEND_FE(gsl_stats_kurtosis, arginfo_gsl_stats_kurtosis) + ZEND_FE(gsl_stats_kurtosis_m_sd, arginfo_gsl_stats_kurtosis_m_sd) + ZEND_FE(gsl_stats_lag1_autocorrelation, arginfo_gsl_stats_lag1_autocorrelation) + ZEND_FE(gsl_stats_lag1_autocorrelation_m, arginfo_gsl_stats_lag1_autocorrelation_m) + ZEND_FE(gsl_stats_covariance, arginfo_gsl_stats_covariance) + ZEND_FE(gsl_stats_covariance_m, arginfo_gsl_stats_covariance_m) + ZEND_FE(gsl_stats_correlation, arginfo_gsl_stats_correlation) + ZEND_FE(gsl_stats_spearman, arginfo_gsl_stats_spearman) + ZEND_FE(gsl_stats_wmean, arginfo_gsl_stats_wmean) + ZEND_FE(gsl_stats_wvariance, arginfo_gsl_stats_wvariance) + ZEND_FE(gsl_stats_wvariance_m, arginfo_gsl_stats_wvariance_m) + ZEND_FE(gsl_stats_wsd, arginfo_gsl_stats_wsd) + ZEND_FE(gsl_stats_wsd_m, arginfo_gsl_stats_wsd_m) + ZEND_FE(gsl_stats_wvariance_with_fixed_mean, arginfo_gsl_stats_wvariance_with_fixed_mean) + ZEND_FE(gsl_stats_wsd_with_fixed_mean, arginfo_gsl_stats_wsd_with_fixed_mean) + ZEND_FE(gsl_stats_wtss, arginfo_gsl_stats_wtss) + ZEND_FE(gsl_stats_wtss_m, arginfo_gsl_stats_wtss_m) + ZEND_FE(gsl_stats_wabsdev, arginfo_gsl_stats_wabsdev) + ZEND_FE(gsl_stats_wabsdev_m, arginfo_gsl_stats_wabsdev_m) + ZEND_FE(gsl_stats_wskew, arginfo_gsl_stats_wskew) + ZEND_FE(gsl_stats_wskew_m_sd, arginfo_gsl_stats_wskew_m_sd) + ZEND_FE(gsl_stats_wkurtosis, arginfo_gsl_stats_wkurtosis) + ZEND_FE(gsl_stats_wkurtosis_m_sd, arginfo_gsl_stats_wkurtosis_m_sd) + ZEND_FE(gsl_stats_max, arginfo_gsl_stats_max) + ZEND_FE(gsl_stats_min, arginfo_gsl_stats_min) + ZEND_FE(gsl_stats_minmax, arginfo_gsl_stats_minmax) + ZEND_FE(gsl_stats_min_index, arginfo_gsl_stats_min_index) + ZEND_FE(gsl_stats_max_index, arginfo_gsl_stats_max_index) + ZEND_FE(gsl_stats_minmax_index, arginfo_gsl_stats_minmax_index) + ZEND_FE(gsl_stats_median_from_sorted_data, arginfo_gsl_stats_median_from_sorted_data) + ZEND_FE(gsl_stats_median, arginfo_gsl_stats_median) + ZEND_FE(gsl_stats_quantile_from_sorted_data, arginfo_gsl_stats_quantile_from_sorted_data) + ZEND_FE(gsl_stats_select, arginfo_gsl_stats_select) + ZEND_FE(gsl_stats_trmean_from_sorted_data, arginfo_gsl_stats_trmean_from_sorted_data) + ZEND_FE(gsl_stats_gastwirth_from_sorted_data, arginfo_gsl_stats_gastwirth_from_sorted_data) + ZEND_FE(gsl_stats_mad0, arginfo_gsl_stats_mad0) + ZEND_FE(gsl_stats_mad, arginfo_gsl_stats_mad) + ZEND_FE(gsl_stats_Sn0_from_sorted_data, arginfo_gsl_stats_Sn0_from_sorted_data) + ZEND_FE(gsl_stats_Sn_from_sorted_data, arginfo_gsl_stats_Sn_from_sorted_data) + ZEND_FE(gsl_stats_Qn0_from_sorted_data, arginfo_gsl_stats_Qn0_from_sorted_data) + ZEND_FE(gsl_stats_Qn_from_sorted_data, arginfo_gsl_stats_Qn_from_sorted_data) + ZEND_FE(gsl_rstat_min, arginfo_gsl_rstat_min) + ZEND_FE(gsl_rstat_max, arginfo_gsl_rstat_max) + ZEND_FE(gsl_rstat_mean, arginfo_gsl_rstat_mean) + ZEND_FE(gsl_rstat_variance, arginfo_gsl_rstat_variance) + ZEND_FE(gsl_rstat_sd, arginfo_gsl_rstat_sd) + ZEND_FE(gsl_rstat_sd_mean, arginfo_gsl_rstat_sd_mean) + ZEND_FE(gsl_rstat_rms, arginfo_gsl_rstat_rms) + ZEND_FE(gsl_rstat_skew, arginfo_gsl_rstat_skew) + ZEND_FE(gsl_rstat_kurtosis, arginfo_gsl_rstat_kurtosis) + ZEND_FE(gsl_rstat_median, arginfo_gsl_rstat_median) + ZEND_FE(gsl_rstat_quantile_get, arginfo_gsl_rstat_quantile_get) ZEND_FE_END }; diff --git a/gslext_helpers.c b/gslext_helpers.c new file mode 100644 index 0000000..7b27040 --- /dev/null +++ b/gslext_helpers.c @@ -0,0 +1,164 @@ +#ifndef REG_ERANGE +#define REG_ERANGE 11 +#endif + +#ifndef ERR_MALLOC +#define ERR_MALLOC (-300) +#endif + +#ifndef ERR_BAD_TYPE +#define ERR_BAD_TYPE (-400) +#endif + +#ifndef ERR_TOO_FEW_ELEMENTS +#define ERR_TOO_FEW_ELEMENTS (-600) +#endif + +void __double_to_zval(double d, zval *zv) +{ + convert_to_double(zv); + ZVAL_DOUBLE(zv, d); +} + +void __long_to_zval(long l, zval *zv) +{ + convert_to_long(zv); + ZVAL_LONG(zv, l); +} + +void __alloc_double_array(double **var, long max) +{ + *var = (double *) emalloc((max + 1) * sizeof(double)); +} + +void __alloc_int_array(int **var, long max) +{ + *var = (int *) emalloc((max + 1) * sizeof(int)); +} + +void __alloc_long_array(long **var, long max) +{ + *var = (long *) emalloc((max + 1) * sizeof(long)); +} + +static inline int __is_numeric_string(char *str, int length, long *lval, double *dval) +{ + long local_lval; + double local_dval; + char *end_ptr; + + while (str[length - 1] == ' ' && length > 0) length--; + if (!length) { + return 0; + } + + errno=0; + local_lval = strtol(str, &end_ptr, 10); + if (errno!=REG_ERANGE && end_ptr == str+length) { /* integer string */ + if (lval) { + *lval = local_lval; + } + return IS_LONG; + } + + errno=0; + local_dval = strtod(str, &end_ptr); + if (errno!=REG_ERANGE && end_ptr == str+length) { /* floating point string */ + if (dval) { + *dval = local_dval; + } + return IS_DOUBLE; + } + + return 0; +} + + +int __zval_to_double(zval *p, double *d) +{ + long local_lval; + double local_dval; + + if (Z_TYPE_P(p) == IS_STRING) + { + *d = 0; + if (p->value.str->len == 0) return 0; + switch (__is_numeric_string(p->value.str->val, p->value.str->len, &local_lval, &local_dval)) + { + case IS_LONG: *d = (double)local_lval; break; + case IS_DOUBLE: *d = local_dval; break; + default: return ERR_BAD_TYPE; + } + return 0; + } + + switch (Z_TYPE_P(p)) + { + case IS_DOUBLE: *d = p->value.dval; break; + case IS_LONG: *d = (double)p->value.lval; break; + default: return ERR_BAD_TYPE; + } + return 0; +} + +int __zval_to_long(zval *p, long *l) +{ + long local_lval; + double local_dval; + + if (Z_TYPE_P(p) == IS_STRING) + { + *l = 0; + if (p->value.str->len == 0) return 0; + switch (__is_numeric_string(p->value.str->val, p->value.str->len, &local_lval, &local_dval)) + { + case IS_DOUBLE: *l = (long)local_dval; break; + case IS_LONG: *l = local_lval; break; + default: return ERR_BAD_TYPE; + } + return 0; + } + + switch (Z_TYPE_P(p)) + { + case IS_DOUBLE: *l = (long)p->value.dval; break; + case IS_LONG: *l = p->value.lval; break; + default: return ERR_BAD_TYPE; + } + return 0; +} + +int __zval_to_int(zval *p, int *i) +{ + long local_lval = (long)i; + int error = __zval_to_long(p, &local_lval); + *i = (int)local_lval; + return error; +} + +int __zval_to_size_t(zval *p, size_t *t) { + long local_lval = (long)t; + int error = __zval_to_long(p, &local_lval); + *t = (size_t) local_lval; + return error; +} + +int __zval_to_double_array(zval *p, double *d, long n) { + int i, errcode; + zval *val; + HashTable *ht; + HashPosition pos; + if (n > zend_array_count(Z_ARR_P(p))) return ERR_TOO_FEW_ELEMENTS; + ht = HASH_OF(p); + zend_hash_internal_pointer_reset_ex(ht, &pos); + for (i = 0; i < n; i++) { + val = zend_hash_get_current_data_ex(ht, &pos); + errcode = __zval_to_double(val, &d[i]); + if (errcode) return errcode; + zend_hash_move_forward_ex(ht, &pos); + } + return 0; +} + + + diff --git a/inc/_functions.inc b/inc/_functions.inc index c9bc243..fdf118e 100644 --- a/inc/_functions.inc +++ b/inc/_functions.inc @@ -1,4 +1,6 @@ #include "elementary.c" #include "small_int_pows.c" #include "min_max.c" -#include "gsl_fcmp.c" \ No newline at end of file +#include "gsl_fcmp.c" +#include "statistics.c" +#include "running_statistics.c" \ No newline at end of file diff --git a/inc/running_statistics.c b/inc/running_statistics.c new file mode 100644 index 0000000..604a58c --- /dev/null +++ b/inc/running_statistics.c @@ -0,0 +1,320 @@ +// https://www.gnu.org/software/gsl/doc/html/rstat.html + +#include +#include + +PHP_FUNCTION(gsl_rstat_min) +{ + zval *p_data; + long i, n; + double *data, rv; + + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ZVAL(p_data) + ZEND_PARSE_PARAMETERS_END(); + + gsl_rstat_workspace *rstat_p = gsl_rstat_alloc(); + + n = (long) zend_array_count(Z_ARR_P(p_data)); + + __alloc_double_array(&data, n); + __zval_to_double_array(p_data, data, n); + + for (i = 0; i < n; ++i) + gsl_rstat_add(data[i], rstat_p); + + rv = gsl_rstat_min(rstat_p); + + gsl_rstat_reset(rstat_p); + gsl_rstat_free(rstat_p); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_rstat_max) +{ + zval *p_data; + long i, n; + double *data, rv; + + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ZVAL(p_data) + ZEND_PARSE_PARAMETERS_END(); + + gsl_rstat_workspace *rstat_p = gsl_rstat_alloc(); + + n = (long) zend_array_count(Z_ARR_P(p_data)); + + __alloc_double_array(&data, n); + __zval_to_double_array(p_data, data, n); + + for (i = 0; i < n; ++i) + gsl_rstat_add(data[i], rstat_p); + + rv = gsl_rstat_max(rstat_p); + + gsl_rstat_reset(rstat_p); + gsl_rstat_free(rstat_p); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_rstat_mean) +{ + zval *p_data; + long i, n; + double *data, rv; + + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ZVAL(p_data) + ZEND_PARSE_PARAMETERS_END(); + + gsl_rstat_workspace *rstat_p = gsl_rstat_alloc(); + + n = (long) zend_array_count(Z_ARR_P(p_data)); + + __alloc_double_array(&data, n); + __zval_to_double_array(p_data, data, n); + + for (i = 0; i < n; ++i) + gsl_rstat_add(data[i], rstat_p); + + rv = gsl_rstat_mean(rstat_p); + + gsl_rstat_reset(rstat_p); + gsl_rstat_free(rstat_p); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_rstat_variance) +{ + zval *p_data; + long i, n; + double *data, rv; + + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ZVAL(p_data) + ZEND_PARSE_PARAMETERS_END(); + + gsl_rstat_workspace *rstat_p = gsl_rstat_alloc(); + + n = (long) zend_array_count(Z_ARR_P(p_data)); + + __alloc_double_array(&data, n); + __zval_to_double_array(p_data, data, n); + + for (i = 0; i < n; ++i) + gsl_rstat_add(data[i], rstat_p); + + rv = gsl_rstat_variance(rstat_p); + + gsl_rstat_reset(rstat_p); + gsl_rstat_free(rstat_p); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_rstat_sd) +{ + zval *p_data; + long i, n; + double *data, rv; + + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ZVAL(p_data) + ZEND_PARSE_PARAMETERS_END(); + + gsl_rstat_workspace *rstat_p = gsl_rstat_alloc(); + + n = (long) zend_array_count(Z_ARR_P(p_data)); + + __alloc_double_array(&data, n); + __zval_to_double_array(p_data, data, n); + + for (i = 0; i < n; ++i) + gsl_rstat_add(data[i], rstat_p); + + rv = gsl_rstat_sd(rstat_p); + + gsl_rstat_reset(rstat_p); + gsl_rstat_free(rstat_p); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_rstat_sd_mean) +{ + zval *p_data; + long i, n; + double *data, rv; + + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ZVAL(p_data) + ZEND_PARSE_PARAMETERS_END(); + + gsl_rstat_workspace *rstat_p = gsl_rstat_alloc(); + + n = (long) zend_array_count(Z_ARR_P(p_data)); + + __alloc_double_array(&data, n); + __zval_to_double_array(p_data, data, n); + + for (i = 0; i < n; ++i) + gsl_rstat_add(data[i], rstat_p); + + rv = gsl_rstat_sd_mean(rstat_p); + + gsl_rstat_reset(rstat_p); + gsl_rstat_free(rstat_p); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_rstat_rms) +{ + zval *p_data; + long i, n; + double *data, rv; + + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ZVAL(p_data) + ZEND_PARSE_PARAMETERS_END(); + + gsl_rstat_workspace *rstat_p = gsl_rstat_alloc(); + + n = (long) zend_array_count(Z_ARR_P(p_data)); + + __alloc_double_array(&data, n); + __zval_to_double_array(p_data, data, n); + + for (i = 0; i < n; ++i) + gsl_rstat_add(data[i], rstat_p); + + rv = gsl_rstat_rms(rstat_p); + + gsl_rstat_reset(rstat_p); + gsl_rstat_free(rstat_p); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_rstat_skew) +{ + zval *p_data; + long i, n; + double *data, rv; + + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ZVAL(p_data) + ZEND_PARSE_PARAMETERS_END(); + + gsl_rstat_workspace *rstat_p = gsl_rstat_alloc(); + + n = (long) zend_array_count(Z_ARR_P(p_data)); + + __alloc_double_array(&data, n); + __zval_to_double_array(p_data, data, n); + + for (i = 0; i < n; ++i) + gsl_rstat_add(data[i], rstat_p); + + rv = gsl_rstat_skew(rstat_p); + + gsl_rstat_reset(rstat_p); + gsl_rstat_free(rstat_p); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_rstat_kurtosis) +{ + zval *p_data; + long i, n; + double *data, rv; + + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ZVAL(p_data) + ZEND_PARSE_PARAMETERS_END(); + + gsl_rstat_workspace *rstat_p = gsl_rstat_alloc(); + + n = (long) zend_array_count(Z_ARR_P(p_data)); + + __alloc_double_array(&data, n); + __zval_to_double_array(p_data, data, n); + + for (i = 0; i < n; ++i) + gsl_rstat_add(data[i], rstat_p); + + rv = gsl_rstat_kurtosis(rstat_p); + + gsl_rstat_reset(rstat_p); + gsl_rstat_free(rstat_p); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_rstat_median) +{ + zval *p_data; + long i, n; + double *data, rv; + + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ZVAL(p_data) + ZEND_PARSE_PARAMETERS_END(); + + gsl_rstat_workspace *rstat_p = gsl_rstat_alloc(); + + n = (long) zend_array_count(Z_ARR_P(p_data)); + + __alloc_double_array(&data, n); + __zval_to_double_array(p_data, data, n); + + for (i = 0; i < n; ++i) + gsl_rstat_add(data[i], rstat_p); + + rv = gsl_rstat_median(rstat_p); + + gsl_rstat_reset(rstat_p); + gsl_rstat_free(rstat_p); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_rstat_quantile_get) +{ + zval *p_data, *p_factor; + long i, n; + double *data, factor, rv; + + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_ZVAL(p_data) + Z_PARAM_ZVAL(p_factor) + ZEND_PARSE_PARAMETERS_END(); + + n = (long) zend_array_count(Z_ARR_P(p_data)); + __alloc_double_array(&data, n); + __zval_to_double_array(p_data, data, n); + + __zval_to_double(p_factor, &factor); + + gsl_rstat_quantile_workspace *work = gsl_rstat_quantile_alloc(factor); + + n = (long) zend_array_count(Z_ARR_P(p_data)); + + __alloc_double_array(&data, n); + __zval_to_double_array(p_data, data, n); + + for (i = 0; i < n; ++i) + gsl_rstat_quantile_add(data[i], work); + + rv = gsl_rstat_quantile_get(work); + + gsl_rstat_quantile_reset(work); + gsl_rstat_quantile_free(work); + + RETURN_DOUBLE(rv); +} + diff --git a/inc/statistics.c b/inc/statistics.c new file mode 100644 index 0000000..6614dd8 --- /dev/null +++ b/inc/statistics.c @@ -0,0 +1,1384 @@ +// https://www.gnu.org/software/gsl/doc/html/statistics.html + +#include + +PHP_FUNCTION(gsl_stats_mean) +{ + zval *p_data, *p_stride; + long stride, n; + double *data, rv; + + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_ZVAL(p_data) + Z_PARAM_ZVAL(p_stride) + ZEND_PARSE_PARAMETERS_END(); + + __zval_to_long(p_stride, &stride); + + n = (long) zend_array_count(Z_ARR_P(p_data)); + + __alloc_double_array(&data, n); + __zval_to_double_array(p_data, data, n); + + rv = gsl_stats_mean(data, stride, n); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_stats_variance) +{ + zval *p_data, *p_stride; + long stride, n; + double *data, rv; + + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_ZVAL(p_data) + Z_PARAM_ZVAL(p_stride) + ZEND_PARSE_PARAMETERS_END(); + + __zval_to_long(p_stride, &stride); + + n = (long) zend_array_count(Z_ARR_P(p_data)); + + __alloc_double_array(&data, n); + __zval_to_double_array(p_data, data, n); + + rv = gsl_stats_variance(data, stride, n); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_stats_variance_m) +{ + zval *p_data, *p_stride, *p_mean; + long stride, n; + double *data, mean, rv; + + ZEND_PARSE_PARAMETERS_START(3, 3) + Z_PARAM_ZVAL(p_data) + Z_PARAM_ZVAL(p_stride) + Z_PARAM_ZVAL(p_mean) + ZEND_PARSE_PARAMETERS_END(); + + __zval_to_long(p_stride, &stride); + __zval_to_double(p_mean, &mean); + + n = (long) zend_array_count(Z_ARR_P(p_data)); + + __alloc_double_array(&data, n); + __zval_to_double_array(p_data, data, n); + + rv = gsl_stats_variance_m(data, stride, n, mean); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_stats_sd) +{ + zval *p_data, *p_stride; + long stride, n; + double *data, rv; + + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_ZVAL(p_data) + Z_PARAM_ZVAL(p_stride) + ZEND_PARSE_PARAMETERS_END(); + + __zval_to_long(p_stride, &stride); + + n = (long) zend_array_count(Z_ARR_P(p_data)); + + __alloc_double_array(&data, n); + __zval_to_double_array(p_data, data, n); + + rv = gsl_stats_sd(data, stride, n); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_stats_tss) +{ + zval *p_data, *p_stride; + long stride, n; + double *data, rv; + + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_ZVAL(p_data) + Z_PARAM_ZVAL(p_stride) + ZEND_PARSE_PARAMETERS_END(); + + __zval_to_long(p_stride, &stride); + + n = (long) zend_array_count(Z_ARR_P(p_data)); + + __alloc_double_array(&data, n); + __zval_to_double_array(p_data, data, n); + + rv = gsl_stats_tss(data, stride, n); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_stats_tss_m) +{ + zval *p_data, *p_stride, *p_mean; + long stride, n; + double *data, mean, rv; + + ZEND_PARSE_PARAMETERS_START(3, 3) + Z_PARAM_ZVAL(p_data) + Z_PARAM_ZVAL(p_stride) + Z_PARAM_ZVAL(p_mean) + ZEND_PARSE_PARAMETERS_END(); + + __zval_to_long(p_stride, &stride); + __zval_to_double(p_mean, &mean); + + n = (long) zend_array_count(Z_ARR_P(p_data)); + + __alloc_double_array(&data, n); + __zval_to_double_array(p_data, data, n); + + rv = gsl_stats_tss_m(data, stride, n, mean); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_stats_variance_with_fixed_mean) +{ + zval *p_data, *p_stride, *p_mean; + long stride, n; + double *data, mean, rv; + + ZEND_PARSE_PARAMETERS_START(3, 3) + Z_PARAM_ZVAL(p_data) + Z_PARAM_ZVAL(p_stride) + Z_PARAM_ZVAL(p_mean) + ZEND_PARSE_PARAMETERS_END(); + + __zval_to_long(p_stride, &stride); + __zval_to_double(p_mean, &mean); + + n = (long) zend_array_count(Z_ARR_P(p_data)); + + __alloc_double_array(&data, n); + __zval_to_double_array(p_data, data, n); + + rv = gsl_stats_variance_with_fixed_mean(data, stride, n, mean); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_stats_sd_with_fixed_mean) +{ + zval *p_data, *p_stride, *p_mean; + long stride, n; + double *data, mean, rv; + + ZEND_PARSE_PARAMETERS_START(3, 3) + Z_PARAM_ZVAL(p_data) + Z_PARAM_ZVAL(p_stride) + Z_PARAM_ZVAL(p_mean) + ZEND_PARSE_PARAMETERS_END(); + + __zval_to_long(p_stride, &stride); + __zval_to_double(p_mean, &mean); + + n = (long) zend_array_count(Z_ARR_P(p_data)); + + __alloc_double_array(&data, n); + __zval_to_double_array(p_data, data, n); + + rv = gsl_stats_sd_with_fixed_mean(data, stride, n, mean); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_stats_absdev) +{ + zval *p_data, *p_stride; + long stride, n; + double *data, rv; + + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_ZVAL(p_data) + Z_PARAM_ZVAL(p_stride) + ZEND_PARSE_PARAMETERS_END(); + + __zval_to_long(p_stride, &stride); + + n = (long) zend_array_count(Z_ARR_P(p_data)); + + __alloc_double_array(&data, n); + __zval_to_double_array(p_data, data, n); + + rv = gsl_stats_absdev(data, stride, n); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_stats_absdev_m) +{ + zval *p_data, *p_stride, *p_mean; + long stride, n; + double *data, mean, rv; + + ZEND_PARSE_PARAMETERS_START(3, 3) + Z_PARAM_ZVAL(p_data) + Z_PARAM_ZVAL(p_stride) + Z_PARAM_ZVAL(p_mean) + ZEND_PARSE_PARAMETERS_END(); + + __zval_to_long(p_stride, &stride); + __zval_to_double(p_mean, &mean); + + n = (long) zend_array_count(Z_ARR_P(p_data)); + + __alloc_double_array(&data, n); + __zval_to_double_array(p_data, data, n); + + rv = gsl_stats_absdev_m(data, stride, n, mean); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_stats_skew) +{ + zval *p_data, *p_stride; + long stride, n; + double *data, rv; + + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_ZVAL(p_data) + Z_PARAM_ZVAL(p_stride) + ZEND_PARSE_PARAMETERS_END(); + + __zval_to_long(p_stride, &stride); + + n = (long) zend_array_count(Z_ARR_P(p_data)); + + __alloc_double_array(&data, n); + __zval_to_double_array(p_data, data, n); + + rv = gsl_stats_skew(data, stride, n); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_stats_skew_m_sd) +{ + zval *p_data, *p_stride, *p_mean, *p_sd; + long stride, n; + double *data, mean, sd, rv; + + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ZVAL(p_data) + Z_PARAM_ZVAL(p_stride) + Z_PARAM_ZVAL(p_mean) + Z_PARAM_ZVAL(p_sd) + ZEND_PARSE_PARAMETERS_END(); + + __zval_to_long(p_stride, &stride); + __zval_to_double(p_mean, &mean); + __zval_to_double(p_sd, &sd); + + n = (long) zend_array_count(Z_ARR_P(p_data)); + + __alloc_double_array(&data, n); + __zval_to_double_array(p_data, data, n); + + rv = gsl_stats_skew_m_sd(data, stride, n, mean, sd); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_stats_kurtosis) +{ + zval *p_data, *p_stride; + long stride, n; + double *data, rv; + + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_ZVAL(p_data) + Z_PARAM_ZVAL(p_stride) + ZEND_PARSE_PARAMETERS_END(); + + __zval_to_long(p_stride, &stride); + + n = (long) zend_array_count(Z_ARR_P(p_data)); + + __alloc_double_array(&data, n); + __zval_to_double_array(p_data, data, n); + + rv = gsl_stats_kurtosis(data, stride, n); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_stats_kurtosis_m_sd) +{ + zval *p_data, *p_stride, *p_mean, *p_sd; + long stride, n; + double *data, mean, sd, rv; + + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ZVAL(p_data) + Z_PARAM_ZVAL(p_stride) + Z_PARAM_ZVAL(p_mean) + Z_PARAM_ZVAL(p_sd) + ZEND_PARSE_PARAMETERS_END(); + + __zval_to_long(p_stride, &stride); + __zval_to_double(p_mean, &mean); + __zval_to_double(p_sd, &sd); + + n = (long) zend_array_count(Z_ARR_P(p_data)); + + __alloc_double_array(&data, n); + __zval_to_double_array(p_data, data, n); + + rv = gsl_stats_kurtosis_m_sd(data, stride, n, mean, sd); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_stats_lag1_autocorrelation) +{ + zval *p_data, *p_stride; + long stride, n; + double *data, rv; + + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_ZVAL(p_data) + Z_PARAM_ZVAL(p_stride) + ZEND_PARSE_PARAMETERS_END(); + + __zval_to_long(p_stride, &stride); + + n = (long) zend_array_count(Z_ARR_P(p_data)); + + __alloc_double_array(&data, n); + __zval_to_double_array(p_data, data, n); + + rv = gsl_stats_lag1_autocorrelation(data, stride, n); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_stats_lag1_autocorrelation_m) +{ + zval *p_data, *p_stride, *p_mean; + long stride, n; + double *data, mean, rv; + + ZEND_PARSE_PARAMETERS_START(3, 3) + Z_PARAM_ZVAL(p_data) + Z_PARAM_ZVAL(p_stride) + Z_PARAM_ZVAL(p_mean) + ZEND_PARSE_PARAMETERS_END(); + + __zval_to_long(p_stride, &stride); + __zval_to_double(p_mean, &mean); + + n = (long) zend_array_count(Z_ARR_P(p_data)); + + __alloc_double_array(&data, n); + __zval_to_double_array(p_data, data, n); + + rv = gsl_stats_lag1_autocorrelation_m(data, stride, n, mean); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_stats_covariance) +{ + zval *p_data1, *p_data2, *p_stride1, *p_stride2; + long stride1, stride2, n; + double *data1, *data2, rv; + + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ZVAL(p_data1) + Z_PARAM_ZVAL(p_stride1) + Z_PARAM_ZVAL(p_data2) + Z_PARAM_ZVAL(p_stride2) + ZEND_PARSE_PARAMETERS_END(); + + __zval_to_long(p_stride1, &stride1); + __zval_to_long(p_stride2, &stride2); + + n = (long) zend_array_count(Z_ARR_P(p_data1)); + + __alloc_double_array(&data1, n); + __alloc_double_array(&data2, n); + __zval_to_double_array(p_data1, data1, n); + __zval_to_double_array(p_data2, data2, n); + + rv = gsl_stats_covariance(data1, stride1, data2, stride2, n); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_stats_covariance_m) +{ + zval *p_data1, *p_data2, *p_stride1, *p_stride2, *p_mean1, *p_mean2; + long stride1, stride2, n; + double *data1, *data2, mean1, mean2, rv; + + ZEND_PARSE_PARAMETERS_START(6, 6) + Z_PARAM_ZVAL(p_data1) + Z_PARAM_ZVAL(p_stride1) + Z_PARAM_ZVAL(p_data2) + Z_PARAM_ZVAL(p_stride2) + Z_PARAM_ZVAL(p_mean1) + Z_PARAM_ZVAL(p_mean2) + ZEND_PARSE_PARAMETERS_END(); + + __zval_to_long(p_stride1, &stride1); + __zval_to_long(p_stride2, &stride2); + __zval_to_double(p_mean1, &mean1); + __zval_to_double(p_mean2, &mean2); + + n = (long) zend_array_count(Z_ARR_P(p_data1)); + + __alloc_double_array(&data1, n); + __alloc_double_array(&data2, n); + __zval_to_double_array(p_data1, data1, n); + __zval_to_double_array(p_data2, data2, n); + + rv = gsl_stats_covariance_m(data1, stride1, data2, stride2, n, mean1, mean2); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_stats_correlation) +{ + zval *p_data1, *p_data2, *p_stride1, *p_stride2; + long stride1, stride2, n; + double *data1, *data2, rv; + + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ZVAL(p_data1) + Z_PARAM_ZVAL(p_stride1) + Z_PARAM_ZVAL(p_data2) + Z_PARAM_ZVAL(p_stride2) + ZEND_PARSE_PARAMETERS_END(); + + __zval_to_long(p_stride1, &stride1); + __zval_to_long(p_stride2, &stride2); + + n = (long) zend_array_count(Z_ARR_P(p_data1)); + + __alloc_double_array(&data1, n); + __alloc_double_array(&data2, n); + __zval_to_double_array(p_data1, data1, n); + __zval_to_double_array(p_data2, data2, n); + + rv = gsl_stats_correlation(data1, stride1, data2, stride2, n); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_stats_spearman) +{ + zval *p_data1, *p_data2, *p_stride1, *p_stride2, *p_work; + long stride1, stride2, n; + double *data1, *data2, *work, rv; + + ZEND_PARSE_PARAMETERS_START(5, 5) + Z_PARAM_ZVAL(p_data1) + Z_PARAM_ZVAL(p_stride1) + Z_PARAM_ZVAL(p_data2) + Z_PARAM_ZVAL(p_stride2) + Z_PARAM_ZVAL(p_work) + ZEND_PARSE_PARAMETERS_END(); + + __zval_to_long(p_stride1, &stride1); + __zval_to_long(p_stride2, &stride2); + + n = (long) zend_array_count(Z_ARR_P(p_data1)); + + __alloc_double_array(&data1, n); + __alloc_double_array(&data2, n); + __alloc_double_array(&work, n * 2); + __zval_to_double_array(p_data1, data1, n); + __zval_to_double_array(p_data2, data2, n); + __zval_to_double_array(p_work, work, n * 2); + + rv = gsl_stats_spearman(data1, stride1, data2, stride2, n, work); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_stats_wmean) +{ + zval *p_w, *p_wstride, *p_data, *p_stride; + long wstride, stride, n; + double *w, *data, rv; + + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ZVAL(p_w) + Z_PARAM_ZVAL(p_wstride) + Z_PARAM_ZVAL(p_data) + Z_PARAM_ZVAL(p_stride) + ZEND_PARSE_PARAMETERS_END(); + + __zval_to_long(p_wstride, &wstride); + __zval_to_long(p_stride, &stride); + + n = (long) zend_array_count(Z_ARR_P(p_data)); + + __alloc_double_array(&data, n); + __alloc_double_array(&w, n); + __zval_to_double_array(p_w, w, n); + __zval_to_double_array(p_data, data, n); + + rv = gsl_stats_wmean(w, wstride, data, stride, n); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_stats_wvariance) +{ + zval *p_w, *p_wstride, *p_data, *p_stride; + long wstride, stride, n; + double *w, *data, rv; + + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ZVAL(p_w) + Z_PARAM_ZVAL(p_wstride) + Z_PARAM_ZVAL(p_data) + Z_PARAM_ZVAL(p_stride) + ZEND_PARSE_PARAMETERS_END(); + + __zval_to_long(p_wstride, &wstride); + __zval_to_long(p_stride, &stride); + + n = (long) zend_array_count(Z_ARR_P(p_data)); + + __alloc_double_array(&data, n); + __alloc_double_array(&w, n); + __zval_to_double_array(p_w, w, n); + __zval_to_double_array(p_data, data, n); + + rv = gsl_stats_wvariance(w, wstride, data, stride, n); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_stats_wvariance_m) +{ + zval *p_w, *p_wstride, *p_data, *p_stride, *p_wmean; + long wstride, stride, n; + double *w, *data, wmean, rv; + + ZEND_PARSE_PARAMETERS_START(5, 5) + Z_PARAM_ZVAL(p_w) + Z_PARAM_ZVAL(p_wstride) + Z_PARAM_ZVAL(p_data) + Z_PARAM_ZVAL(p_stride) + Z_PARAM_ZVAL(p_wmean) + ZEND_PARSE_PARAMETERS_END(); + + __zval_to_long(p_wstride, &wstride); + __zval_to_long(p_stride, &stride); + __zval_to_double(p_wmean, &wmean); + + n = (long) zend_array_count(Z_ARR_P(p_data)); + + __alloc_double_array(&data, n); + __alloc_double_array(&w, n); + __zval_to_double_array(p_w, w, n); + __zval_to_double_array(p_data, data, n); + + rv = gsl_stats_wvariance_m(w, wstride, data, stride, n, wmean); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_stats_wsd) +{ + zval *p_w, *p_wstride, *p_data, *p_stride; + long wstride, stride, n; + double *w, *data, rv; + + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ZVAL(p_w) + Z_PARAM_ZVAL(p_wstride) + Z_PARAM_ZVAL(p_data) + Z_PARAM_ZVAL(p_stride) + ZEND_PARSE_PARAMETERS_END(); + + __zval_to_long(p_wstride, &wstride); + __zval_to_long(p_stride, &stride); + + n = (long) zend_array_count(Z_ARR_P(p_data)); + + __alloc_double_array(&data, n); + __alloc_double_array(&w, n); + __zval_to_double_array(p_w, w, n); + __zval_to_double_array(p_data, data, n); + + rv = gsl_stats_wsd(w, wstride, data, stride, n); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_stats_wsd_m) +{ + zval *p_w, *p_wstride, *p_data, *p_stride, *p_wmean; + long wstride, stride, n; + double *w, *data, wmean, rv; + + ZEND_PARSE_PARAMETERS_START(5, 5) + Z_PARAM_ZVAL(p_w) + Z_PARAM_ZVAL(p_wstride) + Z_PARAM_ZVAL(p_data) + Z_PARAM_ZVAL(p_stride) + Z_PARAM_ZVAL(p_wmean) + ZEND_PARSE_PARAMETERS_END(); + + __zval_to_long(p_wstride, &wstride); + __zval_to_long(p_stride, &stride); + __zval_to_double(p_wmean, &wmean); + + n = (long) zend_array_count(Z_ARR_P(p_data)); + + __alloc_double_array(&data, n); + __alloc_double_array(&w, n); + __zval_to_double_array(p_w, w, n); + __zval_to_double_array(p_data, data, n); + + rv = gsl_stats_wsd_m(w, wstride, data, stride, n, wmean); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_stats_wvariance_with_fixed_mean) +{ + zval *p_w, *p_wstride, *p_data, *p_stride, *p_mean; + long wstride, stride, n; + double *w, *data, mean, rv; + + ZEND_PARSE_PARAMETERS_START(5, 5) + Z_PARAM_ZVAL(p_w) + Z_PARAM_ZVAL(p_wstride) + Z_PARAM_ZVAL(p_data) + Z_PARAM_ZVAL(p_stride) + Z_PARAM_ZVAL(p_mean) + ZEND_PARSE_PARAMETERS_END(); + + __zval_to_long(p_wstride, &wstride); + __zval_to_long(p_stride, &stride); + __zval_to_double(p_mean, &mean); + + n = (long) zend_array_count(Z_ARR_P(p_data)); + + __alloc_double_array(&data, n); + __alloc_double_array(&w, n); + __zval_to_double_array(p_w, w, n); + __zval_to_double_array(p_data, data, n); + + rv = gsl_stats_wvariance_with_fixed_mean(w, wstride, data, stride, n, mean); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_stats_wsd_with_fixed_mean) +{ + zval *p_w, *p_wstride, *p_data, *p_stride, *p_mean; + long wstride, stride, n; + double *w, *data, mean, rv; + + ZEND_PARSE_PARAMETERS_START(5, 5) + Z_PARAM_ZVAL(p_w) + Z_PARAM_ZVAL(p_wstride) + Z_PARAM_ZVAL(p_data) + Z_PARAM_ZVAL(p_stride) + Z_PARAM_ZVAL(p_mean) + ZEND_PARSE_PARAMETERS_END(); + + __zval_to_long(p_wstride, &wstride); + __zval_to_long(p_stride, &stride); + __zval_to_double(p_mean, &mean); + + n = (long) zend_array_count(Z_ARR_P(p_data)); + + __alloc_double_array(&data, n); + __alloc_double_array(&w, n); + __zval_to_double_array(p_w, w, n); + __zval_to_double_array(p_data, data, n); + + rv = gsl_stats_wsd_with_fixed_mean(w, wstride, data, stride, n, mean); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_stats_wtss) +{ + zval *p_w, *p_wstride, *p_data, *p_stride; + long wstride, stride, n; + double *w, *data, rv; + + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ZVAL(p_w) + Z_PARAM_ZVAL(p_wstride) + Z_PARAM_ZVAL(p_data) + Z_PARAM_ZVAL(p_stride) + ZEND_PARSE_PARAMETERS_END(); + + __zval_to_long(p_wstride, &wstride); + __zval_to_long(p_stride, &stride); + + n = (long) zend_array_count(Z_ARR_P(p_data)); + + __alloc_double_array(&data, n); + __alloc_double_array(&w, n); + __zval_to_double_array(p_w, w, n); + __zval_to_double_array(p_data, data, n); + + rv = gsl_stats_wtss(w, wstride, data, stride, n); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_stats_wtss_m) +{ + zval *p_w, *p_wstride, *p_data, *p_stride, *p_mean; + long wstride, stride, n; + double *w, *data, mean, rv; + + ZEND_PARSE_PARAMETERS_START(5, 5) + Z_PARAM_ZVAL(p_w) + Z_PARAM_ZVAL(p_wstride) + Z_PARAM_ZVAL(p_data) + Z_PARAM_ZVAL(p_stride) + Z_PARAM_ZVAL(p_mean) + ZEND_PARSE_PARAMETERS_END(); + + __zval_to_long(p_wstride, &wstride); + __zval_to_long(p_stride, &stride); + __zval_to_double(p_mean, &mean); + + n = (long) zend_array_count(Z_ARR_P(p_data)); + + __alloc_double_array(&data, n); + __alloc_double_array(&w, n); + __zval_to_double_array(p_w, w, n); + __zval_to_double_array(p_data, data, n); + + rv = gsl_stats_wtss_m(w, wstride, data, stride, n, mean); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_stats_wabsdev) +{ + zval *p_w, *p_wstride, *p_data, *p_stride; + long wstride, stride, n; + double *w, *data, rv; + + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ZVAL(p_w) + Z_PARAM_ZVAL(p_wstride) + Z_PARAM_ZVAL(p_data) + Z_PARAM_ZVAL(p_stride) + ZEND_PARSE_PARAMETERS_END(); + + __zval_to_long(p_wstride, &wstride); + __zval_to_long(p_stride, &stride); + + n = (long) zend_array_count(Z_ARR_P(p_data)); + + __alloc_double_array(&data, n); + __alloc_double_array(&w, n); + __zval_to_double_array(p_w, w, n); + __zval_to_double_array(p_data, data, n); + + rv = gsl_stats_wabsdev(w, wstride, data, stride, n); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_stats_wabsdev_m) +{ + zval *p_w, *p_wstride, *p_data, *p_stride, *p_mean; + long wstride, stride, n; + double *w, *data, mean, rv; + + ZEND_PARSE_PARAMETERS_START(5, 5) + Z_PARAM_ZVAL(p_w) + Z_PARAM_ZVAL(p_wstride) + Z_PARAM_ZVAL(p_data) + Z_PARAM_ZVAL(p_stride) + Z_PARAM_ZVAL(p_mean) + ZEND_PARSE_PARAMETERS_END(); + + __zval_to_long(p_wstride, &wstride); + __zval_to_long(p_stride, &stride); + __zval_to_double(p_mean, &mean); + + n = (long) zend_array_count(Z_ARR_P(p_data)); + + __alloc_double_array(&data, n); + __alloc_double_array(&w, n); + __zval_to_double_array(p_w, w, n); + __zval_to_double_array(p_data, data, n); + + rv = gsl_stats_wabsdev_m(w, wstride, data, stride, n, mean); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_stats_wskew) +{ + zval *p_w, *p_wstride, *p_data, *p_stride; + long wstride, stride, n; + double *w, *data, rv; + + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ZVAL(p_w) + Z_PARAM_ZVAL(p_wstride) + Z_PARAM_ZVAL(p_data) + Z_PARAM_ZVAL(p_stride) + ZEND_PARSE_PARAMETERS_END(); + + __zval_to_long(p_wstride, &wstride); + __zval_to_long(p_stride, &stride); + + n = (long) zend_array_count(Z_ARR_P(p_data)); + + __alloc_double_array(&data, n); + __alloc_double_array(&w, n); + __zval_to_double_array(p_w, w, n); + __zval_to_double_array(p_data, data, n); + + rv = gsl_stats_wskew(w, wstride, data, stride, n); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_stats_wskew_m_sd) +{ + zval *p_w, *p_wstride, *p_data, *p_stride, *p_wmean, *p_wsd; + long wstride, stride, n; + double *w, *data, wmean, wsd, rv; + + ZEND_PARSE_PARAMETERS_START(6, 6) + Z_PARAM_ZVAL(p_w) + Z_PARAM_ZVAL(p_wstride) + Z_PARAM_ZVAL(p_data) + Z_PARAM_ZVAL(p_stride) + Z_PARAM_ZVAL(p_wmean) + Z_PARAM_ZVAL(p_wsd) + ZEND_PARSE_PARAMETERS_END(); + + __zval_to_long(p_wstride, &wstride); + __zval_to_long(p_stride, &stride); + __zval_to_double(p_wmean, &wmean); + __zval_to_double(p_wsd, &wsd); + + n = (long) zend_array_count(Z_ARR_P(p_data)); + + __alloc_double_array(&data, n); + __alloc_double_array(&w, n); + __zval_to_double_array(p_w, w, n); + __zval_to_double_array(p_data, data, n); + + rv = gsl_stats_wskew_m_sd(w, wstride, data, stride, n, wmean, wsd); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_stats_wkurtosis) +{ + zval *p_w, *p_wstride, *p_data, *p_stride; + long wstride, stride, n; + double *w, *data, rv; + + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ZVAL(p_w) + Z_PARAM_ZVAL(p_wstride) + Z_PARAM_ZVAL(p_data) + Z_PARAM_ZVAL(p_stride) + ZEND_PARSE_PARAMETERS_END(); + + __zval_to_long(p_wstride, &wstride); + __zval_to_long(p_stride, &stride); + + n = (long) zend_array_count(Z_ARR_P(p_data)); + + __alloc_double_array(&data, n); + __alloc_double_array(&w, n); + __zval_to_double_array(p_w, w, n); + __zval_to_double_array(p_data, data, n); + + rv = gsl_stats_wkurtosis(w, wstride, data, stride, n); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_stats_wkurtosis_m_sd) +{ + zval *p_w, *p_wstride, *p_data, *p_stride, *p_wmean, *p_wsd; + long wstride, stride, n; + double *w, *data, wmean, wsd, rv; + + ZEND_PARSE_PARAMETERS_START(6, 6) + Z_PARAM_ZVAL(p_w) + Z_PARAM_ZVAL(p_wstride) + Z_PARAM_ZVAL(p_data) + Z_PARAM_ZVAL(p_stride) + Z_PARAM_ZVAL(p_wmean) + Z_PARAM_ZVAL(p_wsd) + ZEND_PARSE_PARAMETERS_END(); + + __zval_to_long(p_wstride, &wstride); + __zval_to_long(p_stride, &stride); + __zval_to_double(p_wmean, &wmean); + __zval_to_double(p_wsd, &wsd); + + n = (long) zend_array_count(Z_ARR_P(p_data)); + + __alloc_double_array(&data, n); + __alloc_double_array(&w, n); + __zval_to_double_array(p_w, w, n); + __zval_to_double_array(p_data, data, n); + + rv = gsl_stats_wkurtosis_m_sd(w, wstride, data, stride, n, wmean, wsd); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_stats_max) +{ + zval *p_data, *p_stride; + long stride, n; + double *data, rv; + + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_ZVAL(p_data) + Z_PARAM_ZVAL(p_stride) + ZEND_PARSE_PARAMETERS_END(); + + __zval_to_long(p_stride, &stride); + + n = (long) zend_array_count(Z_ARR_P(p_data)); + + __alloc_double_array(&data, n); + __zval_to_double_array(p_data, data, n); + + rv = gsl_stats_max(data, stride, n); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_stats_min) +{ + zval *p_data, *p_stride; + long stride, n; + double *data, rv; + + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_ZVAL(p_data) + Z_PARAM_ZVAL(p_stride) + ZEND_PARSE_PARAMETERS_END(); + + __zval_to_long(p_stride, &stride); + + n = (long) zend_array_count(Z_ARR_P(p_data)); + + __alloc_double_array(&data, n); + __zval_to_double_array(p_data, data, n); + + rv = gsl_stats_min(data, stride, n); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_stats_minmax) { + zval *p_min, *p_max, *p_data, *p_stride; + long stride, n; + double *data, min, max, rv; + + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ZVAL(p_min) + Z_PARAM_ZVAL(p_max) + Z_PARAM_ZVAL(p_data) + Z_PARAM_ZVAL(p_stride) + ZEND_PARSE_PARAMETERS_END(); + + ZVAL_DEREF(p_min); + ZVAL_DEREF(p_max); + + __zval_to_long(p_stride, &stride); + __zval_to_double(p_min, &min); + __zval_to_double(p_max, &max); + + n = (long) zend_array_count(Z_ARR_P(p_data)); + + __alloc_double_array(&data, n); + __zval_to_double_array(p_data, data, n); + + gsl_stats_minmax(&min, &max, data, stride, n); + __double_to_zval(min, p_min); + __double_to_zval(max, p_max); +} + +PHP_FUNCTION(gsl_stats_min_index) +{ + zval *p_data, *p_stride; + long stride, n, rv; + double *data; + + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_ZVAL(p_data) + Z_PARAM_ZVAL(p_stride) + ZEND_PARSE_PARAMETERS_END(); + + __zval_to_long(p_stride, &stride); + + n = (long) zend_array_count(Z_ARR_P(p_data)); + + __alloc_double_array(&data, n); + __zval_to_double_array(p_data, data, n); + + rv = (long) gsl_stats_min_index(data, stride, n); + + RETURN_LONG(rv); +} + +PHP_FUNCTION(gsl_stats_max_index) +{ + zval *p_data, *p_stride; + long stride, n, rv; + double *data; + + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_ZVAL(p_data) + Z_PARAM_ZVAL(p_stride) + ZEND_PARSE_PARAMETERS_END(); + + __zval_to_long(p_stride, &stride); + + n = (long) zend_array_count(Z_ARR_P(p_data)); + + __alloc_double_array(&data, n); + __zval_to_double_array(p_data, data, n); + + rv = (long) gsl_stats_max_index(data, stride, n); + + RETURN_LONG(rv); +} + +PHP_FUNCTION(gsl_stats_minmax_index) { + zval *p_min_index, *p_max_index, *p_data, *p_stride; + long stride, n; + size_t min_index, max_index; + double *data; + + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ZVAL(p_min_index) + Z_PARAM_ZVAL(p_max_index) + Z_PARAM_ZVAL(p_data) + Z_PARAM_ZVAL(p_stride) + ZEND_PARSE_PARAMETERS_END(); + + ZVAL_DEREF(p_min_index); + ZVAL_DEREF(p_max_index); + + __zval_to_long(p_stride, &stride); + __zval_to_size_t(p_min_index, &min_index); + __zval_to_size_t(p_max_index, &max_index); + + n = (long) zend_array_count(Z_ARR_P(p_data)); + + __alloc_double_array(&data, n); + __zval_to_double_array(p_data, data, n); + + gsl_stats_minmax_index(&min_index, &max_index, data, stride, n); + __long_to_zval((long)min_index, p_min_index); + __long_to_zval((long)max_index, p_max_index); +} + +PHP_FUNCTION(gsl_stats_median_from_sorted_data) +{ + zval *p_sorted_data, *p_stride; + long stride, n; + double *sorted_data, rv; + + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_ZVAL(p_sorted_data) + Z_PARAM_ZVAL(p_stride) + ZEND_PARSE_PARAMETERS_END(); + + __zval_to_long(p_stride, &stride); + + n = (long) zend_array_count(Z_ARR_P(p_sorted_data)); + + __alloc_double_array(&sorted_data, n); + __zval_to_double_array(p_sorted_data, sorted_data, n); + + rv = gsl_stats_median_from_sorted_data(sorted_data, stride, n); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_stats_median) +{ + zval *p_data, *p_stride; + long stride, n; + double *data, rv; + + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_ZVAL(p_data) + Z_PARAM_ZVAL(p_stride) + ZEND_PARSE_PARAMETERS_END(); + + __zval_to_long(p_stride, &stride); + + n = (long) zend_array_count(Z_ARR_P(p_data)); + + __alloc_double_array(&data, n); + __zval_to_double_array(p_data, data, n); + + rv = gsl_stats_median(data, stride, n); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_stats_quantile_from_sorted_data) +{ + zval *p_sorted_data, *p_stride, *p_f; + long stride, n; + double *sorted_data, f, rv; + + ZEND_PARSE_PARAMETERS_START(3, 3) + Z_PARAM_ZVAL(p_sorted_data) + Z_PARAM_ZVAL(p_stride) + Z_PARAM_ZVAL(p_f) + ZEND_PARSE_PARAMETERS_END(); + + __zval_to_long(p_stride, &stride); + __zval_to_double(p_f, &f); + + n = (long) zend_array_count(Z_ARR_P(p_sorted_data)); + + __alloc_double_array(&sorted_data, n); + + rv = gsl_stats_quantile_from_sorted_data(sorted_data, stride, n, f); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_stats_select) +{ + zval *p_data, *p_stride, *p_k; + long stride, n, k; + double *data, rv; + + ZEND_PARSE_PARAMETERS_START(3, 3) + Z_PARAM_ZVAL(p_data) + Z_PARAM_ZVAL(p_stride) + Z_PARAM_ZVAL(p_k) + ZEND_PARSE_PARAMETERS_END(); + + __zval_to_long(p_stride, &stride); + __zval_to_long(p_k, &k); + + n = (long) zend_array_count(Z_ARR_P(p_data)); + + __alloc_double_array(&data, n); + + rv = gsl_stats_select(data, stride, n, k); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_stats_trmean_from_sorted_data) +{ + zval *p_alpha, *p_sorted_data, *p_stride; + long stride, n; + double *sorted_data, alpha, rv; + + ZEND_PARSE_PARAMETERS_START(3, 3) + Z_PARAM_ZVAL(p_alpha) + Z_PARAM_ZVAL(p_sorted_data) + Z_PARAM_ZVAL(p_stride) + ZEND_PARSE_PARAMETERS_END(); + + __zval_to_long(p_stride, &stride); + __zval_to_double(p_alpha, &alpha); + + n = (long) zend_array_count(Z_ARR_P(p_sorted_data)); + + __alloc_double_array(&sorted_data, n); + + rv = gsl_stats_trmean_from_sorted_data(alpha, sorted_data, stride, n); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_stats_gastwirth_from_sorted_data) +{ + zval *p_sorted_data, *p_stride; + long stride, n; + double *sorted_data, rv; + + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_ZVAL(p_sorted_data) + Z_PARAM_ZVAL(p_stride) + ZEND_PARSE_PARAMETERS_END(); + + __zval_to_long(p_stride, &stride); + + n = (long) zend_array_count(Z_ARR_P(p_sorted_data)); + + __alloc_double_array(&sorted_data, n); + + rv = gsl_stats_gastwirth_from_sorted_data(sorted_data, stride, n); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_stats_mad0) +{ + zval *p_data, *p_stride; + long stride, n; + double *data, *work, rv; + + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_ZVAL(p_data) + Z_PARAM_ZVAL(p_stride) + ZEND_PARSE_PARAMETERS_END(); + + __zval_to_long(p_stride, &stride); + + n = (long) zend_array_count(Z_ARR_P(p_data)); + + __alloc_double_array(&data, n); + __alloc_double_array(&work, n); + + rv = gsl_stats_mad0(data, stride, n, work); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_stats_mad) +{ + zval *p_data, *p_stride; + long stride, n; + double *data, *work, rv; + + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_ZVAL(p_data) + Z_PARAM_ZVAL(p_stride) + ZEND_PARSE_PARAMETERS_END(); + + __zval_to_long(p_stride, &stride); + + n = (long) zend_array_count(Z_ARR_P(p_data)); + + __alloc_double_array(&data, n); + __alloc_double_array(&work, n); + + rv = gsl_stats_mad(data, stride, n, work); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_stats_Sn0_from_sorted_data) +{ + zval *p_sorted_data, *p_stride; + long stride, n; + double *sorted_data, *work, rv; + + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_ZVAL(p_sorted_data) + Z_PARAM_ZVAL(p_stride) + ZEND_PARSE_PARAMETERS_END(); + + __zval_to_long(p_stride, &stride); + + n = (long) zend_array_count(Z_ARR_P(p_sorted_data)); + + __alloc_double_array(&sorted_data, n); + __alloc_double_array(&work, n); + + rv = gsl_stats_Sn0_from_sorted_data(sorted_data, stride, n, work); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_stats_Sn_from_sorted_data) +{ + zval *p_sorted_data, *p_stride; + long stride, n; + double *sorted_data, *work, rv; + + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_ZVAL(p_sorted_data) + Z_PARAM_ZVAL(p_stride) + ZEND_PARSE_PARAMETERS_END(); + + __zval_to_long(p_stride, &stride); + + n = (long) zend_array_count(Z_ARR_P(p_sorted_data)); + + __alloc_double_array(&sorted_data, n); + __alloc_double_array(&work, n); + + rv = gsl_stats_Sn_from_sorted_data(sorted_data, stride, n, work); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_stats_Qn0_from_sorted_data) +{ + zval *p_sorted_data, *p_stride; + long stride, n; + int *work_int; + double *sorted_data, *work, rv; + + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_ZVAL(p_sorted_data) + Z_PARAM_ZVAL(p_stride) + ZEND_PARSE_PARAMETERS_END(); + + __zval_to_long(p_stride, &stride); + + n = (long) zend_array_count(Z_ARR_P(p_sorted_data)); + + __alloc_double_array(&sorted_data, n); + __alloc_double_array(&work, 3 * n); + __alloc_int_array(&work_int, 5 * n); + + rv = gsl_stats_Qn0_from_sorted_data(sorted_data, stride, n, work, work_int); + + RETURN_DOUBLE(rv); +} + +PHP_FUNCTION(gsl_stats_Qn_from_sorted_data) +{ + zval *p_sorted_data, *p_stride; + long stride, n; + int *work_int; + double *sorted_data, *work, rv; + + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_ZVAL(p_sorted_data) + Z_PARAM_ZVAL(p_stride) + ZEND_PARSE_PARAMETERS_END(); + + __zval_to_long(p_stride, &stride); + + n = (long) zend_array_count(Z_ARR_P(p_sorted_data)); + + __alloc_double_array(&sorted_data, n); + __alloc_double_array(&work, 3 * n); + __alloc_int_array(&work_int, 5 * n); + + rv = gsl_stats_Qn_from_sorted_data(sorted_data, stride, n, work, work_int); + + RETURN_DOUBLE(rv); +} + diff --git a/tests/0007.statistics.phpt b/tests/0007.statistics.phpt new file mode 100644 index 0000000..6197f0f --- /dev/null +++ b/tests/0007.statistics.phpt @@ -0,0 +1,369 @@ +--TEST-- +statistics +--EXTENSIONS-- +gslext +--FILE-- + +--EXPECT-- +string(14) "gsl_stats_mean" +float(1) +float(1.4) +string(18) "gsl_stats_variance" +float(0) +float(0.3) +string(20) "gsl_stats_variance_m" +float(0.3) +string(12) "gsl_stats_sd" +float(0.5477225575051661) +string(13) "gsl_stats_tss" +float(1.2) +string(15) "gsl_stats_tss_m" +float(1.2) +string(34) "gsl_stats_variance_with_fixed_mean" +float(0.24) +string(28) "gsl_stats_sd_with_fixed_mean" +float(0.4898979485566356) +string(16) "gsl_stats_absdev" +float(0.48) +string(18) "gsl_stats_absdev_m" +float(1.1) +string(14) "gsl_stats_skew" +float(0.292118697336089) +string(19) "gsl_stats_skew_m_sd" +float(60.41127528730834) +string(18) "gsl_stats_kurtosis" +float(-2.253333333333333) +string(23) "gsl_stats_kurtosis_m_sd" +float(290.8559988397203) +string(30) "gsl_stats_lag1_autocorrelation" +float(-0.9166666666666666) +string(32) "gsl_stats_lag1_autocorrelation_m" +float(0.6454635108481263) +string(20) "gsl_stats_covariance" +float(-0.2727272727272727) +string(22) "gsl_stats_covariance_m" +float(3.1145454545454543) +string(21) "gsl_stats_correlation" +float(0.07881104062391005) +string(18) "gsl_stats_spearman" +float(-0.6446583712203042) +string(15) "gsl_stats_wmean" +float(3.2222222222222223) +string(19) "gsl_stats_wvariance" +float(6.5578231292517) +string(21) "gsl_stats_wvariance_m" +float(15.968571428571424) +string(13) "gsl_stats_wsd" +float(2.560824697095) +string(15) "gsl_stats_wsd_m" +float(3.996069497465156) +string(15) "gsl_stats_wsd_m" +float(3.996069497465156) +string(35) "gsl_stats_wvariance_with_fixed_mean" +float(14.489999999999998) +string(29) "gsl_stats_wsd_with_fixed_mean" +float(3.806573262134856) +string(14) "gsl_stats_wtss" +float(107.11111111111111) +string(16) "gsl_stats_wtss_m" +float(260.82) +string(17) "gsl_stats_wabsdev" +float(1.5061728395061729) +string(19) "gsl_stats_wabsdev_m" +float(2.922222222222222) +string(15) "gsl_stats_wskew" +float(1.9994421970524316) +string(20) "gsl_stats_wskew_m_sd" +float(32.79957201646089) +string(19) "gsl_stats_wkurtosis" +float(2.4812425732532066) +string(24) "gsl_stats_wkurtosis_m_sd" +float(195.71870288065836) +string(13) "gsl_stats_max" +float(10) +string(13) "gsl_stats_min" +float(-1) +string(16) "gsl_stats_minmax" +float(-1) +float(10) +string(19) "gsl_stats_min_index" +int(4) +string(19) "gsl_stats_max_index" +int(11) +string(22) "gsl_stats_minmax_index" +int(4) +int(11) +string(33) "gsl_stats_median_from_sorted_data" +float(11) +string(16) "gsl_stats_median" +float(11) +string(35) "gsl_stats_quantile_from_sorted_data" +float(1.5996441192502115E+252) +string(33) "gsl_stats_trmean_from_sorted_data" +float(9.4E-323) diff --git a/tests/0008.running_statistics.phpt b/tests/0008.running_statistics.phpt new file mode 100644 index 0000000..8067d9e --- /dev/null +++ b/tests/0008.running_statistics.phpt @@ -0,0 +1,79 @@ +--TEST-- +statistics +--EXTENSIONS-- +gslext +--FILE-- + +--EXPECT-- +string(13) "gsl_rstat_min" +float(12.6) +string(13) "gsl_rstat_max" +float(18.3) +string(14) "gsl_rstat_mean" +float(16.54) +string(18) "gsl_rstat_variance" +float(5.372999999999998) +string(12) "gsl_rstat_sd" +float(2.3179732526498227) +string(17) "gsl_rstat_sd_mean" +float(1.0366291525902596) +string(13) "gsl_rstat_rms" +float(16.66943310373811) +string(14) "gsl_rstat_skew" +float(-0.8290575000369654) +string(18) "gsl_rstat_kurtosis" +float(-1.2217029020861698) +string(16) "gsl_rstat_median" +float(17.2) +string(22) "gsl_rstat_quantile_get" +float(0.0074002) +string(22) "gsl_rstat_quantile_get" +float(0.0120706) +string(22) "gsl_rstat_quantile_get" +float(0.0207256) \ No newline at end of file