@stdlib/blas-ext-base-dsortins 0.2.1 → 0.2.2

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/README.md CHANGED
@@ -77,12 +77,10 @@ The `N` and `stride` parameters determine which elements in `x` are accessed at
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,17 +88,15 @@ 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
 
@@ -159,27 +155,11 @@ 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 filledarrayBy = require( '@stdlib/array-filled-by' );
159
+ var uniform = require( '@stdlib/random-base-uniform' ).factory;
165
160
  var dsortins = require( '@stdlib/blas-ext-base-dsortins' );
166
161
 
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
- }
162
+ var x = filledarrayBy( 100, 'float64', uniform( -100.0, 100.0 ) );
183
163
  console.log( x );
184
164
 
185
165
  dsortins( x.length, -1.0, x, -1 );
@@ -245,8 +225,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
245
225
  [npm-image]: http://img.shields.io/npm/v/@stdlib/blas-ext-base-dsortins.svg
246
226
  [npm-url]: https://npmjs.org/package/@stdlib/blas-ext-base-dsortins
247
227
 
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
228
+ [test-image]: https://github.com/stdlib-js/blas-ext-base-dsortins/actions/workflows/test.yml/badge.svg?branch=v0.2.2
229
+ [test-url]: https://github.com/stdlib-js/blas-ext-base-dsortins/actions/workflows/test.yml?query=branch:v0.2.2
250
230
 
251
231
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/blas-ext-base-dsortins/main.svg
252
232
  [coverage-url]: https://codecov.io/github/stdlib-js/blas-ext-base-dsortins?branch=main
@@ -20,7 +20,7 @@
20
20
 
21
21
  // MODULES //
22
22
 
23
- var Float64Array = require( '@stdlib/array-float64' );
23
+ var offsetView = require( '@stdlib/strided-base-offset-view' );
24
24
  var addon = require( './dsortins.native.js' );
25
25
 
26
26
 
@@ -50,7 +50,7 @@ function dsortins( N, order, x, stride, offset ) {
50
50
  stride *= -1;
51
51
  offset -= (N-1) * stride;
52
52
  }
53
- view = new Float64Array( x.buffer, x.byteOffset+(x.BYTES_PER_ELEMENT*offset), x.length-offset ); // eslint-disable-line max-len
53
+ view = offsetView( x, offset );
54
54
  addon( N, order, view, stride );
55
55
  return x;
56
56
  }
package/manifest.json CHANGED
@@ -1,43 +1,68 @@
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/dsortins.c"
32
+ ],
33
+ "include": [
34
+ "./include"
35
+ ],
36
+ "libraries": [
37
+ "-lm"
38
+ ],
39
+ "libpath": [],
40
+ "dependencies": [
41
+ "@stdlib/math-base-assert-is-nan",
42
+ "@stdlib/math-base-assert-is-negative-zero",
43
+ "@stdlib/napi-argv",
44
+ "@stdlib/napi-argv-int64",
45
+ "@stdlib/napi-argv-double",
46
+ "@stdlib/napi-argv-strided-float64array",
47
+ "@stdlib/napi-export"
48
+ ]
49
+ },
50
+ {
51
+ "task": "examples",
52
+ "src": [
53
+ "./src/dsortins.c"
54
+ ],
55
+ "include": [
56
+ "./include"
57
+ ],
58
+ "libraries": [
59
+ "-lm"
60
+ ],
61
+ "libpath": [],
62
+ "dependencies": [
63
+ "@stdlib/math-base-assert-is-negative-zero",
64
+ "@stdlib/math-base-assert-is-nan"
65
+ ]
66
+ }
67
+ ]
43
68
  }
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.2.2",
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,17 @@
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/math-base-assert-is-nan": "^0.2.2",
39
+ "@stdlib/math-base-assert-is-negative-zero": "^0.2.2",
40
+ "@stdlib/napi-argv": "^0.2.2",
41
+ "@stdlib/napi-argv-double": "^0.2.1",
42
+ "@stdlib/napi-argv-int64": "^0.2.2",
43
+ "@stdlib/napi-argv-strided-float64array": "^0.2.2",
44
+ "@stdlib/napi-export": "^0.2.2",
45
+ "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2",
46
+ "@stdlib/utils-library-manifest": "^0.2.2",
47
+ "@stdlib/utils-try-require": "^0.2.2"
43
48
  },
44
49
  "devDependencies": {},
45
50
  "engines": {
package/src/addon.c ADDED
@@ -0,0 +1,45 @@
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, order, argv, 2 );
40
+
41
+ c_dsortins( N, order, X, strideX );
42
+ return NULL;
43
+ }
44
+
45
+ STDLIB_NAPI_MODULE_EXPORT_FCN( addon )
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