Skip to content

Commit c1552d8

Browse files
refactor: update blas/ext/base/ssort2hp to follow current project conventions
PR-URL: #2960 Closes: #1534 Co-authored-by: Philipp Burckhardt <[email protected]> Reviewed-by: Philipp Burckhardt <[email protected]>
1 parent 46662f2 commit c1552d8

File tree

9 files changed

+135
-236
lines changed

9 files changed

+135
-236
lines changed

lib/node_modules/@stdlib/blas/ext/base/ssort2hp/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 [`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' );
6665

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

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

7371
console.log( x );
7472
// => <Float32Array>[ 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 Float32Array = require( '@stdlib/array/float32' );
84-
var floor = require( '@stdlib/math/base/special/floor' );
8582

8683
// Initial arrays...
8784
var x0 = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] );
@@ -90,10 +87,9 @@ var y0 = new Float32Array( [ 0.0, 1.0, 2.0, 3.0 ] );
9087
// Create offset views...
9188
var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
9289
var y1 = new Float32Array( 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-
ssort2hp( N, -1.0, x1, 2, y1, 2 );
92+
ssort2hp( 2, -1.0, x1, 2, y1, 2 );
9793

9894
console.log( x0 );
9995
// => <Float32Array>[ 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 Float32Array = require( '@stdlib/array/float32' );
@@ -176,12 +172,10 @@ var ssort2hp = require( '@stdlib/blas/ext/base/ssort2hp' );
176172

177173
var rand;
178174
var sign;
179-
var x;
180-
var y;
181175
var i;
182176

183-
x = new Float32Array( 10 );
184-
y = new Float32Array( 10 ); // index array
177+
var x = new Float32Array( 10 );
178+
var y = new Float32Array( 10 ); // index array
185179
for ( i = 0; i < x.length; i++ ) {
186180
rand = round( randu()*100.0 );
187181
sign = randu();

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

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
Simultaneously sorts two single-precision floating-point strided arrays
44
based on the sort order of the first array using heapsort.
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.
@@ -52,7 +52,7 @@
5252
Returns
5353
-------
5454
x: Float32Array
55-
Input array `x`.
55+
Input array.
5656

5757
Examples
5858
--------
@@ -67,8 +67,7 @@
6767
// Using `N` and `stride` parameters:
6868
> x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, -4.0 ] );
6969
> y = new {{alias:@stdlib/array/float32}}( [ 0.0, 1.0, 2.0, 3.0 ] );
70-
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
71-
> {{alias}}( N, -1, x, 2, y, 2 )
70+
> {{alias}}( 2, -1, x, 2, y, 2 )
7271
<Float32Array>[ 3.0, -2.0, 1.0, -4.0 ]
7372
> y
7473
<Float32Array>[ 2.0, 1.0, 0.0, 3.0 ]
@@ -78,21 +77,21 @@
7877
> var x1 = new {{alias:@stdlib/array/float32}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 );
7978
> var y0 = new {{alias:@stdlib/array/float32}}( [ 0.0, 1.0, 2.0, 3.0 ] );
8079
> var y1 = new {{alias:@stdlib/array/float32}}( y0.buffer, y0.BYTES_PER_ELEMENT*1 );
81-
> N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 );
82-
> {{alias}}( N, 1, x1, 2, y1, 2 )
80+
> {{alias}}( 2, 1, x1, 2, y1, 2 )
8381
<Float32Array>[ -4.0, 3.0, -2.0 ]
8482
> x0
8583
<Float32Array>[ 1.0, -4.0, 3.0, -2.0 ]
8684
> y0
8785
<Float32Array>[ 0.0, 3.0, 2.0, 1.0 ]
8886

87+
8988
{{alias}}.ndarray( N, order, x, strideX, offsetX, y, strideY, offsetY )
9089
Simultaneously sorts two single-precision floating-point strided arrays
9190
based on the sort order of the first array using heapsort and alternative
9291
indexing semantics.
9392

9493
While typed array views mandate a view offset based on the underlying
95-
buffer, the `offset` parameter supports indexing semantics based on a
94+
buffer, the offset parameter supports indexing semantics based on a
9695
starting index.
9796

9897
Parameters
@@ -125,7 +124,7 @@
125124
Returns
126125
-------
127126
x: Float32Array
128-
Input array `x`.
127+
Input array.
129128

130129
Examples
131130
--------
@@ -140,8 +139,7 @@
140139
// Using an index offset:
141140
> x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, -4.0 ] );
142141
> y = new {{alias:@stdlib/array/float32}}( [ 0.0, 1.0, 2.0, 3.0 ] );
143-
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
144-
> {{alias}}.ndarray( N, 1, x, 2, 1, y, 2, 1 )
142+
> {{alias}}.ndarray( 2, 1, x, 2, 1, y, 2, 1 )
145143
<Float32Array>[ 1.0, -4.0, 3.0, -2.0 ]
146144
> y
147145
<Float32Array>[ 0.0, 3.0, 2.0, 1.0 ]

lib/node_modules/@stdlib/blas/ext/base/ssort2hp/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/ssort2hp/examples/index.js

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

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

32-
x = new Float32Array( 10 );
33-
y = new Float32Array( 10 ); // index array
30+
var x = new Float32Array( 10 );
31+
var y = new Float32Array( 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/ssort2hp/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/ssort2hp.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-positive-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/ssort2hp.c"
32+
],
33+
"include": [
34+
"./include"
35+
],
36+
"libraries": [
37+
"-lm"
38+
],
39+
"libpath": [],
40+
"dependencies": [
41+
"@stdlib/math/base/assert/is-nanf",
42+
"@stdlib/math/base/assert/is-positive-zerof",
43+
"@stdlib/napi/export",
44+
"@stdlib/napi/argv",
45+
"@stdlib/napi/argv-float",
46+
"@stdlib/napi/argv-int64",
47+
"@stdlib/napi/argv-strided-float32array"
48+
]
49+
},
50+
{
51+
"task": "examples",
52+
"src": [
53+
"./src/ssort2hp.c"
54+
],
55+
"include": [
56+
"./include"
57+
],
58+
"libraries": [
59+
"-lm"
60+
],
61+
"libpath": [],
62+
"dependencies": [
63+
"@stdlib/math/base/assert/is-nanf",
64+
"@stdlib/math/base/assert/is-positive-zerof"
65+
]
66+
}
67+
]
4368
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,7 @@
7373
"single",
7474
"float32array"
7575
],
76-
"__stdlib__": {}
76+
"__stdlib__": {
77+
"wasm": false
78+
}
7779
}
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/ssort2hp.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_float.h"
24+
#include "stdlib/napi/argv_strided_float32array.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_FLOAT( 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_FLOAT32ARRAY( env, X, N, strideX, argv, 2 );
41+
STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, Y, N, strideY, argv, 4 );
42+
c_ssort2hp( N, order, X, strideX, Y, strideY );
43+
return NULL;
44+
}
45+
46+
STDLIB_NAPI_MODULE_EXPORT_FCN( addon )

0 commit comments

Comments
 (0)