Skip to content

Commit ba183d8

Browse files
committed
Merge branch 'develop' of https://github.com/stdlib-js/stdlib into develop
2 parents fe062d3 + d7ff4d9 commit ba183d8

File tree

13 files changed

+768
-18
lines changed

13 files changed

+768
-18
lines changed

lib/node_modules/@stdlib/ndarray/base/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ var o = ns;
6060
- <span class="signature">[`bytesPerElement( dtype )`][@stdlib/ndarray/base/bytes-per-element]</span><span class="delimiter">: </span><span class="description">return the number of bytes per element provided an underlying array data type.</span>
6161
- <span class="signature">[`char2dtype( [ch] )`][@stdlib/ndarray/base/char2dtype]</span><span class="delimiter">: </span><span class="description">return the data type string associated with a provided single letter character abbreviation.</span>
6262
- <span class="signature">[`clampIndex( idx, max )`][@stdlib/ndarray/base/clamp-index]</span><span class="delimiter">: </span><span class="description">restrict an index to the interval `[0,max]`.</span>
63+
- <span class="signature">[`countTruthy( arrays )`][@stdlib/ndarray/base/count-truthy]</span><span class="delimiter">: </span><span class="description">count the number of truthy elements in an ndarray.</span>
6364
- <span class="signature">[`ndarray( dtype, buffer, shape, strides, offset, order )`][@stdlib/ndarray/base/ctor]</span><span class="delimiter">: </span><span class="description">create a multidimensional array.</span>
6465
- <span class="signature">[`data( x )`][@stdlib/ndarray/base/data-buffer]</span><span class="delimiter">: </span><span class="description">return the underlying data buffer of a provided ndarray.</span>
6566
- <span class="signature">[`dtypeChar( [dtype] )`][@stdlib/ndarray/base/dtype-char]</span><span class="delimiter">: </span><span class="description">return the single letter abbreviation for an underlying array data type.</span>
@@ -153,6 +154,7 @@ var o = ns;
153154
- <span class="signature">[`unaryReduceStrided1dDispatchFactory( table, idtypes, odtypes, policies )`][@stdlib/ndarray/base/unary-reduce-strided1d-dispatch-factory]</span><span class="delimiter">: </span><span class="description">create a function for performing a reduction on an input ndarray.</span>
154155
- <span class="signature">[`unaryReduceStrided1dDispatch( table, idtypes, odtypes, policies )`][@stdlib/ndarray/base/unary-reduce-strided1d-dispatch]</span><span class="delimiter">: </span><span class="description">constructor for performing a reduction on an input ndarray.</span>
155156
- <span class="signature">[`unaryReduceStrided1d( fcn, arrays, dims[, options] )`][@stdlib/ndarray/base/unary-reduce-strided1d]</span><span class="delimiter">: </span><span class="description">perform a reduction over a list of specified dimensions in an input ndarray via a one-dimensional strided array reduction function and assign results to a provided output ndarray.</span>
157+
- <span class="signature">[`unaryReduceSubarrayBy( fcn, arrays, dims[, options], clbk[, thisArg] )`][@stdlib/ndarray/base/unary-reduce-subarray-by]</span><span class="delimiter">: </span><span class="description">perform a reduction over a list of specified dimensions in an input ndarray according to a callback function and assign results to a provided output ndarray.</span>
156158
- <span class="signature">[`unaryReduceSubarray( fcn, arrays, dims[, options] )`][@stdlib/ndarray/base/unary-reduce-subarray]</span><span class="delimiter">: </span><span class="description">perform a reduction over a list of specified dimensions in an input ndarray and assign results to a provided output ndarray.</span>
157159
- <span class="signature">[`unaryStrided1dDispatchFactory( table, idtypes, odtypes, policies[, options] )`][@stdlib/ndarray/base/unary-strided1d-dispatch-factory]</span><span class="delimiter">: </span><span class="description">create a function for applying a strided function an input ndarray.</span>
158160
- <span class="signature">[`unaryStrided1dDispatch( table, idtypes, odtypes, policies[, options] )`][@stdlib/ndarray/base/unary-strided1d-dispatch]</span><span class="delimiter">: </span><span class="description">constructor for applying a strided function to an input ndarray.</span>
@@ -253,6 +255,8 @@ console.log( objectKeys( ns ) );
253255

