@@ -36,36 +36,33 @@ limitations under the License.
36
36
var dminabs = require ( ' @stdlib/stats/base/dminabs' );
37
37
```
38
38
39
- #### dminabs( N, x, stride )
39
+ #### dminabs( N, x, strideX )
40
40
41
41
Computes the minimum absolute value of a double-precision floating-point strided array ` x ` .
42
42
43
43
``` javascript
44
44
var Float64Array = require ( ' @stdlib/array/float64' );
45
45
46
46
var x = new Float64Array ( [ 1.0 , - 2.0 , 2.0 ] );
47
- var N = x .length ;
48
47
49
- var v = dminabs ( N , x, 1 );
48
+ var v = dminabs ( x . length , x, 1 );
50
49
// returns 1.0
51
50
```
52
51
53
52
The function has the following parameters:
54
53
55
54
- ** N** : number of indexed elements.
56
55
- ** x** : input [ ` Float64Array ` ] [ @stdlib/array/float64 ] .
57
- - ** stride** : index increment for ` x ` .
56
+ - ** stride** : stride length for ` x ` .
58
57
59
- The ` N ` and ` stride ` parameters determine which elements in ` x ` are accessed at runtime. For example, to compute the minimum absolute value of every other element in ` x ` ,
58
+ The ` N ` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the minimum absolute value of every other element in ` x ` ,
60
59
61
60
``` javascript
62
61
var Float64Array = require ( ' @stdlib/array/float64' );
63
- var floor = require ( ' @stdlib/math/base/special/floor' );
64
62
65
63
var x = new Float64Array ( [ 1.0 , 2.0 , 2.0 , - 7.0 , - 2.0 , 3.0 , 4.0 , 2.0 ] );
66
- var N = floor ( x .length / 2 );
67
64
68
- var v = dminabs ( N , x, 2 );
65
+ var v = dminabs ( 4 , x, 2 );
69
66
// returns 1.0
70
67
```
71
68
@@ -75,45 +72,39 @@ Note that indexing is relative to the first index. To introduce an offset, use [
75
72
76
73
``` javascript
77
74
var Float64Array = require ( ' @stdlib/array/float64' );
78
- var floor = require ( ' @stdlib/math/base/special/floor' );
79
75
80
76
var x0 = new Float64Array ( [ 2.0 , 1.0 , 2.0 , - 2.0 , - 2.0 , 2.0 , 3.0 , 4.0 ] );
81
77
var x1 = new Float64Array ( x0 .buffer , x0 .BYTES_PER_ELEMENT * 1 ); // start at 2nd element
82
78
83
- var N = floor ( x0 .length / 2 );
84
-
85
- var v = dminabs ( N , x1, 2 );
79
+ var v = dminabs ( 4 , x1, 2 );
86
80
// returns 1.0
87
81
```
88
82
89
- #### dminabs.ndarray( N, x, stride, offset )
83
+ #### dminabs.ndarray( N, x, strideX, offsetX )
90
84
91
85
Computes the minimum absolute value of a double-precision floating-point strided array using alternative indexing semantics.
92
86
93
87
``` javascript
94
88
var Float64Array = require ( ' @stdlib/array/float64' );
95
89
96
90
var x = new Float64Array ( [ 1.0 , - 2.0 , 2.0 ] );
97
- var N = x .length ;
98
91
99
- var v = dminabs .ndarray ( N , x, 1 , 0 );
92
+ var v = dminabs .ndarray ( x . length , x, 1 , 0 );
100
93
// returns 1.0
101
94
```
102
95
103
96
The function has the following additional parameters:
104
97
105
- - ** offset ** : starting index for ` x ` .
98
+ - ** offsetX ** : starting index for ` x ` .
106
99
107
- 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 minimum absolute value for every other value in ` x ` starting from the second value
100
+ 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 minimum absolute value for every other element in ` x ` starting from the second element
108
101
109
102
``` javascript
110
103
var Float64Array = require ( ' @stdlib/array/float64' );
111
- var floor = require ( ' @stdlib/math/base/special/floor' );
112
104
113
105
var x = new Float64Array ( [ 2.0 , 1.0 , 2.0 , - 2.0 , - 2.0 , 2.0 , 3.0 , 4.0 ] );
114
- var N = floor ( x .length / 2 );
115
106
116
- var v = dminabs .ndarray ( N , x, 2 , 1 );
107
+ var v = dminabs .ndarray ( 4 , x, 2 , 1 );
117
108
// returns 1.0
118
109
```
119
110
@@ -138,18 +129,12 @@ var v = dminabs.ndarray( N, x, 2, 1 );
138
129
<!-- eslint no-undef: "error" -->
139
130
140
131
``` javascript
141
- var randu = require ( ' @stdlib/random/base/randu' );
142
- var round = require ( ' @stdlib/math/base/special/round' );
143
- var Float64Array = require ( ' @stdlib/array/float64' );
132
+ var discreteUniform = require ( ' @stdlib/random/array/discrete-uniform' );
144
133
var dminabs = require ( ' @stdlib/stats/base/dminabs' );
145
134
146
- var x;
147
- var i;
148
-
149
- x = new Float64Array ( 10 );
150
- for ( i = 0 ; i < x .length ; i++ ) {
151
- x[ i ] = round ( (randu ()* 100.0 ) - 50.0 );
152
- }
135
+ var x = discreteUniform ( 10 , - 50 , 50 , {
136
+ ' dtype' : ' float64'
137
+ });
153
138
console .log ( x );
154
139
155
140
var v = dminabs ( x .length , x, 1 );
@@ -160,6 +145,107 @@ console.log( v );
160
145
161
146
<!-- /.examples -->
162
147
148
+ <!-- C usage documentation. -->
149
+
150
+ <section class =" usage " >
151
+
152
+ ### Usage
153
+
154
+ ``` c
155
+ #include " stdlib/stats/base/dminabs.h"
156
+ ```
157
+
158
+ #### stdlib_strided_dminabs( N, \* X, strideX )
159
+
160
+ Computes the minimum absolute value of a double-precision floating-point strided array.
161
+
162
+ ``` c
163
+ const double x[] = { 1.0, -2.0, 2.0 };
164
+
165
+ double v = stdlib_strided_dminabs( 3, x, 1 );
166
+ // returns 1.0
167
+ ```
168
+
169
+ The function accepts the following arguments:
170
+
171
+ - **N**: `[in] CBLAS_INT` number of indexed elements.
172
+ - **X**: `[in] double*` input array.
173
+ - **strideX**: `[in] CBLAS_INT` stride length for `X`.
174
+
175
+ ```c
176
+ double stdlib_strided_dminabs( const CBLAS_INT N, const double *X, const CBLAS_INT strideX );
177
+ ```
178
+
179
+ #### stdlib_strided_dminabs_ndarray( N, \* X, strideX, offsetX )
180
+
181
+ Computes the minimum absolute value of a double-precision floating-point strided array using alternative indexing semantics.
182
+
183
+ ``` c
184
+ const double x[] = { 1.0, -2.0, 2.0 };
185
+
186
+ double v = stdlib_strided_dminabs_ndarray( 3, x, 1, 0 );
187
+ // returns 1.0
188
+ ```
189
+
190
+ The function accepts the following arguments:
191
+
192
+ - **N**: `[in] CBLAS_INT` number of indexed elements.
193
+ - **X**: `[in] double*` input array.
194
+ - **strideX**: `[in] CBLAS_INT` stride length for `X`.
195
+ - **offsetX**: `[in] CBLAS_INT` starting index for `X`.
196
+
197
+ ```c
198
+ double stdlib_strided_dminabs_ndarray( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX );
199
+ ```
200
+
201
+ </section >
202
+
203
+ <!-- /.usage -->
204
+
205
+ <!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
206
+
207
+ <section class =" notes " >
208
+
209
+ </section >
210
+
211
+ <!-- /.notes -->
212
+
213
+ <!-- C API usage examples. -->
214
+
215
+ <section class =" examples " >
216
+
217
+ ### Examples
218
+
219
+ ``` c
220
+ #include " stdlib/stats/base/dminabs.h"
221
+ #include < stdio.h>
222
+
223
+ int main ( void ) {
224
+ // Create a strided array:
225
+ const double x[ ] = { 1.0, 2.0, -3.0, -4.0, 5.0, -6.0, -7.0, 8.0 };
226
+
227
+ // Specify the number of elements:
228
+ const int N = 4;
229
+
230
+ // Specify the stride length:
231
+ const int strideX = 2;
232
+
233
+ // Compute the minimum absolute value:
234
+ double v = stdlib_strided_dminabs( N, x, strideX );
235
+
236
+ // Print the result:
237
+ printf( "minabs: %lf\n", v );
238
+ }
239
+ ```
240
+
241
+ </section>
242
+
243
+ <!-- /.examples -->
244
+
245
+ </section>
246
+
247
+ <!-- /.c -->
248
+
163
249
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
164
250
165
251
<section class="related">
0 commit comments