@stdlib/blas-ext-base-dsortins 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 CHANGED
@@ -1 +1 @@
1
- Copyright (c) 2016-2024 The Stdlib Authors.
1
+ Copyright (c) 2016-2026 The Stdlib Authors.
package/README.md CHANGED
@@ -53,9 +53,9 @@ npm install @stdlib/blas-ext-base-dsortins
53
53
  var dsortins = require( '@stdlib/blas-ext-base-dsortins' );
54
54
  ```
55
55
 
56
- #### dsortins( N, order, x, stride )
56
+ #### dsortins( N, order, x, strideX )
57
57
 
58
- Sorts a double-precision floating-point strided array `x` using insertion sort.
58
+ Sorts a double-precision floating-point strided array using insertion sort.
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
- - **stride**: index increment.
74
+ - **strideX**: stride length.
75
75
 
76
- The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to sort every other element
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
- dsortins( N, -1.0, x, 2 );
83
+ dsortins( 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
- dsortins( N, -1.0, x1, 2 );
99
+ dsortins( 2, -1.0, x1, 2 );
104
100
  // x0 => <Float64Array>[ 1.0, 4.0, 3.0, 2.0 ]
105
101
  ```
106
102
 
107
- #### dsortins.ndarray( N, order, x, stride, offset )
103
+ #### dsortins.ndarray( N, order, x, strideX, offsetX )
108
104
 
109
- Sorts a double-precision floating-point strided array `x` using insertion sort and alternative indexing semantics.
105
+ Sorts a double-precision floating-point strided array using insertion sort and alternative indexing semantics.
110
106
 
111
107
  ```javascript
112
108
  var Float64Array = require( '@stdlib/array-float64' );
@@ -119,9 +115,9 @@ dsortins.ndarray( x.length, 1.0, x, 1, 0 );
119
115
 
120
116
  The function has the following additional parameters:
121
117
 
122
- - **offset**: starting index.
118
+ - **offsetX**: starting index.
123
119
 
124
- 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 of `x`
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' );
@@ -159,27 +155,12 @@ dsortins.ndarray( 3, 1.0, x, 1, x.length-3 );
159
155
  <!-- eslint no-undef: "error" -->
160
156
 
161
157
  ```javascript
162
- var round = require( '@stdlib/math-base-special-round' );
163
- var randu = require( '@stdlib/random-base-randu' );
164
- var Float64Array = require( '@stdlib/array-float64' );
158
+ var discreteUniform = require( '@stdlib/random-array-discrete-uniform' );
165
159
  var dsortins = require( '@stdlib/blas-ext-base-dsortins' );
166
160
 
167
- var rand;
168
- var sign;
169
- var x;
170
- var i;
171
-
172
- x = new Float64Array( 10 );
173
- for ( i = 0; i < x.length; i++ ) {
174
- rand = round( randu()*100.0 );
175
- sign = randu();
176
- if ( sign < 0.5 ) {
177
- sign = -1.0;
178
- } else {
179
- sign = 1.0;
180
- }
181
- x[ i ] = sign * rand;
182
- }
161
+ var x = discreteUniform( 10, -100, 100, {
162
+ 'dtype': 'float64'
163
+ });
183
164
  console.log( x );
184
165
 
185
166
  dsortins( x.length, -1.0, x, -1 );
@@ -190,6 +171,129 @@ console.log( x );
190
171
 
191
172
  <!-- /.examples -->
192
173
 
174
+ <!-- C interface documentation. -->
175
+
176
+ * * *
177
+
178
+ <section class="c">
179
+
180
+ ## C APIs
181
+
182
+ <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
183
+
184
+ <section class="intro">
185
+
186
+ </section>
187
+
188
+ <!-- /.intro -->
189
+
190
+ <!-- C usage documentation. -->
191
+
192
+ <section class="usage">
193
+
194
+ ### Usage
195
+
196
+ ```c
197
+ #include "stdlib/blas/ext/base/dsortins.h"
198
+ ```
199
+
200
+ #### stdlib_strided_dsortins( N, order, \*X, strideX )
201
+
202
+ Sorts a double-precision floating-point strided array using insertion sort.
203
+
204
+ ```c
205
+ double x[] = { 1.0, -2.0, 3.0, -4.0 };
206
+
207
+ stdlib_strided_dsortins( 2, -1.0, x, 1 );
208
+ ```
209
+
210
+ The function accepts the following arguments:
211
+
212
+ - **N**: `[in] CBLAS_INT` number of indexed elements.
213
+ - **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.
214
+ - **X**: `[inout] double*` input array.
215
+ - **strideX**: `[in] CBLAS_INT` stride length for `X`.
216
+
217
+ ```c
218
+ stdlib_strided_dsortins( const CBLAS_INT N, const double order, double *X, const CBLAS_INT strideX );
219
+ ```
220
+
221
+ <!--lint disable maximum-heading-length-->
222
+
223
+ #### stdlib_strided_dsortins_ndarray( N, order, \*X, strideX, offsetX )
224
+
225
+ <!--lint enable maximum-heading-length-->
226
+
227
+ Sorts a double-precision floating-point strided array using insertion sort and alternative indexing semantics.
228
+
229
+ ```c
230
+ double x[] = { 1.0, -2.0, 3.0, -4.0 };
231
+
232
+ stdlib_strided_dsortins_ndarray( 4, 1.0, x, 1, 0 );
233
+ ```
234
+
235
+ The function accepts the following arguments:
236
+
237
+ - **N**: `[in] CBLAS_INT` number of indexed elements.
238
+ - **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.
239
+ - **X**: `[inout] double*` input array.
240
+ - **strideX**: `[in] CBLAS_INT` stride length for `X`.
241
+ - **offsetX**: `[in] CBLAS_INT` starting index for `X`.
242
+
243
+ ```c
244
+ stdlib_strided_dsortins_ndarray( const CBLAS_INT N, const double order, double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX );
245
+ ```
246
+
247
+ </section>
248
+
249
+ <!-- /.usage -->
250
+
251
+ <!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
252
+
253
+ <section class="notes">
254
+
255
+ </section>
256
+
257
+ <!-- /.notes -->
258
+
259
+ <!-- C API usage examples. -->
260
+
261
+ <section class="examples">
262
+
263
+ ### Examples
264
+
265
+ ```c
266
+ #include "stdlib/blas/ext/base/dsortins.h"
267
+ #include <stdio.h>
268
+
269
+ int main( void ) {
270
+ // Create a strided array:
271
+ double x[] = { 1.0, -2.0, 3.0, -4.0, 5.0, -6.0, 7.0, -8.0 };
272
+
273
+ // Specify the number of elements:
274
+ int N = 8;
275
+
276
+ // Specify a stride:
277
+ int strideX = 1;
278
+
279
+ // Sort the array:
280
+ stdlib_strided_dsortins( N, 1.0, x, strideX );
281
+
282
+ // Print the result:
283
+ for ( int i = 0; i < 8; i++ ) {
284
+ printf( "x[ %i ] = %lf\n", i, x[ i ] );
285
+ }
286
+ }
287
+ ```
288
+
289
+ </section>
290
+
291
+ <!-- /.examples -->
292
+
293
+ </section>
294
+
295
+ <!-- /.c -->
296
+
193
297
  <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
