Skip to content

Commit

Permalink
refactor: update blas/ext/base/dsort2hp to follow current project c…
Browse files Browse the repository at this point in the history
…onventions

PR-URL: #2302
Closes: #1495
Ref: #1152

---------

Signed-off-by: Philipp Burckhardt <[email protected]>
Co-authored-by: Athan Reines <[email protected]>
Co-authored-by: Philipp Burckhardt <[email protected]>
Reviewed-by: Philipp Burckhardt <[email protected]>
  • Loading branch information
3 people authored Jun 25, 2024
1 parent 51608dc commit e87d921
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 215 deletions.
8 changes: 2 additions & 6 deletions lib/node_modules/@stdlib/blas/ext/base/dsort2sh/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,11 @@ The `N` and `stride` parameters determine which elements in `x` and `y` are acce

```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 y = new Float64Array( [ 0.0, 1.0, 2.0, 3.0 ] );
var N = floor( x.length / 2 );

dsort2sh( N, -1.0, x, 2, y, 2 );
dsort2sh( 2, -1.0, x, 2, y, 2 );

console.log( x );
// => <Float64Array>[ 3.0, -2.0, 1.0, -4.0 ]
Expand All @@ -81,7 +79,6 @@ Note that indexing is relative to the first index. To introduce an offset, use [

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

// Initial arrays...
var x0 = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] );
Expand All @@ -90,10 +87,9 @@ var y0 = new Float64Array( [ 0.0, 1.0, 2.0, 3.0 ] );
// Create offset views...
var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
var y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
var N = floor( x0.length/2 );

// Sort every other element...
dsort2sh( N, -1.0, x1, 2, y1, 2 );
dsort2sh( 2, -1.0, x1, 2, y1, 2 );

console.log( x0 );
// => <Float64Array>[ 1.0, 4.0, 3.0, 2.0 ]
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( './dsort2sh.native.js' );


Expand Down Expand Up @@ -68,8 +68,8 @@ function dsort2sh( N, order, x, strideX, offsetX, y, strideY, offsetY ) {
if ( strideY < 0 ) {
offsetY += (N-1) * strideY;
}
viewX = new Float64Array( x.buffer, x.byteOffset+(x.BYTES_PER_ELEMENT*offsetX), x.length-offsetX ); // eslint-disable-line max-len
viewY = new Float64Array( y.buffer, y.byteOffset+(y.BYTES_PER_ELEMENT*offsetY), y.length-offsetY ); // eslint-disable-line max-len
viewX = offsetView( x, offsetX );
viewY = offsetView( y, offsetY );
addon( N, order, viewX, strideX, viewY, flg*strideY );
return x;
}
Expand Down
120 changes: 79 additions & 41 deletions lib/node_modules/@stdlib/blas/ext/base/dsort2sh/manifest.json
Original file line number Diff line number Diff line change
@@ -1,43 +1,81 @@
{
"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/dsort2sh.c"
],
"include": [
"./include"
],
"libraries": [
"-lm"
],
"libpath": [],
"dependencies": [
"@stdlib/math/base/assert/is-nan",
"@stdlib/math/base/assert/is-negative-zero"
]
}
]
"options": {
"task": "build"
},
"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": [
{
"task": "build",
"src": [
"./src/dsort2sh.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"
]
},
{
"task": "benchmark",
"src": [
"./src/dsort2sh.c"
],
"include": [
"./include"
],
"libraries": [],
"libpath": [],
"dependencies": [
"@stdlib/math/base/assert/is-nan",
"@stdlib/math/base/assert/is-negative-zero"
]
},
{
"task": "examples",
"src": [
"./src/dsort2sh.c"
],
"include": [
"./include"
],
"libraries": [],
"libpath": [],
"dependencies": [
"@stdlib/math/base/assert/is-nan",
"@stdlib/math/base/assert/is-negative-zero"
]
}
]
}
49 changes: 49 additions & 0 deletions lib/node_modules/@stdlib/blas/ext/base/dsort2sh/src/addon.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* @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/dsort2sh.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, 6 );
STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 );
STDLIB_NAPI_ARGV_DOUBLE( env, order, argv, 1 );
STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, order, argv, 2 );
STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 );
STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, Y, N, order, argv, 4 );
STDLIB_NAPI_ARGV_INT64( env, strideY, argv, 5 );

c_dsort2sh( N, order, X, strideX, Y, strideY );

return NULL;
}

STDLIB_NAPI_MODULE_EXPORT_FCN( addon )
Loading

1 comment on commit e87d921

@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/dsort2sh $\color{green}543/543$
$\color{green}+100.00\%$
$\color{green}53/53$
$\color{green}+100.00\%$
$\color{green}4/4$
$\color{green}+100.00\%$
$\color{green}543/543$
$\color{green}+100.00\%$

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

Please sign in to comment.