@@ -59,10 +59,9 @@ Computes the [arithmetic mean][arithmetic-mean] of a single-precision floating-p
5959var Float32Array = require ( ' @stdlib/array/float32' );
6060
6161var x = new Float32Array ( [ 1.0 , - 2.0 , 2.0 ] );
62- var N = x .length ;
6362
64- var v = dsmean ( N , x, 1 );
65- // returns ~0.3333
63+ var v = dsmean ( x . length , x, 1 );
64+ // returns ~1.25
6665```
6766
6867The function has the following parameters:
@@ -78,9 +77,8 @@ var Float32Array = require( '@stdlib/array/float32' );
7877var floor = require ( ' @stdlib/math/base/special/floor' );
7978
8079var x = new Float32Array ( [ 1.0 , 2.0 , 2.0 , - 7.0 , - 2.0 , 3.0 , 4.0 , 2.0 ] );
81- var N = floor ( x .length / 2 );
8280
83- var v = dsmean ( N , x, 2 );
81+ var v = dsmean ( x . length , x, 2 );
8482// returns 1.25
8583```
8684
@@ -90,45 +88,39 @@ Note that indexing is relative to the first index. To introduce an offset, use [
9088
9189``` javascript
9290var Float32Array = require ( ' @stdlib/array/float32' );
93- var floor = require ( ' @stdlib/math/base/special/floor' );
9491
9592var x0 = new Float32Array ( [ 2.0 , 1.0 , 2.0 , - 2.0 , - 2.0 , 2.0 , 3.0 , 4.0 ] );
9693var x1 = new Float32Array ( x0 .buffer , x0 .BYTES_PER_ELEMENT * 1 ); // start at 2nd element
9794
98- var N = floor ( x0 .length / 2 );
99-
100- var v = dsmean ( N , x1, 2 );
95+ var v = dsmean ( 5 , x1, 2 );
10196// returns 1.25
10297```
10398
104- #### dsmean.ndarray( N, x, stride, offset )
99+ #### dsmean.ndarray( N, x, strideX, offsetX )
105100
106101Computes the [ arithmetic mean] [ arithmetic-mean ] of a single-precision floating-point strided array using extended accumulation and alternative indexing semantics and returning an extended precision result.
107102
108103``` javascript
109104var Float32Array = require ( ' @stdlib/array/float32' );
110105
111106var x = new Float32Array ( [ 1.0 , - 2.0 , 2.0 ] );
112- var N = x .length ;
113107
114- var v = dsmean .ndarray ( N , x, 1 , 0 );
115- // returns ~0.33333
108+ var v = dsmean .ndarray ( 5 , x, 1 , 0 );
109+ // returns ~1.25
116110```
117111
118112The function has the following additional parameters:
119113
120- - ** offset ** : starting index for ` x ` .
114+ - ** offsetX ** : starting index for ` x ` .
121115
122116While [ ` 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 [ arithmetic mean] [ arithmetic-mean ] for every other value in ` x ` starting from the second value
123117
124118``` javascript
125119var Float32Array = require ( ' @stdlib/array/float32' );
126- var floor = require ( ' @stdlib/math/base/special/floor' );
127120
128121var x = new Float32Array ( [ 2.0 , 1.0 , 2.0 , - 2.0 , - 2.0 , 2.0 , 3.0 , 4.0 ] );
129- var N = floor ( x .length / 2 );
130122
131- var v = dsmean .ndarray ( N , x, 2 , 1 );
123+ var v = dsmean .ndarray ( 5 , x, 2 , 1 );
132124// returns 1.25
133125```
134126
@@ -141,7 +133,7 @@ var v = dsmean.ndarray( N, x, 2, 1 );
141133## Notes
142134
143135- If ` N <= 0 ` , both functions return ` NaN ` .
144- - Accumulated intermediate values are stored as double-precision floating-point numbers.
136+ - Accumulated intermediate values are stored as double-precision floating-point numbers.
145137
146138</section >
147139
@@ -176,6 +168,107 @@ console.log( v );
176168
177169<!-- /.examples -->
178170
171+ <!-- C usage documentation. -->
172+
173+ <section class =" usage " >
174+
175+ ### Usage
176+
177+ ``` c
178+ #include " stdlib/stats/base/dnanmax.h"
179+ ```
180+
181+ #### stdlib_strided_dsmean( N, \* X, strideX )
182+
183+ Calculate the Arithmetic Mean value of a double-precision floating-point strided array, ignoring ` NaN ` values.
184+
185+ ``` c
186+ const double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 0.0/0.0, 0.0/0.0 };
187+
188+ double v = stdlib_strided_dsmean( 5, x, 2 );
189+ // returns 1.25
190+ ```
191+
192+ The function accepts the following arguments:
193+
194+ - **N**: `[in] CBLAS_INT` number of indexed elements.
195+ - **X**: `[in] double*` input array.
196+ - **strideX**: `[in] CBLAS_INT` stride length for `X`.
197+
198+ ```c
199+ double stdlib_strided_dsmean( const CBLAS_INT N, const double *X, const CBLAS_INT strideX );
200+ ```
201+
202+ #### stdlib_strided_dsmean_ndarray( N, \* X, strideX, offsetX )
203+
204+ Computes the Arithmetic Mean value of a double-precision floating-point strided array, ignoring ` NaN ` values and using alternative indexing semantics.
205+
206+ ``` c
207+ const double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 0.0/0.0, 0.0/0.0 };
208+
209+ double v = stdlib_strided_dsmean_ndarray( 5, x, 2, 0 );
210+ // returns 1.25
211+ ```
212+
213+ The function accepts the following arguments:
214+
215+ - **N**: `[in] CBLAS_INT` number of indexed elements.
216+ - **X**: `[in] double*` input array.
217+ - **strideX**: `[in] CBLAS_INT` stride length for `X`.
218+ - **offsetX**: `[in] CBLAS_INT` starting index for `X`.
219+
220+ ```c
221+ double stdlib_strided_dsmean_ndarray( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX );
222+ ```
223+
224+ </section >
225+
226+ <!-- /.usage -->
227+
228+ <!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
229+
230+ <section class =" notes " >
231+
232+ </section >
233+
234+ <!-- /.notes -->
235+
236+ <!-- C API usage examples. -->
237+
238+ <section class =" examples " >
239+
240+ ### Examples
241+
242+ ``` c
243+ #include " stdlib/stats/base/dsmean.h"
244+ #include < stdio.h>
245+
246+ int main ( void ) {
247+ // Create a strided array:
248+ float x[ ] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 };
249+
250+ // Specify the number of elements:
251+ const int N = 4;
252+
253+ // Specify the stride length:
254+ const int stride = 2;
255+
256+ // Compute the arithmetic mean:
257+ double v = stdlib_strided_dsmean( N, x, strideX );
258+
259+ // Print the result:
260+ printf( "mean: %lf\n", v );
261+ }
262+ ```
263+
264+ </section>
265+
266+ <!-- /.examples -->
267+
268+ </section>
269+
270+ <!-- /.c -->
271+
179272<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
180273
181274<section class="related">
0 commit comments