Skip to content

Commit

Permalink
refactor: update blas/ext/ssort2ins to follow current project conve…
Browse files Browse the repository at this point in the history
…ntions

PR-URL: #1874
Closes: #1535
Ref: #1152

---------

Co-authored-by: Philipp Burckhardt <[email protected]>
Reviewed-by: Athan Reines <[email protected]>
Reviewed-by: Philipp Burckhardt <[email protected]>
  • Loading branch information
vr-varad and Planeshifter authored Apr 28, 2024
1 parent 6bcf620 commit f1b1fce
Show file tree
Hide file tree
Showing 11 changed files with 167 additions and 268 deletions.
15 changes: 5 additions & 10 deletions lib/node_modules/@stdlib/blas/ext/base/ssort2ins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,14 @@ The function has the following parameters:
- **y**: second input [`Float32Array`][@stdlib/array/float32].
- **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 Float32Array = require( '@stdlib/array/float32' );
var floor = require( '@stdlib/math/base/special/floor' );

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

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

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

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

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

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

console.log( x0 );
// => <Float32Array>[ 1.0, 4.0, 3.0, 2.0 ]
Expand All @@ -104,7 +99,7 @@ console.log( y0 );

#### ssort2ins.ndarray( N, order, x, strideX, offsetX, y, strideY, offsetY )

Simultaneously sorts two single-precision floating-point strided arrays based on the sort order of the first array `x` using insertion sort and alternative indexing semantics.
Simultaneously sorts two single-precision floating-point strided arrays based on the sort order of the first array the strided array using insertion sort and alternative indexing semantics.