254256
[@stdlib/ndarray/base/clamp-index]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/clamp-index
255257

258+
[@stdlib/ndarray/base/count-truthy]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/count-truthy
259+
256260
[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/ctor
257261

258262
[@stdlib/ndarray/base/data-buffer]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/data-buffer
@@ -439,6 +443,8 @@ console.log( objectKeys( ns ) );
439443

440444
[@stdlib/ndarray/base/unary-reduce-strided1d]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/unary-reduce-strided1d
441445

446+
[@stdlib/ndarray/base/unary-reduce-subarray-by]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/unary-reduce-subarray-by
447+
442448
[@stdlib/ndarray/base/unary-reduce-subarray]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/unary-reduce-subarray
443449

444450
[@stdlib/ndarray/base/unary-strided1d-dispatch-factory]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/unary-strided1d-dispatch-factory

lib/node_modules/@stdlib/stats/array/maxsorted/benchmark/benchmark.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,13 @@
2121
// MODULES //
2222

2323
var bench = require( '@stdlib/bench' );
24-
var uniform = require( '@stdlib/random/array/uniform' );
24+
var linspace = require( '@stdlib/array/base/linspace' );
2525
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2626
var pow = require( '@stdlib/math/base/special/pow' );
2727
var pkg = require( './../package.json' ).name;
2828
var maxsorted = require( './../lib' );
2929

3030

31-
// VARIABLES //
32-
33-
var options = {
34-
'dtype': 'generic'
35-
};
36-
37-
3831
// FUNCTIONS //
3932

4033
/**
@@ -45,7 +38,7 @@ var options = {
4538
* @returns {Function} benchmark function
4639
*/
4740
function createBenchmark( len ) {
48-
var x = uniform( len, -10, 10, options );
41+
var x = linspace( 0.0, len, len );
4942
return benchmark;
5043

5144
function benchmark( b ) {
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2025 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+
# mediansorted
22+
23+
> Calculate the median value of a sorted 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 mediansorted = require( '@stdlib/stats/array/mediansorted' );
37+
```
38+
39+
#### mediansorted( x )
40+
41+
Computes the median value of a sorted array.
42+
43+
```javascript
44+
var x = [ 1.0, 2.0, 3.0 ];
45+
46+
var v = mediansorted( x );
47+
// returns 2.0
48+
49+
x = [ 3.0, 2.0, 1.0 ];
50+
51+
v = mediansorted( x );
52+
// returns 2.0
53+
```
54+
55+
The function has the following parameters:
56+
57+
- **x**: input array.
58+
59+
</section>
60+
61+
<!-- /.usage -->
62+
63+
<section class="notes">
64+
65+
## Notes
66+
67+
- If provided an empty array, the function returns `NaN`.
68+
- The function supports array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]).
69+
70+
</section>
71+
72+
<!-- /.notes -->
73+
74+
<section class="examples">
75+
76+
## Examples
77+
78+
<!-- eslint no-undef: "error" -->
79+
80+
```javascript
81+
var linspace = require( '@stdlib/array/base/linspace' );
82+
var mediansorted = require( '@stdlib/stats/array/mediansorted' );
83+
84+
var x = linspace( -50.0, 50.0, 10 );
85+
console.log( x );
86+
87+
var v = mediansorted( x );
88+
console.log( v );
89+
```
90+
91+
</section>
92+
93+
<!-- /.examples -->
94+
95+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
96+
97+
<section class="related">
98+
99+
</section>
100+
101+
<!-- /.related -->
102+
103+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
104+
105+
<section class="links">
106+
107+
[@stdlib/array/base/accessor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/accessor
108+
109+
</section>
110+
111+
<!-- /.links -->
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var linspace = require( '@stdlib/array/base/linspace' );
25+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
26+
var pow = require( '@stdlib/math/base/special/pow' );
27+
var pkg = require( './../package.json' ).name;
28+
var mediansorted = require( './../lib' );
29+
30+
31+
// FUNCTIONS //
32+
33+
/**
34+
* Creates a benchmark function.
35+
*
36+
* @private
37+
* @param {PositiveInteger} len - array length
38+
* @returns {Function} benchmark function
39+
*/
40+
function createBenchmark( len ) {
41+
var x = linspace( 0.0, len, len );
42+
return benchmark;
43+
44+
function benchmark( b ) {
45+
var v;
46+
var i;
47+
48+
b.tic();
49+
for ( i = 0; i < b.iterations; i++ ) {
50+
v = mediansorted( x );
51+
if ( isnan( v ) ) {
52+
b.fail( 'should not return NaN' );
53+
}
54+
}
55+
b.toc();
56+
if ( isnan( v ) ) {
57+
b.fail( 'should not return NaN' );
58+
}
59+
b.pass( 'benchmark finished' );
60+
b.end();
61+
}
62+
}
63+
64+
65+
// MAIN //
66+
67+
/**
68+
* Main execution sequence.
69+
*
70+
* @private
71+
*/
72+
function main() {
73+
var len;
74+
var min;
75+
var max;
76+
var f;
77+
var i;
78+
79+
min = 1; // 10^min
80+
max = 6; // 10^max
81+
82+
for ( i = min; i <= max; i++ ) {
83+
len = pow( 10, i );
84+
f = createBenchmark( len );
85+
bench( pkg+':len='+len, f );
86+
}
87+
}
88+
89+
main();
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
{{alias}}( x )
3+
Computes the median value of a sorted array.
4+
5+
If provided an empty array, the function returns `NaN`.
6+
7+
Parameters
8+
----------
9+
x: Array<number>|TypedArray
10+
Input array.
11+
12+
Returns
13+
-------
14+
out: number
15+
Median value.
16+
17+
Examples
18+
--------
19+
> var x = [ 1.0, 2.0, 3.0 ];
20+
> {{alias}}( x )
21+
2.0
22+
23+
See Also
24+
--------
25+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
// TypeScript Version: 4.1
20+
21+
/// <reference types="@stdlib/types"/>
22+
23+
import { NumericArray, Collection, AccessorArrayLike } from '@stdlib/types/array';
24+
25+
/**
26+
* Input array.
27+
*/
28+
type InputArray = NumericArray | Collection<number> | AccessorArrayLike<number>;
29+
30+
/**
31+
* Computes the median value of a sorted array.
32+
*
33+
* @param x - input array
34+
* @returns median value
35+
*
36+
* @example
37+
* var x = [ 1.0, 2.0, 3.0 ];
38+
*
39+
* var v = mediansorted( x );
40+
* // returns 2.0
41+
*/
42+
declare function mediansorted( x: InputArray ): number;
43+
44+
45+
// EXPORTS //
46+
47+
export = mediansorted;
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
import AccessorArray = require( '@stdlib/array/base/accessor' );
20+
import mediansorted = require( './index' );
21+
22+
23+
// TESTS //
24+
25+
// The function returns a number...
26+
{
27+
const x = new Float64Array( 10 );
28+
29+
mediansorted( x ); // $ExpectType number
30+
mediansorted( new AccessorArray( x ) ); // $ExpectType number
31+
}
32+
33+
// The compiler throws an error if the function is provided a first argument which is not a numeric array...
34+
{
35+
mediansorted( 10 ); // $ExpectError
36+
mediansorted( '10' ); // $ExpectError
37+
mediansorted( true ); // $ExpectError
38+
mediansorted( false ); // $ExpectError
39+
mediansorted( null ); // $ExpectError
40+
mediansorted( undefined ); // $ExpectError
41+
mediansorted( {} ); // $ExpectError
42+
mediansorted( ( x: number ): number => x ); // $ExpectError
43+
}
44+
45+
// The compiler throws an error if the function is provided an unsupported number of arguments...
46+
{
47+
const x = new Float64Array( 10 );
48+
49+
mediansorted(); // $ExpectError
50+
mediansorted( x, {} ); // $ExpectError
51+
}

0 commit comments

Comments
 (0)