Skip to content

Commit 0b47144

Browse files
refactor: update blas/ext/base/ssortins to follow current project conventions
PR-URL: #2917 Closes: #1538 --------- Co-authored-by: Philipp Burckhardt <[email protected]> Reviewed-by: Philipp Burckhardt <[email protected]>
1 parent d93e862 commit 0b47144

File tree

10 files changed

+156
-205
lines changed

10 files changed

+156
-205
lines changed

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

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,34 +50,30 @@ The function has the following parameters:
5050
- **x**: input [`Float32Array`][@stdlib/array/float32].
5151
- **stride**: index increment.
5252

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

5555
```javascript
5656
var Float32Array = require( '@stdlib/array/float32' );
57-
var floor = require( '@stdlib/math/base/special/floor' );
5857

5958
var x = new Float32Array( [ 1.0, -2.0, 3.0, -4.0 ] );
60-
var N = floor( x.length / 2 );
6159

62-
ssortins( N, -1.0, x, 2 );
60+
ssortins( 2, -1.0, x, 2 );
6361
// x => <Float32Array>[ 3.0, -2.0, 1.0, -4.0 ]
6462
```
6563

6664
Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views.
6765

6866
```javascript
6967
var Float32Array = require( '@stdlib/array/float32' );
70-
var floor = require( '@stdlib/math/base/special/floor' );
7168

7269
// Initial array...
7370
var x0 = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] );
7471

7572
// Create an offset view...
7673
var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
77-
var N = floor( x0.length/2 );
7874

7975
// Sort every other element...
80-
ssortins( N, -1.0, x1, 2 );
76+
ssortins( 2, -1.0, x1, 2 );
8177
// x0 => <Float32Array>[ 1.0, 4.0, 3.0, 2.0 ]
8278
```
8379

@@ -98,7 +94,7 @@ The function has the following additional parameters:
9894

9995
- **offset**: starting index.
10096

101-
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`
97+
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`
10298