194
298
 
195
299
  <section class="related">
@@ -232,7 +336,7 @@ See [LICENSE][stdlib-license].
232
336
 
233
337
  ## Copyright
234
338
 
235
- Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
339
+ Copyright &copy; 2016-2026. The Stdlib [Authors][stdlib-authors].
236
340
 
237
341
  </section>
238
342
 
@@ -245,8 +349,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
245
349
  [npm-image]: http://img.shields.io/npm/v/@stdlib/blas-ext-base-dsortins.svg
246
350
  [npm-url]: https://npmjs.org/package/@stdlib/blas-ext-base-dsortins
247
351
 
248
- [test-image]: https://github.com/stdlib-js/blas-ext-base-dsortins/actions/workflows/test.yml/badge.svg?branch=v0.2.1
249
- [test-url]: https://github.com/stdlib-js/blas-ext-base-dsortins/actions/workflows/test.yml?query=branch:v0.2.1
352
+ [test-image]: https://github.com/stdlib-js/blas-ext-base-dsortins/actions/workflows/test.yml/badge.svg?branch=v0.3.0
353
+ [test-url]: https://github.com/stdlib-js/blas-ext-base-dsortins/actions/workflows/test.yml?query=branch:v0.3.0
250
354
 
251
355
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/blas-ext-base-dsortins/main.svg
252
356
  [coverage-url]: https://codecov.io/github/stdlib-js/blas-ext-base-dsortins?branch=main
@@ -258,8 +362,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
258
362
 
259
363
  -->
260
364
 
