Skip to content

Commit f1b1fce

Browse files
refactor: update blas/ext/ssort2ins to follow current project conventions
PR-URL: #1874 Closes: #1535 Ref: #1152 --------- Co-authored-by: Philipp Burckhardt <pburckhardt@outlook.com> Reviewed-by: Athan Reines <kgryte@gmail.com> Reviewed-by: Philipp Burckhardt <pburckhardt@outlook.com>
1 parent 6bcf620 commit f1b1fce

File tree

11 files changed

+167
-268
lines changed

11 files changed

+167
-268
lines changed

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

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,14 @@ The function has the following parameters:
5858
- **y**: second input [`Float32Array`][@stdlib/array/float32].
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 Float32Array = require( '@stdlib/array/float32' );
65-
var floor = require( '@stdlib/math/base/special/floor' );
66-
6765
var x = new Float32Array( [ 1.0, -2.0, 3.0, -4.0 ] );
6866
var y = new Float32Array( [ 0.0, 1.0, 2.0, 3.0 ] );
69-
var N = floor( x.length / 2 );
7067

71-
ssort2ins( N, -1.0, x, 2, y, 2 );
68+
ssort2ins( 2, -1.0, x, 2, y, 2 );
7269

7370
console.log( x );
7471
// => <Float32Array>[ 3.0, -2.0, 1.0, -4.0 ]
@@ -81,7 +78,6 @@ Note that indexing is relative to the first index. To introduce an offset, use [
8178

8279
```javascript
8380
var Float32Array = require( '@stdlib/array/float32' );
84-
var floor = require( '@stdlib/math/base/special/floor' );
8581

8682
// Initial arrays...
8783
var x0 = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] );
@@ -90,10 +86,9 @@ var y0 = new Float32Array( [ 0.0, 1.0, 2.0, 3.0 ] );
9086
// Create offset views...
9187
var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
9288
var y1 = new Float32Array( y0.buffer, y0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
93-
var N = floor( x0.length/2 );
9489

9590
// Sort every other element...
96-
ssort2ins( N, -1.0, x1, 2, y1, 2 );
91+
ssort2ins( 2, -1.0, x1, 2, y1, 2 );
9792

9893
console.log( x0 );
9994
// => <Float32Array>[ 1.0, 4.0, 3.0, 2.0 ]
@@ -104,7 +99,7 @@ console.log( y0 );
10499

105100
#### ssort2ins.ndarray( N, order, x, strideX, offsetX, y, strideY, offsetY )
106101

107-
Simultaneously sorts two single-precision floating-point strided arrays based on the sort order of the first array `x` using insertion sort and alternative indexing semantics.
102+
Simultaneously sorts two single-precision floating-point strided arrays based on the sort order of the first array the strided array using insertion sort and alternative indexing semantics.
108103

109104
```javascript
110105
var Float32Array = require( '@stdlib/array/float32' );
@@ -126,7 +121,7 @@ The function has the following additional parameters:
126121
- **offsetX**: `x` starting index.
127122
- **offsetY**: `y` starting index.
128123

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`
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`.
130125

131126
```javascript
132127
var Float32Array = require( '@stdlib/array/float32' );

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

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
Simultaneously sorts two single-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
7+
arrays are accessed at runtime.
88

99
Indexing is relative to the first index. To introduce an offset, use typed
1010
array views.
1111

12-
If `N <= 0` or `order == 0`, the function leaves `x` and `y` unchanged.
12+
If `N <= 0` or `order == 0`, the function leaves the strided arrays
13+
are unchanged.
1314

1415
The algorithm distinguishes between `-0` and `+0`. When sorted in increasing
1516
order, `-0` is sorted before `+0`. When sorted in decreasing order, `-0` is
@@ -57,7 +58,7 @@
5758
Returns
5859
-------
5960
x: Float32Array
60-
Input array `x`.
61+
First input array.
6162

6263
Examples
6364
--------
@@ -69,11 +70,10 @@
6970
> y
7071
<Float32Array>[ 3.0, 1.0, 0.0, 2.0 ]
7172

72-
// Using `N` and `stride` parameters:
73+
// Using `N` and stride parameters:
7374
> x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, -4.0 ] );
7475
> y = new {{alias:@stdlib/array/float32}}( [ 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 )
76+
> {{alias}}( 2, -1, x, 2, y, 2 )
7777
<Float32Array>[ 3.0, -2.0, 1.0, -4.0 ]
7878
> y
7979
<Float32Array>[ 2.0, 1.0, 0.0, 3.0 ]
@@ -83,21 +83,21 @@
8383
> var x1 = new {{alias:@stdlib/array/float32}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 );
8484
> var y0 = new {{alias:@stdlib/array/float32}}( [ 0.0, 1.0, 2.0, 3.0 ] );
8585
> var y1 = new {{alias:@stdlib/array/float32}}( 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 )
86+
> {{alias}}( 2, 1, x1, 2, y1, 2 )
8887
<Float32Array>[ -4.0, 3.0, -2.0 ]
8988
> x0
9089
<Float32Array>[ 1.0, -4.0, 3.0, -2.0 ]
9190
> y0
9291
<Float32Array>[ 0.0, 3.0, 2.0, 1.0 ]
9392

93+
9494
{{alias}}.ndarray( N, order, x, strideX, offsetX, y, strideY, offsetY )
9595
Simultaneously sorts two single-precision floating-point strided arrays
9696
based on the sort order of the first array using insertion sort and
9797
alternative indexing semantics.
9898

9999
While typed array views mandate a view offset based on the underlying
100-
buffer, the `offset` parameter supports indexing semantics based on a
100+
buffer, the offset parameter supports indexing semantics based on a
101101
starting index.
102102

103103
Parameters
@@ -130,7 +130,7 @@
130130
Returns
131131
-------
132132
x: Float32Array
133-
Input array `x`.
133+
First input array.
134134

135135
Examples
136136
--------
@@ -145,8 +145,7 @@
145145
// Using an index offset:
146146
> x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, -4.0 ] );
147147
> y = new {{alias:@stdlib/array/float32}}( [ 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 )
148+
> {{alias}}.ndarray( 2, 1, x, 2, 1, y, 2, 1 )
150149
<Float32Array>[ 1.0, -4.0, 3.0, -2.0 ]
151150
> y
152151
<Float32Array>[ 0.0, 3.0, 2.0, 1.0 ]

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ interface Routine {
3131
* @param strideX - `x` stride length
3232
* @param y - second input array
3333
* @param strideY - `y` stride length
34-
* @returns `x`
34+
* @returns first input array
3535
*
3636
* @example
3737
* var Float32Array = require( '@stdlib/array/float32' );
@@ -60,7 +60,7 @@ interface Routine {
6060
* @param y - second input array
6161
* @param strideY - `y` stride length
6262
* @param offsetY - `y` starting index
63-
* @returns `x`
63+
* @returns first input array
6464
*
6565
* @example
6666
* var Float32Array = require( '@stdlib/array/float32' );
@@ -88,7 +88,7 @@ interface Routine {
8888
* @param strideX - `x` stride length
8989
* @param y - second input array
9090
* @param strideY - `y` stride length
91-
* @returns `x`
91+
* @returns first input array
9292
*
9393
* @example
9494
* var Float32Array = require( '@stdlib/array/float32' );

lib/node_modules/@stdlib/blas/ext/base/ssort2ins/examples/c/example.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,4 @@ int main( void ) {
4141
printf( "y[ %i ] = %"PRId64"\n", i, (int64_t)y[ i ] );
4242
}
4343
}
44+

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

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,35 +18,14 @@
1818

1919
'use strict';
2020

21-
var round = require( '@stdlib/math/base/special/round' );
22-
var randu = require( '@stdlib/random/base/randu' );
23-
var Float32Array = require( '@stdlib/array/float32' );
21+
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory;
22+
var filledarrayBy = require( '@stdlib/array/filled-by' );
2423
var ssort2ins = require( './../lib' );
2524

26-
var rand;
27-
var sign;
28-
var x;
29-
var y;
30-
var i;
31-
32-
x = new Float32Array( 10 );
33-
y = new Float32Array( 10 ); // index array
34-
for ( i = 0; i < x.length; i++ ) {
35-
if ( randu() < 0.2 ) {
36-
x[ i ] = NaN;
37-
} else {
38-
rand = round( randu()*100.0 );
39-
sign = randu();
40-
if ( sign < 0.5 ) {
41-
sign = -1.0;
42-
} else {
43-
sign = 1.0;
44-
}
45-
x[ i ] = sign * rand;
46-
}
47-
y[ i ] = i;
48-
}
25+
var x = filledarrayBy( 10, 'float32', discreteUniform( 0, 100 ) );
4926
console.log( x );
27+
28+
var y = filledarrayBy( x.length, 'float32', discreteUniform( 0, 10 ) );
5029
console.log( y );
5130

5231
ssort2ins( x.length, -1.0, x, -1, y, -1 );

lib/node_modules/@stdlib/blas/ext/base/ssort2ins/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

lib/node_modules/@stdlib/blas/ext/base/ssort2ins/lib/ndarray.native.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020

2121
// MODULES //
2222

23-
var Float32Array = require( '@stdlib/array/float32' );
23+
var minViewBufferIndex = require( '@stdlib/strided/base/min-view-buffer-index' );
24+
var offsetView = require( '@stdlib/strided/base/offset-view' );
2425
var addon = require( './ssort2ins.native.js' );
2526

2627

@@ -56,20 +57,19 @@ var addon = require( './ssort2ins.native.js' );
5657
function ssort2ins( N, order, x, strideX, offsetX, y, strideY, offsetY ) {
5758
var viewX;
5859
var viewY;
59-
var flg;
60+
var flg = 1.0;
6061

61-
flg = 1.0;
62+
offsetX = minViewBufferIndex( N, strideX, offsetX );
63+
offsetY = minViewBufferIndex( N, strideY, offsetY );
6264
if ( strideX < 0 ) {
6365
flg *= -1.0; // reversing order
6466
order *= -1.0;
6567
strideX *= -1;
66-
offsetX -= (N-1) * strideX;
6768
}
68-
if ( strideY < 0 ) {
69-
offsetY += (N-1) * strideY;
70-
}
71-
viewX = new Float32Array( x.buffer, x.byteOffset+(x.BYTES_PER_ELEMENT*offsetX), x.length-offsetX ); // eslint-disable-line max-len
72-
viewY = new Float32Array( y.buffer, y.byteOffset+(y.BYTES_PER_ELEMENT*offsetY), y.length-offsetY ); // eslint-disable-line max-len
69+
70+
viewX = offsetView( x, offsetX );
71+
viewY = offsetView( y, offsetY );
72+
7373
addon( N, order, viewX, strideX, viewY, flg*strideY );
7474
return x;
7575
}
Lines changed: 80 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,82 @@
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/ssort2ins.c"
29-
],
30-
"include": [
31-
"./include"
32-
],
33-
"libraries": [
34-
"-lm"
35-
],
36-
"libpath": [],
37-
"dependencies": [
38-
"@stdlib/math/base/assert/is-nanf",
39-
"@stdlib/math/base/assert/is-negative-zerof"
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/ssort2ins.c"
32+
],
33+
"include": [
34+
"./include"
35+
],
36+
"libraries": [
37+
"-lm"
38+
],
39+
"libpath": [],
40+
"dependencies": [
41+
"@stdlib/napi/export",
42+
"@stdlib/napi/argv",
43+
"@stdlib/napi/argv-int64",
44+
"@stdlib/napi/argv-double",
45+
"@stdlib/napi/argv-strided-float32array",
46+
"@stdlib/math/base/assert/is-nanf",
47+
"@stdlib/math/base/assert/is-negative-zerof"
48+
]
49+
},
50+
{
51+
"task": "benchmark",
52+
"src": [
53+
"./src/ssort2ins.c"
54+
],
55+
"include": [
56+
"./include"
57+
],
58+
"libraries": [
59+
"-lm"
60+
],
61+
"libpath": [],
62+
"dependencies": []
63+
},
64+
{
65+
"task": "examples",
66+
"src": [
67+
"./src/ssort2ins.c"
68+
],
69+
"include": [
70+
"./include"
71+
],
72+
"libraries": [
73+
"-lm"
74+
],
75+
"libpath": [],
76+
"dependencies": [
77+
"@stdlib/math/base/assert/is-nanf",
78+
"@stdlib/math/base/assert/is-negative-zerof"
79+
]
80+
}
81+
]
4382
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,7 @@
7272
"single",
7373
"float32array"
7474
],
75-
"__stdlib__": {}
75+
"__stdlib__": {
76+
"wasm": false
77+
}
7678
}

0 commit comments

Comments
 (0)