10399
```javascript
104100
var Float32Array = require( '@stdlib/array/float32' );
@@ -143,10 +139,9 @@ var ssortins = require( '@stdlib/blas/ext/base/ssortins' );
143139

144140
var rand;
145141
var sign;
146-
var x;
147142
var i;
148143

149-
x = new Float32Array( 10 );
144+
var x = new Float32Array( 10 );
150145
for ( i = 0; i < x.length; i++ ) {
151146
rand = round( randu()*100.0 );
152147
sign = randu();

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

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
{{alias}}( N, order, x, stride )
33
Sorts a single-precision floating-point strided array using insertion sort.
44

5-
The `N` and `stride` parameters determine which elements in `x` are accessed
6-
at runtime.
5+
The `N` and stride parameters determine which elements in the strided array
6+
are accessed at runtime.
77

88
Indexing is relative to the first index. To introduce an offset, use typed
99
array views.
@@ -50,7 +50,7 @@
5050
Returns
5151
-------
5252
x: Float32Array
53-
Input array `x`.
53+
Input array.
5454

5555
Examples
5656
--------
@@ -59,27 +59,26 @@
5959
> {{alias}}( x.length, 1, x, 1 )
6060
<Float32Array>[ -4.0, -2.0, 1.0, 3.0 ]
6161

62-
// Using `N` and `stride` parameters:
62+
// Using `N` and stride parameters:
6363
> x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, -4.0 ] );
64-
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
65-
> {{alias}}( N, -1, x, 2 )
64+
> {{alias}}( 2, -1, x, 2 )
6665
<Float32Array>[ 3.0, -2.0, 1.0, -4.0 ]
6766

6867
// Using view offsets:
6968
> var x0 = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, -4.0 ] );
7069
> var x1 = new {{alias:@stdlib/array/float32}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 );
71-
> N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 );
72-
> {{alias}}( N, 1, x1, 2 )
70+
> {{alias}}( 2, 1, x1, 2 )
7371
<Float32Array>[ -4.0, 3.0, -2.0 ]
7472
> x0
7573
<Float32Array>[ 1.0, -4.0, 3.0, -2.0 ]
7674

75+
7776
{{alias}}.ndarray( N, order, x, stride, offset )
7877
Sorts a single-precision floating-point strided array using insertion sort
7978
and alternative indexing semantics.
8079

8180
While typed array views mandate a view offset based on the underlying
82-
buffer, the `offset` parameter supports indexing semantics based on a
81+
buffer, the offset parameter supports indexing semantics based on a
8382
starting index.
8483

8584
Parameters
@@ -103,7 +102,7 @@
103102
Returns
104103
-------
105104
x: Float32Array
106-
Input array `x`.
105+
Input array.
107106

108107
Examples
109108
--------
@@ -114,8 +113,7 @@
114113

115114
// Using an index offset:
116115
> x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, -4.0 ] );
117-
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
118-
> {{alias}}.ndarray( N, 1, x, 2, 1 )
116+
> {{alias}}.ndarray( 2, 1, x, 2, 1 )
119117
<Float32Array>[ 1.0, -4.0, 3.0, -2.0 ]
120118

121119
See Also

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ interface Routine {
2929
* @param order - sort order
3030
* @param x - input array
3131
* @param stride - stride length
32-
* @returns `x`
32+
* @returns input array
3333
*
3434
* @example
3535
* var Float32Array = require( '@stdlib/array/float32' );
@@ -49,7 +49,7 @@ interface Routine {
4949
* @param x - input array
5050
* @param stride - stride length
5151
* @param offset - starting index
52-
* @returns `x`
52+
* @returns input array
5353
*
5454
* @example
5555
* var Float32Array = require( '@stdlib/array/float32' );
@@ -69,7 +69,7 @@ interface Routine {
6969
* @param order - sort order
7070
* @param x - input array
7171
* @param stride - stride length
72-
* @returns `x`
72+
* @returns input array
7373
*
7474
* @example
7575
* var Float32Array = require( '@stdlib/array/float32' );

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@ var ssortins = require( './../lib' );
2525

2626
var rand;
2727
var sign;
28-
var x;
2928
var i;
3029

31-
x = new Float32Array( 10 );
30+
var x = new Float32Array( 10 );
3231
for ( i = 0; i < x.length; i++ ) {
3332
if ( randu() < 0.2 ) {
3433
x[ i ] = NaN;

lib/node_modules/@stdlib/blas/ext/base/ssortins/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/ssortins/lib/ndarray.native.js

Lines changed: 6 additions & 7 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( './ssortins.native.js' );
2526

2627

@@ -45,12 +46,10 @@ var addon = require( './ssortins.native.js' );
4546
*/
4647
function ssortins( N, order, x, stride, offset ) {
4748
var view;
48-
if ( stride < 0 ) {
49-
order *= -1.0;
50-
stride *= -1;
51-
offset -= (N-1) * stride;
52-
}
53-
view = new Float32Array( x.buffer, x.byteOffset+(x.BYTES_PER_ELEMENT*offset), x.length-offset ); // eslint-disable-line max-len
49+
50+
offset = minViewBufferIndex( N, stride, offset );
51+
view = offsetView( x, offset );
52+
5453
addon( N, order, view, stride );
5554
return x;
5655
}
Lines changed: 83 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,85 @@
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/ssortins.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/ssortins.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-negative-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": "benchmark",
52+
"src": [
53+
"./src/ssortins.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-negative-zerof"
65+
]
66+
},
67+
{
68+
"task": "examples",
69+
"src": [
70+
"./src/ssortins.c"
71+
],
72+
"include": [
73+
"./include"
74+
],
75+
"libraries": [
76+
"-lm"
77+
],
78+
"libpath": [],
79+
"dependencies": [
80+
"@stdlib/math/base/assert/is-nanf",
81+
"@stdlib/math/base/assert/is-negative-zerof"
82+
]
83+
}
84+
]
4385
}

lib/node_modules/@stdlib/blas/ext/base/ssortins/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
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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/ssortins.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, 4 );
36+
STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 );
37+
STDLIB_NAPI_ARGV_FLOAT( env, order, argv, 1 );
38+
STDLIB_NAPI_ARGV_INT64( env, stride, argv, 3 );
39+
STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, stride, argv, 2 );
40+
c_ssortins( N, order, X, stride );
41+
return NULL;
42+
}
43+
44+
STDLIB_NAPI_MODULE_EXPORT_FCN( addon )

0 commit comments

Comments
 (0)