Skip to content

Commit a958d5e

Browse files
committed
Done Reviewed Changes
1 parent f1e7758 commit a958d5e

File tree

6 files changed

+162
-8
lines changed

6 files changed

+162
-8
lines changed

lib/node_modules/@stdlib/blas/ext/base/ndarray/dsort2hp/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ var order = scalar2ndarray( 1.0, {
5959
var out = dsort2hp( [ x, y, order ] );
6060
// returns <ndarray>
6161

62+
var bool = ( out === x );
63+
// returns true
64+
6265
var arrX = ndarray2array( out );
6366
// returns [ -4.0, -2.0, 1.0, 3.0 ]
6467

@@ -80,7 +83,8 @@ The function has the following parameters:
8083

8184
- Both input ndarrays are sorted **in-place** (i.e., the input ndarrays are **mutated**).
8285
- Both ndarrays must have the same length.
83-
- When the sort order is less than zero, the input ndarrays are sorted in **decreasing** order. When the sort order is greater than zero, the input ndarrays are sorted in **increasing** order. When the sort order is equal to zero, the input ndarrays are left unchanged.
86+
- If the input ndarrays have zero elements or the sort order is equal to zero, the function leaves both input ndarrays unchanged.
87+
- When the sort order is less than zero, the first input ndarray is sorted in **decreasing** order. When the sort order is greater than zero, the first input ndarray is sorted in **increasing** order. When the sort order is equal to zero, the input ndarrays are left unchanged. The second input ndarray is reordered based on the sort order of the first input ndarray.
8488
- The algorithm distinguishes between `-0` and `+0`. When sorted in increasing order, `-0` is sorted before `+0`. When sorted in decreasing order, `-0` is sorted after `+0`.
8589
- The algorithm sorts `NaN` values to the end. When sorted in increasing order, `NaN` values are sorted last. When sorted in decreasing order, `NaN` values are sorted first.
8690
- The algorithm has space complexity `O(1)` and time complexity `O(N log2 N)`.

lib/node_modules/@stdlib/blas/ext/base/ndarray/dsort2hp/benchmark/benchmark.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
var bench = require( '@stdlib/bench' );
2424
var uniform = require( '@stdlib/random/array/uniform' );
2525
var pow = require( '@stdlib/math/base/special/pow' );
26+
var format = require( '@stdlib/string/format' );
2627
var ndarray = require( '@stdlib/ndarray/base/ctor' );
2728
var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
2829
var pkg = require( './../package.json' ).name;
@@ -103,7 +104,7 @@ function main() {
103104
for ( i = min; i <= max; i++ ) {
104105
len = pow( 10, i );
105106
f = createBenchmark( len );
106-
bench( pkg+':len='+len, f );
107+
bench( format( '%s::len=%d', pkg, len ), f );
107108
}
108109
}
109110

lib/node_modules/@stdlib/blas/ext/base/ndarray/dsort2hp/docs/repl.txt

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,27 @@
33
Simultaneously sorts two one-dimensional double-precision floating-point
44
ndarrays based on the sort order of the first array using heapsort.
55

6-
When the sort order is less than zero, the input ndarrays are sorted in
7-
decreasing order. When the sort order is greater than zero, the input
8-
ndarrays are sorted in increasing order. When the sort order is equal to
6+
When the sort order is less than zero, the first input ndarray is sorted in
7+
decreasing order. When the sort order is greater than zero, the first input
8+
ndarray is sorted in increasing order. When the sort order is equal to
99
zero, the input ndarrays are left unchanged.
1010

11+
If the input ndarrays have zero elements or the sort order is equal to
12+
zero, the function leaves both input ndarrays unchanged.
13+
14+
The algorithm distinguishes between `-0` and `+0`. When sorted in increasing
15+
order, `-0` is sorted before `+0`. When sorted in decreasing order, `-0` is
16+
sorted after `+0`.
17+
18+
The algorithm sorts `NaN` values to the end. When sorted in increasing
19+
order, `NaN` values are sorted last. When sorted in decreasing order, `NaN`
20+
values are sorted first.
21+
22+
The algorithm has space complexity O(1) and time complexity O(N log2 N).
23+
24+
The algorithm is *unstable*, meaning that the algorithm may change the order
25+
of ndarray elements which are equal or equivalent (e.g., `NaN` values).
26+
1127
Both input ndarrays are sorted *in-place* (i.e., the input ndarrays are
1228
*mutated*).
1329

lib/node_modules/@stdlib/blas/ext/base/ndarray/dsort2hp/docs/types/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { typedndarray, float64ndarray } from '@stdlib/types/ndarray';
2727
*
2828
* ## Notes
2929
*
30-
* - When the sort order is less than zero, the input ndarrays are sorted in **decreasing** order. When the sort order is greater than zero, the input ndarrays are sorted in **increasing** order. When the sort order is equal to zero, the input ndarrays are left unchanged.
30+
* - When the sort order is less than zero, the first input ndarray is sorted in **decreasing** order. When the sort order is greater than zero, the first input ndarray is sorted in **increasing** order. When the sort order is equal to zero, the input ndarrays are left unchanged. The second input ndarray is reordered based on the sort order of the first input ndarray.
3131
*
3232
* @param arrays - array-like object containing two one-dimensional input ndarrays and a zero-dimensional ndarray specifying the sort order
3333
* @returns first input ndarray

lib/node_modules/@stdlib/blas/ext/base/ndarray/dsort2hp/lib/main.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ var strided = require( '@stdlib/blas/ext/base/dsort2hp' ).ndarray;
3535
*
3636
* ## Notes
3737
*
38-
* - When the sort order is less than zero, the input ndarrays are sorted in **decreasing** order. When the sort order is greater than zero, the input ndarrays are sorted in **increasing** order. When the sort order is equal to zero, the input ndarrays are left unchanged.
38+
* - When the sort order is less than zero, the first input ndarray is sorted in **decreasing** order. When the sort order is greater than zero, the first input ndarray is sorted in **increasing** order. When the sort order is equal to zero, the input ndarrays are left unchanged. The second input ndarray is reordered based on the sort order of the first input ndarray.
3939
*
4040
* @param {ArrayLikeObject<Object>} arrays - array-like object containing two one-dimensional input ndarrays and a zero-dimensional ndarray specifying the sort order
41-
* @returns {ndarray} first input ndarray
41+
* @returns {Object} first input ndarray
4242
*
4343
* @example
4444
* var Float64Array = require( '@stdlib/array/float64' );
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
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+
# dsortsh
22+
23+
> Sort a one-dimensional double-precision floating-point ndarray using Shellsort.
24+
25+
<section class="intro">
26+
27+
</section>
28+
29+
<!-- /.intro -->
30+
31+
<section class="usage">
32+
33+
## Usage
34+
35+
```javascript
36+
var dsortsh = require( '@stdlib/blas/ext/base/ndarray/dsortsh' );
37+
```
38+
39+
#### dsortsh( arrays )
40+
41+
Sorts a one-dimensional double-precision floating-point ndarray using Shellsort.
42+
43+
```javascript
44+
var Float64Array = require( '@stdlib/array/float64' );
45+
var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
46+
var ndarray2array = require( '@stdlib/ndarray/to-array' );
47+
var ndarray = require( '@stdlib/ndarray/base/ctor' );
48+
49+
var xbuf = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] );
50+
var x = new ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' );
51+
52+
var order = scalar2ndarray( 1.0, {
53+
'dtype': 'generic'
54+
});
55+
56+
var out = dsortsh( [ x, order ] );
57+
// returns <ndarray>
58+
59+
var arr = ndarray2array( out );
60+
// returns [ -4.0, -2.0, 1.0, 3.0 ]
61+
```
62+
63+
The function has the following parameters:
64+
65+
- **arrays**: array-like object containing a one-dimensional input ndarray and a zero-dimensional ndarray specifying the sort order.
66+
67+
</section>
68+
69+
<!-- /.usage -->
70+
71+
<section class="notes">
72+
73+
## Notes
74+
75+
- The input ndarray is sorted **in-place** (i.e., the input ndarray is **mutated**).
76+
- When the sort order is less than zero, the input ndarray is sorted in **decreasing** order. When the sort order is greater than zero, the input ndarray is sorted in **increasing** order. When the sort order is equal to zero, the input ndarray is left unchanged.
77+
- The algorithm distinguishes between `-0` and `+0`. When sorted in increasing order, `-0` is sorted before `+0`. When sorted in decreasing order, `-0` is sorted after `+0`.
78+
- The algorithm sorts `NaN` values to the end. When sorted in increasing order, `NaN` values are sorted last. When sorted in decreasing order, `NaN` values are sorted first.
79+
- The algorithm has space complexity `O(1)` and worst case time complexity `O(N^(4/3))`.
80+
- The algorithm is efficient for **shorter** ndarrays (typically `N <= 50`).
81+
82+
</section>
83+
84+
<!-- /.notes -->
85+
86+
<section class="examples">
87+
88+
## Examples
89+
90+
<!-- eslint no-undef: "error" -->
91+
92+
```javascript
93+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
94+
var ndarray = require( '@stdlib/ndarray/base/ctor' );
95+
var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
96+
var ndarray2array = require( '@stdlib/ndarray/to-array' );
97+
var ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' );
98+
var dsortsh = require( '@stdlib/blas/ext/base/ndarray/dsortsh' );
99+
100+
var xbuf = discreteUniform( 10, -100, 100, {
101+
'dtype': 'float64'
102+
});
103+
var x = new ndarray( 'float64', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' );
104+
console.log( ndarray2array( x ) );
105+
106+
var order = scalar2ndarray( 1.0, {
107+
'dtype': 'generic'
108+
});
109+
console.log( 'Order:', ndarraylike2scalar( order ) );
110+
111+
dsortsh( [ x, order ] );
112+
console.log( ndarray2array( x ) );
113+
```
114+
115+
</section>
116+
117+
<!-- /.examples -->
118+
119+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
120+
121+
<section class="related">
122+
123+
</section>
124+
125+
<!-- /.related -->
126+
127+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
128+
129+
<section class="links">
130+
131+
</section>
132+
133+
<!-- /.links -->

0 commit comments

Comments
 (0)