Skip to content

Commit cf62100

Browse files
refactor: update blas/ext/base/dsort2ins to follow current project conventions
PR-URL: #2961 Closes: #1496 Co-authored-by: Philipp Burckhardt <[email protected]> Reviewed-by: Philipp Burckhardt <[email protected]>
1 parent c1552d8 commit cf62100

File tree

9 files changed

+134
-235
lines changed

9 files changed

+134
-235
lines changed

lib/node_modules/@stdlib/blas/ext/base/dsort2ins/README.md

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,15 @@ The function has the following parameters:
5858
- **y**: second input [`Float64Array`][@stdlib/array/float64].
5959
- **strideY**: `y` index increment.
6060

61-
The `N` and `stride` parameters determine which elements in `x` and `y` are accessed at runtime. For example, to sort every other element
61+
The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to sort every other element
6262

6363
```javascript
6464
var Float64Array = require( '@stdlib/array/float64' );
65-
var floor = require( '@stdlib/math/base/special/floor' );
6665

6766
var x = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] );
6867
var y = new Float64Array( [ 0.0, 1.0, 2.0, 3.0 ] );
69-
var N = floor( x.length / 2 );
7068

71-
dsort2ins( N, -1.0, x, 2, y, 2 );
69+
dsort2ins( 2, -1.0, x, 2, y, 2 );
7270

7371
console.log( x );
7472
// => <Float64Array>[ 3.0, -2.0, 1.0, -4.0 ]
@@ -81,7 +79,6 @@ Note that indexing is relative to the first index. To introduce an offset, use [
8179

8280
```javascript
8381
var Float64Array = require( '@stdlib/array/float64' );
84-
var floor = require( '@stdlib/math/base/special/floor' );
8582

8683
// Initial arrays...
8784
var x0 = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] );
@@ -90,10 +87,9 @@ var y0 = new Float64Array( [ 0.0, 1.0, 2.0, 3.0 ] );
9087
// Create offset views...
9188
var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
9289
var y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
93-
var N = floor( x0.length/2 );
9490

9591
// Sort every other element...
96-
dsort2ins( N, -1.0, x1, 2, y1, 2 );
92+
dsort2ins( 2, -1.0, x1, 2, y1, 2 );
9793

9894
console.log( x0 );
9995
// => <Float64Array>[ 1.0, 4.0, 3.0, 2.0 ]
@@ -126,7 +122,7 @@ The function has the following additional parameters:
126122
- **offsetX**: `x` starting index.
127123
- **offsetY**: `y` starting index.
128124

129-
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`
125+
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`
130126

