diff --git a/.editorconfig b/.editorconfig index 0779e8a..dab5d2a 100644 --- a/.editorconfig +++ b/.editorconfig @@ -86,7 +86,6 @@ indent_style = tab [*.{f,f.txt}] indent_style = space indent_size = 2 -insert_final_newline = false # Set properties for shell files: [*.{sh,sh.txt}] diff --git a/CHANGELOG.md b/CHANGELOG.md index abb0f22..d454874 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,17 @@
-## Unreleased (2024-12-25) +## Unreleased (2025-01-17) + +
+ +### Features + +- [`0091053`](https://github.com/stdlib-js/stdlib/commit/009105308118f21e4430e906806c1305a5827bc1) - add C ndarray interface and refactor implementation for `stats/base/dsemch` [(#4653)](https://github.com/stdlib-js/stdlib/pull/4653) + +
+ +
@@ -12,7 +22,8 @@
-- [`81fee17`](https://github.com/stdlib-js/stdlib/commit/81fee17fd854cbb34230e10f4f72c4d5ece650d1) - **refactor:** update `stats/base/dsemch` native addon from C++ to C [(#4219)](https://github.com/stdlib-js/stdlib/pull/4219) _(by Vivek maurya)_ +- [`0091053`](https://github.com/stdlib-js/stdlib/commit/009105308118f21e4430e906806c1305a5827bc1) - **feat:** add C ndarray interface and refactor implementation for `stats/base/dsemch` [(#4653)](https://github.com/stdlib-js/stdlib/pull/4653) _(by Aayush Khanna)_ +- [`81fee17`](https://github.com/stdlib-js/stdlib/commit/81fee17fd854cbb34230e10f4f72c4d5ece650d1) - **refactor:** update `stats/base/dsemch` native addon from C++ to C [(#4219)](https://github.com/stdlib-js/stdlib/pull/4219) _(by Vivek Maurya)_ - [`62364f6`](https://github.com/stdlib-js/stdlib/commit/62364f62ea823a3b52c2ad25660ecd80c71f8f36) - **style:** fix C comment alignment _(by Philipp Burckhardt)_ - [`9e689ff`](https://github.com/stdlib-js/stdlib/commit/9e689ffcb7c6223afc521f1e574b42f10921cf5e) - **chore:** fix indentation in manifest.json files _(by Philipp Burckhardt)_ - [`272ae7a`](https://github.com/stdlib-js/stdlib/commit/272ae7ac5c576c68cfab1b6e304c86407faa20cd) - **docs:** remove comment _(by Athan Reines)_ @@ -28,11 +39,12 @@ ### Contributors -A total of 3 people contributed to this release. Thank you to the following contributors: +A total of 4 people contributed to this release. Thank you to the following contributors: +- Aayush Khanna - Athan Reines - Philipp Burckhardt -- Vivek maurya +- Vivek Maurya
diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 173c07b..92d7552 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -27,6 +27,7 @@ Daniel Killenberger Daniel Yu <40680511+Daniel777y@users.noreply.github.com> Debashis Maharana Desh Deepak Kant <118960904+DeshDeepakKant@users.noreply.github.com> +Dhruv Arvind Singh <154677013+DhruvArvindSingh@users.noreply.github.com> Divyansh Seth <59174836+sethdivyansh@users.noreply.github.com> Dominic Lim <46486515+domlimm@users.noreply.github.com> Dominik Moritz @@ -49,6 +50,7 @@ Joey Reed Jordan Gallivan <115050475+Jordan-Gallivan@users.noreply.github.com> Joris Labie Justin Dennison +Karan Anand <119553199+anandkaranubc@users.noreply.github.com> Karthik Prakash <116057817+skoriop@users.noreply.github.com> Kohantika Nath <145763549+kohantikanath@users.noreply.github.com> Krishnendu Das <86651039+itskdhere@users.noreply.github.com> @@ -117,7 +119,7 @@ UtkershBasnet <119008923+UtkershBasnet@users.noreply.github.com> Vaibhav Patel <98279986+noobCoderVP@users.noreply.github.com> Varad Gupta Vinit Pandit <106718914+MeastroZI@users.noreply.github.com> -Vivek maurya <155618190+vivekmaurya001@users.noreply.github.com> +Vivek Maurya Xiaochuan Ye Yaswanth Kosuru <116426380+yaswanthkosuru@users.noreply.github.com> Yernar Yergaziyev diff --git a/NOTICE b/NOTICE index e6e7482..cbd3a29 100644 --- a/NOTICE +++ b/NOTICE @@ -1 +1 @@ -Copyright (c) 2016-2024 The Stdlib Authors. +Copyright (c) 2016-2025 The Stdlib Authors. diff --git a/README.md b/README.md index fa4eaad..d552345 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,7 @@ To view installation and usage instructions specific to each branch build, be su var dsemch = require( '@stdlib/stats-base-dsemch' ); ``` -#### dsemch( N, correction, x, stride ) +#### dsemch( N, correction, x, strideX ) Computes the [standard error of the mean][standard-error] of a double-precision floating-point strided array `x` using a one-pass trial mean algorithm. @@ -111,9 +111,8 @@ Computes the [standard error of the mean][standard-error] of a double-precision var Float64Array = require( '@stdlib/array-float64' ); var x = new Float64Array( [ 1.0, -2.0, 2.0 ] ); -var N = x.length; -var v = dsemch( N, 1, x, 1 ); +var v = dsemch( x.length, 1, x, 1 ); // returns ~1.20185 ``` @@ -122,18 +121,16 @@ The function has the following parameters: - **N**: number of indexed elements. - **correction**: degrees of freedom adjustment. Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the [standard deviation][standard-deviation] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the [standard deviation][standard-deviation] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the corrected sample [standard deviation][standard-deviation], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction). - **x**: input [`Float64Array`][@stdlib/array/float64]. -- **stride**: index increment for `x`. +- **strideX**: stride length for `x`. -The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to compute the [standard error of the mean][standard-error] of every other element in `x`, +The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the [standard error of the mean][standard-error] of every other element in `x`, ```javascript var Float64Array = require( '@stdlib/array-float64' ); -var floor = require( '@stdlib/math-base-special-floor' ); var x = new Float64Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ] ); -var N = floor( x.length / 2 ); -var v = dsemch( N, 1, x, 2 ); +var v = dsemch( 4, 1, x, 2 ); // returns 1.25 ``` @@ -143,18 +140,15 @@ Note that indexing is relative to the first index. To introduce an offset, use [ ```javascript var Float64Array = require( '@stdlib/array-float64' ); -var floor = require( '@stdlib/math-base-special-floor' ); var x0 = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element -var N = floor( x0.length / 2 ); - -var v = dsemch( N, 1, x1, 2 ); +var v = dsemch( 4, 1, x1, 2 ); // returns 1.25 ``` -#### dsemch.ndarray( N, correction, x, stride, offset ) +#### dsemch.ndarray( N, correction, x, strideX, offsetX ) Computes the [standard error of the mean][standard-error] of a double-precision floating-point strided array using a one-pass trial mean algorithm and alternative indexing semantics. @@ -162,26 +156,23 @@ Computes the [standard error of the mean][standard-error] of a double-precision var Float64Array = require( '@stdlib/array-float64' ); var x = new Float64Array( [ 1.0, -2.0, 2.0 ] ); -var N = x.length; -var v = dsemch.ndarray( N, 1, x, 1, 0 ); +var v = dsemch.ndarray( x.length, 1, x, 1, 0 ); // returns ~1.20185 ``` The function has the following additional parameters: -- **offset**: starting index for `x`. +- **offsetX**: starting index for `x`. -While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the `offset` parameter supports indexing semantics based on a starting index. For example, to calculate the [standard error of the mean][standard-error] for every other value in `x` starting from the second value +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to calculate the [standard error of the mean][standard-error] for every other element in `x` starting from the second element ```javascript var Float64Array = require( '@stdlib/array-float64' ); -var floor = require( '@stdlib/math-base-special-floor' ); var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); -var N = floor( x.length / 2 ); -var v = dsemch.ndarray( N, 1, x, 2, 1 ); +var v = dsemch.ndarray( 4, 1, x, 2, 1 ); // returns 1.25 ``` @@ -208,18 +199,12 @@ var v = dsemch.ndarray( N, 1, x, 2, 1 ); ```javascript -var randu = require( '@stdlib/random-base-randu' ); -var round = require( '@stdlib/math-base-special-round' ); -var Float64Array = require( '@stdlib/array-float64' ); +var discreteUniform = require( '@stdlib/random-array-discrete-uniform' ); var dsemch = require( '@stdlib/stats-base-dsemch' ); -var x; -var i; - -x = new Float64Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - x[ i ] = round( (randu()*100.0) - 50.0 ); -} +var x = discreteUniform( 10, -50, 50, { + 'dtype': 'float64' +}); console.log( x ); var v = dsemch( x.length, 1, x, 1 ); @@ -230,6 +215,125 @@ console.log( v ); + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/base/dsemch.h" +``` + +#### stdlib_strided_dsemch( N, correction, \*X, strideX ) + +Computes the [standard error of the mean][standard-error] of a double-precision floating-point strided array using a one-pass trial mean algorithm. + +```c +const double x[] = { 1.0, -2.0, 2.0 }; + +double v = stdlib_strided_dsemch( 3, 1.0, x, 1 ); +// returns ~1.20185 +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **correction**: `[in] double` degrees of freedom adjustment. Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the [standard deviation][standard-deviation] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the [standard deviation][standard-deviation] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the corrected sample [standard deviation][standard-deviation], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction). +- **X**: `[in] double*` input array. +- **strideX**: `[in] CBLAS_INT` stride length for `X`. + +```c +double stdlib_strided_dsemch( const CBLAS_INT N, const double correction, const double *X, const CBLAS_INT strideX ); +``` + +#### stdlib_strided_dsemch_ndarray( N, correction, \*X, strideX, offsetX ) + +Computes the [standard error of the mean][standard-error] of a double-precision floating-point strided array using a one-pass trial mean algorithm and alternative indexing semantics. + +```c +const double x[] = { 1.0, -2.0, 2.0 }; + +double v = stdlib_strided_dsemch_ndarray( 3, 1.0, x, 1, 0 ); +// returns ~1.20185 +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **correction**: `[in] double` degrees of freedom adjustment. Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the [standard deviation][standard-deviation] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the [standard deviation][standard-deviation] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the corrected sample [standard deviation][standard-deviation], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction). +- **X**: `[in] double*` input array. +- **strideX**: `[in] CBLAS_INT` stride length for `X`. +- **offsetX**: `[in] CBLAS_INT` starting index for `X`. + +```c +double stdlib_strided_dsemch_ndarray( const CBLAS_INT N, const double correction, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/base/dsemch.h" +#include + +int main( void ) { + // Create a strided array: + const double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }; + + // Specify the number of elements: + const int N = 4; + + // Specify the stride length: + const int strideX = 2; + + // Compute the standard error of the mean: + double v = stdlib_strided_dsemch( N, 1.0, x, strideX ); + + // Print the result: + printf( "standard error of the mean: %lf\n", v ); +} +``` + +
+ + + +
+ + + * * *
@@ -286,7 +390,7 @@ See [LICENSE][stdlib-license]. ## Copyright -Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. +Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors].
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js index d1fcaeb..34c80bf 100644 --- a/benchmark/benchmark.js +++ b/benchmark/benchmark.js @@ -21,14 +21,20 @@ // MODULES // var bench = require( '@stdlib/bench-harness' ); -var randu = require( '@stdlib/random-base-randu' ); +var uniform = require( '@stdlib/random-array-uniform' ); var isnan = require( '@stdlib/math-base-assert-is-nan' ); var pow = require( '@stdlib/math-base-special-pow' ); -var Float64Array = require( '@stdlib/array-float64' ); var pkg = require( './../package.json' ).name; var dsemch = require( './../lib/dsemch.js' ); +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + // FUNCTIONS // /** @@ -39,13 +45,7 @@ var dsemch = require( './../lib/dsemch.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = new Float64Array( len ); - for ( i = 0; i < x.length; i++ ) { - x[ i ] = ( randu()*20.0 ) - 10.0; - } + var x = uniform( len, -10.0, 10.0, options ); return benchmark; function benchmark( b ) { diff --git a/benchmark/benchmark.native.js b/benchmark/benchmark.native.js index 44523cf..f42bfdc 100644 --- a/benchmark/benchmark.native.js +++ b/benchmark/benchmark.native.js @@ -22,10 +22,9 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench-harness' ); -var randu = require( '@stdlib/random-base-randu' ); +var uniform = require( '@stdlib/random-array-uniform' ); var isnan = require( '@stdlib/math-base-assert-is-nan' ); var pow = require( '@stdlib/math-base-special-pow' ); -var Float64Array = require( '@stdlib/array-float64' ); var tryRequire = require( '@stdlib/utils-try-require' ); var pkg = require( './../package.json' ).name; @@ -36,6 +35,9 @@ var dsemch = tryRequire( resolve( __dirname, './../lib/dsemch.native.js' ) ); var opts = { 'skip': ( dsemch instanceof Error ) }; +var options = { + 'dtype': 'float64' +}; // FUNCTIONS // @@ -48,13 +50,7 @@ var opts = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = new Float64Array( len ); - for ( i = 0; i < x.length; i++ ) { - x[ i ] = ( randu()*20.0 ) - 10.0; - } + var x = uniform( len, -10.0, 10.0, options ); return benchmark; function benchmark( b ) { diff --git a/benchmark/benchmark.ndarray.js b/benchmark/benchmark.ndarray.js index 5fd5c49..2697f05 100644 --- a/benchmark/benchmark.ndarray.js +++ b/benchmark/benchmark.ndarray.js @@ -21,14 +21,20 @@ // MODULES // var bench = require( '@stdlib/bench-harness' ); -var randu = require( '@stdlib/random-base-randu' ); +var uniform = require( '@stdlib/random-array-uniform' ); var isnan = require( '@stdlib/math-base-assert-is-nan' ); var pow = require( '@stdlib/math-base-special-pow' ); -var Float64Array = require( '@stdlib/array-float64' ); var pkg = require( './../package.json' ).name; var dsemch = require( './../lib/ndarray.js' ); +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + // FUNCTIONS // /** @@ -39,13 +45,7 @@ var dsemch = require( './../lib/ndarray.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = new Float64Array( len ); - for ( i = 0; i < x.length; i++ ) { - x[ i ] = ( randu()*20.0 ) - 10.0; - } + var x = uniform( len, -10.0, 10.0, options ); return benchmark; function benchmark( b ) { diff --git a/benchmark/benchmark.ndarray.native.js b/benchmark/benchmark.ndarray.native.js index 2158a62..f806100 100644 --- a/benchmark/benchmark.ndarray.native.js +++ b/benchmark/benchmark.ndarray.native.js @@ -22,10 +22,9 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench-harness' ); -var randu = require( '@stdlib/random-base-randu' ); +var uniform = require( '@stdlib/random-array-uniform' ); var isnan = require( '@stdlib/math-base-assert-is-nan' ); var pow = require( '@stdlib/math-base-special-pow' ); -var Float64Array = require( '@stdlib/array-float64' ); var tryRequire = require( '@stdlib/utils-try-require' ); var pkg = require( './../package.json' ).name; @@ -36,6 +35,9 @@ var dsemch = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); var opts = { 'skip': ( dsemch instanceof Error ) }; +var options = { + 'dtype': 'float64' +}; // FUNCTIONS // @@ -48,13 +50,7 @@ var opts = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = new Float64Array( len ); - for ( i = 0; i < x.length; i++ ) { - x[ i ] = ( randu()*20.0 ) - 10.0; - } + var x = uniform( len, -10.0, 10.0, options ); return benchmark; function benchmark( b ) { diff --git a/benchmark/c/benchmark.length.c b/benchmark/c/benchmark.length.c index 56179cd..bc1fc6a 100644 --- a/benchmark/c/benchmark.length.c +++ b/benchmark/c/benchmark.length.c @@ -94,7 +94,7 @@ static double rand_double( void ) { * @param len array length * @return elapsed time in seconds */ -static double benchmark( int iterations, int len ) { +static double benchmark1( int iterations, int len ) { double elapsed; double x[ len ]; double v; @@ -107,7 +107,42 @@ static double benchmark( int iterations, int len ) { v = 0.0; t = tic(); for ( i = 0; i < iterations; i++ ) { - v = stdlib_strided_dsemch( len, 1, x, 1 ); + // cppcheck-suppress uninitvar + v = stdlib_strided_dsemch( len, 1.0, x, 1 ); + if ( v != v ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( v != v ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param len array length +* @return elapsed time in seconds +*/ +static double benchmark2( int iterations, int len ) { + double elapsed; + double x[ len ]; + double v; + double t; + int i; + + for ( i = 0; i < len; i++ ) { + x[ i ] = ( rand_double() * 20000.0 ) - 10000.0; + } + v = 0.0; + t = tic(); + for ( i = 0; i < iterations; i++ ) { + // cppcheck-suppress uninitvar + v = stdlib_strided_dsemch_ndarray( len, 1.0, x, 1, 0 ); if ( v != v ) { printf( "should not return NaN\n" ); break; @@ -142,7 +177,18 @@ int main( void ) { for ( j = 0; j < REPEATS; j++ ) { count += 1; printf( "# c::%s:len=%d\n", NAME, len ); - elapsed = benchmark( iter, len ); + elapsed = benchmark1( iter, len ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + } + for ( i = MIN; i <= MAX; i++ ) { + len = pow( 10, i ); + iter = ITERATIONS / pow( 10, i-1 ); + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s:ndarray:len=%d\n", NAME, len ); + elapsed = benchmark2( iter, len ); print_results( iter, elapsed ); printf( "ok %d benchmark finished\n", count ); } diff --git a/dist/index.js b/dist/index.js index 5c9d0d9..d7089bb 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,9 +1,9 @@ -"use strict";var s=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var n=s(function(w,u){ -var p=require('@stdlib/stats-base-dvariancech/dist'),y=require('@stdlib/math-base-special-sqrt/dist');function x(e,r,a,i){return y(p(e,r,a,i)/e)}u.exports=x -});var c=s(function(z,v){ -var f=require('@stdlib/stats-base-dvariancech/dist').ndarray,j=require('@stdlib/math-base-special-sqrt/dist');function l(e,r,a,i,h){return j(f(e,r,a,i,h)/e)}v.exports=l +"use strict";var s=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var t=s(function(w,n){ +var f=require('@stdlib/stats-base-dvariancech/dist').ndarray,h=require('@stdlib/math-base-special-sqrt/dist');function p(e,r,i,a,y){return h(f(e,r,i,a,y)/e)}n.exports=p +});var q=s(function(z,v){ +var x=require('@stdlib/strided-base-stride2offset/dist'),j=t();function l(e,r,i,a){return j(e,r,i,a,x(e,a))}v.exports=l });var o=s(function(A,d){ -var R=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),q=n(),_=c();R(q,"ndarray",_);d.exports=q -});var E=require("path").join,O=require('@stdlib/utils-try-require/dist'),b=require('@stdlib/assert-is-error/dist'),g=o(),t,m=O(E(__dirname,"./native.js"));b(m)?t=g:t=m;module.exports=t; +var R=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),c=q(),_=t();R(c,"ndarray",_);d.exports=c +});var E=require("path").join,O=require('@stdlib/utils-try-require/dist'),b=require('@stdlib/assert-is-error/dist'),g=o(),u,m=O(E(__dirname,"./native.js"));b(m)?u=g:u=m;module.exports=u; /** @license Apache-2.0 */ //# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map index def156d..9708e0e 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1,7 +1,7 @@ { "version": 3, - "sources": ["../lib/dsemch.js", "../lib/ndarray.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar dvariancech = require( '@stdlib/stats-base-dvariancech' );\nvar sqrt = require( '@stdlib/math-base-special-sqrt' );\n\n\n// MAIN //\n\n/**\n* Computes the standard error of the mean for a double-precision floating-point strided array using a one-pass trial mean algorithm.\n*\n* @param {PositiveInteger} N - number of indexed elements\n* @param {number} correction - degrees of freedom adjustment\n* @param {Float64Array} x - input array\n* @param {integer} stride - stride length\n* @returns {number} standard error of the mean\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var x = new Float64Array( [ 1.0, -2.0, 2.0 ] );\n* var N = x.length;\n*\n* var v = dsemch( N, 1, x, 1 );\n* // returns ~1.20185\n*/\nfunction dsemch( N, correction, x, stride ) {\n\treturn sqrt( dvariancech( N, correction, x, stride ) / N );\n}\n\n\n// EXPORTS //\n\nmodule.exports = dsemch;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar dvariancech = require( '@stdlib/stats-base-dvariancech' ).ndarray;\nvar sqrt = require( '@stdlib/math-base-special-sqrt' );\n\n\n// MAIN //\n\n/**\n* Computes the standard error of the mean for a double-precision floating-point strided array using a one-pass trial mean algorithm.\n*\n* @param {PositiveInteger} N - number of indexed elements\n* @param {number} correction - degrees of freedom adjustment\n* @param {Float64Array} x - input array\n* @param {integer} stride - stride length\n* @param {NonNegativeInteger} offset - starting index\n* @returns {number} standard error of the mean\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var floor = require( '@stdlib/math-base-special-floor' );\n*\n* var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] );\n* var N = floor( x.length / 2 );\n*\n* var v = dsemch( N, 1, x, 2, 1 );\n* // returns 1.25\n*/\nfunction dsemch( N, correction, x, stride, offset ) {\n\treturn sqrt( dvariancech( N, correction, x, stride, offset ) / N );\n}\n\n\n// EXPORTS //\n\nmodule.exports = dsemch;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar dsemch = require( './dsemch.js' );\nvar ndarray = require( './ndarray.js' );\n\n\n// MAIN //\n\nsetReadOnly( dsemch, 'ndarray', ndarray );\n\n\n// EXPORTS //\n\nmodule.exports = dsemch;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Compute the standard error of the mean for a double-precision floating-point strided array using a one-pass trial mean algorithm.\n*\n* @module @stdlib/stats-base-dsemch\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var dsemch = require( '@stdlib/stats-base-dsemch' );\n*\n* var x = new Float64Array( [ 1.0, -2.0, 2.0 ] );\n* var N = x.length;\n*\n* var v = dsemch( N, 1, x, 1 );\n* // returns ~1.20185\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var floor = require( '@stdlib/math-base-special-floor' );\n* var dsemch = require( '@stdlib/stats-base-dsemch' );\n*\n* var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] );\n* var N = floor( x.length / 2 );\n*\n* var v = dsemch.ndarray( N, 1, x, 2, 1 );\n* // returns 1.25\n*/\n\n// MODULES //\n\nvar join = require( 'path' ).join;\nvar tryRequire = require( '@stdlib/utils-try-require' );\nvar isError = require( '@stdlib/assert-is-error' );\nvar main = require( './main.js' );\n\n\n// MAIN //\n\nvar dsemch;\nvar tmp = tryRequire( join( __dirname, './native.js' ) );\nif ( isError( tmp ) ) {\n\tdsemch = main;\n} else {\n\tdsemch = tmp;\n}\n\n\n// EXPORTS //\n\nmodule.exports = dsemch;\n\n// exports: { \"ndarray\": \"dsemch.ndarray\" }\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,gCAAiC,EACxDC,EAAO,QAAS,gCAAiC,EAuBrD,SAASC,EAAQC,EAAGC,EAAYC,EAAGC,EAAS,CAC3C,OAAOL,EAAMD,EAAaG,EAAGC,EAAYC,EAAGC,CAAO,EAAIH,CAAE,CAC1D,CAKAJ,EAAO,QAAUG,ICrDjB,IAAAK,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,gCAAiC,EAAE,QAC1DC,EAAO,QAAS,gCAAiC,EAyBrD,SAASC,EAAQC,EAAGC,EAAYC,EAAGC,EAAQC,EAAS,CACnD,OAAON,EAAMD,EAAaG,EAAGC,EAAYC,EAAGC,EAAQC,CAAO,EAAIJ,CAAE,CAClE,CAKAJ,EAAO,QAAUG,ICvDjB,IAAAM,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAS,IACTC,EAAU,IAKdF,EAAaC,EAAQ,UAAWC,CAAQ,EAKxCH,EAAO,QAAUE,ICejB,IAAIE,EAAO,QAAS,MAAO,EAAE,KACzBC,EAAa,QAAS,2BAA4B,EAClDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAO,IAKPC,EACAC,EAAMJ,EAAYD,EAAM,UAAW,aAAc,CAAE,EAClDE,EAASG,CAAI,EACjBD,EAASD,EAETC,EAASC,EAMV,OAAO,QAAUD", - "names": ["require_dsemch", "__commonJSMin", "exports", "module", "dvariancech", "sqrt", "dsemch", "N", "correction", "x", "stride", "require_ndarray", "__commonJSMin", "exports", "module", "dvariancech", "sqrt", "dsemch", "N", "correction", "x", "stride", "offset", "require_main", "__commonJSMin", "exports", "module", "setReadOnly", "dsemch", "ndarray", "join", "tryRequire", "isError", "main", "dsemch", "tmp"] + "sources": ["../lib/ndarray.js", "../lib/dsemch.js", "../lib/main.js", "../lib/index.js"], + "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar dvariancech = require( '@stdlib/stats-base-dvariancech' ).ndarray;\nvar sqrt = require( '@stdlib/math-base-special-sqrt' );\n\n\n// MAIN //\n\n/**\n* Computes the standard error of the mean for a double-precision floating-point strided array using a one-pass trial mean algorithm.\n*\n* @param {PositiveInteger} N - number of indexed elements\n* @param {number} correction - degrees of freedom adjustment\n* @param {Float64Array} x - input array\n* @param {integer} strideX - stride length\n* @param {NonNegativeInteger} offsetX - starting index\n* @returns {number} standard error of the mean\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] );\n*\n* var v = dsemch( 4, 1, x, 2, 1 );\n* // returns 1.25\n*/\nfunction dsemch( N, correction, x, strideX, offsetX ) {\n\treturn sqrt( dvariancech( N, correction, x, strideX, offsetX ) / N );\n}\n\n\n// EXPORTS //\n\nmodule.exports = dsemch;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar stride2offset = require( '@stdlib/strided-base-stride2offset' );\nvar ndarray = require( './ndarray.js' );\n\n\n// MAIN //\n\n/**\n* Computes the standard error of the mean for a double-precision floating-point strided array using a one-pass trial mean algorithm.\n*\n* @param {PositiveInteger} N - number of indexed elements\n* @param {number} correction - degrees of freedom adjustment\n* @param {Float64Array} x - input array\n* @param {integer} strideX - stride length\n* @returns {number} standard error of the mean\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var x = new Float64Array( [ 1.0, -2.0, 2.0 ] );\n*\n* var v = dsemch( x.length, 1, x, 1 );\n* // returns ~1.20185\n*/\nfunction dsemch( N, correction, x, strideX ) {\n\treturn ndarray( N, correction, x, strideX, stride2offset( N, strideX ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = dsemch;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar dsemch = require( './dsemch.js' );\nvar ndarray = require( './ndarray.js' );\n\n\n// MAIN //\n\nsetReadOnly( dsemch, 'ndarray', ndarray );\n\n\n// EXPORTS //\n\nmodule.exports = dsemch;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Compute the standard error of the mean for a double-precision floating-point strided array using a one-pass trial mean algorithm.\n*\n* @module @stdlib/stats-base-dsemch\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var dsemch = require( '@stdlib/stats-base-dsemch' );\n*\n* var x = new Float64Array( [ 1.0, -2.0, 2.0 ] );\n*\n* var v = dsemch( x.length, 1, x, 1 );\n* // returns ~1.20185\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var dsemch = require( '@stdlib/stats-base-dsemch' );\n*\n* var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] );\n*\n* var v = dsemch.ndarray( 4, 1, x, 2, 1 );\n* // returns 1.25\n*/\n\n// MODULES //\n\nvar join = require( 'path' ).join;\nvar tryRequire = require( '@stdlib/utils-try-require' );\nvar isError = require( '@stdlib/assert-is-error' );\nvar main = require( './main.js' );\n\n\n// MAIN //\n\nvar dsemch;\nvar tmp = tryRequire( join( __dirname, './native.js' ) );\nif ( isError( tmp ) ) {\n\tdsemch = main;\n} else {\n\tdsemch = tmp;\n}\n\n\n// EXPORTS //\n\nmodule.exports = dsemch;\n\n// exports: { \"ndarray\": \"dsemch.ndarray\" }\n"], + "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,gCAAiC,EAAE,QAC1DC,EAAO,QAAS,gCAAiC,EAuBrD,SAASC,EAAQC,EAAGC,EAAYC,EAAGC,EAASC,EAAU,CACrD,OAAON,EAAMD,EAAaG,EAAGC,EAAYC,EAAGC,EAASC,CAAQ,EAAIJ,CAAE,CACpE,CAKAJ,EAAO,QAAUG,ICrDjB,IAAAM,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,oCAAqC,EAC9DC,EAAU,IAsBd,SAASC,EAAQC,EAAGC,EAAYC,EAAGC,EAAU,CAC5C,OAAOL,EAASE,EAAGC,EAAYC,EAAGC,EAASN,EAAeG,EAAGG,CAAQ,CAAE,CACxE,CAKAP,EAAO,QAAUG,ICpDjB,IAAAK,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAS,IACTC,EAAU,IAKdF,EAAaC,EAAQ,UAAWC,CAAQ,EAKxCH,EAAO,QAAUE,ICYjB,IAAIE,EAAO,QAAS,MAAO,EAAE,KACzBC,EAAa,QAAS,2BAA4B,EAClDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAO,IAKPC,EACAC,EAAMJ,EAAYD,EAAM,UAAW,aAAc,CAAE,EAClDE,EAASG,CAAI,EACjBD,EAASD,EAETC,EAASC,EAMV,OAAO,QAAUD", + "names": ["require_ndarray", "__commonJSMin", "exports", "module", "dvariancech", "sqrt", "dsemch", "N", "correction", "x", "strideX", "offsetX", "require_dsemch", "__commonJSMin", "exports", "module", "stride2offset", "ndarray", "dsemch", "N", "correction", "x", "strideX", "require_main", "__commonJSMin", "exports", "module", "setReadOnly", "dsemch", "ndarray", "join", "tryRequire", "isError", "main", "dsemch", "tmp"] } diff --git a/docs/repl.txt b/docs/repl.txt index 2b814a4..054f5eb 100644 --- a/docs/repl.txt +++ b/docs/repl.txt @@ -1,10 +1,10 @@ -{{alias}}( N, correction, x, stride ) +{{alias}}( N, correction, x, strideX ) Computes the standard error of the mean for a double-precision floating- point strided array using a one-pass trial mean algorithm. - The `N` and `stride` parameters determine which elements in `x` are accessed - at runtime. + The `N` and stride parameters determine which elements in the strided array + are accessed at runtime. Indexing is relative to the first index. To introduce an offset, use a typed array view. @@ -31,8 +31,8 @@ x: Float64Array Input array. - stride: integer - Index increment. + strideX: integer + Stride length. Returns ------- @@ -46,22 +46,19 @@ > {{alias}}( x.length, 1, x, 1 ) ~1.20185 - // Using `N` and `stride` parameters: + // Using `N` and stride parameters: > x = new {{alias:@stdlib/array/float64}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ] ); - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > var stride = 2; - > {{alias}}( N, 1, x, stride ) + > {{alias}}( 3, 1, x, 2 ) ~1.20185 // Using view offsets: > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); - > N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 ); - > stride = 2; - > {{alias}}( N, 1, x1, stride ) + > {{alias}}( 3, 1, x1, 2 ) ~1.20185 -{{alias}}.ndarray( N, correction, x, stride, offset ) + +{{alias}}.ndarray( N, correction, x, strideX, offsetX ) Computes the standard error of the mean for a double-precision floating- point strided array using a one-pass trial mean algorithm and alternative indexing semantics. @@ -90,10 +87,10 @@ x: Float64Array Input array. - stride: integer - Index increment. + strideX: integer + Stride length. - offset: integer + offsetX: integer Starting index. Returns @@ -110,8 +107,7 @@ // Using offset parameter: > var x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > {{alias}}.ndarray( N, 1, x, 2, 1 ) + > {{alias}}.ndarray( 3, 1, x, 2, 1 ) ~1.20185 See Also diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts index 0fbea57..6696ec0 100644 --- a/docs/types/index.d.ts +++ b/docs/types/index.d.ts @@ -28,7 +28,7 @@ interface Routine { * @param N - number of indexed elements * @param correction - degrees of freedom adjustment * @param x - input array - * @param stride - stride length + * @param strideX - stride length * @returns standard error of the mean * * @example @@ -39,7 +39,7 @@ interface Routine { * var v = dsemch( x.length, 1, x, 1 ); * // returns ~1.20185 */ - ( N: number, correction: number, x: Float64Array, stride: number ): number; + ( N: number, correction: number, x: Float64Array, strideX: number ): number; /** * Computes the standard error of the mean for a double-precision floating-point strided array using a one-pass trial mean algorithm and alternative indexing semantics. @@ -47,8 +47,8 @@ interface Routine { * @param N - number of indexed elements * @param correction - degrees of freedom adjustment * @param x - input array - * @param stride - stride length - * @param offset - starting index + * @param strideX - stride length + * @param offsetX - starting index * @returns standard error of the mean * * @example @@ -59,7 +59,7 @@ interface Routine { * var v = dsemch.ndarray( x.length, 1, x, 1, 0 ); * // returns ~1.20185 */ - ndarray( N: number, correction: number, x: Float64Array, stride: number, offset: number ): number; + ndarray( N: number, correction: number, x: Float64Array, strideX: number, offsetX: number ): number; } /** @@ -68,7 +68,7 @@ interface Routine { * @param N - number of indexed elements * @param correction - degrees of freedom adjustment * @param x - input array -* @param stride - stride length +* @param strideX - stride length * @returns standard error of the mean * * @example diff --git a/examples/c/example.c b/examples/c/example.c index bb5d65f..3fc66e0 100644 --- a/examples/c/example.c +++ b/examples/c/example.c @@ -17,21 +17,20 @@ */ #include "stdlib/stats/base/dsemch.h" -#include #include int main( void ) { // Create a strided array: - double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }; + const double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }; // Specify the number of elements: - int64_t N = 4; + const int N = 4; // Specify the stride length: - int64_t stride = 2; + const int strideX = 2; // Compute the standard error of the mean: - double v = stdlib_strided_dsemch( N, 1, x, stride ); + double v = stdlib_strided_dsemch( N, 1.0, x, strideX ); // Print the result: printf( "standard error of the mean: %lf\n", v ); diff --git a/examples/index.js b/examples/index.js index 9f1648c..b837f39 100644 --- a/examples/index.js +++ b/examples/index.js @@ -18,18 +18,12 @@ 'use strict'; -var randu = require( '@stdlib/random-base-randu' ); -var round = require( '@stdlib/math-base-special-round' ); -var Float64Array = require( '@stdlib/array-float64' ); +var discreteUniform = require( '@stdlib/random-array-discrete-uniform' ); var dsemch = require( './../lib' ); -var x; -var i; - -x = new Float64Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - x[ i ] = round( (randu()*100.0) - 50.0 ); -} +var x = discreteUniform( 10, -50, 50, { + 'dtype': 'float64' +}); console.log( x ); var v = dsemch( x.length, 1, x, 1 ); diff --git a/include/stdlib/stats/base/dsemch.h b/include/stdlib/stats/base/dsemch.h index 191e1c1..c0b72ef 100644 --- a/include/stdlib/stats/base/dsemch.h +++ b/include/stdlib/stats/base/dsemch.h @@ -19,7 +19,7 @@ #ifndef STDLIB_STATS_BASE_DSEMCH_H #define STDLIB_STATS_BASE_DSEMCH_H -#include +#include "stdlib/blas/base/shared.h" /* * If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. @@ -31,7 +31,12 @@ extern "C" { /** * Computes the standard error of the mean for a double-precision floating-point strided array using a one-pass trial mean algorithm. */ -double stdlib_strided_dsemch( const int64_t N, const double correction, const double *X, const int64_t stride ); +double API_SUFFIX(stdlib_strided_dsemch)( const CBLAS_INT N, const double correction, const double *X, const CBLAS_INT strideX ); + +/** +* Computes the standard error of the mean for a double-precision floating-point strided array using a one-pass trial mean algorithm and alternative indexing semantics. +*/ +double API_SUFFIX(stdlib_strided_dsemch_ndarray)( const CBLAS_INT N, const double correction, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); #ifdef __cplusplus } diff --git a/lib/dsemch.js b/lib/dsemch.js index 01556a8..0f257b9 100644 --- a/lib/dsemch.js +++ b/lib/dsemch.js @@ -20,8 +20,8 @@ // MODULES // -var dvariancech = require( '@stdlib/stats-base-dvariancech' ); -var sqrt = require( '@stdlib/math-base-special-sqrt' ); +var stride2offset = require( '@stdlib/strided-base-stride2offset' ); +var ndarray = require( './ndarray.js' ); // MAIN // @@ -32,20 +32,19 @@ var sqrt = require( '@stdlib/math-base-special-sqrt' ); * @param {PositiveInteger} N - number of indexed elements * @param {number} correction - degrees of freedom adjustment * @param {Float64Array} x - input array -* @param {integer} stride - stride length +* @param {integer} strideX - stride length * @returns {number} standard error of the mean * * @example * var Float64Array = require( '@stdlib/array-float64' ); * * var x = new Float64Array( [ 1.0, -2.0, 2.0 ] ); -* var N = x.length; * -* var v = dsemch( N, 1, x, 1 ); +* var v = dsemch( x.length, 1, x, 1 ); * // returns ~1.20185 */ -function dsemch( N, correction, x, stride ) { - return sqrt( dvariancech( N, correction, x, stride ) / N ); +function dsemch( N, correction, x, strideX ) { + return ndarray( N, correction, x, strideX, stride2offset( N, strideX ) ); } diff --git a/lib/dsemch.native.js b/lib/dsemch.native.js index 665e50e..e762dd0 100644 --- a/lib/dsemch.native.js +++ b/lib/dsemch.native.js @@ -31,20 +31,19 @@ var addon = require( './../src/addon.node' ); * @param {PositiveInteger} N - number of indexed elements * @param {number} correction - degrees of freedom adjustment * @param {Float64Array} x - input array -* @param {integer} stride - stride length +* @param {integer} strideX - stride length * @returns {number} standard error of the mean * * @example * var Float64Array = require( '@stdlib/array-float64' ); * * var x = new Float64Array( [ 1.0, -2.0, 2.0 ] ); -* var N = x.length; * -* var v = dsemch( N, 1, x, 1 ); +* var v = dsemch( x.length, 1, x, 1 ); * // returns ~1.20185 */ -function dsemch( N, correction, x, stride ) { - return addon( N, correction, x, stride ); +function dsemch( N, correction, x, strideX ) { + return addon( N, correction, x, strideX ); } diff --git a/lib/index.js b/lib/index.js index abdbad8..7a207f9 100644 --- a/lib/index.js +++ b/lib/index.js @@ -28,20 +28,17 @@ * var dsemch = require( '@stdlib/stats-base-dsemch' ); * * var x = new Float64Array( [ 1.0, -2.0, 2.0 ] ); -* var N = x.length; * -* var v = dsemch( N, 1, x, 1 ); +* var v = dsemch( x.length, 1, x, 1 ); * // returns ~1.20185 * * @example * var Float64Array = require( '@stdlib/array-float64' ); -* var floor = require( '@stdlib/math-base-special-floor' ); * var dsemch = require( '@stdlib/stats-base-dsemch' ); * * var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); -* var N = floor( x.length / 2 ); * -* var v = dsemch.ndarray( N, 1, x, 2, 1 ); +* var v = dsemch.ndarray( 4, 1, x, 2, 1 ); * // returns 1.25 */ diff --git a/lib/ndarray.js b/lib/ndarray.js index e4ec7ba..dba5f47 100644 --- a/lib/ndarray.js +++ b/lib/ndarray.js @@ -32,22 +32,20 @@ var sqrt = require( '@stdlib/math-base-special-sqrt' ); * @param {PositiveInteger} N - number of indexed elements * @param {number} correction - degrees of freedom adjustment * @param {Float64Array} x - input array -* @param {integer} stride - stride length -* @param {NonNegativeInteger} offset - starting index +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index * @returns {number} standard error of the mean * * @example * var Float64Array = require( '@stdlib/array-float64' ); -* var floor = require( '@stdlib/math-base-special-floor' ); * * var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); -* var N = floor( x.length / 2 ); * -* var v = dsemch( N, 1, x, 2, 1 ); +* var v = dsemch( 4, 1, x, 2, 1 ); * // returns 1.25 */ -function dsemch( N, correction, x, stride, offset ) { - return sqrt( dvariancech( N, correction, x, stride, offset ) / N ); +function dsemch( N, correction, x, strideX, offsetX ) { + return sqrt( dvariancech( N, correction, x, strideX, offsetX ) / N ); } diff --git a/lib/ndarray.native.js b/lib/ndarray.native.js index 1903005..6e638a6 100644 --- a/lib/ndarray.native.js +++ b/lib/ndarray.native.js @@ -20,8 +20,7 @@ // MODULES // -var Float64Array = require( '@stdlib/array-float64' ); -var addon = require( './dsemch.native.js' ); +var addon = require( './../src/addon.node' ); // MAIN // @@ -32,27 +31,20 @@ var addon = require( './dsemch.native.js' ); * @param {PositiveInteger} N - number of indexed elements * @param {number} correction - degrees of freedom adjustment * @param {Float64Array} x - input array -* @param {integer} stride - stride length -* @param {NonNegativeInteger} offset - starting index +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index * @returns {number} standard error of the mean * * @example * var Float64Array = require( '@stdlib/array-float64' ); -* var floor = require( '@stdlib/math-base-special-floor' ); * * var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); -* var N = floor( x.length / 2 ); * -* var v = dsemch( N, 1, x, 2, 1 ); +* var v = dsemch( 4, 1, x, 2, 1 ); * // returns 1.25 */ -function dsemch( N, correction, x, stride, offset ) { - var view; - if ( stride < 0 ) { - offset += (N-1) * stride; - } - view = new Float64Array( x.buffer, x.byteOffset+(x.BYTES_PER_ELEMENT*offset), x.length-offset ); // eslint-disable-line max-len - return addon( N, correction, view, stride ); +function dsemch( N, correction, x, strideX, offsetX ) { + return addon.ndarray( N, correction, x, strideX, offsetX ); } diff --git a/manifest.json b/manifest.json index 549b0ea..94c1dca 100644 --- a/manifest.json +++ b/manifest.json @@ -1,5 +1,8 @@ { - "options": {}, + "options": { + "task": "build", + "wasm": false + }, "fields": [ { "field": "src", @@ -25,17 +28,19 @@ "confs": [ { "task": "build", + "wasm": false, "src": [ - "./src/dsemch.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" - ], + "libraries": [], "libpath": [], "dependencies": [ + "@stdlib/blas-base-shared", + "@stdlib/strided-base-stride2offset", + "@stdlib/math-base-special-sqrt", "@stdlib/stats-base-dvariancech", "@stdlib/napi-export", "@stdlib/napi-argv", @@ -47,33 +52,55 @@ }, { "task": "benchmark", + "wasm": false, "src": [ - "./src/dsemch.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" - ], + "libraries": [], "libpath": [], "dependencies": [ + "@stdlib/blas-base-shared", + "@stdlib/strided-base-stride2offset", + "@stdlib/math-base-special-sqrt", "@stdlib/stats-base-dvariancech" ] }, { "task": "examples", + "wasm": false, "src": [ - "./src/dsemch.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas-base-shared", + "@stdlib/strided-base-stride2offset", + "@stdlib/math-base-special-sqrt", + "@stdlib/stats-base-dvariancech" + ] + }, + { + "task": "", + "wasm": true, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" ], + "libraries": [], "libpath": [], "dependencies": [ + "@stdlib/blas-base-shared", + "@stdlib/strided-base-stride2offset", + "@stdlib/math-base-special-sqrt", "@stdlib/stats-base-dvariancech" ] } diff --git a/package.json b/package.json index 9869c8b..11dcbd1 100644 --- a/package.json +++ b/package.json @@ -42,8 +42,16 @@ }, "dependencies": { "@stdlib/assert-is-error": "^0.2.2", + "@stdlib/blas-base-shared": "^0.1.0", "@stdlib/math-base-special-sqrt": "^0.2.2", + "@stdlib/napi-argv": "^0.2.2", + "@stdlib/napi-argv-double": "^0.2.1", + "@stdlib/napi-argv-int64": "^0.2.2", + "@stdlib/napi-argv-strided-float64array": "^0.2.2", + "@stdlib/napi-create-double": "^0.0.2", + "@stdlib/napi-export": "^0.2.2", "@stdlib/stats-base-dvariancech": "^0.2.2", + "@stdlib/strided-base-stride2offset": "^0.1.0", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", "@stdlib/utils-library-manifest": "^0.2.2", "@stdlib/utils-try-require": "^0.2.2" @@ -54,16 +62,9 @@ "@stdlib/constants-float64-eps": "^0.2.2", "@stdlib/math-base-assert-is-nan": "^0.2.2", "@stdlib/math-base-special-abs": "^0.2.2", - "@stdlib/math-base-special-floor": "^0.2.3", "@stdlib/math-base-special-pow": "^0.3.0", - "@stdlib/math-base-special-round": "^0.3.0", - "@stdlib/napi-argv": "^0.2.2", - "@stdlib/napi-argv-double": "^0.2.1", - "@stdlib/napi-argv-int64": "^0.2.2", - "@stdlib/napi-argv-strided-float64array": "^0.2.2", - "@stdlib/napi-create-double": "^0.0.2", - "@stdlib/napi-export": "^0.2.2", - "@stdlib/random-base-randu": "^0.2.1", + "@stdlib/random-array-discrete-uniform": "^0.2.1", + "@stdlib/random-array-uniform": "^0.2.1", "proxyquire": "^2.0.0", "tape": "git+https://github.com/kgryte/tape.git#fix/globby", "istanbul": "^0.4.1", diff --git a/src/addon.c b/src/addon.c index 6b093b2..827e532 100644 --- a/src/addon.c +++ b/src/addon.c @@ -17,6 +17,7 @@ */ #include "stdlib/stats/base/dsemch.h" +#include "stdlib/blas/base/shared.h" #include "stdlib/napi/export.h" #include "stdlib/napi/argv.h" #include "stdlib/napi/argv_int64.h" @@ -35,11 +36,29 @@ static napi_value addon( napi_env env, napi_callback_info info ) { STDLIB_NAPI_ARGV( env, info, argv, argc, 4 ); STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); - STDLIB_NAPI_ARGV_INT64( env, stride, argv, 3 ); STDLIB_NAPI_ARGV_DOUBLE( env, correction, argv, 1 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, stride, argv, 2 ); - STDLIB_NAPI_CREATE_DOUBLE( env, stdlib_strided_dsemch( N, correction, X, stride ), v ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 2 ) + STDLIB_NAPI_CREATE_DOUBLE( env, API_SUFFIX(stdlib_strided_dsemch)( N, correction, X, strideX ), v ); return v; } -STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon_method( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 5 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_DOUBLE( env, correction, argv, 1 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 2 ); + STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 4 ); + STDLIB_NAPI_CREATE_DOUBLE( env, API_SUFFIX(stdlib_strided_dsemch_ndarray)( N, correction, X, strideX, offsetX ), v ); + return v; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method ) diff --git a/src/dsemch.c b/src/dsemch.c deleted file mode 100644 index de4ceb9..0000000 --- a/src/dsemch.c +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/stats/base/dsemch.h" -#include "stdlib/stats/base/dvariancech.h" -#include -#include - -/** -* Computes the standard error of the mean for a double-precision floating-point strided array using a one-pass trial mean algorithm. -* -* @param N number of indexed elements -* @param correction degrees of freedom adjustment -* @param X input array -* @param stride stride length -* @return output value -*/ -double stdlib_strided_dsemch( const int64_t N, const double correction, const double *X, const int64_t stride ) { - return sqrt( stdlib_strided_dvariancech( N, correction, X, stride ) / (double)N ); -} diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..30381ec --- /dev/null +++ b/src/main.c @@ -0,0 +1,51 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/stats/base/dsemch.h" +#include "stdlib/stats/base/dvariancech.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/stride2offset.h" +#include "stdlib/math/base/special/sqrt.h" + +/** +* Computes the standard error of the mean for a double-precision floating-point strided array using a one-pass trial mean algorithm. +* +* @param N number of indexed elements +* @param correction degrees of freedom adjustment +* @param X input array +* @param strideX stride length +* @return output value +*/ +double API_SUFFIX(stdlib_strided_dsemch)( const CBLAS_INT N, const double correction, const double *X, const CBLAS_INT strideX ) { + const CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); + return API_SUFFIX(stdlib_strided_dsemch_ndarray)( N, correction, X, strideX, ox ); +} + +/** +* Computes the standard error of the mean for a double-precision floating-point strided array using a one-pass trial mean algorithm and alternative indexing semantics. +* +* @param N number of indexed elements +* @param correction degrees of freedom adjustment +* @param X input array +* @param strideX stride length +* @param offsetX starting index for X +* @return output value +*/ +double API_SUFFIX(stdlib_strided_dsemch_ndarray)( const CBLAS_INT N, const double correction, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) { + return stdlib_base_sqrt( API_SUFFIX(stdlib_strided_dvariancech_ndarray)( N, correction, X, strideX, offsetX ) / (double)N ); +} diff --git a/test/test.dsemch.js b/test/test.dsemch.js index 8f3c894..8090d98 100644 --- a/test/test.dsemch.js +++ b/test/test.dsemch.js @@ -21,7 +21,6 @@ // MODULES // var tape = require( 'tape' ); -var floor = require( '@stdlib/math-base-special-floor' ); var sqrt = require( '@stdlib/math-base-special-sqrt' ); var abs = require( '@stdlib/math-base-special-abs' ); var isnan = require( '@stdlib/math-base-assert-is-nan' ); @@ -138,7 +137,6 @@ tape( 'if provided a `correction` parameter yielding `N-correction` less than or }); tape( 'the function supports a `stride` parameter', function test( t ) { - var N; var x; var v; @@ -153,15 +151,13 @@ tape( 'the function supports a `stride` parameter', function test( t ) { 2.0 ]); - N = floor( x.length / 2 ); - v = dsemch( N, 1, x, 2 ); + v = dsemch( 4, 1, x, 2 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', function test( t ) { - var N; var x; var v; @@ -176,8 +172,7 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]); - N = floor( x.length / 2 ); - v = dsemch( N, 1, x, -2 ); + v = dsemch( 4, 1, x, -2 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); @@ -198,7 +193,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', tape( 'the function supports view offsets', function test( t ) { var x0; var x1; - var N; var v; x0 = new Float64Array([ @@ -214,9 +208,8 @@ tape( 'the function supports view offsets', function test( t ) { ]); x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - N = floor(x1.length / 2); - v = dsemch( N, 1, x1, 2 ); + v = dsemch( 4, 1, x1, 2 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); diff --git a/test/test.dsemch.native.js b/test/test.dsemch.native.js index 34f5200..7e33bab 100644 --- a/test/test.dsemch.native.js +++ b/test/test.dsemch.native.js @@ -22,7 +22,6 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); -var floor = require( '@stdlib/math-base-special-floor' ); var sqrt = require( '@stdlib/math-base-special-sqrt' ); var abs = require( '@stdlib/math-base-special-abs' ); var isnan = require( '@stdlib/math-base-assert-is-nan' ); @@ -147,7 +146,6 @@ tape( 'if provided a `correction` parameter yielding `N-correction` less than or }); tape( 'the function supports a `stride` parameter', opts, function test( t ) { - var N; var x; var v; @@ -162,15 +160,13 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { 2.0 ]); - N = floor( x.length / 2 ); - v = dsemch( N, 1, x, 2 ); + v = dsemch( 4, 1, x, 2 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { - var N; var x; var v; @@ -185,8 +181,7 @@ tape( 'the function supports a negative `stride` parameter', opts, function test 2.0 ]); - N = floor( x.length / 2 ); - v = dsemch( N, 1, x, -2 ); + v = dsemch( 4, 1, x, -2 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); @@ -207,7 +202,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', tape( 'the function supports view offsets', opts, function test( t ) { var x0; var x1; - var N; var v; x0 = new Float64Array([ @@ -223,9 +217,8 @@ tape( 'the function supports view offsets', opts, function test( t ) { ]); x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - N = floor(x1.length / 2); - v = dsemch( N, 1, x1, 2 ); + v = dsemch( 4, 1, x1, 2 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); diff --git a/test/test.ndarray.js b/test/test.ndarray.js index 2c69221..8aa19f3 100644 --- a/test/test.ndarray.js +++ b/test/test.ndarray.js @@ -21,7 +21,6 @@ // MODULES // var tape = require( 'tape' ); -var floor = require( '@stdlib/math-base-special-floor' ); var sqrt = require( '@stdlib/math-base-special-sqrt' ); var abs = require( '@stdlib/math-base-special-abs' ); var isnan = require( '@stdlib/math-base-assert-is-nan' ); @@ -138,7 +137,6 @@ tape( 'if provided a `correction` parameter yielding `N-correction` less than or }); tape( 'the function supports a `stride` parameter', function test( t ) { - var N; var x; var v; @@ -153,15 +151,13 @@ tape( 'the function supports a `stride` parameter', function test( t ) { 2.0 ]); - N = floor( x.length / 2 ); - v = dsemch( N, 1, x, 2, 0 ); + v = dsemch( 4, 1, x, 2, 0 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', function test( t ) { - var N; var x; var v; @@ -176,8 +172,7 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]); - N = floor( x.length / 2 ); - v = dsemch( N, 1, x, -2, 6 ); + v = dsemch( 4, 1, x, -2, 6 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); @@ -196,7 +191,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', }); tape( 'the function supports an `offset` parameter', function test( t ) { - var N; var x; var v; @@ -210,9 +204,8 @@ tape( 'the function supports an `offset` parameter', function test( t ) { 3.0, 4.0 // 3 ]); - N = floor( x.length / 2 ); - v = dsemch( N, 1, x, 2, 1 ); + v = dsemch( 4, 1, x, 2, 1 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); diff --git a/test/test.ndarray.native.js b/test/test.ndarray.native.js index 2f80ef5..f57a4ca 100644 --- a/test/test.ndarray.native.js +++ b/test/test.ndarray.native.js @@ -22,7 +22,6 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); -var floor = require( '@stdlib/math-base-special-floor' ); var sqrt = require( '@stdlib/math-base-special-sqrt' ); var abs = require( '@stdlib/math-base-special-abs' ); var isnan = require( '@stdlib/math-base-assert-is-nan' ); @@ -147,7 +146,6 @@ tape( 'if provided a `correction` parameter yielding `N-correction` less than or }); tape( 'the function supports a `stride` parameter', opts, function test( t ) { - var N; var x; var v; @@ -162,15 +160,13 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { 2.0 ]); - N = floor( x.length / 2 ); - v = dsemch( N, 1, x, 2, 0 ); + v = dsemch( 4, 1, x, 2, 0 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { - var N; var x; var v; @@ -185,8 +181,7 @@ tape( 'the function supports a negative `stride` parameter', opts, function test 2.0 ]); - N = floor( x.length / 2 ); - v = dsemch( N, 1, x, -2, 6 ); + v = dsemch( 4, 1, x, -2, 6 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); @@ -205,7 +200,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', }); tape( 'the function supports an `offset` parameter', opts, function test( t ) { - var N; var x; var v; @@ -219,9 +213,8 @@ tape( 'the function supports an `offset` parameter', opts, function test( t ) { 3.0, 4.0 // 3 ]); - N = floor( x.length / 2 ); - v = dsemch( N, 1, x, 2, 1 ); + v = dsemch( 4, 1, x, 2, 1 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end();