261
- [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
262
- [chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im
365
+ [chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
366
+ [chat-url]: https://stdlib.zulipchat.com
263
367
 
264
368
  [stdlib]: https://github.com/stdlib-js/stdlib
265
369
 
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
- "use strict";var p=function(l,q){return function(){return q||l((q={exports:{}}).exports,q),q.exports}};var y=p(function(K,k){
2
- var c=require('@stdlib/math-base-assert-is-negative-zero/dist'),g=require('@stdlib/math-base-assert-is-nan/dist');function A(l,q,a,r){var h,i,e,v,o,n,f,u;if(l<=0||q===0)return a;if(q<0&&(r*=-1),r<0){for(v=(1-l)*r,o=0,i=v+r,u=1;u<l;u++)if(n=a[i],g(n)){for(e=i;e>o;)a[e]=a[e+r],e+=r;a[o]=n}else{for(h=c(n),e=i-r;e<=v&&(f=a[e],!(f<=n&&!(h&&f===n&&c(f)===!1)));)a[e+r]=f,e-=r;a[e+r]=n,i+=r}return a}for(v=0,o=(l-1)*r,i=v+r,u=1;u<l;u++)if(n=a[i],g(n)){for(e=i;e<o;)a[e]=a[e+r],e+=r;a[o]=n}else{for(h=c(n),e=i-r;e>=v&&(f=a[e],!(f<=n&&!(h&&f===n&&c(f)===!1)));)a[e+r]=f,e-=r;a[e+r]=n,i+=r}return a}k.exports=A
3
- });var Z=p(function(L,R){
4
- var j=require('@stdlib/math-base-assert-is-negative-zero/dist'),m=require('@stdlib/math-base-assert-is-nan/dist');function B(l,q,a,r,h){var i,e,v,o,n,f,u,w;if(l<=0||q===0)return a;if(q<0&&(r*=-1,h-=(l-1)*r),o=h,n=o+(l-1)*r,e=o+r,r<0){for(w=1;w<l;w++)if(f=a[e],m(f)){for(v=e;v>n;)a[v]=a[v+r],v+=r;a[n]=f}else{for(i=j(f),v=e-r;v<=o&&(u=a[v],!(u<=f&&!(i&&u===f&&j(u)===!1)));)a[v+r]=u,v-=r;a[v+r]=f,e+=r}return a}for(w=1;w<l;w++)if(f=a[e],m(f)){for(v=e;v<n;)a[v]=a[v+r],v+=r;a[n]=f}else{for(i=j(f),v=e-r;v>=o&&(u=a[v],!(u<=f&&!(i&&u===f&&j(u)===!1)));)a[v+r]=u,v-=r;a[v+r]=f,e+=r}return a}R.exports=B
5
- });var O=p(function(M,E){
6
- var C=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),_=y(),D=Z();C(_,"ndarray",D);E.exports=_
7
- });var F=require("path").join,G=require('@stdlib/utils-try-require/dist'),H=require('@stdlib/assert-is-error/dist'),I=O(),b,z=G(F(__dirname,"./native.js"));H(z)?b=I:b=z;module.exports=b;
1
+ "use strict";var c=function(v,u){return function(){return u||v((u={exports:{}}).exports,u),u.exports}};var p=c(function(I,w){
2
+ var t=require('@stdlib/math-base-assert-is-negative-zero/dist'),j=require('@stdlib/math-base-assert-is-nan/dist');function E(v,u,a,r,h){var s,f,e,l,q,i,n,o;if(v<=0||u===0)return a;if(u<0&&(r*=-1,h-=(v-1)*r),l=h,q=l+(v-1)*r,f=l+r,r<0){for(o=1;o<v;o++)if(i=a[f],j(i)){for(e=f;e>q;)a[e]=a[e+r],e+=r;a[q]=i}else{for(s=t(i),e=f-r;e<=l&&(n=a[e],!(n<=i&&!(s&&n===i&&t(n)===!1)));)a[e+r]=n,e-=r;a[e+r]=i,f+=r}return a}for(o=1;o<v;o++)if(i=a[f],j(i)){for(e=f;e<q;)a[e]=a[e+r],e+=r;a[q]=i}else{for(s=t(i),e=f-r;e>=l&&(n=a[e],!(n<=i&&!(s&&n===i&&t(n)===!1)));)a[e+r]=n,e-=r;a[e+r]=i,f+=r}return a}w.exports=E
3
+ });var b=c(function(J,m){
4
+ var O=require('@stdlib/strided-base-stride2offset/dist'),Z=p();function z(v,u,a,r){return Z(v,u,a,r,O(v,r))}m.exports=z
5
+ });var R=c(function(K,k){
6
+ var A=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),g=b(),B=p();A(g,"ndarray",B);k.exports=g
7
+ });var C=require("path").join,D=require('@stdlib/utils-try-require/dist'),F=require('@stdlib/assert-is-error/dist'),G=R(),y,_=D(C(__dirname,"./native.js"));F(_)?y=G:y=_;module.exports=y;
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/dsortins.js", "../lib/ndarray.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 isNegativeZero = require( '@stdlib/math-base-assert-is-negative-zero' );\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\n\n\n// MAIN //\n\n/**\n* Sorts a double-precision floating-point strided array using insertion sort.\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* dsortins( x.length, 1.0, x, 1 );\n* // x => <Float64Array>[ -4.0, -2.0, 1.0, 3.0 ]\n*/\nfunction dsortins( N, order, x, stride ) {\n\tvar flg;\n\tvar ix;\n\tvar jx;\n\tvar fx;\n\tvar lx;\n\tvar v;\n\tvar u;\n\tvar i;\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\t// Traverse the strided array from right-to-left...\n\t\tfx = (1-N) * stride; // first index\n\t\tlx = 0; // last index\n\t\tix = fx + stride;\n\n\t\t// Sort in increasing order...\n\t\tfor ( i = 1; i < N; i++ ) {\n\t\t\tv = x[ ix ];\n\n\t\t\t// Sort `NaN` values to the end (i.e., the left)...\n\t\t\tif ( isnan( v ) ) {\n\t\t\t\tjx = ix;\n\n\t\t\t\t// Shift all values (including NaNs) to the left of the current element to the right...\n\t\t\t\twhile ( jx > lx ) {\n\t\t\t\t\tx[ jx ] = x[ jx+stride ];\n\t\t\t\t\tjx += stride;\n\t\t\t\t}\n\t\t\t\tx[ lx ] = v;\n\t\t\t} else {\n\t\t\t\tflg = isNegativeZero( v );\n\t\t\t\tjx = ix - stride;\n\n\t\t\t\t// Shift all larger values to the right of the current element to the left...\n\t\t\t\twhile ( jx <= fx ) {\n\t\t\t\t\tu = x[ jx ];\n\t\t\t\t\tif ( u <= v && !(flg && u === v && isNegativeZero( u ) === false) ) { // eslint-disable-line max-len\n\t\t\t\t\t\t// Note: positive zeros (and NaNs (e.g., when last element is NaN)) are sorted to the left\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tx[ jx+stride ] = u;\n\t\t\t\t\tjx -= stride;\n\t\t\t\t}\n\t\t\t\tx[ jx+stride ] = v;\n\t\t\t\tix += stride;\n\t\t\t}\n\t\t}\n\t\treturn x;\n\t}\n\t// Traverse the strided array from left-to-right...\n\tfx = 0; // first index\n\tlx = (N-1) * stride; // last index\n\tix = fx + stride;\n\n\t// Sort in increasing order...\n\tfor ( i = 1; i < N; i++ ) {\n\t\tv = x[ ix ];\n\n\t\t// Sort `NaN` values to the end...\n\t\tif ( isnan( v ) ) {\n\t\t\tjx = ix;\n\n\t\t\t// Shift all values (including NaNs) to the right of the current element to the left...\n\t\t\twhile ( jx < lx ) {\n\t\t\t\tx[ jx ] = x[ jx+stride ];\n\t\t\t\tjx += stride;\n\t\t\t}\n\t\t\tx[ lx ] = v;\n\t\t} else {\n\t\t\tflg = isNegativeZero( v );\n\t\t\tjx = ix - stride;\n\n\t\t\t// Shift all larger values to the left of the current element to the right...\n\t\t\twhile ( jx >= fx ) {\n\t\t\t\tu = x[ jx ];\n\t\t\t\tif ( u <= v && !(flg && u === v && isNegativeZero( u ) === false) ) { // eslint-disable-line max-len\n\t\t\t\t\t// Note: positive zeros (and NaNs (e.g., when first element is NaN)) are sorted to the right\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tx[ jx+stride ] = u;\n\t\t\t\tjx -= stride;\n\t\t\t}\n\t\t\tx[ jx+stride ] = v;\n\t\t\tix += stride;\n\t\t}\n\t}\n\treturn x;\n}\n\n\n// EXPORTS //\n\nmodule.exports = dsortins;\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 isNegativeZero = require( '@stdlib/math-base-assert-is-negative-zero' );\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\n\n\n// MAIN //\n\n/**\n* Sorts a double-precision floating-point strided array using insertion sort.\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* dsortins( x.length, 1.0, x, 1, 0 );\n* // x => <Float64Array>[ -4.0, -2.0, 1.0, 3.0 ]\n*/\nfunction dsortins( N, order, x, stride, offset ) {\n\tvar flg;\n\tvar ix;\n\tvar jx;\n\tvar fx;\n\tvar lx;\n\tvar v;\n\tvar u;\n\tvar i;\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\tfx = offset; // first index\n\tlx = fx + ((N-1)*stride); // last index\n\tix = fx + stride;\n\n\tif ( stride < 0 ) {\n\t\t// Traverse the strided array from right-to-left...\n\n\t\t// Sort in increasing order...\n\t\tfor ( i = 1; i < N; i++ ) {\n\t\t\tv = x[ ix ];\n\n\t\t\t// Sort `NaN` values to the end (i.e., the left)...\n\t\t\tif ( isnan( v ) ) {\n\t\t\t\tjx = ix;\n\n\t\t\t\t// Shift all values (including NaNs) to the left of the current element to the right...\n\t\t\t\twhile ( jx > lx ) {\n\t\t\t\t\tx[ jx ] = x[ jx+stride ];\n\t\t\t\t\tjx += stride;\n\t\t\t\t}\n\t\t\t\tx[ lx ] = v;\n\t\t\t} else {\n\t\t\t\tflg = isNegativeZero( v );\n\t\t\t\tjx = ix - stride;\n\n\t\t\t\t// Shift all larger values to the right of the current element to the left...\n\t\t\t\twhile ( jx <= fx ) {\n\t\t\t\t\tu = x[ jx ];\n\t\t\t\t\tif ( u <= v && !(flg && u === v && isNegativeZero( u ) === false) ) { // eslint-disable-line max-len\n\t\t\t\t\t\t// Note: positive zeros (and NaNs (e.g., when last element is NaN)) are sorted to the left\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tx[ jx+stride ] = u;\n\t\t\t\t\tjx -= stride;\n\t\t\t\t}\n\t\t\t\tx[ jx+stride ] = v;\n\t\t\t\tix += stride;\n\t\t\t}\n\t\t}\n\t\treturn x;\n\t}\n\t// Traverse the strided array from left-to-right...\n\n\t// Sort in increasing order...\n\tfor ( i = 1; i < N; i++ ) {\n\t\tv = x[ ix ];\n\n\t\t// Sort `NaN` values to the end...\n\t\tif ( isnan( v ) ) {\n\t\t\tjx = ix;\n\n\t\t\t// Shift all values (including NaNs) to the right of the current element to the left...\n\t\t\twhile ( jx < lx ) {\n\t\t\t\tx[ jx ] = x[ jx+stride ];\n\t\t\t\tjx += stride;\n\t\t\t}\n\t\t\tx[ lx ] = v;\n\t\t} else {\n\t\t\tflg = isNegativeZero( v );\n\t\t\tjx = ix - stride;\n\n\t\t\t// Shift all larger values to the left of the current element to the right...\n\t\t\twhile ( jx >= fx ) {\n\t\t\t\tu = x[ jx ];\n\t\t\t\tif ( u <= v && !(flg && u === v && isNegativeZero( u ) === false) ) { // eslint-disable-line max-len\n\t\t\t\t\t// Note: positive zeros (and NaNs (e.g., when first element is NaN)) are sorted to the right\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tx[ jx+stride ] = u;\n\t\t\t\tjx -= stride;\n\t\t\t}\n\t\t\tx[ jx+stride ] = v;\n\t\t\tix += stride;\n\t\t}\n\t}\n\treturn x;\n}\n\n\n// EXPORTS //\n\nmodule.exports = dsortins;\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 dsortins = require( './dsortins.js' );\nvar ndarray = require( './ndarray.js' );\n\n\n// MAIN //\n\nsetReadOnly( dsortins, 'ndarray', ndarray );\n\n\n// EXPORTS //\n\nmodule.exports = dsortins;\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 insertion sort.\n*\n* @module @stdlib/blas-ext-base-dsortins\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var dsortins = require( '@stdlib/blas-ext-base-dsortins' );\n*\n* var x = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] );\n*\n* dsortins( 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 dsortins = require( '@stdlib/blas-ext-base-dsortins' );\n*\n* var x = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] );\n*\n* dsortins.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 dsortins;\nvar tmp = tryRequire( join( __dirname, './native.js' ) );\nif ( isError( tmp ) ) {\n\tdsortins = main;\n} else {\n\tdsortins = tmp;\n}\n\n\n// EXPORTS //\n\nmodule.exports = dsortins;\n\n// exports: { \"ndarray\": \"dsortins.ndarray\" }\n"],
5
- "mappings": "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",
6
- "names": ["require_dsortins", "__commonJSMin", "exports", "module", "isNegativeZero", "isnan", "dsortins", "N", "order", "x", "stride", "flg", "ix", "jx", "fx", "lx", "v", "u", "i", "require_ndarray", "__commonJSMin", "exports", "module", "isNegativeZero", "isnan", "dsortins", "N", "order", "x", "stride", "offset", "flg", "ix", "jx", "fx", "lx", "v", "i", "require_main", "__commonJSMin", "exports", "module", "setReadOnly", "dsortins", "ndarray", "join", "tryRequire", "isError", "main", "dsortins", "tmp"]
3
+ "sources": ["../lib/ndarray.js", "../lib/dsortins.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 isNegativeZero = require( '@stdlib/math-base-assert-is-negative-zero' );\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\n\n\n// MAIN //\n\n/**\n* Sorts a double-precision floating-point strided array using insertion sort.\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* dsortins( x.length, 1.0, x, 1, 0 );\n* // x => <Float64Array>[ -4.0, -2.0, 1.0, 3.0 ]\n*/\nfunction dsortins( N, order, x, strideX, offsetX ) {\n\tvar flg;\n\tvar ix;\n\tvar jx;\n\tvar fx;\n\tvar lx;\n\tvar v;\n\tvar u;\n\tvar i;\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\tfx = offsetX; // first index\n\tlx = fx + ((N-1)*strideX); // last index\n\tix = fx + strideX;\n\n\tif ( strideX < 0 ) {\n\t\t// Traverse the strided array from right-to-left...\n\n\t\t// Sort in increasing order...\n\t\tfor ( i = 1; i < N; i++ ) {\n\t\t\tv = x[ ix ];\n\n\t\t\t// Sort `NaN` values to the end (i.e., the left)...\n\t\t\tif ( isnan( v ) ) {\n\t\t\t\tjx = ix;\n\n\t\t\t\t// Shift all values (including NaNs) to the left of the current element to the right...\n\t\t\t\twhile ( jx > lx ) {\n\t\t\t\t\tx[ jx ] = x[ jx+strideX ];\n\t\t\t\t\tjx += strideX;\n\t\t\t\t}\n\t\t\t\tx[ lx ] = v;\n\t\t\t} else {\n\t\t\t\tflg = isNegativeZero( v );\n\t\t\t\tjx = ix - strideX;\n\n\t\t\t\t// Shift all larger values to the right of the current element to the left...\n\t\t\t\twhile ( jx <= fx ) {\n\t\t\t\t\tu = x[ jx ];\n\t\t\t\t\tif ( u <= v && !(flg && u === v && isNegativeZero( u ) === false) ) { // eslint-disable-line max-len\n\t\t\t\t\t\t// Note: positive zeros (and NaNs (e.g., when last element is NaN)) are sorted to the left\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tx[ jx+strideX ] = u;\n\t\t\t\t\tjx -= strideX;\n\t\t\t\t}\n\t\t\t\tx[ jx+strideX ] = v;\n\t\t\t\tix += strideX;\n\t\t\t}\n\t\t}\n\t\treturn x;\n\t}\n\t// Traverse the strided array from left-to-right...\n\n\t// Sort in increasing order...\n\tfor ( i = 1; i < N; i++ ) {\n\t\tv = x[ ix ];\n\n\t\t// Sort `NaN` values to the end...\n\t\tif ( isnan( v ) ) {\n\t\t\tjx = ix;\n\n\t\t\t// Shift all values (including NaNs) to the right of the current element to the left...\n\t\t\twhile ( jx < lx ) {\n\t\t\t\tx[ jx ] = x[ jx+strideX ];\n\t\t\t\tjx += strideX;\n\t\t\t}\n\t\t\tx[ lx ] = v;\n\t\t} else {\n\t\t\tflg = isNegativeZero( v );\n\t\t\tjx = ix - strideX;\n\n\t\t\t// Shift all larger values to the left of the current element to the right...\n\t\t\twhile ( jx >= fx ) {\n\t\t\t\tu = x[ jx ];\n\t\t\t\tif ( u <= v && !(flg && u === v && isNegativeZero( u ) === false) ) { // eslint-disable-line max-len\n\t\t\t\t\t// Note: positive zeros (and NaNs (e.g., when first element is NaN)) are sorted to the right\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tx[ jx+strideX ] = u;\n\t\t\t\tjx -= strideX;\n\t\t\t}\n\t\t\tx[ jx+strideX ] = v;\n\t\t\tix += strideX;\n\t\t}\n\t}\n\treturn x;\n}\n\n\n// EXPORTS //\n\nmodule.exports = dsortins;\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 insertion sort.\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* dsortins( x.length, 1.0, x, 1 );\n* // x => <Float64Array>[ -4.0, -2.0, 1.0, 3.0 ]\n*/\nfunction dsortins( N, order, x, strideX ) {\n\treturn ndarray( N, order, x, strideX, stride2offset( N, strideX ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = dsortins;\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 dsortins = require( './dsortins.js' );\nvar ndarray = require( './ndarray.js' );\n\n\n// MAIN //\n\nsetReadOnly( dsortins, 'ndarray', ndarray );\n\n\n// EXPORTS //\n\nmodule.exports = dsortins;\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 insertion sort.\n*\n* @module @stdlib/blas-ext-base-dsortins\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var dsortins = require( '@stdlib/blas-ext-base-dsortins' );\n*\n* var x = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] );\n*\n* dsortins( 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 dsortins = require( '@stdlib/blas-ext-base-dsortins' );\n*\n* var x = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] );\n*\n* dsortins.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 dsortins;\nvar tmp = tryRequire( join( __dirname, './native.js' ) );\nif ( isError( tmp ) ) {\n\tdsortins = main;\n} else {\n\tdsortins = tmp;\n}\n\n\n// EXPORTS //\n\nmodule.exports = dsortins;\n\n// exports: { \"ndarray\": \"dsortins.ndarray\" }\n"],
5
+ "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAiB,QAAS,2CAA4C,EACtEC,EAAQ,QAAS,iCAAkC,EAuBvD,SAASC,EAAUC,EAAGC,EAAOC,EAAGC,EAASC,EAAU,CAClD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAKZ,GAAK,GAAKC,IAAU,EACxB,OAAOC,EAWR,GARKD,EAAQ,IACZE,GAAW,GACXC,IAAYJ,EAAE,GAAKG,GAEpBK,EAAKJ,EACLK,EAAKD,GAAOR,EAAE,GAAGG,EACjBG,EAAKE,EAAKL,EAELA,EAAU,EAAI,CAIlB,IAAMS,EAAI,EAAGA,EAAIZ,EAAGY,IAInB,GAHAF,EAAIR,EAAGI,CAAG,EAGLR,EAAOY,CAAE,EAAI,CAIjB,IAHAH,EAAKD,EAGGC,EAAKE,GACZP,EAAGK,CAAG,EAAIL,EAAGK,EAAGJ,CAAQ,EACxBI,GAAMJ,EAEPD,EAAGO,CAAG,EAAIC,CACX,KAAO,CAKN,IAJAL,EAAMR,EAAgBa,CAAE,EACxBH,EAAKD,EAAKH,EAGFI,GAAMC,IACbG,EAAIT,EAAGK,CAAG,EACL,EAAAI,GAAKD,GAAK,EAAEL,GAAOM,IAAMD,GAAKb,EAAgBc,CAAE,IAAM,OAI3DT,EAAGK,EAAGJ,CAAQ,EAAIQ,EAClBJ,GAAMJ,EAEPD,EAAGK,EAAGJ,CAAQ,EAAIO,EAClBJ,GAAMH,CACP,CAED,OAAOD,CACR,CAIA,IAAMU,EAAI,EAAGA,EAAIZ,EAAGY,IAInB,GAHAF,EAAIR,EAAGI,CAAG,EAGLR,EAAOY,CAAE,EAAI,CAIjB,IAHAH,EAAKD,EAGGC,EAAKE,GACZP,EAAGK,CAAG,EAAIL,EAAGK,EAAGJ,CAAQ,EACxBI,GAAMJ,EAEPD,EAAGO,CAAG,EAAIC,CACX,KAAO,CAKN,IAJAL,EAAMR,EAAgBa,CAAE,EACxBH,EAAKD,EAAKH,EAGFI,GAAMC,IACbG,EAAIT,EAAGK,CAAG,EACL,EAAAI,GAAKD,GAAK,EAAEL,GAAOM,IAAMD,GAAKb,EAAgBc,CAAE,IAAM,OAI3DT,EAAGK,EAAGJ,CAAQ,EAAIQ,EAClBJ,GAAMJ,EAEPD,EAAGK,EAAGJ,CAAQ,EAAIO,EAClBJ,GAAMH,CACP,CAED,OAAOD,CACR,CAKAN,EAAO,QAAUG,ICjJjB,IAAAc,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,oCAAqC,EAC9DC,EAAU,IAsBd,SAASC,EAAUC,EAAGC,EAAOC,EAAGC,EAAU,CACzC,OAAOL,EAASE,EAAGC,EAAOC,EAAGC,EAASN,EAAeG,EAAGG,CAAQ,CAAE,CACnE,CAKAP,EAAO,QAAUG,ICpDjB,IAAAK,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAW,IACXC,EAAU,IAKdF,EAAaC,EAAU,UAAWC,CAAQ,EAK1CH,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,EAAWD,EAEXC,EAAWC,EAMZ,OAAO,QAAUD",
6
+ "names": ["require_ndarray", "__commonJSMin", "exports", "module", "isNegativeZero", "isnan", "dsortins", "N", "order", "x", "strideX", "offsetX", "flg", "ix", "jx", "fx", "lx", "v", "u", "i", "require_dsortins", "__commonJSMin", "exports", "module", "stride2offset", "ndarray", "dsortins", "N", "order", "x", "strideX", "require_main", "__commonJSMin", "exports", "module", "setReadOnly", "dsortins", "ndarray", "join", "tryRequire", "isError", "main", "dsortins", "tmp"]
7
7
  }
