@stdlib/blas-ext-base-dsorthp 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +1 -1
- package/README.md +138 -38
- package/dist/index.js +7 -7
- package/dist/index.js.map +4 -4
- package/docs/types/index.d.ts +6 -6
- package/include/stdlib/blas/ext/base/dsorthp.h +7 -5
- package/lib/dsorthp.js +5 -94
- package/lib/dsorthp.native.js +3 -3
- package/lib/ndarray.js +13 -13
- package/lib/ndarray.native.js +5 -13
- package/manifest.json +83 -41
- package/package.json +15 -9
- package/src/addon.c +62 -0
- package/src/{dsorthp.c → main.c} +52 -32
- package/include.gypi +0 -53
- package/src/addon.cpp +0 -128
package/NOTICE
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Copyright (c) 2016-
|
|
1
|
+
Copyright (c) 2016-2026 The Stdlib Authors.
|
package/README.md
CHANGED
|
@@ -53,9 +53,9 @@ npm install @stdlib/blas-ext-base-dsorthp
|
|
|
53
53
|
var dsorthp = require( '@stdlib/blas-ext-base-dsorthp' );
|
|
54
54
|
```
|
|
55
55
|
|
|
56
|
-
#### dsorthp( N, order, x,
|
|
56
|
+
#### dsorthp( N, order, x, strideX )
|
|
57
57
|
|
|
58
|
-
Sorts a double-precision floating-point strided array
|
|
58
|
+
Sorts a double-precision floating-point strided array using heapsort.
|
|
59
59
|
|
|
60
60
|
```javascript
|
|
61
61
|
var Float64Array = require( '@stdlib/array-float64' );
|
|
@@ -71,18 +71,16 @@ The function has the following parameters:
|
|
|
71
71
|
- **N**: number of indexed elements.
|
|
72
72
|
- **order**: sort order. If `order < 0.0`, the input strided array is sorted in **decreasing** order. If `order > 0.0`, the input strided array is sorted in **increasing** order. If `order == 0.0`, the input strided array is left unchanged.
|
|
73
73
|
- **x**: input [`Float64Array`][@stdlib/array/float64].
|
|
74
|
-
- **
|
|
74
|
+
- **strideX**: stride length.
|
|
75
75
|
|
|
76
|
-
The `N` and
|
|
76
|
+
The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to sort every other element:
|
|
77
77
|
|
|
78
78
|
```javascript
|
|
79
79
|
var Float64Array = require( '@stdlib/array-float64' );
|
|
80
|
-
var floor = require( '@stdlib/math-base-special-floor' );
|
|
81
80
|
|
|
82
81
|
var x = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] );
|
|
83
|
-
var N = floor( x.length / 2 );
|
|
84
82
|
|
|
85
|
-
dsorthp(
|
|
83
|
+
dsorthp( 2, -1.0, x, 2 );
|
|
86
84
|
// x => <Float64Array>[ 3.0, -2.0, 1.0, -4.0 ]
|
|
87
85
|
```
|
|
88
86
|
|
|
@@ -90,23 +88,21 @@ Note that indexing is relative to the first index. To introduce an offset, use [
|
|
|
90
88
|
|
|
91
89
|
```javascript
|
|
92
90
|
var Float64Array = require( '@stdlib/array-float64' );
|
|
93
|
-
var floor = require( '@stdlib/math-base-special-floor' );
|
|
94
91
|
|
|
95
92
|
// Initial array...
|
|
96
93
|
var x0 = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] );
|
|
97
94
|
|
|
98
95
|
// Create an offset view...
|
|
99
96
|
var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
|
|
100
|
-
var N = floor( x0.length/2 );
|
|
101
97
|
|
|
102
98
|
// Sort every other element...
|
|
103
|
-
dsorthp(
|
|
99
|
+
dsorthp( 2, -1.0, x1, 2 );
|
|
104
100
|
// x0 => <Float64Array>[ 1.0, 4.0, 3.0, 2.0 ]
|
|
105
101
|
```
|
|
106
102
|
|
|
107
|
-
#### dsorthp.ndarray( N, order, x,
|
|
103
|
+
#### dsorthp.ndarray( N, order, x, strideX, offsetX )
|
|
108
104
|
|
|
109
|
-
Sorts a double-precision floating-point strided array
|
|
105
|
+
Sorts a double-precision floating-point strided array using heapsort and alternative indexing semantics.
|
|
110
106
|
|
|
111
107
|
```javascript
|
|
112
108
|
var Float64Array = require( '@stdlib/array-float64' );
|
|
@@ -119,9 +115,9 @@ dsorthp.ndarray( x.length, 1.0, x, 1, 0 );
|
|
|
119
115
|
|
|
120
116
|
The function has the following additional parameters:
|
|
121
117
|
|
|
122
|
-
- **
|
|
118
|
+
- **offsetX**: starting index.
|
|
123
119
|
|
|
124
|
-
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying
|
|
120
|
+
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 access only the last three elements:
|
|
125
121
|
|
|
126
122
|
```javascript
|
|
127
123
|
var Float64Array = require( '@stdlib/array-float64' );
|
|
@@ -158,27 +154,12 @@ dsorthp.ndarray( 3, 1.0, x, 1, x.length-3 );
|
|
|
158
154
|
<!-- eslint no-undef: "error" -->
|
|
159
155
|
|
|
160
156
|
```javascript
|
|
161
|
-
var
|
|
162
|
-
var randu = require( '@stdlib/random-base-randu' );
|
|
163
|
-
var Float64Array = require( '@stdlib/array-float64' );
|
|
157
|
+
var discreteUniform = require( '@stdlib/random-array-discrete-uniform' );
|
|
164
158
|
var dsorthp = require( '@stdlib/blas-ext-base-dsorthp' );
|
|
165
159
|
|
|
166
|
-
var
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
var i;
|
|
170
|
-
|
|
171
|
-
x = new Float64Array( 10 );
|
|
172
|
-
for ( i = 0; i < x.length; i++ ) {
|
|
173
|
-
rand = round( randu()*100.0 );
|
|
174
|
-
sign = randu();
|
|
175
|
-
if ( sign < 0.5 ) {
|
|
176
|
-
sign = -1.0;
|
|
177
|
-
} else {
|
|
178
|
-
sign = 1.0;
|
|
179
|
-
}
|
|
180
|
-
x[ i ] = sign * rand;
|
|
181
|
-
}
|
|
160
|
+
var x = discreteUniform( 10, -100, 100, {
|
|
161
|
+
'dtype': 'float64'
|
|
162
|
+
});
|
|
182
163
|
console.log( x );
|
|
183
164
|
|
|
184
165
|
dsorthp( x.length, -1.0, x, -1 );
|
|
@@ -191,6 +172,125 @@ console.log( x );
|
|
|
191
172
|
|
|
192
173
|
* * *
|
|
193
174
|
|
|
175
|
+
<section class="c">
|
|
176
|
+
|
|
177
|
+
## C APIs
|
|
178
|
+
|
|
179
|
+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
|
|
180
|
+
|
|
181
|
+
<section class="intro">
|
|
182
|
+
|
|
183
|
+
</section>
|
|
184
|
+
|
|
185
|
+
<!-- /.intro -->
|
|
186
|
+
|
|
187
|
+
<!-- C usage documentation. -->
|
|
188
|
+
|
|
189
|
+
<section class="usage">
|
|
190
|
+
|
|
191
|
+
### Usage
|
|
192
|
+
|
|
193
|
+
```c
|
|
194
|
+
#include "stdlib/blas/ext/base/dsorthp.h"
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
#### stdlib_strided_dsorthp( N, order, \*X, strideX )
|
|
198
|
+
|
|
199
|
+
Sorts a double-precision floating-point strided array using heapsort.
|
|
200
|
+
|
|
201
|
+
```c
|
|
202
|
+
double x[] = { 1.0, -2.0, 3.0, -4.0 };
|
|
203
|
+
|
|
204
|
+
stdlib_strided_dsorthp( 2, -1.0, x, 1 );
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
The function accepts the following arguments:
|
|
208
|
+
|
|
209
|
+
- **N**: `[in] CBLAS_INT` number of indexed elements.
|
|
210
|
+
- **order**: `[in] double` sort order. If `order < 0.0`, the input strided array is sorted in **decreasing** order. If `order > 0.0`, the input strided array is sorted in **increasing** order. If `order == 0.0`, the input strided array is left unchanged.
|
|
211
|
+
- **X**: `[inout] double*` input array.
|
|
212
|
+
- **strideX**: `[in] CBLAS_INT` stride length.
|
|
213
|
+
|
|
214
|
+
```c
|
|
215
|
+
stdlib_strided_dsorthp( const CBLAS_INT N, const double order, double *X, const CBLAS_INT strideX );
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
<!--lint disable maximum-heading-length-->
|
|
219
|
+
|
|
220
|
+
#### stdlib_strided_dsorthp_ndarray( N, order, \*X, strideX, offsetX )
|
|
221
|
+
|
|
222
|
+
<!--lint enable maximum-heading-length-->
|
|
223
|
+
|
|
224
|
+
Sorts a double-precision floating-point strided array using heapsort and alternative indexing semantics.
|
|
225
|
+
|
|
226
|
+
```c
|
|
227
|
+
double x[] = { 1.0, -2.0, 3.0, -4.0 };
|
|
228
|
+
|
|
229
|
+
stdlib_strided_dsorthp_ndarray( 4, 1.0, x, 1, 0 );
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
The function accepts the following arguments:
|
|
233
|
+
|
|
234
|
+
- **N**: `[in] CBLAS_INT` number of indexed elements.
|
|
235
|
+
- **order**: `[in] double` sort order. If `order < 0.0`, the input strided array is sorted in **decreasing** order. If `order > 0.0`, the input strided array is sorted in **increasing** order. If `order == 0.0`, the input strided array is left unchanged.
|
|
236
|
+
- **X**: `[inout] double*` input array.
|
|
237
|
+
- **strideX**: `[in] CBLAS_INT` stride length.
|
|
238
|
+
- **offsetX**: `[in] CBLAS_INT` starting index.
|
|
239
|
+
|
|
240
|
+
```c
|
|
241
|
+
stdlib_strided_dsorthp_ndarray( const CBLAS_INT N, const double order, double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX );
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
</section>
|
|
245
|
+
|
|
246
|
+
<!-- /.usage -->
|
|
247
|
+
|
|
248
|
+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
249
|
+
|
|
250
|
+
<section class="notes">
|
|
251
|
+
|
|
252
|
+
</section>
|
|
253
|
+
|
|
254
|
+
<!-- /.notes -->
|
|
255
|
+
|
|
256
|
+
<!-- C API usage examples. -->
|
|
257
|
+
|
|
258
|
+
<section class="examples">
|
|
259
|
+
|
|
260
|
+
### Examples
|
|
261
|
+
|
|
262
|
+
```c
|
|
263
|
+
#include "stdlib/blas/ext/base/dsorthp.h"
|
|
264
|
+
#include <stdio.h>
|
|
265
|
+
|
|
266
|
+
int main( void ) {
|
|
267
|
+
// Create a strided array:
|
|
268
|
+
double x[] = { 1.0, -2.0, 3.0, -4.0, 5.0, -6.0, 7.0, -8.0 };
|
|
269
|
+
|
|
270
|
+
// Specify the number of elements:
|
|
271
|
+
int N = 8;
|
|
272
|
+
|
|
273
|
+
// Specify a stride:
|
|
274
|
+
int strideX = 1;
|
|
275
|
+
|
|
276
|
+
// Sort the array:
|
|
277
|
+
stdlib_strided_dsorthp( N, 1.0, x, strideX );
|
|
278
|
+
|
|
279
|
+
// Print the result:
|
|
280
|
+
for ( int i = 0; i < 8; i++ ) {
|
|
281
|
+
printf( "x[ %i ] = %lf\n", i, x[ i ] );
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
</section>
|
|
287
|
+
|
|
288
|
+
<!-- /.examples -->
|
|
289
|
+
|
|
290
|
+
</section>
|
|
291
|
+
|
|
292
|
+
<!-- /.c -->
|
|
293
|
+
|
|
194
294
|
<section class="references">
|
|
195
295
|
|
|
196
296
|
## References
|
|
@@ -244,7 +344,7 @@ See [LICENSE][stdlib-license].
|
|
|
244
344
|
|
|
245
345
|
## Copyright
|
|
246
346
|
|
|
247
|
-
Copyright © 2016-
|
|
347
|
+
Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors].
|
|
248
348
|
|
|
249
349
|
</section>
|
|
250
350
|
|
|
@@ -257,8 +357,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
257
357
|
[npm-image]: http://img.shields.io/npm/v/@stdlib/blas-ext-base-dsorthp.svg
|
|
258
358
|
[npm-url]: https://npmjs.org/package/@stdlib/blas-ext-base-dsorthp
|
|
259
359
|
|
|
260
|
-
[test-image]: https://github.com/stdlib-js/blas-ext-base-dsorthp/actions/workflows/test.yml/badge.svg?branch=v0.
|
|
261
|
-
[test-url]: https://github.com/stdlib-js/blas-ext-base-dsorthp/actions/workflows/test.yml?query=branch:v0.
|
|
360
|
+
[test-image]: https://github.com/stdlib-js/blas-ext-base-dsorthp/actions/workflows/test.yml/badge.svg?branch=v0.3.0
|
|
361
|
+
[test-url]: https://github.com/stdlib-js/blas-ext-base-dsorthp/actions/workflows/test.yml?query=branch:v0.3.0
|
|
262
362
|
|
|
263
363
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/blas-ext-base-dsorthp/main.svg
|
|
264
364
|
[coverage-url]: https://codecov.io/github/stdlib-js/blas-ext-base-dsorthp?branch=main
|
|
@@ -270,8 +370,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
270
370
|
|
|
271
371
|
-->
|
|
272
372
|
|
|
273
|
-
[chat-image]: https://img.shields.io/
|
|
274
|
-
[chat-url]: https://
|
|
373
|
+
[chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
|
|
374
|
+
[chat-url]: https://stdlib.zulipchat.com
|
|
275
375
|
|
|
276
376
|
[stdlib]: https://github.com/stdlib-js/stdlib
|
|
277
377
|
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
var
|
|
3
|
-
});var
|
|
4
|
-
var
|
|
5
|
-
});var E=
|
|
6
|
-
var
|
|
7
|
-
});var
|
|
1
|
+
"use strict";var h=function(i,v){return function(){return v||i((v={exports:{}}).exports,v),v.exports}};var y=h(function(J,w){
|
|
2
|
+
var m=require('@stdlib/math-base-assert-is-positive-zero/dist'),k=require('@stdlib/math-base-assert-is-nan/dist'),P=require('@stdlib/math-base-special-floor/dist');function Z(i,v,r,e,u){var p,n,a,o,t,s,l,q,c;if(i<=0||v===0)return r;for(v<0&&(e*=-1,u-=(i-1)*e),t=i,p=P(i/2);;){if(p>0)p-=1,s=r[u+p*e];else{if(t-=1,t===0)return r;l=u+t*e,s=r[l],r[l]=r[u]}for(q=p,n=q*2+1;n<t&&(c=n+1,c<t&&(a=r[u+c*e],o=r[u+n*e],(a>o||k(a)||a===o&&m(a))&&(n+=1)),a=r[u+n*e],a>s||k(a)||a===s&&m(a));)r[u+q*e]=a,q=n,n=q*2+1;r[u+q*e]=s}}w.exports=Z
|
|
3
|
+
});var _=h(function(K,R){
|
|
4
|
+
var g=require('@stdlib/strided-base-stride2offset/dist'),z=y();function A(i,v,r,e){return z(i,v,r,e,g(i,e))}R.exports=A
|
|
5
|
+
});var E=h(function(L,d){
|
|
6
|
+
var B=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),b=_(),C=y();B(b,"ndarray",C);d.exports=b
|
|
7
|
+
});var D=require("path").join,F=require('@stdlib/utils-try-require/dist'),G=require('@stdlib/assert-is-error/dist'),H=E(),j,O=F(D(__dirname,"./native.js"));G(O)?j=H:j=O;module.exports=j;
|
|
8
8
|
/** @license Apache-2.0 */
|
|
9
9
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../lib/
|
|
4
|
-
"sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isPositiveZero = require( '@stdlib/math-base-assert-is-positive-zero' );\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar floor = require( '@stdlib/math-base-special-floor' );\n\n\n// MAIN //\n\n/**\n* Sorts a double-precision floating-point strided array using heapsort.\n*\n* ## Notes\n*\n* - This implementation uses an in-place algorithm derived from the work of Floyd (1964).\n*\n* ## References\n*\n* - Williams, John William Joseph. 1964. \"Algorithm 232: Heapsort.\" _Communications of the ACM_ 7 (6). New York, NY, USA: Association for Computing Machinery: 347\u201349. doi:[10.1145/512274.512284](https://doi.org/10.1145/512274.512284).\n* - Floyd, Robert W. 1964. \"Algorithm 245: Treesort.\" _Communications of the ACM_ 7 (12). New York, NY, USA: Association for Computing Machinery: 701. doi:[10.1145/355588.365103](https://doi.org/10.1145/355588.365103).\n*\n* @param {PositiveInteger} N - number of indexed elements\n* @param {number} order - sort order\n* @param {Float64Array} x - input array\n* @param {integer} stride - index increment\n* @returns {Float64Array} input array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var x = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] );\n*\n* dsorthp( x.length, 1.0, x, 1 );\n* // x => <Float64Array>[ -4.0, -2.0, 1.0, 3.0 ]\n*/\nfunction dsorthp( N, order, x, stride ) {\n\tvar offset;\n\tvar parent;\n\tvar child;\n\tvar v1;\n\tvar v2;\n\tvar n;\n\tvar t;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tif ( N <= 0 || order === 0.0 ) {\n\t\treturn x;\n\t}\n\t// For a positive stride, sorting in decreasing order is equivalent to providing a negative stride and sorting in increasing order, and, for a negative stride, sorting in decreasing order is equivalent to providing a positive stride and sorting in increasing order...\n\tif ( order < 0.0 ) {\n\t\tstride *= -1;\n\t}\n\tif ( stride < 0 ) {\n\t\toffset = (1-N) * stride;\n\t} else {\n\t\toffset = 0;\n\t}\n\t// Set the initial heap size:\n\tn = N;\n\n\t// Specify an initial \"parent\" index for building the heap:\n\tparent = floor( N / 2 );\n\n\t// Continue looping until the array is sorted...\n\twhile ( true ) {\n\t\tif ( parent > 0 ) {\n\t\t\t// We need to build the heap...\n\t\t\tparent -= 1;\n\t\t\tt = x[ offset+(parent*stride) ];\n\t\t} else {\n\t\t\t// Reduce the heap size:\n\t\t\tn -= 1;\n\n\t\t\t// Check if the heap is empty, and, if so, we are finished sorting...\n\t\t\tif ( n === 0 ) {\n\t\t\t\treturn x;\n\t\t\t}\n\t\t\t// Store the last heap value in a temporary variable in order to make room for the heap root being placed into its sorted position:\n\t\t\ti = offset + (n*stride);\n\t\t\tt = x[ i ];\n\n\t\t\t// Move the heap root to its sorted position:\n\t\t\tx[ i ] = x[ offset ];\n\t\t}\n\t\t// We need to \"sift down\", pushing `t` down the heap to in order to replace the parent and satisfy the heap property...\n\n\t\t// Start at the parent index:\n\t\tj = parent;\n\n\t\t// Get the \"left\" child index:\n\t\tchild = (j*2) + 1;\n\n\t\twhile ( child < n ) {\n\t\t\t// Find the largest child...\n\t\t\tk = child + 1;\n\t\t\tif ( k < n ) {\n\t\t\t\tv1 = x[ offset+(k*stride) ];\n\t\t\t\tv2 = x[ offset+(child*stride) ];\n\n\t\t\t\t// Check if a \"right\" child exists and is \"bigger\"...\n\t\t\t\tif ( v1 > v2 || isnan( v1 ) || (v1 === v2 && isPositiveZero( v1 ) ) ) { // eslint-disable-line max-len\n\t\t\t\t\tchild += 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Check if the largest child is bigger than `t`...\n\t\t\tv1 = x[ offset+(child*stride) ];\n\t\t\tif ( v1 > t || isnan( v1 ) || ( v1 === t && isPositiveZero( v1 ) ) ) { // eslint-disable-line max-len\n\t\t\t\t// Insert the larger child value:\n\t\t\t\tx[ offset+(j*stride) ] = v1;\n\n\t\t\t\t// Update `j` to point to the child index:\n\t\t\t\tj = child;\n\n\t\t\t\t// Get the \"left\" child index and repeat...\n\t\t\t\tchild = (j*2) + 1;\n\t\t\t} else {\n\t\t\t\t// We've found `t`'s place in the heap...\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t// Insert `t` into the heap:\n\t\tx[ offset+(j*stride) ] = t;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = dsorthp;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isPositiveZero = require( '@stdlib/math-base-assert-is-positive-zero' );\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar floor = require( '@stdlib/math-base-special-floor' );\n\n\n// MAIN //\n\n/**\n* Sorts a double-precision floating-point strided array using heapsort.\n*\n* ## Notes\n*\n* - This implementation uses an in-place algorithm derived from the work of Floyd (1964).\n*\n* ## References\n*\n* - Williams, John William Joseph. 1964. \"Algorithm 232: Heapsort.\" _Communications of the ACM_ 7 (6). New York, NY, USA: Association for Computing Machinery: 347\u201349. doi:[10.1145/512274.512284](https://doi.org/10.1145/512274.512284).\n* - Floyd, Robert W. 1964. \"Algorithm 245: Treesort.\" _Communications of the ACM_ 7 (12). New York, NY, USA: Association for Computing Machinery: 701. doi:[10.1145/355588.365103](https://doi.org/10.1145/355588.365103).\n*\n* @param {PositiveInteger} N - number of indexed elements\n* @param {number} order - sort order\n* @param {Float64Array} x - input array\n* @param {integer} stride - index increment\n* @param {NonNegativeInteger} offset - starting index\n* @returns {Float64Array} input array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var x = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] );\n*\n* dsorthp( x.length, 1.0, x, 1, 0 );\n* // x => <Float64Array>[ -4.0, -2.0, 1.0, 3.0 ]\n*/\nfunction dsorthp( N, order, x, stride, offset ) {\n\tvar parent;\n\tvar child;\n\tvar v1;\n\tvar v2;\n\tvar n;\n\tvar t;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tif ( N <= 0 || order === 0.0 ) {\n\t\treturn x;\n\t}\n\t// For a positive stride, sorting in decreasing order is equivalent to providing a negative stride and sorting in increasing order, and, for a negative stride, sorting in decreasing order is equivalent to providing a positive stride and sorting in increasing order...\n\tif ( order < 0.0 ) {\n\t\tstride *= -1;\n\t\toffset -= (N-1) * stride;\n\t}\n\t// Set the initial heap size:\n\tn = N;\n\n\t// Specify an initial \"parent\" index for building the heap:\n\tparent = floor( N / 2 );\n\n\t// Continue looping until the array is sorted...\n\twhile ( true ) {\n\t\tif ( parent > 0 ) {\n\t\t\t// We need to build the heap...\n\t\t\tparent -= 1;\n\t\t\tt = x[ offset+(parent*stride) ];\n\t\t} else {\n\t\t\t// Reduce the heap size:\n\t\t\tn -= 1;\n\n\t\t\t// Check if the heap is empty, and, if so, we are finished sorting...\n\t\t\tif ( n === 0 ) {\n\t\t\t\treturn x;\n\t\t\t}\n\t\t\t// Store the last heap value in a temporary variable in order to make room for the heap root being placed into its sorted position:\n\t\t\ti = offset + (n*stride);\n\t\t\tt = x[ i ];\n\n\t\t\t// Move the heap root to its sorted position:\n\t\t\tx[ i ] = x[ offset ];\n\t\t}\n\t\t// We need to \"sift down\", pushing `t` down the heap to in order to replace the parent and satisfy the heap property...\n\n\t\t// Start at the parent index:\n\t\tj = parent;\n\n\t\t// Get the \"left\" child index:\n\t\tchild = (j*2) + 1;\n\n\t\twhile ( child < n ) {\n\t\t\t// Find the largest child...\n\t\t\tk = child + 1;\n\t\t\tif ( k < n ) {\n\t\t\t\tv1 = x[ offset+(k*stride) ];\n\t\t\t\tv2 = x[ offset+(child*stride) ];\n\n\t\t\t\t// Check if a \"right\" child exists and is \"bigger\"...\n\t\t\t\tif ( v1 > v2 || isnan( v1 ) || (v1 === v2 && isPositiveZero( v1 ) ) ) { // eslint-disable-line max-len\n\t\t\t\t\tchild += 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Check if the largest child is bigger than `t`...\n\t\t\tv1 = x[ offset+(child*stride) ];\n\t\t\tif ( v1 > t || isnan( v1 ) || ( v1 === t && isPositiveZero( v1 ) ) ) { // eslint-disable-line max-len\n\t\t\t\t// Insert the larger child value:\n\t\t\t\tx[ offset+(j*stride) ] = v1;\n\n\t\t\t\t// Update `j` to point to the child index:\n\t\t\t\tj = child;\n\n\t\t\t\t// Get the \"left\" child index and repeat...\n\t\t\t\tchild = (j*2) + 1;\n\t\t\t} else {\n\t\t\t\t// We've found `t`'s place in the heap...\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t// Insert `t` into the heap:\n\t\tx[ offset+(j*stride) ] = t;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = dsorthp;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar dsorthp = require( './dsorthp.js' );\nvar ndarray = require( './ndarray.js' );\n\n\n// MAIN //\n\nsetReadOnly( dsorthp, 'ndarray', ndarray );\n\n\n// EXPORTS //\n\nmodule.exports = dsorthp;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Sort a double-precision floating-point strided array using heapsort.\n*\n* @module @stdlib/blas-ext-base-dsorthp\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var dsorthp = require( '@stdlib/blas-ext-base-dsorthp' );\n*\n* var x = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] );\n*\n* dsorthp( x.length, 1.0, x, 1 );\n* // x => <Float64Array>[ -4.0, -2.0, 1.0, 3.0 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var dsorthp = require( '@stdlib/blas-ext-base-dsorthp' );\n*\n* var x = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] );\n*\n* dsorthp.ndarray( x.length, 1.0, x, 1, 0 );\n* // x => <Float64Array>[ -4.0, -2.0, 1.0, 3.0 ]\n*/\n\n// MODULES //\n\nvar join = require( 'path' ).join;\nvar tryRequire = require( '@stdlib/utils-try-require' );\nvar isError = require( '@stdlib/assert-is-error' );\nvar main = require( './main.js' );\n\n\n// MAIN //\n\nvar dsorthp;\nvar tmp = tryRequire( join( __dirname, './native.js' ) );\nif ( isError( tmp ) ) {\n\tdsorthp = main;\n} else {\n\tdsorthp = tmp;\n}\n\n\n// EXPORTS //\n\nmodule.exports = dsorthp;\n\n// exports: { \"ndarray\": \"dsorthp.ndarray\" }\n"],
|
|
5
|
-
"mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAiB,QAAS,2CAA4C,EACtEC,EAAQ,QAAS,iCAAkC,EACnDC,EAAQ,QAAS,iCAAkC,
|
|
6
|
-
"names": ["
|
|
3
|
+
"sources": ["../lib/ndarray.js", "../lib/dsorthp.js", "../lib/main.js", "../lib/index.js"],
|
|
4
|
+
"sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isPositiveZero = require( '@stdlib/math-base-assert-is-positive-zero' );\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar floor = require( '@stdlib/math-base-special-floor' );\n\n\n// MAIN //\n\n/**\n* Sorts a double-precision floating-point strided array using heapsort.\n*\n* ## Notes\n*\n* - This implementation uses an in-place algorithm derived from the work of Floyd (1964).\n*\n* ## References\n*\n* - Williams, John William Joseph. 1964. \"Algorithm 232: Heapsort.\" _Communications of the ACM_ 7 (6). New York, NY, USA: Association for Computing Machinery: 347\u201349. doi:[10.1145/512274.512284](https://doi.org/10.1145/512274.512284).\n* - Floyd, Robert W. 1964. \"Algorithm 245: Treesort.\" _Communications of the ACM_ 7 (12). New York, NY, USA: Association for Computing Machinery: 701. doi:[10.1145/355588.365103](https://doi.org/10.1145/355588.365103).\n*\n* @param {PositiveInteger} N - number of indexed elements\n* @param {number} order - sort order\n* @param {Float64Array} x - input array\n* @param {integer} strideX - stride length\n* @param {NonNegativeInteger} offsetX - starting index\n* @returns {Float64Array} input array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var x = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] );\n*\n* dsorthp( x.length, 1.0, x, 1, 0 );\n* // x => <Float64Array>[ -4.0, -2.0, 1.0, 3.0 ]\n*/\nfunction dsorthp( N, order, x, strideX, offsetX ) {\n\tvar parent;\n\tvar child;\n\tvar v1;\n\tvar v2;\n\tvar n;\n\tvar t;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tif ( N <= 0 || order === 0.0 ) {\n\t\treturn x;\n\t}\n\t// For a positive stride, sorting in decreasing order is equivalent to providing a negative stride and sorting in increasing order, and, for a negative stride, sorting in decreasing order is equivalent to providing a positive stride and sorting in increasing order...\n\tif ( order < 0.0 ) {\n\t\tstrideX *= -1;\n\t\toffsetX -= (N-1) * strideX;\n\t}\n\t// Set the initial heap size:\n\tn = N;\n\n\t// Specify an initial \"parent\" index for building the heap:\n\tparent = floor( N / 2 );\n\n\t// Continue looping until the array is sorted...\n\twhile ( true ) {\n\t\tif ( parent > 0 ) {\n\t\t\t// We need to build the heap...\n\t\t\tparent -= 1;\n\t\t\tt = x[ offsetX+(parent*strideX) ];\n\t\t} else {\n\t\t\t// Reduce the heap size:\n\t\t\tn -= 1;\n\n\t\t\t// Check if the heap is empty, and, if so, we are finished sorting...\n\t\t\tif ( n === 0 ) {\n\t\t\t\treturn x;\n\t\t\t}\n\t\t\t// Store the last heap value in a temporary variable in order to make room for the heap root being placed into its sorted position:\n\t\t\ti = offsetX + (n*strideX);\n\t\t\tt = x[ i ];\n\n\t\t\t// Move the heap root to its sorted position:\n\t\t\tx[ i ] = x[ offsetX ];\n\t\t}\n\t\t// We need to \"sift down\", pushing `t` down the heap to in order to replace the parent and satisfy the heap property...\n\n\t\t// Start at the parent index:\n\t\tj = parent;\n\n\t\t// Get the \"left\" child index:\n\t\tchild = (j*2) + 1;\n\n\t\twhile ( child < n ) {\n\t\t\t// Find the largest child...\n\t\t\tk = child + 1;\n\t\t\tif ( k < n ) {\n\t\t\t\tv1 = x[ offsetX+(k*strideX) ];\n\t\t\t\tv2 = x[ offsetX+(child*strideX) ];\n\n\t\t\t\t// Check if a \"right\" child exists and is \"bigger\"...\n\t\t\t\tif ( v1 > v2 || isnan( v1 ) || (v1 === v2 && isPositiveZero( v1 ) ) ) { // eslint-disable-line max-len\n\t\t\t\t\tchild += 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Check if the largest child is bigger than `t`...\n\t\t\tv1 = x[ offsetX+(child*strideX) ];\n\t\t\tif ( v1 > t || isnan( v1 ) || ( v1 === t && isPositiveZero( v1 ) ) ) { // eslint-disable-line max-len\n\t\t\t\t// Insert the larger child value:\n\t\t\t\tx[ offsetX+(j*strideX) ] = v1;\n\n\t\t\t\t// Update `j` to point to the child index:\n\t\t\t\tj = child;\n\n\t\t\t\t// Get the \"left\" child index and repeat...\n\t\t\t\tchild = (j*2) + 1;\n\t\t\t} else {\n\t\t\t\t// We've found `t`'s place in the heap...\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t// Insert `t` into the heap:\n\t\tx[ offsetX+(j*strideX) ] = t;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = dsorthp;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar stride2offset = require( '@stdlib/strided-base-stride2offset' );\nvar ndarray = require( './ndarray.js' );\n\n\n// MAIN //\n\n/**\n* Sorts a double-precision floating-point strided array using heapsort.\n*\n* ## Notes\n*\n* - This implementation uses an in-place algorithm derived from the work of Floyd (1964).\n*\n* ## References\n*\n* - Williams, John William Joseph. 1964. \"Algorithm 232: Heapsort.\" _Communications of the ACM_ 7 (6). New York, NY, USA: Association for Computing Machinery: 347\u201349. doi:[10.1145/512274.512284](https://doi.org/10.1145/512274.512284).\n* - Floyd, Robert W. 1964. \"Algorithm 245: Treesort.\" _Communications of the ACM_ 7 (12). New York, NY, USA: Association for Computing Machinery: 701. doi:[10.1145/355588.365103](https://doi.org/10.1145/355588.365103).\n*\n* @param {PositiveInteger} N - number of indexed elements\n* @param {number} order - sort order\n* @param {Float64Array} x - input array\n* @param {integer} strideX - stride length\n* @returns {Float64Array} input array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var x = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] );\n*\n* dsorthp( x.length, 1.0, x, 1 );\n* // x => <Float64Array>[ -4.0, -2.0, 1.0, 3.0 ]\n*/\nfunction dsorthp( N, order, x, strideX ) {\n\treturn ndarray( N, order, x, strideX, stride2offset( N, strideX ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = dsorthp;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar dsorthp = require( './dsorthp.js' );\nvar ndarray = require( './ndarray.js' );\n\n\n// MAIN //\n\nsetReadOnly( dsorthp, 'ndarray', ndarray );\n\n\n// EXPORTS //\n\nmodule.exports = dsorthp;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Sort a double-precision floating-point strided array using heapsort.\n*\n* @module @stdlib/blas-ext-base-dsorthp\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var dsorthp = require( '@stdlib/blas-ext-base-dsorthp' );\n*\n* var x = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] );\n*\n* dsorthp( x.length, 1.0, x, 1 );\n* // x => <Float64Array>[ -4.0, -2.0, 1.0, 3.0 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var dsorthp = require( '@stdlib/blas-ext-base-dsorthp' );\n*\n* var x = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] );\n*\n* dsorthp.ndarray( x.length, 1.0, x, 1, 0 );\n* // x => <Float64Array>[ -4.0, -2.0, 1.0, 3.0 ]\n*/\n\n// MODULES //\n\nvar join = require( 'path' ).join;\nvar tryRequire = require( '@stdlib/utils-try-require' );\nvar isError = require( '@stdlib/assert-is-error' );\nvar main = require( './main.js' );\n\n\n// MAIN //\n\nvar dsorthp;\nvar tmp = tryRequire( join( __dirname, './native.js' ) );\nif ( isError( tmp ) ) {\n\tdsorthp = main;\n} else {\n\tdsorthp = tmp;\n}\n\n\n// EXPORTS //\n\nmodule.exports = dsorthp;\n\n// exports: { \"ndarray\": \"dsorthp.ndarray\" }\n"],
|
|
5
|
+
"mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAiB,QAAS,2CAA4C,EACtEC,EAAQ,QAAS,iCAAkC,EACnDC,EAAQ,QAAS,iCAAkC,EAgCvD,SAASC,EAASC,EAAGC,EAAOC,EAAGC,EAASC,EAAU,CACjD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAKb,GAAK,GAAKC,IAAU,EACxB,OAAOC,EAcR,IAXKD,EAAQ,IACZE,GAAW,GACXC,IAAYJ,EAAE,GAAKG,GAGpBM,EAAIT,EAGJK,EAASP,EAAOE,EAAI,CAAE,IAGP,CACd,GAAKK,EAAS,EAEbA,GAAU,EACVK,EAAIR,EAAGE,EAASC,EAAOF,CAAS,MAC1B,CAKN,GAHAM,GAAK,EAGAA,IAAM,EACV,OAAOP,EAGRS,EAAIP,EAAWK,EAAEN,EACjBO,EAAIR,EAAGS,CAAE,EAGTT,EAAGS,CAAE,EAAIT,EAAGE,CAAQ,CACrB,CASA,IALAQ,EAAIP,EAGJC,EAASM,EAAE,EAAK,EAERN,EAAQG,IAEfI,EAAIP,EAAQ,EACPO,EAAIJ,IACRF,EAAKL,EAAGE,EAASS,EAAEV,CAAS,EAC5BK,EAAKN,EAAGE,EAASE,EAAMH,CAAS,GAG3BI,EAAKC,GAAMX,EAAOU,CAAG,GAAMA,IAAOC,GAAMZ,EAAgBW,CAAG,KAC/DD,GAAS,IAIXC,EAAKL,EAAGE,EAASE,EAAMH,CAAS,EAC3BI,EAAKG,GAAKb,EAAOU,CAAG,GAAOA,IAAOG,GAAKd,EAAgBW,CAAG,IAE9DL,EAAGE,EAASQ,EAAET,CAAS,EAAII,EAG3BK,EAAIN,EAGJA,EAASM,EAAE,EAAK,EAOlBV,EAAGE,EAASQ,EAAET,CAAS,EAAIO,CAC5B,CACD,CAKAf,EAAO,QAAUI,IClJjB,IAAAe,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,oCAAqC,EAC9DC,EAAU,IA+Bd,SAASC,EAASC,EAAGC,EAAOC,EAAGC,EAAU,CACxC,OAAOL,EAASE,EAAGC,EAAOC,EAAGC,EAASN,EAAeG,EAAGG,CAAQ,CAAE,CACnE,CAKAP,EAAO,QAAUG,IC7DjB,IAAAK,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAU,IACVC,EAAU,IAKdF,EAAaC,EAAS,UAAWC,CAAQ,EAKzCH,EAAO,QAAUE,ICYjB,IAAIE,EAAO,QAAS,MAAO,EAAE,KACzBC,EAAa,QAAS,2BAA4B,EAClDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAO,IAKPC,EACAC,EAAMJ,EAAYD,EAAM,UAAW,aAAc,CAAE,EAClDE,EAASG,CAAI,EACjBD,EAAUD,EAEVC,EAAUC,EAMX,OAAO,QAAUD",
|
|
6
|
+
"names": ["require_ndarray", "__commonJSMin", "exports", "module", "isPositiveZero", "isnan", "floor", "dsorthp", "N", "order", "x", "strideX", "offsetX", "parent", "child", "v1", "v2", "n", "t", "i", "j", "k", "require_dsorthp", "__commonJSMin", "exports", "module", "stride2offset", "ndarray", "dsorthp", "N", "order", "x", "strideX", "require_main", "__commonJSMin", "exports", "module", "setReadOnly", "dsorthp", "ndarray", "join", "tryRequire", "isError", "main", "dsorthp", "tmp"]
|
|
7
7
|
}
|
package/docs/types/index.d.ts
CHANGED
|
@@ -28,7 +28,7 @@ interface Routine {
|
|
|
28
28
|
* @param N - number of indexed elements
|
|
29
29
|
* @param order - sort order
|
|
30
30
|
* @param x - input array
|
|
31
|
-
* @param
|
|
31
|
+
* @param strideX - stride length
|
|
32
32
|
* @returns `x`
|
|
33
33
|
*
|
|
34
34
|
* @example
|
|
@@ -39,7 +39,7 @@ interface Routine {
|
|
|
39
39
|
* dsorthp( x.length, 1, x, 1 );
|
|
40
40
|
* // x => <Float64Array>[ -4.0, -2.0, 1.0, 3.0 ]
|
|
41
41
|
*/
|
|
42
|
-
( N: number, order: number, x: Float64Array,
|
|
42
|
+
( N: number, order: number, x: Float64Array, strideX: number ): Float64Array;
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
45
|
* Sorts a double-precision floating-point strided array using heapsort and alternative indexing semantics.
|
|
@@ -47,8 +47,8 @@ interface Routine {
|
|
|
47
47
|
* @param N - number of indexed elements
|
|
48
48
|
* @param order - sort order
|
|
49
49
|
* @param x - input array
|
|
50
|
-
* @param
|
|
51
|
-
* @param
|
|
50
|
+
* @param strideX - stride length
|
|
51
|
+
* @param offsetX - starting index
|
|
52
52
|
* @returns `x`
|
|
53
53
|
*
|
|
54
54
|
* @example
|
|
@@ -59,7 +59,7 @@ interface Routine {
|
|
|
59
59
|
* dsorthp.ndarray( x.length, 1, x, 1, 0 );
|
|
60
60
|
* // x => <Float64Array>[ -4.0, -2.0, 1.0, 3.0 ]
|
|
61
61
|
*/
|
|
62
|
-
ndarray( N: number, order: number, x: Float64Array,
|
|
62
|
+
ndarray( N: number, order: number, x: Float64Array, strideX: number, offsetX: number ): Float64Array;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
/**
|
|
@@ -68,7 +68,7 @@ interface Routine {
|
|
|
68
68
|
* @param N - number of indexed elements
|
|
69
69
|
* @param order - sort order
|
|
70
70
|
* @param x - input array
|
|
71
|
-
* @param
|
|
71
|
+
* @param strideX - stride length
|
|
72
72
|
* @returns `x`
|
|
73
73
|
*
|
|
74
74
|
* @example
|
|
@@ -16,13 +16,10 @@
|
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
/**
|
|
20
|
-
* Header file containing function declarations.
|
|
21
|
-
*/
|
|
22
19
|
#ifndef STDLIB_BLAS_EXT_BASE_DSORTHP_H
|
|
23
20
|
#define STDLIB_BLAS_EXT_BASE_DSORTHP_H
|
|
24
21
|
|
|
25
|
-
#include
|
|
22
|
+
#include "stdlib/blas/base/shared.h"
|
|
26
23
|
|
|
27
24
|
/*
|
|
28
25
|
* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
|
|
@@ -34,7 +31,12 @@ extern "C" {
|
|
|
34
31
|
/**
|
|
35
32
|
* Sorts a double-precision floating-point strided array using heapsort.
|
|
36
33
|
*/
|
|
37
|
-
void
|
|
34
|
+
void API_SUFFIX(stdlib_strided_dsorthp)( const CBLAS_INT N, const double order, double *X, const CBLAS_INT strideX );
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Sorts a double-precision floating-point strided array using heapsort and alternative indexing semantics.
|
|
38
|
+
*/
|
|
39
|
+
void API_SUFFIX(stdlib_strided_dsorthp_ndarray)( const CBLAS_INT N, const double order, double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX );
|
|
38
40
|
|
|
39
41
|
#ifdef __cplusplus
|
|
40
42
|
}
|
package/lib/dsorthp.js
CHANGED
|
@@ -20,9 +20,8 @@
|
|
|
20
20
|
|
|
21
21
|
// MODULES //
|
|
22
22
|
|
|
23
|
-
var
|
|
24
|
-
var
|
|
25
|
-
var floor = require( '@stdlib/math-base-special-floor' );
|
|
23
|
+
var stride2offset = require( '@stdlib/strided-base-stride2offset' );
|
|
24
|
+
var ndarray = require( './ndarray.js' );
|
|
26
25
|
|
|
27
26
|
|
|
28
27
|
// MAIN //
|
|
@@ -42,7 +41,7 @@ var floor = require( '@stdlib/math-base-special-floor' );
|
|
|
42
41
|
* @param {PositiveInteger} N - number of indexed elements
|
|
43
42
|
* @param {number} order - sort order
|
|
44
43
|
* @param {Float64Array} x - input array
|
|
45
|
-
* @param {integer}
|
|
44
|
+
* @param {integer} strideX - stride length
|
|
46
45
|
* @returns {Float64Array} input array
|
|
47
46
|
*
|
|
48
47
|
* @example
|
|
@@ -53,96 +52,8 @@ var floor = require( '@stdlib/math-base-special-floor' );
|
|
|
53
52
|
* dsorthp( x.length, 1.0, x, 1 );
|
|
54
53
|
* // x => <Float64Array>[ -4.0, -2.0, 1.0, 3.0 ]
|
|
55
54
|
*/
|
|
56
|
-
function dsorthp( N, order, x,
|
|
57
|
-
|
|
58
|
-
var parent;
|
|
59
|
-
var child;
|
|
60
|
-
var v1;
|
|
61
|
-
var v2;
|
|
62
|
-
var n;
|
|
63
|
-
var t;
|
|
64
|
-
var i;
|
|
65
|
-
var j;
|
|
66
|
-
var k;
|
|
67
|
-
|
|
68
|
-
if ( N <= 0 || order === 0.0 ) {
|
|
69
|
-
return x;
|
|
70
|
-
}
|
|
71
|
-
// For a positive stride, sorting in decreasing order is equivalent to providing a negative stride and sorting in increasing order, and, for a negative stride, sorting in decreasing order is equivalent to providing a positive stride and sorting in increasing order...
|
|
72
|
-
if ( order < 0.0 ) {
|
|
73
|
-
stride *= -1;
|
|
74
|
-
}
|
|
75
|
-
if ( stride < 0 ) {
|
|
76
|
-
offset = (1-N) * stride;
|
|
77
|
-
} else {
|
|
78
|
-
offset = 0;
|
|
79
|
-
}
|
|
80
|
-
// Set the initial heap size:
|
|
81
|
-
n = N;
|
|
82
|
-
|
|
83
|
-
// Specify an initial "parent" index for building the heap:
|
|
84
|
-
parent = floor( N / 2 );
|
|
85
|
-
|
|
86
|
-
// Continue looping until the array is sorted...
|
|
87
|
-
while ( true ) {
|
|
88
|
-
if ( parent > 0 ) {
|
|
89
|
-
// We need to build the heap...
|
|
90
|
-
parent -= 1;
|
|
91
|
-
t = x[ offset+(parent*stride) ];
|
|
92
|
-
} else {
|
|
93
|
-
// Reduce the heap size:
|
|
94
|
-
n -= 1;
|
|
95
|
-
|
|
96
|
-
// Check if the heap is empty, and, if so, we are finished sorting...
|
|
97
|
-
if ( n === 0 ) {
|
|
98
|
-
return x;
|
|
99
|
-
}
|
|
100
|
-
// Store the last heap value in a temporary variable in order to make room for the heap root being placed into its sorted position:
|
|
101
|
-
i = offset + (n*stride);
|
|
102
|
-
t = x[ i ];
|
|
103
|
-
|
|
104
|
-
// Move the heap root to its sorted position:
|
|
105
|
-
x[ i ] = x[ offset ];
|
|
106
|
-
}
|
|
107
|
-
// We need to "sift down", pushing `t` down the heap to in order to replace the parent and satisfy the heap property...
|
|
108
|
-
|
|
109
|
-
// Start at the parent index:
|
|
110
|
-
j = parent;
|
|
111
|
-
|
|
112
|
-
// Get the "left" child index:
|
|
113
|
-
child = (j*2) + 1;
|
|
114
|
-
|
|
115
|
-
while ( child < n ) {
|
|
116
|
-
// Find the largest child...
|
|
117
|
-
k = child + 1;
|
|
118
|
-
if ( k < n ) {
|
|
119
|
-
v1 = x[ offset+(k*stride) ];
|
|
120
|
-
v2 = x[ offset+(child*stride) ];
|
|
121
|
-
|
|
122
|
-
// Check if a "right" child exists and is "bigger"...
|
|
123
|
-
if ( v1 > v2 || isnan( v1 ) || (v1 === v2 && isPositiveZero( v1 ) ) ) { // eslint-disable-line max-len
|
|
124
|
-
child += 1;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
// Check if the largest child is bigger than `t`...
|
|
128
|
-
v1 = x[ offset+(child*stride) ];
|
|
129
|
-
if ( v1 > t || isnan( v1 ) || ( v1 === t && isPositiveZero( v1 ) ) ) { // eslint-disable-line max-len
|
|
130
|
-
// Insert the larger child value:
|
|
131
|
-
x[ offset+(j*stride) ] = v1;
|
|
132
|
-
|
|
133
|
-
// Update `j` to point to the child index:
|
|
134
|
-
j = child;
|
|
135
|
-
|
|
136
|
-
// Get the "left" child index and repeat...
|
|
137
|
-
child = (j*2) + 1;
|
|
138
|
-
} else {
|
|
139
|
-
// We've found `t`'s place in the heap...
|
|
140
|
-
break;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
// Insert `t` into the heap:
|
|
144
|
-
x[ offset+(j*stride) ] = t;
|
|
145
|
-
}
|
|
55
|
+
function dsorthp( N, order, x, strideX ) {
|
|
56
|
+
return ndarray( N, order, x, strideX, stride2offset( N, strideX ) );
|
|
146
57
|
}
|
|
147
58
|
|
|
148
59
|
|
package/lib/dsorthp.native.js
CHANGED
|
@@ -31,7 +31,7 @@ var addon = require( './../src/addon.node' );
|
|
|
31
31
|
* @param {PositiveInteger} N - number of indexed elements
|
|
32
32
|
* @param {number} order - sort order
|
|
33
33
|
* @param {Float64Array} x - input array
|
|
34
|
-
* @param {integer}
|
|
34
|
+
* @param {integer} strideX - stride length
|
|
35
35
|
* @returns {Float64Array} input array
|
|
36
36
|
*
|
|
37
37
|
* @example
|
|
@@ -42,8 +42,8 @@ var addon = require( './../src/addon.node' );
|
|
|
42
42
|
* dsorthp( x.length, 1.0, x, 1 );
|
|
43
43
|
* // x => <Float64Array>[ -4.0, -2.0, 1.0, 3.0 ]
|
|
44
44
|
*/
|
|
45
|
-
function dsorthp( N, order, x,
|
|
46
|
-
addon( N, order, x,
|
|
45
|
+
function dsorthp( N, order, x, strideX ) {
|
|
46
|
+
addon( N, order, x, strideX );
|
|
47
47
|
return x;
|
|
48
48
|
}
|
|
49
49
|
|
package/lib/ndarray.js
CHANGED
|
@@ -42,8 +42,8 @@ var floor = require( '@stdlib/math-base-special-floor' );
|
|
|
42
42
|
* @param {PositiveInteger} N - number of indexed elements
|
|
43
43
|
* @param {number} order - sort order
|
|
44
44
|
* @param {Float64Array} x - input array
|
|
45
|
-
* @param {integer}
|
|
46
|
-
* @param {NonNegativeInteger}
|
|
45
|
+
* @param {integer} strideX - stride length
|
|
46
|
+
* @param {NonNegativeInteger} offsetX - starting index
|
|
47
47
|
* @returns {Float64Array} input array
|
|
48
48
|
*
|
|
49
49
|
* @example
|
|
@@ -54,7 +54,7 @@ var floor = require( '@stdlib/math-base-special-floor' );
|
|
|
54
54
|
* dsorthp( x.length, 1.0, x, 1, 0 );
|
|
55
55
|
* // x => <Float64Array>[ -4.0, -2.0, 1.0, 3.0 ]
|
|
56
56
|
*/
|
|
57
|
-
function dsorthp( N, order, x,
|
|
57
|
+
function dsorthp( N, order, x, strideX, offsetX ) {
|
|
58
58
|
var parent;
|
|
59
59
|
var child;
|
|
60
60
|
var v1;
|
|
@@ -70,8 +70,8 @@ function dsorthp( N, order, x, stride, offset ) {
|
|
|
70
70
|
}
|
|
71
71
|
// For a positive stride, sorting in decreasing order is equivalent to providing a negative stride and sorting in increasing order, and, for a negative stride, sorting in decreasing order is equivalent to providing a positive stride and sorting in increasing order...
|
|
72
72
|
if ( order < 0.0 ) {
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
strideX *= -1;
|
|
74
|
+
offsetX -= (N-1) * strideX;
|
|
75
75
|
}
|
|
76
76
|
// Set the initial heap size:
|
|
77
77
|
n = N;
|
|
@@ -84,7 +84,7 @@ function dsorthp( N, order, x, stride, offset ) {
|
|
|
84
84
|
if ( parent > 0 ) {
|
|
85
85
|
// We need to build the heap...
|
|
86
86
|
parent -= 1;
|
|
87
|
-
t = x[
|
|
87
|
+
t = x[ offsetX+(parent*strideX) ];
|
|
88
88
|
} else {
|
|
89
89
|
// Reduce the heap size:
|
|
90
90
|
n -= 1;
|
|
@@ -94,11 +94,11 @@ function dsorthp( N, order, x, stride, offset ) {
|
|
|
94
94
|
return x;
|
|
95
95
|
}
|
|
96
96
|
// Store the last heap value in a temporary variable in order to make room for the heap root being placed into its sorted position:
|
|
97
|
-
i =
|
|
97
|
+
i = offsetX + (n*strideX);
|
|
98
98
|
t = x[ i ];
|
|
99
99
|
|
|
100
100
|
// Move the heap root to its sorted position:
|
|
101
|
-
x[ i ] = x[
|
|
101
|
+
x[ i ] = x[ offsetX ];
|
|
102
102
|
}
|
|
103
103
|
// We need to "sift down", pushing `t` down the heap to in order to replace the parent and satisfy the heap property...
|
|
104
104
|
|
|
@@ -112,8 +112,8 @@ function dsorthp( N, order, x, stride, offset ) {
|
|
|
112
112
|
// Find the largest child...
|
|
113
113
|
k = child + 1;
|
|
114
114
|
if ( k < n ) {
|
|
115
|
-
v1 = x[
|
|
116
|
-
v2 = x[
|
|
115
|
+
v1 = x[ offsetX+(k*strideX) ];
|
|
116
|
+
v2 = x[ offsetX+(child*strideX) ];
|
|
117
117
|
|
|
118
118
|
// Check if a "right" child exists and is "bigger"...
|
|
119
119
|
if ( v1 > v2 || isnan( v1 ) || (v1 === v2 && isPositiveZero( v1 ) ) ) { // eslint-disable-line max-len
|
|
@@ -121,10 +121,10 @@ function dsorthp( N, order, x, stride, offset ) {
|
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
123
|
// Check if the largest child is bigger than `t`...
|
|
124
|
-
v1 = x[
|
|
124
|
+
v1 = x[ offsetX+(child*strideX) ];
|
|
125
125
|
if ( v1 > t || isnan( v1 ) || ( v1 === t && isPositiveZero( v1 ) ) ) { // eslint-disable-line max-len
|
|
126
126
|
// Insert the larger child value:
|
|
127
|
-
x[
|
|
127
|
+
x[ offsetX+(j*strideX) ] = v1;
|
|
128
128
|
|
|
129
129
|
// Update `j` to point to the child index:
|
|
130
130
|
j = child;
|
|
@@ -137,7 +137,7 @@ function dsorthp( N, order, x, stride, offset ) {
|
|
|
137
137
|
}
|
|
138
138
|
}
|
|
139
139
|
// Insert `t` into the heap:
|
|
140
|
-
x[
|
|
140
|
+
x[ offsetX+(j*strideX) ] = t;
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
143
|
|
package/lib/ndarray.native.js
CHANGED
|
@@ -20,8 +20,7 @@
|
|
|
20
20
|
|
|
21
21
|
// MODULES //
|
|
22
22
|
|
|
23
|
-
var
|
|
24
|
-
var addon = require( './dsorthp.native.js' );
|
|
23
|
+
var addon = require( './../src/addon.node' );
|
|
25
24
|
|
|
26
25
|
|
|
27
26
|
// MAIN //
|
|
@@ -32,8 +31,8 @@ var addon = require( './dsorthp.native.js' );
|
|
|
32
31
|
* @param {PositiveInteger} N - number of indexed elements
|
|
33
32
|
* @param {number} order - sort order
|
|
34
33
|
* @param {Float64Array} x - input array
|
|
35
|
-
* @param {integer}
|
|
36
|
-
* @param {NonNegativeInteger}
|
|
34
|
+
* @param {integer} strideX - stride length
|
|
35
|
+
* @param {NonNegativeInteger} offsetX - starting index
|
|
37
36
|
* @returns {Float64Array} input array
|
|
38
37
|
*
|
|
39
38
|
* @example
|
|
@@ -43,15 +42,8 @@ var addon = require( './dsorthp.native.js' );
|
|
|
43
42
|
*
|
|
44
43
|
* dsorthp( x.length, 1.0, x, 1, 0 );
|
|
45
44
|
*/
|
|
46
|
-
function dsorthp( N, order, x,
|
|
47
|
-
|
|
48
|
-
if ( stride < 0 ) {
|
|
49
|
-
order *= -1.0;
|
|
50
|
-
stride *= -1;
|
|
51
|
-
offset -= (N-1) * stride;
|
|
52
|
-
}
|
|
53
|
-
view = new Float64Array( x.buffer, x.byteOffset+(x.BYTES_PER_ELEMENT*offset), x.length-offset ); // eslint-disable-line max-len
|
|
54
|
-
addon( N, order, view, stride );
|
|
45
|
+
function dsorthp( N, order, x, strideX, offsetX ) {
|
|
46
|
+
addon.ndarray( N, order, x, strideX, offsetX );
|
|
55
47
|
return x;
|
|
56
48
|
}
|
|
57
49
|
|
package/manifest.json
CHANGED
|
@@ -1,43 +1,85 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
2
|
+
"options": {
|
|
3
|
+
"task": "build"
|
|
4
|
+
},
|
|
5
|
+
"fields": [
|
|
6
|
+
{
|
|
7
|
+
"field": "src",
|
|
8
|
+
"resolve": true,
|
|
9
|
+
"relative": true
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"field": "include",
|
|
13
|
+
"resolve": true,
|
|
14
|
+
"relative": true
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"field": "libraries",
|
|
18
|
+
"resolve": false,
|
|
19
|
+
"relative": false
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"field": "libpath",
|
|
23
|
+
"resolve": true,
|
|
24
|
+
"relative": false
|
|
25
|
+
}
|
|
26
|
+
],
|
|
27
|
+
"confs": [
|
|
28
|
+
{
|
|
29
|
+
"task": "build",
|
|
30
|
+
"src": [
|
|
31
|
+
"./src/main.c"
|
|
32
|
+
],
|
|
33
|
+
"include": [
|
|
34
|
+
"./include"
|
|
35
|
+
],
|
|
36
|
+
"libraries": [],
|
|
37
|
+
"libpath": [],
|
|
38
|
+
"dependencies": [
|
|
39
|
+
"@stdlib/napi-export",
|
|
40
|
+
"@stdlib/napi-argv",
|
|
41
|
+
"@stdlib/napi-argv-int64",
|
|
42
|
+
"@stdlib/napi-argv-double",
|
|
43
|
+
"@stdlib/napi-argv-strided-float64array",
|
|
44
|
+
"@stdlib/math-base-assert-is-nan",
|
|
45
|
+
"@stdlib/math-base-assert-is-positive-zero",
|
|
46
|
+
"@stdlib/strided-base-stride2offset",
|
|
47
|
+
"@stdlib/blas-base-shared"
|
|
48
|
+
]
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"task": "benchmark",
|
|
52
|
+
"src": [
|
|
53
|
+
"./src/main.c"
|
|
54
|
+
],
|
|
55
|
+
"include": [
|
|
56
|
+
"./include"
|
|
57
|
+
],
|
|
58
|
+
"libraries": [],
|
|
59
|
+
"libpath": [],
|
|
60
|
+
"dependencies": [
|
|
61
|
+
"@stdlib/math-base-assert-is-nan",
|
|
62
|
+
"@stdlib/math-base-assert-is-positive-zero",
|
|
63
|
+
"@stdlib/strided-base-stride2offset",
|
|
64
|
+
"@stdlib/blas-base-shared"
|
|
65
|
+
]
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
"task": "examples",
|
|
69
|
+
"src": [
|
|
70
|
+
"./src/main.c"
|
|
71
|
+
],
|
|
72
|
+
"include": [
|
|
73
|
+
"./include"
|
|
74
|
+
],
|
|
75
|
+
"libraries": [],
|
|
76
|
+
"libpath": [],
|
|
77
|
+
"dependencies": [
|
|
78
|
+
"@stdlib/math-base-assert-is-nan",
|
|
79
|
+
"@stdlib/math-base-assert-is-positive-zero",
|
|
80
|
+
"@stdlib/strided-base-stride2offset",
|
|
81
|
+
"@stdlib/blas-base-shared"
|
|
82
|
+
]
|
|
83
|
+
}
|
|
84
|
+
]
|
|
43
85
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/blas-ext-base-dsorthp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Sort a double-precision floating-point strided array using heapsort.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -34,13 +34,20 @@
|
|
|
34
34
|
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@stdlib/assert-is-error": "^0.2.
|
|
38
|
-
"@stdlib/
|
|
39
|
-
"@stdlib/math-base-assert-is-
|
|
40
|
-
"@stdlib/math-base-
|
|
41
|
-
"@stdlib/
|
|
42
|
-
"@stdlib/
|
|
43
|
-
"@stdlib/
|
|
37
|
+
"@stdlib/assert-is-error": "^0.2.2",
|
|
38
|
+
"@stdlib/blas-base-shared": "^0.1.0",
|
|
39
|
+
"@stdlib/math-base-assert-is-nan": "^0.2.2",
|
|
40
|
+
"@stdlib/math-base-assert-is-positive-zero": "^0.2.2",
|
|
41
|
+
"@stdlib/math-base-special-floor": "^0.2.3",
|
|
42
|
+
"@stdlib/napi-argv": "^0.2.2",
|
|
43
|
+
"@stdlib/napi-argv-double": "^0.2.1",
|
|
44
|
+
"@stdlib/napi-argv-int64": "^0.2.2",
|
|
45
|
+
"@stdlib/napi-argv-strided-float64array": "^0.2.2",
|
|
46
|
+
"@stdlib/napi-export": "^0.3.0",
|
|
47
|
+
"@stdlib/strided-base-stride2offset": "^0.1.0",
|
|
48
|
+
"@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2",
|
|
49
|
+
"@stdlib/utils-library-manifest": "^0.2.3",
|
|
50
|
+
"@stdlib/utils-try-require": "^0.2.2"
|
|
44
51
|
},
|
|
45
52
|
"devDependencies": {},
|
|
46
53
|
"engines": {
|
|
@@ -78,7 +85,6 @@
|
|
|
78
85
|
"double",
|
|
79
86
|
"float64array"
|
|
80
87
|
],
|
|
81
|
-
"__stdlib__": {},
|
|
82
88
|
"funding": {
|
|
83
89
|
"type": "opencollective",
|
|
84
90
|
"url": "https://opencollective.com/stdlib"
|
package/src/addon.c
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2020 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
|
+
#include "stdlib/blas/ext/base/dsorthp.h"
|
|
20
|
+
#include "stdlib/napi/export.h"
|
|
21
|
+
#include "stdlib/napi/argv.h"
|
|
22
|
+
#include "stdlib/napi/argv_double.h"
|
|
23
|
+
#include "stdlib/napi/argv_int64.h"
|
|
24
|
+
#include "stdlib/napi/argv_strided_float64array.h"
|
|
25
|
+
#include <node_api.h>
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Receives JavaScript callback invocation data.
|
|
29
|
+
*
|
|
30
|
+
* @param env environment under which the function is invoked
|
|
31
|
+
* @param info callback data
|
|
32
|
+
* @return Node-API value
|
|
33
|
+
*/
|
|
34
|
+
static napi_value addon( napi_env env, napi_callback_info info ) {
|
|
35
|
+
STDLIB_NAPI_ARGV( env, info, argv, argc, 4 );
|
|
36
|
+
STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 );
|
|
37
|
+
STDLIB_NAPI_ARGV_DOUBLE( env, order, argv, 1 );
|
|
38
|
+
STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 );
|
|
39
|
+
STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 2 );
|
|
40
|
+
API_SUFFIX(stdlib_strided_dsorthp)( N, order, X, strideX );
|
|
41
|
+
return NULL;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Receives JavaScript callback invocation data.
|
|
46
|
+
*
|
|
47
|
+
* @param env environment under which the function is invoked
|
|
48
|
+
* @param info callback data
|
|
49
|
+
* @return Node-API value
|
|
50
|
+
*/
|
|
51
|
+
static napi_value addon_method( napi_env env, napi_callback_info info ) {
|
|
52
|
+
STDLIB_NAPI_ARGV( env, info, argv, argc, 5 );
|
|
53
|
+
STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 );
|
|
54
|
+
STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 );
|
|
55
|
+
STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 4 );
|
|
56
|
+
STDLIB_NAPI_ARGV_DOUBLE( env, order, argv, 1 );
|
|
57
|
+
STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 2 );
|
|
58
|
+
API_SUFFIX(stdlib_strided_dsorthp_ndarray)( N, order, X, strideX, offsetX );
|
|
59
|
+
return NULL;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method );
|
package/src/{dsorthp.c → main.c}
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license Apache-2.0
|
|
3
3
|
*
|
|
4
|
-
* Copyright (c)
|
|
4
|
+
* Copyright (c) 2025 The Stdlib Authors.
|
|
5
5
|
*
|
|
6
6
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
7
|
* you may not use this file except in compliance with the License.
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
#include "stdlib/blas/ext/base/dsorthp.h"
|
|
20
20
|
#include "stdlib/math/base/assert/is_positive_zero.h"
|
|
21
21
|
#include "stdlib/math/base/assert/is_nan.h"
|
|
22
|
-
#include
|
|
23
|
-
#include
|
|
22
|
+
#include "stdlib/blas/base/shared.h"
|
|
23
|
+
#include "stdlib/strided/base/stride2offset.h"
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* Sorts a double-precision floating-point strided array using heapsort.
|
|
@@ -34,20 +34,43 @@
|
|
|
34
34
|
* - Williams, John William Joseph. 1964. "Algorithm 232: Heapsort." _Communications of the ACM_ 7 (6). New York, NY, USA: Association for Computing Machinery: 347–49. doi:[10.1145/512274.512284](https://doi.org/10.1145/512274.512284).
|
|
35
35
|
* - Floyd, Robert W. 1964. "Algorithm 245: Treesort." _Communications of the ACM_ 7 (12). New York, NY, USA: Association for Computing Machinery: 701. doi:[10.1145/355588.365103](https://doi.org/10.1145/355588.365103).
|
|
36
36
|
*
|
|
37
|
-
* @param N
|
|
38
|
-
* @param order
|
|
39
|
-
* @param X
|
|
40
|
-
* @param stride
|
|
37
|
+
* @param N number of indexed elements
|
|
38
|
+
* @param order sort order
|
|
39
|
+
* @param X input array
|
|
40
|
+
* @param strideX stride length
|
|
41
41
|
*/
|
|
42
|
-
void
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
42
|
+
void API_SUFFIX(stdlib_strided_dsorthp)( const CBLAS_INT N, const double order, double *X, const CBLAS_INT strideX) {
|
|
43
|
+
CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX );
|
|
44
|
+
API_SUFFIX(stdlib_strided_dsorthp_ndarray)( N, order, X, strideX, ox );
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Sorts a double-precision floating-point strided array using heapsort and alternative indexing semantics.
|
|
49
|
+
*
|
|
50
|
+
* ## Notes
|
|
51
|
+
*
|
|
52
|
+
* - This implementation uses an in-place algorithm derived from the work of Floyd (1964).
|
|
53
|
+
*
|
|
54
|
+
* ## References
|
|
55
|
+
*
|
|
56
|
+
* - Williams, John William Joseph. 1964. "Algorithm 232: Heapsort." _Communications of the ACM_ 7 (6). New York, NY, USA: Association for Computing Machinery: 347–49. doi:[10.1145/512274.512284](https://doi.org/10.1145/512274.512284).
|
|
57
|
+
* - Floyd, Robert W. 1964. "Algorithm 245: Treesort." _Communications of the ACM_ 7 (12). New York, NY, USA: Association for Computing Machinery: 701. doi:[10.1145/355588.365103](https://doi.org/10.1145/355588.365103).
|
|
58
|
+
*
|
|
59
|
+
* @param N number of indexed elements
|
|
60
|
+
* @param order sort order
|
|
61
|
+
* @param X input array
|
|
62
|
+
* @param strideX stride length
|
|
63
|
+
* @param offsetX starting index
|
|
64
|
+
*/
|
|
65
|
+
void API_SUFFIX(stdlib_strided_dsorthp_ndarray)( const CBLAS_INT N, const double order, double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) {
|
|
66
|
+
CBLAS_INT parent;
|
|
67
|
+
CBLAS_INT child;
|
|
68
|
+
CBLAS_INT ox;
|
|
69
|
+
CBLAS_INT sx;
|
|
70
|
+
CBLAS_INT n;
|
|
71
|
+
CBLAS_INT i;
|
|
72
|
+
CBLAS_INT j;
|
|
73
|
+
CBLAS_INT k;
|
|
51
74
|
double v1;
|
|
52
75
|
double v2;
|
|
53
76
|
double t;
|
|
@@ -57,27 +80,24 @@ void c_dsorthp( const int64_t N, const double order, double *X, const int64_t st
|
|
|
57
80
|
}
|
|
58
81
|
// For a positive stride, sorting in decreasing order is equivalent to providing a negative stride and sorting in increasing order, and, for a negative stride, sorting in decreasing order is equivalent to providing a positive stride and sorting in increasing order...
|
|
59
82
|
if ( order < 0.0 ) {
|
|
60
|
-
sx = -
|
|
61
|
-
|
|
62
|
-
sx = stride;
|
|
63
|
-
}
|
|
64
|
-
if ( sx < 0 ) {
|
|
65
|
-
offset = (1-N) * sx;
|
|
83
|
+
sx = -strideX;
|
|
84
|
+
ox = offsetX - ( (N-1)*sx );
|
|
66
85
|
} else {
|
|
67
|
-
|
|
86
|
+
sx = strideX;
|
|
87
|
+
ox = offsetX;
|
|
68
88
|
}
|
|
69
89
|
// Set the initial heap size:
|
|
70
90
|
n = N;
|
|
71
91
|
|
|
72
92
|
// Specify an initial "parent" index for building the heap:
|
|
73
|
-
parent =
|
|
93
|
+
parent = N / 2;
|
|
74
94
|
|
|
75
95
|
// Continue looping until the array is sorted...
|
|
76
96
|
while ( true ) {
|
|
77
97
|
if ( parent > 0 ) {
|
|
78
98
|
// We need to build the heap...
|
|
79
99
|
parent -= 1;
|
|
80
|
-
t = X[
|
|
100
|
+
t = X[ ox+(parent*sx) ];
|
|
81
101
|
} else {
|
|
82
102
|
// Reduce the heap size:
|
|
83
103
|
n -= 1;
|
|
@@ -87,11 +107,11 @@ void c_dsorthp( const int64_t N, const double order, double *X, const int64_t st
|
|
|
87
107
|
return;
|
|
88
108
|
}
|
|
89
109
|
// Store the last heap value in a temporary variable in order to make room for the heap root being placed into its sorted position:
|
|
90
|
-
i =
|
|
110
|
+
i = ox + (n*sx);
|
|
91
111
|
t = X[ i ];
|
|
92
112
|
|
|
93
113
|
// Move the heap root to its sorted position:
|
|
94
|
-
X[ i ] = X[
|
|
114
|
+
X[ i ] = X[ ox ];
|
|
95
115
|
}
|
|
96
116
|
// We need to "sift down", pushing `t` down the heap to in order to replace the parent and satisfy the heap property...
|
|
97
117
|
|
|
@@ -105,8 +125,8 @@ void c_dsorthp( const int64_t N, const double order, double *X, const int64_t st
|
|
|
105
125
|
// Find the largest child...
|
|
106
126
|
k = child + 1;
|
|
107
127
|
if ( k < n ) {
|
|
108
|
-
v1 = X[
|
|
109
|
-
v2 = X[
|
|
128
|
+
v1 = X[ ox+(k*sx) ];
|
|
129
|
+
v2 = X[ ox+(child*sx) ];
|
|
110
130
|
|
|
111
131
|
// Check if a "right" child exists and is "bigger"...
|
|
112
132
|
if ( v1 > v2 || stdlib_base_is_nan( v1 ) || (v1 == v2 && stdlib_base_is_positive_zero( v1 ) ) ) {
|
|
@@ -114,10 +134,10 @@ void c_dsorthp( const int64_t N, const double order, double *X, const int64_t st
|
|
|
114
134
|
}
|
|
115
135
|
}
|
|
116
136
|
// Check if the largest child is bigger than `t`...
|
|
117
|
-
v1 = X[
|
|
137
|
+
v1 = X[ ox+(child*sx) ];
|
|
118
138
|
if ( v1 > t || stdlib_base_is_nan( v1 ) || ( v1 == t && stdlib_base_is_positive_zero( v1 ) ) ) {
|
|
119
139
|
// Insert the larger child value:
|
|
120
|
-
X[
|
|
140
|
+
X[ ox+(j*sx) ] = v1;
|
|
121
141
|
|
|
122
142
|
// Update `j` to point to the child index:
|
|
123
143
|
j = child;
|
|
@@ -130,6 +150,6 @@ void c_dsorthp( const int64_t N, const double order, double *X, const int64_t st
|
|
|
130
150
|
}
|
|
131
151
|
}
|
|
132
152
|
// Insert `t` into the heap:
|
|
133
|
-
X[
|
|
153
|
+
X[ ox+(j*sx) ] = t;
|
|
134
154
|
}
|
|
135
155
|
}
|
package/include.gypi
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
# @license Apache-2.0
|
|
2
|
-
#
|
|
3
|
-
# Copyright (c) 2020 The Stdlib Authors.
|
|
4
|
-
#
|
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
-
# you may not use this file except in compliance with the License.
|
|
7
|
-
# You may obtain a copy of the License at
|
|
8
|
-
#
|
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
#
|
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
-
# See the License for the specific language governing permissions and
|
|
15
|
-
# limitations under the License.
|
|
16
|
-
|
|
17
|
-
# A GYP include file for building a Node.js native add-on.
|
|
18
|
-
#
|
|
19
|
-
# Main documentation:
|
|
20
|
-
#
|
|
21
|
-
# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md
|
|
22
|
-
# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md
|
|
23
|
-
{
|
|
24
|
-
# Define variables to be used throughout the configuration for all targets:
|
|
25
|
-
'variables': {
|
|
26
|
-
# Source directory:
|
|
27
|
-
'src_dir': './src',
|
|
28
|
-
|
|
29
|
-
# Include directories:
|
|
30
|
-
'include_dirs': [
|
|
31
|
-
'<!@(node -e "var arr = require(\'@stdlib/utils-library-manifest\')(\'./manifest.json\',{},{\'basedir\':process.cwd(),\'paths\':\'posix\'}).include; for ( var i = 0; i < arr.length; i++ ) { console.log( arr[ i ] ); }")',
|
|
32
|
-
],
|
|
33
|
-
|
|
34
|
-
# Add-on destination directory:
|
|
35
|
-
'addon_output_dir': './src',
|
|
36
|
-
|
|
37
|
-
# Source files:
|
|
38
|
-
'src_files': [
|
|
39
|
-
'<(src_dir)/addon.cpp',
|
|
40
|
-
'<!@(node -e "var arr = require(\'@stdlib/utils-library-manifest\')(\'./manifest.json\',{},{\'basedir\':process.cwd(),\'paths\':\'posix\'}).src; for ( var i = 0; i < arr.length; i++ ) { console.log( arr[ i ] ); }")',
|
|
41
|
-
],
|
|
42
|
-
|
|
43
|
-
# Library dependencies:
|
|
44
|
-
'libraries': [
|
|
45
|
-
'<!@(node -e "var arr = require(\'@stdlib/utils-library-manifest\')(\'./manifest.json\',{},{\'basedir\':process.cwd(),\'paths\':\'posix\'}).libraries; for ( var i = 0; i < arr.length; i++ ) { console.log( arr[ i ] ); }")',
|
|
46
|
-
],
|
|
47
|
-
|
|
48
|
-
# Library directories:
|
|
49
|
-
'library_dirs': [
|
|
50
|
-
'<!@(node -e "var arr = require(\'@stdlib/utils-library-manifest\')(\'./manifest.json\',{},{\'basedir\':process.cwd(),\'paths\':\'posix\'}).libpath; for ( var i = 0; i < arr.length; i++ ) { console.log( arr[ i ] ); }")',
|
|
51
|
-
],
|
|
52
|
-
}, # end variables
|
|
53
|
-
}
|
package/src/addon.cpp
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Apache-2.0
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2020 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
|
-
#include "stdlib/blas/ext/base/dsorthp.h"
|
|
20
|
-
#include <node_api.h>
|
|
21
|
-
#include <stdint.h>
|
|
22
|
-
#include <stdlib.h>
|
|
23
|
-
#include <stdbool.h>
|
|
24
|
-
#include <assert.h>
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Add-on namespace.
|
|
28
|
-
*/
|
|
29
|
-
namespace stdlib_blas_ext_base_dsorthp {
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Sorts a double-precision floating-point strided array using heapsort.
|
|
33
|
-
*
|
|
34
|
-
* ## Notes
|
|
35
|
-
*
|
|
36
|
-
* - When called from JavaScript, the function expects four arguments:
|
|
37
|
-
*
|
|
38
|
-
* - `N`: number of indexed elements
|
|
39
|
-
* - `order`: sort order
|
|
40
|
-
* - `X`: input array
|
|
41
|
-
* - `strideX`: `X` stride length
|
|
42
|
-
*/
|
|
43
|
-
napi_value node_dsorthp( napi_env env, napi_callback_info info ) {
|
|
44
|
-
napi_status status;
|
|
45
|
-
|
|
46
|
-
size_t argc = 4;
|
|
47
|
-
napi_value argv[ 4 ];
|
|
48
|
-
status = napi_get_cb_info( env, info, &argc, argv, nullptr, nullptr );
|
|
49
|
-
assert( status == napi_ok );
|
|
50
|
-
|
|
51
|
-
if ( argc < 4 ) {
|
|
52
|
-
napi_throw_error( env, nullptr, "invalid invocation. Must provide 4 arguments." );
|
|
53
|
-
return nullptr;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
napi_valuetype vtype0;
|
|
57
|
-
status = napi_typeof( env, argv[ 0 ], &vtype0 );
|
|
58
|
-
assert( status == napi_ok );
|
|
59
|
-
if ( vtype0 != napi_number ) {
|
|
60
|
-
napi_throw_type_error( env, nullptr, "invalid argument. First argument must be a number." );
|
|
61
|
-
return nullptr;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
napi_valuetype vtype1;
|
|
65
|
-
status = napi_typeof( env, argv[ 1 ], &vtype1 );
|
|
66
|
-
assert( status == napi_ok );
|
|
67
|
-
if ( vtype1 != napi_number ) {
|
|
68
|
-
napi_throw_type_error( env, nullptr, "invalid argument. Second argument must be a number." );
|
|
69
|
-
return nullptr;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
bool res2;
|
|
73
|
-
status = napi_is_typedarray( env, argv[ 2 ], &res2 );
|
|
74
|
-
assert( status == napi_ok );
|
|
75
|
-
if ( res2 == false ) {
|
|
76
|
-
napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a Float64Array." );
|
|
77
|
-
return nullptr;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
napi_valuetype vtype3;
|
|
81
|
-
status = napi_typeof( env, argv[ 3 ], &vtype3 );
|
|
82
|
-
assert( status == napi_ok );
|
|
83
|
-
if ( vtype3 != napi_number ) {
|
|
84
|
-
napi_throw_type_error( env, nullptr, "invalid argument. Fourth argument must be a number." );
|
|
85
|
-
return nullptr;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
int64_t N;
|
|
89
|
-
status = napi_get_value_int64( env, argv[ 0 ], &N );
|
|
90
|
-
assert( status == napi_ok );
|
|
91
|
-
|
|
92
|
-
double order;
|
|
93
|
-
status = napi_get_value_double( env, argv[ 1 ], &order );
|
|
94
|
-
assert( status == napi_ok );
|
|
95
|
-
|
|
96
|
-
int64_t strideX;
|
|
97
|
-
status = napi_get_value_int64( env, argv[ 3 ], &strideX );
|
|
98
|
-
assert( status == napi_ok );
|
|
99
|
-
|
|
100
|
-
napi_typedarray_type vtype2;
|
|
101
|
-
size_t xlen;
|
|
102
|
-
void *X;
|
|
103
|
-
status = napi_get_typedarray_info( env, argv[ 2 ], &vtype2, &xlen, &X, nullptr, nullptr );
|
|
104
|
-
assert( status == napi_ok );
|
|
105
|
-
if ( vtype2 != napi_float64_array ) {
|
|
106
|
-
napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a Float64Array." );
|
|
107
|
-
return nullptr;
|
|
108
|
-
}
|
|
109
|
-
if ( (N-1)*llabs(strideX) >= (int64_t)xlen ) {
|
|
110
|
-
napi_throw_range_error( env, nullptr, "invalid argument. Third argument has insufficient elements based on the associated stride and the number of indexed elements." );
|
|
111
|
-
return nullptr;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
c_dsorthp( N, order, (double *)X, strideX );
|
|
115
|
-
|
|
116
|
-
return nullptr;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
napi_value Init( napi_env env, napi_value exports ) {
|
|
120
|
-
napi_status status;
|
|
121
|
-
napi_value fcn;
|
|
122
|
-
status = napi_create_function( env, "exports", NAPI_AUTO_LENGTH, node_dsorthp, NULL, &fcn );
|
|
123
|
-
assert( status == napi_ok );
|
|
124
|
-
return fcn;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
NAPI_MODULE( NODE_GYP_MODULE_NAME, Init )
|
|
128
|
-
} // end namespace stdlib_blas_ext_base_dsorthp
|