```javascript
var Float32Array = require( '@stdlib/array/float32' );
Expand All @@ -126,7 +121,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 Float32Array = require( '@stdlib/array/float32' );
Expand Down
25 changes: 12 additions & 13 deletions lib/node_modules/@stdlib/blas/ext/base/ssort2ins/docs/repl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
Simultaneously sorts two single-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.

If `N <= 0` or `order == 0`, the function leaves `x` and `y` unchanged.
If `N <= 0` or `order == 0`, the function leaves the strided arrays
are unchanged.

The algorithm distinguishes between `-0` and `+0`. When sorted in increasing
order, `-0` is sorted before `+0`. When sorted in decreasing order, `-0` is
Expand Down Expand Up @@ -57,7 +58,7 @@
Returns
-------
x: Float32Array
Input array `x`.
First input array.

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

// Using `N` and `stride` parameters:
// Using `N` and stride parameters:
> x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, -4.0 ] );
> y = new {{alias:@stdlib/array/float32}}( [ 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 )
<Float32Array>[ 3.0, -2.0, 1.0, -4.0 ]
> y
<Float32Array>[ 2.0, 1.0, 0.0, 3.0 ]
Expand All @@ -83,21 +83,21 @@
> var x1 = new {{alias:@stdlib/array/float32}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 );
> var y0 = new {{alias:@stdlib/array/float32}}( [ 0.0, 1.0, 2.0, 3.0 ] );
> var y1 = new {{alias:@stdlib/array/float32}}( 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 )
<Float32Array>[ -4.0, 3.0, -2.0 ]
> x0
<Float32Array>[ 1.0, -4.0, 3.0, -2.0 ]
> y0
<Float32Array>[ 0.0, 3.0, 2.0, 1.0 ]


{{alias}}.ndarray( N, order, x, strideX, offsetX, y, strideY, offsetY )
Simultaneously sorts two single-precision floating-point strided arrays
based on the sort order of the first array using insertion sort and
alternative indexing semantics.

While typed array views mandate a view offset based on the underlying
buffer, the `offset` parameter supports indexing semantics based on a
buffer, the offset parameter supports indexing semantics based on a
starting index.

Parameters
Expand Down Expand Up @@ -130,7 +130,7 @@
Returns
-------
x: Float32Array
Input array `x`.
First input array.

Examples
--------
Expand All @@ -145,8 +145,7 @@
// Using an index offset:
> x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, -4.0 ] );
> y = new {{alias:@stdlib/array/float32}}( [ 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 )
<Float32Array>[ 1.0, -4.0, 3.0, -2.0 ]
> y
<Float32Array>[ 0.0, 3.0, 2.0, 1.0 ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ interface Routine {
* @param strideX - `x` stride length
* @param y - second input array
* @param strideY - `y` stride length
* @returns `x`
* @returns first input array
*
* @example
* var Float32Array = require( '@stdlib/array/float32' );
Expand Down Expand Up @@ -60,7 +60,7 @@ interface Routine {
* @param y - second input array
* @param strideY - `y` stride length
* @param offsetY - `y` starting index
* @returns `x`
* @returns first input array
*
* @example
* var Float32Array = require( '@stdlib/array/float32' );
Expand Down Expand Up @@ -88,7 +88,7 @@ interface Routine {
* @param strideX - `x` stride length
* @param y - second input array
* @param strideY - `y` stride length
* @returns `x`
* @returns first input array
*
* @example
* var Float32Array = require( '@stdlib/array/float32' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ int main( void ) {
printf( "y[ %i ] = %"PRId64"\n", i, (int64_t)y[ i ] );
}
}

31 changes: 5 additions & 26 deletions lib/node_modules/@stdlib/blas/ext/base/ssort2ins/examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,14 @@

'use strict';

var round = require( '@stdlib/math/base/special/round' );
var randu = require( '@stdlib/random/base/randu' );
var Float32Array = require( '@stdlib/array/float32' );
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory;
var filledarrayBy = require( '@stdlib/array/filled-by' );
var ssort2ins = require( './../lib' );

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

x = new Float32Array( 10 );
y = new Float32Array( 10 ); // index array
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;
}
y[ i ] = i;
}
var x = filledarrayBy( 10, 'float32', discreteUniform( 0, 100 ) );
console.log( x );

var y = filledarrayBy( x.length, 'float32', discreteUniform( 0, 10 ) );
console.log( y );

ssort2ins( x.length, -1.0, x, -1, y, -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,8 @@

// MODULES //

var Float32Array = require( '@stdlib/array/float32' );
var minViewBufferIndex = require( '@stdlib/strided/base/min-view-buffer-index' );
var offsetView = require( '@stdlib/strided/base/offset-view' );
var addon = require( './ssort2ins.native.js' );


Expand Down Expand Up @@ -56,20 +57,19 @@ var addon = require( './ssort2ins.native.js' );
function ssort2ins( N, order, x, strideX, offsetX, y, strideY, offsetY ) {
var viewX;
var viewY;
var flg;
var flg = 1.0;

flg = 1.0;
offsetX = minViewBufferIndex( N, strideX, offsetX );
offsetY = minViewBufferIndex( N, strideY, offsetY );
if ( strideX < 0 ) {
flg *= -1.0; // reversing order
order *= -1.0;
strideX *= -1;
offsetX -= (N-1) * strideX;
}
if ( strideY < 0 ) {
offsetY += (N-1) * strideY;
}
viewX = new Float32Array( x.buffer, x.byteOffset+(x.BYTES_PER_ELEMENT*offsetX), x.length-offsetX ); // eslint-disable-line max-len
viewY = new Float32Array( 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
121 changes: 80 additions & 41 deletions lib/node_modules/@stdlib/blas/ext/base/ssort2ins/manifest.json
Original file line number Diff line number Diff line change
@@ -1,43 +1,82 @@
{
"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/ssort2ins.c"
],
"include": [
"./include"
],
"libraries": [
"-lm"
],
"libpath": [],
"dependencies": [
"@stdlib/math/base/assert/is-nanf",
"@stdlib/math/base/assert/is-negative-zerof"
]
}
]
"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/ssort2ins.c"
],
"include": [
"./include"
],
"libraries": [
"-lm"
],
"libpath": [],
"dependencies": [
"@stdlib/napi/export",
"@stdlib/napi/argv",
"@stdlib/napi/argv-int64",
"@stdlib/napi/argv-double",
"@stdlib/napi/argv-strided-float32array",
"@stdlib/math/base/assert/is-nanf",
"@stdlib/math/base/assert/is-negative-zerof"
]
},
{
"task": "benchmark",
"src": [
"./src/ssort2ins.c"
],
"include": [
"./include"
],
"libraries": [
"-lm"
],
"libpath": [],
"dependencies": []
},
{
"task": "examples",
"src": [
"./src/ssort2ins.c"
],
"include": [
"./include"
],
"libraries": [
"-lm"
],
"libpath": [],
"dependencies": [
"@stdlib/math/base/assert/is-nanf",
"@stdlib/math/base/assert/is-negative-zerof"
]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,7 @@
"single",
"float32array"
],
"__stdlib__": {}
"__stdlib__": {
"wasm": false
}
}
Loading

1 comment on commit f1b1fce

@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/ssort2ins $\color{green}666/666$
$\color{green}+100.00\%$
$\color{green}73/73$
$\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.