@@ -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 stride - stride length
31
+ * @param strideX - stride length
32
32
  * @returns `x`
33
33
  *
34
34
  * @example
@@ -39,7 +39,7 @@ interface Routine {
39
39
  * dsortins( 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, stride: number ): 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 insertion sort 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 stride - stride length
51
- * @param offset - starting index
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
  * dsortins.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, stride: number, offset: number ): 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 stride - stride length
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_DSORTINS_H
23
20
  #define STDLIB_BLAS_EXT_BASE_DSORTINS_H
24
21
 
25
- #include <stdint.h>
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 insertion sort.
36
33
  */
37
- void c_dsortins( const int64_t N, const double order, double *X, const int64_t stride );
34
+ void API_SUFFIX(stdlib_strided_dsortins)( 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 insertion sort and alternative indexing semantics.
38
+ */
39
+ void API_SUFFIX(stdlib_strided_dsortins_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/dsortins.js CHANGED
@@ -20,8 +20,8 @@
20
20
 
21
21
  // MODULES //
22
22
 
23
- var isNegativeZero = require( '@stdlib/math-base-assert-is-negative-zero' );
24
- var isnan = require( '@stdlib/math-base-assert-is-nan' );
23
+ var stride2offset = require( '@stdlib/strided-base-stride2offset' );
24
+ var ndarray = require( './ndarray.js' );
25
25
 
26
26
 
27
27
  // MAIN //
@@ -32,7 +32,7 @@ var isnan = require( '@stdlib/math-base-assert-is-nan' );
32
32
  * @param {PositiveInteger} N - number of indexed elements
33
33
  * @param {number} order - sort order
34
34
  * @param {Float64Array} x - input array
35
- * @param {integer} stride - index increment
35
+ * @param {integer} strideX - stride length
36
36
  * @returns {Float64Array} input array
37
37
  *
38
38
  * @example
@@ -43,101 +43,8 @@ var isnan = require( '@stdlib/math-base-assert-is-nan' );
43
43
  * dsortins( x.length, 1.0, x, 1 );
44
44
  * // x => <Float64Array>[ -4.0, -2.0, 1.0, 3.0 ]
45
45
  */
46
- function dsortins( N, order, x, stride ) {
47
- var flg;
48
- var ix;
49
- var jx;
50
- var fx;
51
- var lx;
52
- var v;
53
- var u;
54
- var i;
55
-
56
- if ( N <= 0 || order === 0.0 ) {
57
- return x;
58
- }
59
- // 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...
60
- if ( order < 0.0 ) {
61
- stride *= -1;
62
- }
63
- if ( stride < 0 ) {
64
- // Traverse the strided array from right-to-left...
65
- fx = (1-N) * stride; // first index
66
- lx = 0; // last index
67
- ix = fx + stride;
68
-
69
- // Sort in increasing order...
70
- for ( i = 1; i < N; i++ ) {
71
- v = x[ ix ];
72
-
73
- // Sort `NaN` values to the end (i.e., the left)...
74
- if ( isnan( v ) ) {
75
- jx = ix;
76
-
77
- // Shift all values (including NaNs) to the left of the current element to the right...
78
- while ( jx > lx ) {
79
- x[ jx ] = x[ jx+stride ];
80
- jx += stride;
81
- }
82
- x[ lx ] = v;
83
- } else {
84
- flg = isNegativeZero( v );
85
- jx = ix - stride;
86
-
87
- // Shift all larger values to the right of the current element to the left...
88
- while ( jx <= fx ) {
89
- u = x[ jx ];
90
- if ( u <= v && !(flg && u === v && isNegativeZero( u ) === false) ) { // eslint-disable-line max-len
91
- // Note: positive zeros (and NaNs (e.g., when last element is NaN)) are sorted to the left
92
- break;
93
- }
94
- x[ jx+stride ] = u;
95
- jx -= stride;
96
- }
97
- x[ jx+stride ] = v;
98
- ix += stride;
99
- }
100
- }
101
- return x;
102
- }
103
- // Traverse the strided array from left-to-right...
104
- fx = 0; // first index
105
- lx = (N-1) * stride; // last index
106
- ix = fx + stride;
107
-
108
- // Sort in increasing order...
109
- for ( i = 1; i < N; i++ ) {
110
- v = x[ ix ];
111
-
112
- // Sort `NaN` values to the end...
113
- if ( isnan( v ) ) {
114
- jx = ix;
115
-
116
- // Shift all values (including NaNs) to the right of the current element to the left...
117
- while ( jx < lx ) {
118
- x[ jx ] = x[ jx+stride ];
119
- jx += stride;
120
- }
121
- x[ lx ] = v;
122
- } else {
123
- flg = isNegativeZero( v );
124
- jx = ix - stride;
125
-
126
- // Shift all larger values to the left of the current element to the right...
127
- while ( jx >= fx ) {
128
- u = x[ jx ];
129
- if ( u <= v && !(flg && u === v && isNegativeZero( u ) === false) ) { // eslint-disable-line max-len
130
- // Note: positive zeros (and NaNs (e.g., when first element is NaN)) are sorted to the right
131
- break;
132
- }
133
- x[ jx+stride ] = u;
134
- jx -= stride;
135
- }
136
- x[ jx+stride ] = v;
137
- ix += stride;
138
- }
139
- }
140
- return x;
46
+ function dsortins( N, order, x, strideX ) {
47
+ return ndarray( N, order, x, strideX, stride2offset( N, strideX ) );
141
48
  }
142
49
 
143
50
 
@@ -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} stride - index increment
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
  * dsortins( x.length, 1.0, x, 1 );
43
43
  * // x => <Float64Array>[ -4.0, -2.0, 1.0, 3.0 ]
44
44
  */
45
- function dsortins( N, order, x, stride ) {
46
- addon( N, order, x, stride );
45
+ function dsortins( N, order, x, strideX ) {
46
+ addon( N, order, x, strideX );
47
47
  return x;
48
48
  }
49
49
 
package/lib/ndarray.js CHANGED
@@ -32,8 +32,8 @@ var isnan = require( '@stdlib/math-base-assert-is-nan' );
32
32
  * @param {PositiveInteger} N - number of indexed elements
33
33
  * @param {number} order - sort order
34
34
  * @param {Float64Array} x - input array
35
- * @param {integer} stride - index increment
36
- * @param {NonNegativeInteger} offset - starting index
35
+ * @param {integer} strideX - stride length
36
+ * @param {NonNegativeInteger} offsetX - starting index
37
37
  * @returns {Float64Array} input array
38
38
  *
39
39
  * @example
@@ -44,7 +44,7 @@ var isnan = require( '@stdlib/math-base-assert-is-nan' );
44
44
  * dsortins( x.length, 1.0, x, 1, 0 );
45
45
  * // x => <Float64Array>[ -4.0, -2.0, 1.0, 3.0 ]
46
46
  */
47
- function dsortins( N, order, x, stride, offset ) {
47
+ function dsortins( N, order, x, strideX, offsetX ) {
48
48
  var flg;
49
49
  var ix;
50
50
  var jx;
@@ -59,14 +59,14 @@ function dsortins( N, order, x, stride, offset ) {
59
59
  }
60
60
  // 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...
61
61
  if ( order < 0.0 ) {
62
- stride *= -1;
63
- offset -= (N-1) * stride;
62
+ strideX *= -1;
63
+ offsetX -= (N-1) * strideX;
64
64
  }
65
- fx = offset; // first index
66
- lx = fx + ((N-1)*stride); // last index
67
- ix = fx + stride;
65
+ fx = offsetX; // first index
66
+ lx = fx + ((N-1)*strideX); // last index
67
+ ix = fx + strideX;
68
68
 
69
- if ( stride < 0 ) {
69
+ if ( strideX < 0 ) {
70
70
  // Traverse the strided array from right-to-left...
71
71
 
72
72
  // Sort in increasing order...
@@ -79,13 +79,13 @@ function dsortins( N, order, x, stride, offset ) {
79
79
 
80
80
  // Shift all values (including NaNs) to the left of the current element to the right...
81
81
  while ( jx > lx ) {
82
- x[ jx ] = x[ jx+stride ];
83
- jx += stride;
82
+ x[ jx ] = x[ jx+strideX ];
83
+ jx += strideX;
84
84
  }
85
85
  x[ lx ] = v;
86
86
  } else {
87
87
  flg = isNegativeZero( v );
88
- jx = ix - stride;
88
+ jx = ix - strideX;
89
89
 
90
90
  // Shift all larger values to the right of the current element to the left...
91
91
  while ( jx <= fx ) {
@@ -94,11 +94,11 @@ function dsortins( N, order, x, stride, offset ) {
94
94
  // Note: positive zeros (and NaNs (e.g., when last element is NaN)) are sorted to the left
95
95
  break;
96
96
  }
97
- x[ jx+stride ] = u;
98
- jx -= stride;
97
+ x[ jx+strideX ] = u;
98
+ jx -= strideX;
99
99
  }
100
- x[ jx+stride ] = v;
101
- ix += stride;
100
+ x[ jx+strideX ] = v;
101
+ ix += strideX;
102
102
  }
103
103
  }
104
104
  return x;
@@ -115,13 +115,13 @@ function dsortins( N, order, x, stride, offset ) {
115
115
 
116
116
  // Shift all values (including NaNs) to the right of the current element to the left...
117
117
  while ( jx < lx ) {
118
- x[ jx ] = x[ jx+stride ];
119
- jx += stride;
118
+ x[ jx ] = x[ jx+strideX ];
119
+ jx += strideX;
120
120
  }
121
121
  x[ lx ] = v;
122
122
  } else {
123
123
  flg = isNegativeZero( v );
124
- jx = ix - stride;
124
+ jx = ix - strideX;
125
125
 
126
126
  // Shift all larger values to the left of the current element to the right...
127
127
  while ( jx >= fx ) {
@@ -130,11 +130,11 @@ function dsortins( N, order, x, stride, offset ) {
130
130
  // Note: positive zeros (and NaNs (e.g., when first element is NaN)) are sorted to the right
131
131
  break;
132
132
  }
133
- x[ jx+stride ] = u;
134
- jx -= stride;
133
+ x[ jx+strideX ] = u;
134
+ jx -= strideX;
135
135
  }
136
- x[ jx+stride ] = v;
137
- ix += stride;
136
+ x[ jx+strideX ] = v;
137
+ ix += strideX;
138
138
  }
139
139
  }
140
140
  return x;
@@ -20,8 +20,7 @@
20
20
 
21
21
  // MODULES //
22
22
 
23
- var Float64Array = require( '@stdlib/array-float64' );
24
- var addon = require( './dsortins.native.js' );
23
+ var addon = require( './../src/addon.node' );
25
24
 
26
25
 
27
26
  // MAIN //
@@ -32,8 +31,8 @@ var addon = require( './dsortins.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} stride - index increment
36
- * @param {NonNegativeInteger} offset - starting index
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( './dsortins.native.js' );
43
42
  *
44
43
  * dsortins( x.length, 1.0, x, 1, 0 );
45
44
  */
46
- function dsortins( N, order, x, stride, offset ) {
47
- var view;
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 dsortins( 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
- "options": {},
3
- "fields": [
4
- {
5
- "field": "src",
6
- "resolve": true,
7
- "relative": true
8
- },
9
- {
10
- "field": "include",
11
- "resolve": true,
12
- "relative": true
13
- },
14
- {
15
- "field": "libraries",
16
- "resolve": false,
17
- "relative": false
18
- },
19
- {
20
- "field": "libpath",
21
- "resolve": true,
22
- "relative": false
23
- }
24
- ],
25
- "confs": [
26
- {
27
- "src": [
28
- "./src/dsortins.c"
29
- ],
30
- "include": [
31
- "./include"
32
- ],
33
- "libraries": [
34
- "-lm"
35
- ],
36
- "libpath": [],
37
- "dependencies": [
38
- "@stdlib/math-base-assert-is-nan",
39
- "@stdlib/math-base-assert-is-negative-zero"
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-argv-double",
40
+ "@stdlib/napi-argv-int64",
41
+ "@stdlib/napi-export",
42
+ "@stdlib/napi-argv",
43
+ "@stdlib/napi-argv-strided-float64array",
44
+ "@stdlib/math-base-assert-is-nan",
45
+ "@stdlib/math-base-assert-is-negative-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-negative-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-negative-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-dsortins",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "Sort a double-precision floating-point strided array using insertion sort.",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -34,12 +34,19 @@
34
34
  "url": "https://github.com/stdlib-js/stdlib/issues"
35
35
  },
36
36
  "dependencies": {
37
- "@stdlib/assert-is-error": "^0.2.1",
38
- "@stdlib/math-base-assert-is-nan": "^0.2.1",
39
- "@stdlib/math-base-assert-is-negative-zero": "^0.2.1",
40
- "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1",
41
- "@stdlib/utils-library-manifest": "^0.2.1",
42
- "@stdlib/utils-try-require": "^0.2.1"
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-negative-zero": "^0.2.2",
41
+ "@stdlib/napi-argv": "^0.2.2",
42
+ "@stdlib/napi-argv-double": "^0.2.1",
43
+ "@stdlib/napi-argv-int64": "^0.2.2",
44
+ "@stdlib/napi-argv-strided-float64array": "^0.2.2",
45
+ "@stdlib/napi-export": "^0.3.0",
46
+ "@stdlib/strided-base-stride2offset": "^0.1.0",
47
+ "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2",
48
+ "@stdlib/utils-library-manifest": "^0.2.3",
49
+ "@stdlib/utils-try-require": "^0.2.2"
43
50
  },
44
51
  "devDependencies": {},
45
52
  "engines": {
@@ -76,7 +83,6 @@
76
83
  "double",
77
84
  "float64array"
78
85
  ],
79
- "__stdlib__": {},
80
86
  "funding": {
81
87
  "type": "opencollective",
82
88
  "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/dsortins.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_dsortins)( 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_dsortins_ndarray)( N, order, X, strideX, offsetX );
59
+ return NULL;
60
+ }
61
+
62
+ STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method );
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @license Apache-2.0
3
3
  *
4
- * Copyright (c) 2020 The Stdlib Authors.
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,7 +19,8 @@
19
19
  #include "stdlib/blas/ext/base/dsortins.h"
20
20
  #include "stdlib/math/base/assert/is_negative_zero.h"
21
21
  #include "stdlib/math/base/assert/is_nan.h"
22
- #include <stdint.h>
22
+ #include "stdlib/blas/base/shared.h"
23
+ #include "stdlib/strided/base/stride2offset.h"
23
24
  #include <stdbool.h>
24
25
 
25
26
  /**
@@ -28,15 +29,30 @@
28
29
  * @param N number of indexed elements
29
30
  * @param order sort order
30
31
  * @param X input array
31
- * @param stride index increment
32
+ * @param strideX index increment
32
33
  */
33
- void c_dsortins( const int64_t N, const double order, double *X, const int64_t stride ) {
34
- int64_t ix;
35
- int64_t jx;
36
- int64_t fx;
37
- int64_t lx;
38
- int64_t sx;
39
- int64_t i;
34
+ void API_SUFFIX(stdlib_strided_dsortins)( const CBLAS_INT N, const double order, double *X, const CBLAS_INT strideX ) {
35
+ CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX );
36
+ API_SUFFIX(stdlib_strided_dsortins_ndarray)( N, order, X, strideX, ox );
37
+ }
38
+
39
+ /**
40
+ * Sorts a double-precision floating-point strided array using insertion sort and alternative indexing semantics.
41
+ *
42
+ * @param N number of indexed elements
43
+ * @param order sort order
44
+ * @param X input array
45
+ * @param strideX index increment
46
+ * @param offsetX starting index
47
+ */
48
+ void API_SUFFIX(stdlib_strided_dsortins_ndarray)( const CBLAS_INT N, const double order, double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) {
49
+ CBLAS_INT ix;
50
+ CBLAS_INT jx;
51
+ CBLAS_INT fx;
52
+ CBLAS_INT lx;
53
+ CBLAS_INT sx;
54
+ CBLAS_INT ox;
55
+ CBLAS_INT i;
40
56
  double v;
41
57
  double u;
42
58
  bool flg;
@@ -46,15 +62,17 @@ void c_dsortins( const int64_t N, const double order, double *X, const int64_t s
46
62
  }
47
63
  // 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...
48
64
  if ( order < 0.0 ) {
49
- sx = -stride;
65
+ sx = -strideX;
66
+ ox = offsetX - ( (N-1) * sx );
50
67
  } else {
51
- sx = stride;
68
+ sx = strideX;
69
+ ox = offsetX;
52
70
  }
71
+ fx = ox;
72
+ lx = fx + ( (N-1) * sx );
73
+ ix = fx + sx;
53
74
  if ( sx < 0 ) {
54
75
  // Traverse the strided array from right-to-left...
55
- fx = (1-N) * sx; // first index
56
- lx = 0; // last index
57
- ix = fx + sx;
58
76
 
59
77
  // Sort in increasing order...
60
78
  for ( i = 1; i < N; i++ ) {
@@ -90,9 +108,6 @@ void c_dsortins( const int64_t N, const double order, double *X, const int64_t s
90
108
  return;
91
109
  }
92
110
  // Traverse the strided array from left-to-right...
93
- fx = 0; // first index
94
- lx = (N-1) * sx; // last index
95
- ix = fx + sx;
96
111
 
97
112
  // Sort in increasing order...
98
113
  for ( i = 1; i < N; i++ ) {
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/dsortins.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_dsortins {
30
-
31
- /**
32
- * Sorts a double-precision floating-point strided array using insertion sort.
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_dsortins( 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_dsortins( 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_dsortins, 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_dsortins