Skip to content

Commit 2ca4ab3

Browse files
refactor: update blas/ext/base/ssortsh to follow current project conventions
PR-URL: #1905 Closes: #1539 Ref: #1152 --------- Co-authored-by: Philipp Burckhardt <[email protected]> Reviewed-by: Philipp Burckhardt <[email protected]>
1 parent 657f3c3 commit 2ca4ab3

File tree

6 files changed

+92
-179
lines changed

6 files changed

+92
-179
lines changed

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,18 @@
5959

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

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

73+
7574
{{alias}}.ndarray( N, order, x, stride, offset )
7675
Sorts a single-precision floating-point strided array using Shellsort and
7776
alternative indexing semantics.
@@ -112,8 +111,7 @@
112111

113112
// Using an index offset:
114113
> x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, -4.0 ] );
115-
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
116-
> {{alias}}.ndarray( N, 1, x, 2, 1 )
114+
> {{alias}}.ndarray( 2, 1, x, 2, 1 )
117115
<Float32Array>[ 1.0, -4.0, 3.0, -2.0 ]
118116

119117
See Also

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

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

2627

@@ -45,12 +46,12 @@ var addon = require( './ssortsh.native.js' );
4546
*/
4647
function ssortsh( N, order, x, stride, offset ) {
4748
var view;
49+
offset = minViewBufferIndex( N, stride, offset );
4850
if ( stride < 0 ) {
4951
order *= -1.0;
5052
stride *= -1;
51-
offset -= (N-1) * stride;
5253
}
53-
view = new Float32Array( x.buffer, x.byteOffset+(x.BYTES_PER_ELEMENT*offset), x.length-offset ); // eslint-disable-line max-len
54+
view = offsetView( x, offset );
5455
addon( N, order, view, stride );
5556
return x;
5657
}
Lines changed: 46 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,48 @@
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/ssortsh.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+
"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/ssortsh.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+
"@stdlib/napi/export",
41+
"@stdlib/napi/argv",
42+
"@stdlib/napi/argv-float",
43+
"@stdlib/napi/argv-int64",
44+
"@stdlib/napi/argv-strided-float32array"
45+
]
46+
}
47+
]
4348
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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/ssortsh.h"
20+
#include "stdlib/napi/export.h"
21+
#include "stdlib/napi/argv.h"
22+
#include "stdlib/napi/argv_float.h"
23+
#include "stdlib/napi/argv_int64.h"
24+
#include "stdlib/napi/argv_strided_float32array.h"
25+
#include <node_api.h>
26+
27+
static napi_value addon( napi_env env, napi_callback_info info ) {
28+
STDLIB_NAPI_ARGV( env, info, argv, argc, 4 );
29+
STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 );
30+
STDLIB_NAPI_ARGV_FLOAT( env, order, argv, 1 );
31+
STDLIB_NAPI_ARGV_INT64( env, stride, argv, 3 );
32+
STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, stride, argv, 2 );
33+
c_ssortsh( N, order, X, stride );
34+
return NULL;
35+
}
36+
37+
STDLIB_NAPI_MODULE_EXPORT_FCN( addon )

lib/node_modules/@stdlib/blas/ext/base/ssortsh/src/addon.cpp

Lines changed: 0 additions & 128 deletions
This file was deleted.

0 commit comments

Comments
 (0)