Skip to content

Commit 900ccd7

Browse files
refactor: update blas/ext/base/dsorthp to follow current project conventions
PR-URL: #2051 Closes: #1498 Ref: #1152 --------- Co-authored-by: Philipp Burckhardt <[email protected]> Reviewed-by: Philipp Burckhardt <[email protected]>
1 parent 2ca4ab3 commit 900ccd7

File tree

6 files changed

+102
-179
lines changed

6 files changed

+102
-179
lines changed

Diff for: lib/node_modules/@stdlib/blas/ext/base/dsorthp/README.md

+2-6
Original file line numberDiff line numberDiff line change
@@ -54,30 +54,26 @@ The `N` and `stride` parameters determine which elements in `x` are accessed at
5454

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

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

62-
dsorthp( N, -1.0, x, 2 );
60+
dsorthp( 2, -1.0, x, 2 );
6361
// x => <Float64Array>[ 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 Float64Array = require( '@stdlib/array/float64' );
70-
var floor = require( '@stdlib/math/base/special/floor' );
7168

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

7572
// Create an offset view...
7673
var x1 = new Float64Array( 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-
dsorthp( N, -1.0, x1, 2 );
76+
dsorthp( 2, -1.0, x1, 2 );
8177
// x0 => <Float64Array>[ 1.0, 4.0, 3.0, 2.0 ]
8278
```
8379

Diff for: lib/node_modules/@stdlib/blas/ext/base/dsorthp/include.gypi

+1-1
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

Diff for: lib/node_modules/@stdlib/blas/ext/base/dsorthp/lib/ndarray.native.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020

2121
// MODULES //
2222

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

2627

@@ -45,12 +46,13 @@ var addon = require( './dsorthp.native.js' );
4546
*/
4647
function dsorthp( 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 Float64Array( x.buffer, x.byteOffset+(x.BYTES_PER_ELEMENT*offset), x.length-offset ); // eslint-disable-line max-len
54+
view = offsetView( x, offset );
55+
5456
addon( N, order, view, stride );
5557
return x;
5658
}
+49-41
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,51 @@
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/dsorthp.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-positive-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/dsorthp.c"
32+
],
33+
"include": [
34+
"./include"
35+
],
36+
"libraries": [
37+
"-lm"
38+
],
39+
"libpath": [],
40+
"dependencies": [
41+
"@stdlib/math/base/assert/is-nan",
42+
"@stdlib/math/base/assert/is-positive-zero",
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+
]
4351
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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/dsorthp.h"
20+
#include "stdlib/napi/export.h"
21+
#include "stdlib/napi/argv.h"
22+
#include "stdlib/napi/argv_double.h"
23+
#include "stdlib/napi/argv_int64.h"
24+
#include "stdlib/napi/argv_strided_float64array.h"
25+
#include <node_api.h>
26+
27+
/**
28+
* Receives JavaScript callback invocation data.
29+
*
30+
* @private
31+
* @param env environment under which the function is invoked
32+
* @param info callback data
33+
* @return Node-API value
34+
*/
35+
static napi_value addon( napi_env env, napi_callback_info info ) {
36+
STDLIB_NAPI_ARGV( env, info, argv, argc, 4 );
37+
STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 );
38+
STDLIB_NAPI_ARGV_DOUBLE( env, order, argv, 1 );
39+
STDLIB_NAPI_ARGV_INT64( env, stride, argv, 3 );
40+
STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, stride, argv, 2 );
41+
c_dsorthp( N, order, X, stride );
42+
return NULL;
43+
}
44+
45+
STDLIB_NAPI_MODULE_EXPORT_FCN( addon )

Diff for: lib/node_modules/@stdlib/blas/ext/base/dsorthp/src/addon.cpp

-128
This file was deleted.

0 commit comments

Comments
 (0)