Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 17 additions & 37 deletions lib/node_modules/@stdlib/blas/ext/base/gsort2hp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var gsort2hp = require( '@stdlib/blas/ext/base/gsort2hp' );

#### gsort2hp( N, order, x, strideX, y, strideY )

Simultaneously sorts two strided arrays based on the sort order of the first array `x` using heapsort.
Simultaneously sorts two strided arrays based on the sort order of the first array using heapsort.

```javascript
var x = [ 1.0, -2.0, 3.0, -4.0 ];
Expand All @@ -52,20 +52,17 @@ The function has the following parameters:
- **N**: number of indexed elements.
- **order**: sort order. If `order < 0.0`, the input strided array `x` is sorted in **decreasing** order. If `order > 0.0`, the input strided array `x` is sorted in **increasing** order. If `order == 0.0`, the input strided arrays are left unchanged.
- **x**: first input [`Array`][mdn-array] or [`typed array`][mdn-typed-array].
- **strideX**: `x` index increment.
- **strideX**: stride length for `x`.
- **y**: second input [`Array`][mdn-array] or [`typed array`][mdn-typed-array].
- **strideY**: `y` index increment.
- **strideY**: stride length for `y`.

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 floor = require( '@stdlib/math/base/special/floor' );

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

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

console.log( x );
// => [ 3.0, -2.0, 1.0, -4.0 ]
Expand All @@ -78,7 +75,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 @@ -87,10 +83,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...
gsort2hp( N, -1.0, x1, 2, y1, 2 );
gsort2hp( 2, -1.0, x1, 2, y1, 2 );

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

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

Simultaneously sorts two strided arrays based on the sort order of the first array `x` using heapsort and alternative indexing semantics.
Simultaneously sorts two strided arrays based on the sort order of the first array using heapsort and alternative indexing semantics.

```javascript
var x = [ 1.0, -2.0, 3.0, -4.0 ];
Expand All @@ -118,10 +113,10 @@ console.log( y );

The function has the following additional parameters:

- **offsetX**: `x` starting index.
- **offsetY**: `y` starting index.
- **offsetX**: starting index for `x`.
- **offsetY**: starting index for `y`.

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 parameters support indexing semantics based on starting indices. For example, to access only the last three elements:

```javascript
var x = [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ];
Expand Down Expand Up @@ -164,30 +159,15 @@ console.log( y );
<!-- 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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var gsort2hp = require( '@stdlib/blas/ext/base/gsort2hp' );

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

x = new Float64Array( 10 );
y = new Float64Array( 10 ); // index array
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;
y[ i ] = i;
}
var x = discreteUniform( 10, -100, 100, {
'dtype': 'float64'
});
var y = discreteUniform( 10, -100, 100, {
'dtype': 'float64'
});
console.log( x );
console.log( y );

Expand Down
28 changes: 13 additions & 15 deletions lib/node_modules/@stdlib/blas/ext/base/gsort2hp/docs/repl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
Simultaneously sorts two strided arrays based on the sort order of the first
array using heapsort.

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 @@ -41,13 +41,13 @@
First input array.

strideX: integer
Index increment for `x`.
Stride length for `x`.

y: Array<number>|TypedArray
Second input array.

strideY: integer
Index increment for `y`.
Stride length for `y`.

Returns
-------
Expand All @@ -64,11 +64,10 @@
> y
[ 3.0, 1.0, 0.0, 2.0 ]

// Using `N` and `stride` parameters:
// Using `N` and stride parameters:
> x = [ 1.0, -2.0, 3.0, -4.0 ];
> y = [ 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 )
[ 3.0, -2.0, 1.0, -4.0 ]
> y
[ 2.0, 1.0, 0.0, 3.0 ]
Expand All @@ -78,21 +77,21 @@
> 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 strided arrays based on the sort order of the first
array using heapsort 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
starting index.
buffer, the offset parameters support indexing semantics based on starting
indices.

Parameters
----------
Expand All @@ -107,7 +106,7 @@
First input array.

strideX: integer
Index increment for `x`.
Stride length for `x`.

offsetX: integer
Starting index of `x`.
Expand All @@ -116,7 +115,7 @@
Second input array.

strideY: integer
Index increment for `y`.
Stride length for `y`.

offsetY: integer
Starting index of `y`.
Expand All @@ -139,8 +138,7 @@
// Using an index offset:
> x = [ 1.0, -2.0, 3.0, -4.0 ];
> y = [ 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 )
[ 1.0, -4.0, 3.0, -2.0 ]
> y
[ 0.0, 3.0, 2.0, 1.0 ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,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 - stride length for `x`
* @param y - second input array
* @param strideY - `y` stride length
* @param strideY - stride length for `x`
* @returns `x`
*
* @example
Expand All @@ -57,11 +57,11 @@ interface Routine {
* @param N - number of indexed elements
* @param order - sort order
* @param x - first input array
* @param strideX - `x` stride length
* @param offsetX - `x` starting index
* @param strideX - stride length for `x`
* @param offsetX - starting index for `x`
* @param y - second input array
* @param strideY - `y` stride length
* @param offsetY - `y` starting index
* @param strideY - stride length for `x`
* @param offsetY - starting index for `y`
* @returns `x`
*
* @example
Expand All @@ -85,9 +85,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 - stride length for `x`
* @param y - second input array
* @param strideY - `y` stride length
* @param strideY - stride length for `x`
* @returns `x`
*
* @example
Expand Down
35 changes: 8 additions & 27 deletions lib/node_modules/@stdlib/blas/ext/base/gsort2hp/examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,15 @@

'use strict';

var round = require( '@stdlib/math/base/special/round' );
var randu = require( '@stdlib/random/base/randu' );
var Float64Array = require( '@stdlib/array/float64' );
var gsort2hp = require( './../lib' );
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var gsort2hp = require( '@stdlib/blas/ext/base/gsort2hp' );

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

x = new Float64Array( 10 );
y = new Float64Array( 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 = discreteUniform( 10, -100, 100, {
'dtype': 'float64'
});
var y = discreteUniform( 10, -100, 100, {
'dtype': 'float64'
});
console.log( x );
console.log( y );

Expand Down
Loading
Loading