Skip to content

Commit 6bcf620

Browse files
refactor: update blas/ext/base/dsortsh to follow current project conventions
PR-URL: #2007 Closes: #1500 Ref: #1152 --------- Co-authored-by: Philipp Burckhardt <[email protected]> Reviewed-by: Pranav Goswami <[email protected]> Reviewed-by: Philipp Burckhardt <[email protected]>
1 parent 0af3cdf commit 6bcf620

File tree

7 files changed

+105
-220
lines changed

7 files changed

+105
-220
lines changed

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

+5-25
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-
dsortsh( N, -1.0, x, 2 );
60+
dsortsh( 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-
dsortsh( N, -1.0, x1, 2 );
76+
dsortsh( 2, -1.0, x1, 2 );
8177
// x0 => <Float64Array>[ 1.0, 4.0, 3.0, 2.0 ]
8278
```
8379

@@ -136,27 +132,11 @@ dsortsh.ndarray( 3, 1.0, x, 1, x.length-3 );
136132
<!-- eslint no-undef: "error" -->
137133

138134
```javascript
139-
var round = require( '@stdlib/math/base/special/round' );
140-
var randu = require( '@stdlib/random/base/randu' );
141-
var Float64Array = require( '@stdlib/array/float64' );
135+
var filledarrayBy = require( '@stdlib/array/filled-by' );
136+
var uniform = require( '@stdlib/random/base/uniform' ).factory;
142137
var dsortsh = require( '@stdlib/blas/ext/base/dsortsh' );
143138

144-
var rand;
145-
var sign;
146-
var x;
147-
var i;
148-
149-
x = new Float64Array( 10 );
150-
for ( i = 0; i < x.length; i++ ) {
151-
rand = round( randu()*100.0 );
152-
sign = randu();
153-
if ( sign < 0.5 ) {
154-
sign = -1.0;
155-
} else {
156-
sign = 1.0;
157-
}
158-
x[ i ] = sign * rand;
159-
}
139+
var x = filledarrayBy( 100, 'float64', uniform( -100.0, 100.0 ) );
160140
console.log( x );
161141

162142
dsortsh( x.length, -1.0, x, -1 );

Diff for: lib/node_modules/@stdlib/blas/ext/base/dsortsh/examples/index.js

+3-23
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,11 @@
1818

1919
'use strict';
2020

21-
var round = require( '@stdlib/math/base/special/round' );
22-
var randu = require( '@stdlib/random/base/randu' );
23-
var Float64Array = require( '@stdlib/array/float64' );
21+
var filledarrayBy = require( '@stdlib/array/filled-by' );
22+
var uniform = require( '@stdlib/random/base/uniform' ).factory;
2423
var dsortsh = require( './../lib' );
2524

26-
var rand;
27-
var sign;
28-
var x;
29-
var i;
30-
31-
x = new Float64Array( 10 );
32-
for ( i = 0; i < x.length; i++ ) {
33-
if ( randu() < 0.2 ) {
34-
x[ i ] = NaN;
35-
} else {
36-
rand = round( randu()*100.0 );
37-
sign = randu();
38-
if ( sign < 0.5 ) {
39-
sign = -1.0;
40-
} else {
41-
sign = 1.0;
42-
}
43-
x[ i ] = sign * rand;
44-
}
45-
}
25+
var x = filledarrayBy( 100, 'float64', uniform( -100.0, 100.0 ) );
4626
console.log( x );
4727

4828
dsortsh( x.length, -1.0, x, -1 );

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

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

2121
// MODULES //
2222

23-
var Float64Array = require( '@stdlib/array/float64' );
23+
var offsetView = require( '@stdlib/strided/base/offset-view' );
2424
var addon = require( './dsortsh.native.js' );
2525

2626

@@ -50,8 +50,9 @@ function dsortsh( N, order, x, stride, offset ) {
5050
stride *= -1;
5151
offset -= (N-1) * stride;
5252
}
53-
view = new Float64Array( x.buffer, x.byteOffset+(x.BYTES_PER_ELEMENT*offset), x.length-offset ); // eslint-disable-line max-len
53+
view = offsetView( x, offset );
5454
addon( N, order, view, stride );
55+
5556
return x;
5657
}
5758

+46-41
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/dsortsh.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-negative-zero"
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/dsortsh.c"
29+
],
30+
"include": [
31+
"./include"
32+
],
33+
"libraries": [
34+
"-lm"
35+
],
36+
"libpath": [],
37+
"dependencies": [
38+
"@stdlib/napi/export",
39+
"@stdlib/math/base/assert/is-nan",
40+
"@stdlib/math/base/assert/is-negative-zero",
41+
"@stdlib/napi/argv",
42+
"@stdlib/napi/argv-int64",
43+
"@stdlib/napi/argv-double",
44+
"@stdlib/napi/argv-strided-float64array"
45+
]
46+
}
47+
]
4348
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 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/dsortsh.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_double.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, strideX, argv, 3 );
40+
STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, order, argv, 2 );
41+
42+
c_dsortsh( N, order, X, strideX );
43+
44+
return NULL;
45+
}
46+
47+
STDLIB_NAPI_MODULE_EXPORT_FCN( addon )

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

-128
This file was deleted.

0 commit comments

Comments
 (0)