Skip to content

Commit

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

PR-URL: #2961
Closes: #1496

Co-authored-by: Philipp Burckhardt <pburckhardt@outlook.com>
Reviewed-by: Philipp Burckhardt <pburckhardt@outlook.com>
  • Loading branch information
aayush0325 and Planeshifter authored Sep 30, 2024
1 parent c1552d8 commit cf62100
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 235 deletions.
18 changes: 6 additions & 12 deletions lib/node_modules/@stdlib/blas/ext/base/dsort2ins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,15 @@ The function has the following parameters:
- **y**: second input [`Float64Array`][@stdlib/array/float64].
- **strideY**: `y` index increment.

The `N` and `stride` parameters determine which elements in `x` and `y` are accessed at runtime. For example, to sort every other element
The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to sort every other element

```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 );

dsort2ins( N, -1.0, x, 2, y, 2 );
dsort2ins( 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...
dsort2ins( N, -1.0, x1, 2, y1, 2 );
dsort2ins( 2, -1.0, x1, 2, y1, 2 );

console.log( x0 );
// => <Float64Array>[ 1.0, 4.0, 3.0, 2.0 ]
Expand Down Expand Up @@ -126,7 +122,7 @@ The function has the following additional parameters:
- **offsetX**: `x` starting index.
- **offsetY**: `y` starting index.

While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the `offset` parameter supports indexing semantics based on a starting index. For example, to access only the last three elements of `x`
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the offset parameter supports indexing semantics based on a starting index. For example, to access only the last three elements of `x`

```javascript
var Float64Array = require( '@stdlib/array/float64' );
Expand Down Expand Up @@ -177,12 +173,10 @@ var dsort2ins = require( '@stdlib/blas/ext/base/dsort2ins' );

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

x = new Float64Array( 10 );
y = new Float64Array( 10 ); // index array
var x = new Float64Array( 10 );
var y = new Float64Array( 10 ); // index array
for ( i = 0; i < x.length; i++ ) {
rand = round( randu()*100.0 );
sign = randu();
Expand Down
18 changes: 8 additions & 10 deletions lib/node_modules/@stdlib/blas/ext/base/dsort2ins/docs/repl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
Simultaneously sorts two double-precision floating-point strided arrays
based on the sort order of the first array using insertion sort.

The `N` and `stride` parameters determine which elements in `x` and `y` are
accessed at runtime.
The `N` and stride parameters determine which elements in the strided arrays
are accessed at runtime.

Indexing is relative to the first index. To introduce an offset, use typed
array views.
Expand Down Expand Up @@ -57,7 +57,7 @@
Returns
-------
x: Float64Array
Input array `x`.
Input array.

Examples
--------
Expand All @@ -69,11 +69,10 @@
> y
<Float64Array>[ 3.0, 1.0, 0.0, 2.0 ]

// Using `N` and `stride` parameters:
// Using `N` and stride parameters:
> x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, -4.0 ] );
> y = new {{alias:@stdlib/array/float64}}( [ 0.0, 1.0, 2.0, 3.0 ] );
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
> {{alias}}( N, -1, x, 2, y, 2 )
> {{alias}}( 2, -1, x, 2, y, 2 )
<Float64Array>[ 3.0, -2.0, 1.0, -4.0 ]
> y
<Float64Array>[ 2.0, 1.0, 0.0, 3.0 ]
Expand All @@ -83,14 +82,14 @@
> var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 );
> var y0 = new {{alias:@stdlib/array/float64}}( [ 0.0, 1.0, 2.0, 3.0 ] );
> var y1 = new {{alias:@stdlib/array/float64}}( y0.buffer, y0.BYTES_PER_ELEMENT*1 );
> N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 );
> {{alias}}( N, 1, x1, 2, y1, 2 )
> {{alias}}( 2, 1, x1, 2, y1, 2 )
<Float64Array>[ -4.0, 3.0, -2.0 ]
> x0
<Float64Array>[ 1.0, -4.0, 3.0, -2.0 ]
> y0
<Float64Array>[ 0.0, 3.0, 2.0, 1.0 ]


{{alias}}.ndarray( N, order, x, strideX, offsetX, y, strideY, offsetY )
Simultaneously sorts two double-precision floating-point strided arrays
based on the sort order of the first array using insertion sort and
Expand Down Expand Up @@ -145,8 +144,7 @@
// Using an index offset:
> x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, -4.0 ] );
> y = new {{alias:@stdlib/array/float64}}( [ 0.0, 1.0, 2.0, 3.0 ] );
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
> {{alias}}.ndarray( N, 1, x, 2, 1, y, 2, 1 )
> {{alias}}.ndarray( 2, 1, x, 2, 1, y, 2, 1 )
<Float64Array>[ 1.0, -4.0, 3.0, -2.0 ]
> y
<Float64Array>[ 0.0, 3.0, 2.0, 1.0 ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ interface Routine {
* @param N - number of indexed elements
* @param order - sort order
* @param x - first input array
* @param strideX - `x` stride length
* @param strideX - first stride length
* @param y - second input array
* @param strideY - `y` stride length
* @param strideY - second stride length
* @returns `x`
*
* @example
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@ var dsort2ins = require( './../lib' );

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

x = new Float64Array( 10 );
y = new Float64Array( 10 ); // index array
var x = new Float64Array( 10 );
var y = new Float64Array( 10 ); // index array
for ( i = 0; i < x.length; i++ ) {
if ( randu() < 0.2 ) {
x[ i ] = NaN;
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
107 changes: 66 additions & 41 deletions lib/node_modules/@stdlib/blas/ext/base/dsort2ins/manifest.json
Original file line number Diff line number Diff line change
@@ -1,43 +1,68 @@
{
"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/dsort2ins.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/dsort2ins.c"
],
"include": [
"./include"
],
"libraries": [
"-lm"
],
"libpath": [],
"dependencies": [
"@stdlib/math/base/assert/is-negative-zero",
"@stdlib/math/base/assert/is-nan",
"@stdlib/napi/export",
"@stdlib/napi/argv",
"@stdlib/napi/argv-double",
"@stdlib/napi/argv-int64",
"@stdlib/napi/argv-strided-float64array"
]
},
{
"task": "examples",
"src": [
"./src/dsort2ins.c"
],
"include": [
"./include"
],
"libraries": [
"-lm"
],
"libpath": [],
"dependencies": [
"@stdlib/math/base/assert/is-nan",
"@stdlib/math/base/assert/is-negative-zero"
]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,7 @@
"double",
"float64array"
],
"__stdlib__": {}
"__stdlib__": {
"wasm": false
}
}
46 changes: 46 additions & 0 deletions lib/node_modules/@stdlib/blas/ext/base/dsort2ins/src/addon.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2018 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/dsort2ins.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.
*
* @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_INT64( env, strideX, argv, 3 );
STDLIB_NAPI_ARGV_INT64( env, strideY, argv, 5 );
STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 2 );
STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, Y, N, strideY, argv, 4 );
c_dsort2ins( N, order, X, strideX, Y, strideY );
return NULL;
}

STDLIB_NAPI_MODULE_EXPORT_FCN( addon )
Loading

1 comment on commit cf62100

@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/dsort2ins $\color{green}666/666$
$\color{green}+100.00\%$
$\color{green}74/74$
$\color{green}+100.00\%$
$\color{green}4/4$
$\color{green}+100.00\%$
$\color{green}666/666$
$\color{green}+100.00\%$

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

Please sign in to comment.