131127
```javascript
132128
var Float64Array = require( '@stdlib/array/float64' );
@@ -177,12 +173,10 @@ var dsort2ins = require( '@stdlib/blas/ext/base/dsort2ins' );
177173

178174
var rand;
179175
var sign;
180-
var x;
181-
var y;
182176
var i;
183177

184-
x = new Float64Array( 10 );
185-
y = new Float64Array( 10 ); // index array
178+
var x = new Float64Array( 10 );
179+
var y = new Float64Array( 10 ); // index array
186180
for ( i = 0; i < x.length; i++ ) {
187181
rand = round( randu()*100.0 );
188182
sign = randu();

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
Simultaneously sorts two double-precision floating-point strided arrays
44
based on the sort order of the first array using insertion sort.
55

6-
The `N` and `stride` parameters determine which elements in `x` and `y` are
7-
accessed at runtime.
6+
The `N` and stride parameters determine which elements in the strided arrays
7+
are accessed at runtime.
88

99
Indexing is relative to the first index. To introduce an offset, use typed
1010
array views.
@@ -57,7 +57,7 @@
5757
Returns
5858
-------
5959
x: Float64Array
60-
Input array `x`.
60+
Input array.
6161

6262
Examples
6363
--------
@@ -69,11 +69,10 @@
6969
> y
7070
<Float64Array>[ 3.0, 1.0, 0.0, 2.0 ]
7171

72-
// Using `N` and `stride` parameters:
72+
// Using `N` and stride parameters:
7373
> x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, -4.0 ] );
7474
> y = new {{alias:@stdlib/array/float64}}( [ 0.0, 1.0, 2.0, 3.0 ] );
75-
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
76-
> {{alias}}( N, -1, x, 2, y, 2 )
75+
> {{alias}}( 2, -1, x, 2, y, 2 )
7776
<Float64Array>[ 3.0, -2.0, 1.0, -4.0 ]
7877
> y
7978
<Float64Array>[ 2.0, 1.0, 0.0, 3.0 ]
@@ -83,14 +82,14 @@
8382
> var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 );
8483
> var y0 = new {{alias:@stdlib/array/float64}}( [ 0.0, 1.0, 2.0, 3.0 ] );
8584
> var y1 = new {{alias:@stdlib/array/float64}}( y0.buffer, y0.BYTES_PER_ELEMENT*1 );
86-
> N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 );
87-
> {{alias}}( N, 1, x1, 2, y1, 2 )
85+
> {{alias}}( 2, 1, x1, 2, y1, 2 )
8886
<Float64Array>[ -4.0, 3.0, -2.0 ]
8987
> x0
9088
<Float64Array>[ 1.0, -4.0, 3.0, -2.0 ]
9189
> y0
9290
<Float64Array>[ 0.0, 3.0, 2.0, 1.0 ]
9391

92+
9493
{{alias}}.ndarray( N, order, x, strideX, offsetX, y, strideY, offsetY )
9594
Simultaneously sorts two double-precision floating-point strided arrays
9695
based on the sort order of the first array using insertion sort and
@@ -145,8 +144,7 @@
145144
// Using an index offset:
146145
> x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, -4.0 ] );
147146
> y = new {{alias:@stdlib/array/float64}}( [ 0.0, 1.0, 2.0, 3.0 ] );
148-
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
149-
> {{alias}}.ndarray( N, 1, x, 2, 1, y, 2, 1 )
147+
> {{alias}}.ndarray( 2, 1, x, 2, 1, y, 2, 1 )
150148
<Float64Array>[ 1.0, -4.0, 3.0, -2.0 ]
151149
> y
152150
<Float64Array>[ 0.0, 3.0, 2.0, 1.0 ]

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ interface Routine {
2828
* @param N - number of indexed elements
2929
* @param order - sort order
3030
* @param x - first input array
31-
* @param strideX - `x` stride length
31+
* @param strideX - first stride length
3232
* @param y - second input array
33-
* @param strideY - `y` stride length
33+
* @param strideY - second stride length
3434
* @returns `x`
3535
*
3636
* @example

lib/node_modules/@stdlib/blas/ext/base/dsort2ins/examples/index.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,10 @@ var dsort2ins = require( './../lib' );
2525

2626
var rand;
2727
var sign;
28-
var x;
29-
var y;
3028
var i;
3129

32-
x = new Float64Array( 10 );
33-
y = new Float64Array( 10 ); // index array
30+
var x = new Float64Array( 10 );
31+
var y = new Float64Array( 10 ); // index array
3432
for ( i = 0; i < x.length; i++ ) {
3533
if ( randu() < 0.2 ) {
3634
x[ i ] = NaN;

lib/node_modules/@stdlib/blas/ext/base/dsort2ins/include.gypi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
# Source files:
3838
'src_files': [
39-
'<(src_dir)/addon.cpp',
39+
'<(src_dir)/addon.c',
4040
'<!@(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 ] ); }")',
4141
],
4242

Lines changed: 66 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,68 @@
11
{
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/dsort2ins.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/dsort2ins.c"
32+
],
33+
"include": [
34+
"./include"
35+
],
36+
"libraries": [
37+
"-lm"
38+
],
39+
"libpath": [],
40+
"dependencies": [
41+
"@stdlib/math/base/assert/is-negative-zero",
42+
"@stdlib/math/base/assert/is-nan",
43+
"@stdlib/napi/export",
44+
"@stdlib/napi/argv",
45+
"@stdlib/napi/argv-double",
46+
"@stdlib/napi/argv-int64",
47+
"@stdlib/napi/argv-strided-float64array"
48+
]
49+
},
50+
{
51+
"task": "examples",
52+
"src": [
53+
"./src/dsort2ins.c"
54+
],
55+
"include": [
56+
"./include"
57+
],
58+
"libraries": [
59+
"-lm"
60+
],
61+
"libpath": [],
62+
"dependencies": [
63+
"@stdlib/math/base/assert/is-nan",
64+
"@stdlib/math/base/assert/is-negative-zero"
65+
]
66+
}
67+
]
4368
}

lib/node_modules/@stdlib/blas/ext/base/dsort2ins/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,7 @@
7171
"double",
7272
"float64array"
7373
],
74-
"__stdlib__": {}
74+
"__stdlib__": {
75+
"wasm": false
76+
}
7577
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2018 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/dsort2ins.h"
20+
#include "stdlib/napi/export.h"
21+
#include "stdlib/napi/argv.h"
22+
#include "stdlib/napi/argv_int64.h"
23+
#include "stdlib/napi/argv_double.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, 6 );
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_INT64( env, strideY, argv, 5 );
40+
STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 2 );
41+
STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, Y, N, strideY, argv, 4 );
42+
c_dsort2ins( N, order, X, strideX, Y, strideY );
43+
return NULL;
44+
}
45+
46+
STDLIB_NAPI_MODULE_EXPORT_FCN( addon )

0 commit comments

Comments
 (0)