Skip to content

Commit cea29e5

Browse files
committed
feat: add stats/strided/dminsorted
Ref: stdlib-js#4797 --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: passed - task: lint_c_benchmarks status: passed - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent c122b62 commit cea29e5

33 files changed

+3438
-0
lines changed
Lines changed: 311 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,311 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2020 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# dminsorted
22+
23+
> Calculate the minimum value of a sorted double-precision floating-point strided array.
24+
25+
<section class="intro">
26+
27+
</section>
28+
29+
<!-- /.intro -->
30+
31+
<section class="usage">
32+
33+
## Usage
34+
35+
```javascript
36+
var dminsorted = require( '@stdlib/stats/strided/dminsorted' );
37+
```
38+
39+
#### dminsorted( N, x, strideX )
40+
41+
Computes the minimum value of a sorted double-precision floating-point strided array `x`.
42+
43+
```javascript
44+
var Float64Array = require( '@stdlib/array/float64' );
45+
46+
var x = new Float64Array( [ 1.0, 2.0, 3.0 ] );
47+
48+
var v = dminsorted( x.length, x, 1 );
49+
// returns 1.0
50+
51+
x = new Float64Array( [ 3.0, 2.0, 1.0 ] );
52+
53+
v = dminsorted( x.length, x, 1 );
54+
// returns 1.0
55+
```
56+
57+
The function has the following parameters:
58+
59+
- **N**: number of indexed elements.
60+
- **x**: sorted input [`Float64Array`][@stdlib/array/float64].
61+
- **strideX**: stride length for `x`.
62+
63+
The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the minimum value of every other element in `x`,
64+
65+
```javascript
66+
var Float64Array = require( '@stdlib/array/float64' );
67+
68+
var x = new Float64Array( [ 1.0, 2.0, 2.0, -7.0, 3.0, 3.0, 4.0, 2.0 ] );
69+
70+
var v = dminsorted( 4, x, 2 );
71+
// returns 1.0
72+
```
73+
74+
Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views.
75+
76+
<!-- eslint-disable stdlib/capitalized-comments -->
77+
78+
```javascript
79+
var Float64Array = require( '@stdlib/array/float64' );
80+
81+
var x0 = new Float64Array( [ 2.0, 1.0, 2.0, 2.0, -2.0, 2.0, 3.0, 4.0 ] );
82+
var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
83+
84+
var v = dminsorted( 4, x1, 2 );
85+
// returns 1.0
86+
```
87+
88+
#### dminsorted.ndarray( N, x, strideX, offsetX )
89+
90+
Computes the minimum value of a sorted double-precision floating-point strided array using alternative indexing semantics.
91+
92+
```javascript
93+
var Float64Array = require( '@stdlib/array/float64' );
94+
95+
var x = new Float64Array( [ 1.0, 2.0, 3.0 ] );
96+
97+
var v = dminsorted.ndarray( x.length, x, 1, 0 );
98+
// returns 1.0
99+
```
100+
101+
The function has the following additional parameters:
102+
103+
- **offsetX**: starting index for `x`.
104+
105+
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 value for every other element in `x` starting from the second element
106+
107+
```javascript
108+
var Float64Array = require( '@stdlib/array/float64' );
109+
110+
var x = new Float64Array( [ 2.0, 1.0, 2.0, 2.0, -2.0, 2.0, 3.0, 4.0 ] );
111+
112+
var v = dminsorted.ndarray( 4, x, 2, 1 );
113+
// returns 1.0
114+
```
115+
116+
</section>
117+
118+
<!-- /.usage -->
119+
120+
<section class="notes">
121+
122+
## Notes
123+
124+
- If `N <= 0`, both functions return `NaN`.
125+
- The input strided array must be sorted in either **strictly** ascending or descending order.
126+
127+
</section>
128+
129+
<!-- /.notes -->
130+
131+
<section class="examples">
132+
133+
## Examples
134+
135+
<!-- eslint no-undef: "error" -->
136+
137+
```javascript
138+
var linspace = require( '@stdlib/array/linspace' );
139+
var dminsorted = require( '@stdlib/stats/strided/dminsorted' );
140+
141+
var options = {
142+
'dtype': 'float64'
143+
};
144+
var x = linspace( -5.0, 5.0, 10, options );
145+
console.log( x );
146+
147+
var v = dminsorted( x.length, x, 1 );
148+
console.log( v );
149+
```
150+
151+
</section>
152+
153+
<!-- /.examples -->
154+
155+
<!-- C interface documentation. -->
156+
157+
* * *
158+
159+
<section class="c">
160+
161+
## C APIs
162+
163+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
164+
165+
<section class="intro">
166+
167+
</section>
168+
169+
<!-- /.intro -->
170+
171+
<!-- C usage documentation. -->
172+
173+
<section class="usage">
174+
175+
### Usage
176+
177+
```c
178+
#include "stdlib/stats/strided/dminsorted.h"
179+
```
180+
181+
#### stdlib_strided_dminsorted( N, \*X, strideX )
182+
183+
Computes the minimum value of a sorted double-precision floating-point strided array.
184+
185+
```c
186+
const double x[] = { 1.0, 2.0, 3.0 };
187+
188+
double v = stdlib_strided_dminsorted( 3, x, 1 );
189+
// returns 1.0
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_dminsorted( const CBLAS_INT N, const double *X, const CBLAS_INT strideX );
200+
```
201+
202+
#### stdlib_strided_dminsorted_ndarray( N, \*X, strideX, offsetX )
203+
204+
Computes the minimum value of a sorted double-precision floating-point strided array using alternative indexing semantics.
205+
206+
```c
207+
const double x[] = { 1.0, 2.0, 3.0 };
208+
209+
double v = stdlib_strided_dminsorted_ndarray( 3, x, 1, 0 );
210+
// returns 1.0
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_dminsorted_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/strided/dminsorted.h"
244+
#include <stdio.h>
245+
246+
int main( void ) {
247+
// Create a strided array:
248+
const double 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 strideX = 2;
255+
256+
// Compute the minimum value:
257+
double v = stdlib_strided_dminsorted( N, x, strideX );
258+
259+
// Print the result:
260+
printf( "min: %lf\n", v );
261+
}
262+
```
263+
264+
</section>
265+
266+
<!-- /.examples -->
267+
268+
</section>
269+
270+
<!-- /.c -->
271+
272+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
273+
274+
<section class="related">
275+
276+
* * *
277+
278+
## See Also
279+
280+
- <span class="package-name">[`@stdlib/stats/strided/dmin`][@stdlib/stats/strided/dmin]</span><span class="delimiter">: </span><span class="description">calculate the minimum value of a double-precision floating-point strided array.</span>
281+
- <span class="package-name">[`@stdlib/stats/strided/dmaxsorted`][@stdlib/stats/strided/dmaxsorted]</span><span class="delimiter">: </span><span class="description">calculate the maximum value of a sorted double-precision floating-point strided array.</span>
282+
- <span class="package-name">[`@stdlib/stats/base/minsorted`][@stdlib/stats/base/minsorted]</span><span class="delimiter">: </span><span class="description">calculate the minimum value of a sorted strided array.</span>
283+
- <span class="package-name">[`@stdlib/stats/base/sminsorted`][@stdlib/stats/base/sminsorted]</span><span class="delimiter">: </span><span class="description">calculate the minimum value of a sorted single-precision floating-point strided array.</span>
284+
285+
</section>
286+
287+
<!-- /.related -->
288+
289+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
290+
291+
<section class="links">
292+
293+
[@stdlib/array/float64]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/float64
294+
295+
[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
296+
297+
<!-- <related-links> -->
298+
299+
[@stdlib/stats/strided/dmin]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/dmin
300+
301+
[@stdlib/stats/strided/dmaxsorted]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/dmaxsorted
302+
303+
[@stdlib/stats/base/minsorted]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/minsorted
304+
305+
[@stdlib/stats/base/sminsorted]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/sminsorted
306+
307+
<!-- </related-links> -->
308+
309+
</section>
310+
311+
<!-- /.links -->

0 commit comments

Comments
 (0)