Skip to content

Commit

Permalink
refactor: update blas/ext/base/dsortsh to follow current project co…
Browse files Browse the repository at this point in the history
…nventions

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]>
  • Loading branch information
liberocks and Planeshifter authored Apr 28, 2024
1 parent 0af3cdf commit 6bcf620
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 220 deletions.
30 changes: 5 additions & 25 deletions lib/node_modules/@stdlib/blas/ext/base/dsortsh/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,30 +54,26 @@ The `N` and `stride` parameters determine which elements in `x` are accessed at

```javascript
var Float64Array = require( '@stdlib/array/float64' );
var floor = require( '@stdlib/math/base/special/floor' );

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

dsortsh( N, -1.0, x, 2 );
dsortsh( 2, -1.0, x, 2 );
// x => <Float64Array>[ 3.0, -2.0, 1.0, -4.0 ]
```

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

```javascript
var Float64Array = require( '@stdlib/array/float64' );
var floor = require( '@stdlib/math/base/special/floor' );

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

// Create an offset view...
var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
var N = floor( x0.length/2 );

// Sort every other element...
dsortsh( N, -1.0, x1, 2 );
dsortsh( 2, -1.0, x1, 2 );
// x0 => <Float64Array>[ 1.0, 4.0, 3.0, 2.0 ]
```

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

```javascript
var round = require( '@stdlib/math/base/special/round' );
var randu = require( '@stdlib/random/base/randu' );
var Float64Array = require( '@stdlib/array/float64' );
var filledarrayBy = require( '@stdlib/array/filled-by' );
var uniform = require( '@stdlib/random/base/uniform' ).factory;
var dsortsh = require( '@stdlib/blas/ext/base/dsortsh' );

var rand;
var sign;
var x;
var i;

x = new Float64Array( 10 );
for ( i = 0; i < x.length; i++ ) {
rand = round( randu()*100.0 );
sign = randu();
if ( sign < 0.5 ) {
sign = -1.0;
} else {
sign = 1.0;
}
x[ i ] = sign * rand;
}
var x = filledarrayBy( 100, 'float64', uniform( -100.0, 100.0 ) );
console.log( x );

dsortsh( x.length, -1.0, x, -1 );
Expand Down
26 changes: 3 additions & 23 deletions lib/node_modules/@stdlib/blas/ext/base/dsortsh/examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,11 @@

'use strict';

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

var rand;
var sign;
var x;
var i;

x = new Float64Array( 10 );
for ( i = 0; i < x.length; i++ ) {
if ( randu() < 0.2 ) {
x[ i ] = NaN;
} else {
rand = round( randu()*100.0 );
sign = randu();
if ( sign < 0.5 ) {
sign = -1.0;
} else {
sign = 1.0;
}
x[ i ] = sign * rand;
}
}
var x = filledarrayBy( 100, 'float64', uniform( -100.0, 100.0 ) );
console.log( x );

dsortsh( x.length, -1.0, x, -1 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

# Source files:
'src_files': [
'<(src_dir)/addon.cpp',
'<(src_dir)/addon.c',
'<!@(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 ] ); }")',
],

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

// MODULES //

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


Expand Down Expand Up @@ -50,8 +50,9 @@ function dsortsh( N, order, x, stride, offset ) {
stride *= -1;
offset -= (N-1) * stride;
}
view = new Float64Array( x.buffer, x.byteOffset+(x.BYTES_PER_ELEMENT*offset), x.length-offset ); // eslint-disable-line max-len
view = offsetView( x, offset );
addon( N, order, view, stride );

return x;
}

Expand Down
87 changes: 46 additions & 41 deletions lib/node_modules/@stdlib/blas/ext/base/dsortsh/manifest.json
Original file line number Diff line number Diff line change
@@ -1,43 +1,48 @@
{
"options": {},
"fields": [
{
"field": "src",
"resolve": true,
"relative": true
},
{
"field": "include",
"resolve": true,
"relative": true
},
{
"field": "libraries",
"resolve": false,
"relative": false
},
{
"field": "libpath",
"resolve": true,
"relative": false
}
],
"confs": [
{
"src": [
"./src/dsortsh.c"
],
"include": [
"./include"
],
"libraries": [
"-lm"
],
"libpath": [],
"dependencies": [
"@stdlib/math/base/assert/is-nan",
"@stdlib/math/base/assert/is-negative-zero"
]
}
]
"options": {},
"fields": [
{
"field": "src",
"resolve": true,
"relative": true
},
{
"field": "include",
"resolve": true,
"relative": true
},
{
"field": "libraries",
"resolve": false,
"relative": false
},
{
"field": "libpath",
"resolve": true,
"relative": false
}
],
"confs": [
{
"src": [
"./src/dsortsh.c"
],
"include": [
"./include"
],
"libraries": [
"-lm"
],
"libpath": [],
"dependencies": [
"@stdlib/napi/export",
"@stdlib/math/base/assert/is-nan",
"@stdlib/math/base/assert/is-negative-zero",
"@stdlib/napi/argv",
"@stdlib/napi/argv-int64",
"@stdlib/napi/argv-double",
"@stdlib/napi/argv-strided-float64array"
]
}
]
}
47 changes: 47 additions & 0 deletions lib/node_modules/@stdlib/blas/ext/base/dsortsh/src/addon.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2024 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "stdlib/blas/ext/base/dsortsh.h"
#include "stdlib/napi/export.h"
#include "stdlib/napi/argv.h"
#include "stdlib/napi/argv_int64.h"
#include "stdlib/napi/argv_double.h"
#include "stdlib/napi/argv_strided_float64array.h"
#include <node_api.h>

/**
* Receives JavaScript callback invocation data.
*
* @private
* @param env environment under which the function is invoked
* @param info callback data
* @return Node-API value
*/
static napi_value addon( napi_env env, napi_callback_info info ) {
STDLIB_NAPI_ARGV( env, info, argv, argc, 4 );
STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 );
STDLIB_NAPI_ARGV_DOUBLE( env, order, argv, 1 );
STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 );
STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, order, argv, 2 );

c_dsortsh( N, order, X, strideX );

return NULL;
}

STDLIB_NAPI_MODULE_EXPORT_FCN( addon )
128 changes: 0 additions & 128 deletions lib/node_modules/@stdlib/blas/ext/base/dsortsh/src/addon.cpp

This file was deleted.

1 comment on commit 6bcf620

@stdlib-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage Report

Package Statements Branches Functions Lines
blas/ext/base/dsortsh $\color{green}469/469$
$\color{green}+100.00\%$
$\color{green}49/49$
$\color{green}+100.00\%$
$\color{green}4/4$
$\color{green}+100.00\%$
$\color{green}469/469$
$\color{green}+100.00\%$

The above coverage report was generated for the changes in this push.

Please sign in to comment.