Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
140 changes: 129 additions & 11 deletions lib/node_modules/@stdlib/blas/ext/base/ssorthp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ limitations under the License.
var ssorthp = require( '@stdlib/blas/ext/base/ssorthp' );
```

#### ssorthp( N, order, x, stride )
#### ssorthp( N, order, x, strideX )

Sorts a single-precision floating-point strided array using heapsort.

Expand All @@ -48,9 +48,9 @@ The function has the following parameters:
- **N**: number of indexed elements.
- **order**: sort order. If `order < 0.0`, the input strided array is sorted in **decreasing** order. If `order > 0.0`, the input strided array is sorted in **increasing** order. If `order == 0.0`, the input strided array is left unchanged.
- **x**: input [`Float32Array`][@stdlib/array/float32].
- **stride**: index increment.
- **strideX**: stride length.

The `N` and stride parameters determine which elements in the strided arrays 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' );
Expand All @@ -77,7 +77,7 @@ ssorthp( 2, -1.0, x1, 2 );
// x0 => <Float32Array>[ 1.0, 4.0, 3.0, 2.0 ]
```

#### ssorthp.ndarray( N, order, x, stride, offset )
#### ssorthp.ndarray( N, order, x, strideX, offsetX )

Sorts a single-precision floating-point strided array using heapsort and alternative indexing semantics.

Expand All @@ -92,9 +92,9 @@ ssorthp.ndarray( x.length, 1.0, x, 1, 0 );

The function has the following additional parameters:

- **offset**: starting index.
- **offsetX**: 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 the strided array
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:

```javascript
var Float32Array = require( '@stdlib/array/float32' );
Expand Down Expand Up @@ -131,13 +131,12 @@ ssorthp.ndarray( 3, 1.0, x, 1, x.length-3 );
<!-- eslint no-undef: "error" -->

```javascript
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory;
var filledarrayBy = require( '@stdlib/array/filled-by' );
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var ssorthp = require( '@stdlib/blas/ext/base/ssorthp' );

var rand = discreteUniform( -100, 100 );
var x = filledarrayBy( 10, 'float32', rand );

var x = discreteUniform( 10, -100, 100, {
'dtype': 'float32'
});
console.log( x );

ssorthp( x.length, -1.0, x, -1 );
Expand All @@ -150,6 +149,125 @@ console.log( x );

* * *

<section class="c">

## C APIs

<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

<section class="intro">

</section>

<!-- /.intro -->

<!-- C usage documentation. -->

<section class="usage">

### Usage

```c
#include "stdlib/blas/ext/base/ssorthp.h"
```

#### stdlib_strided_ssorthp( N, order, \*X, strideX )

Sorts a single-precision floating-point strided array using heapsort.

```c
float x[] = { 1.0f, -2.0f, 3.0f, -4.0f };

stdlib_strided_ssorthp( 2, -1.0f, x, 1 );
```

The function accepts the following arguments:

- **N**: `[in] CBLAS_INT` number of indexed elements.
- **order**: `[in] float` sort order. If `order < 0.0`, the input strided array is sorted in **decreasing** order. If `order > 0.0`, the input strided array is sorted in **increasing** order. If `order == 0.0`, the input strided array is left unchanged.
- **X**: `[inout] float*` input array.
- **strideX**: `[in] CBLAS_INT` stride length.

```c
stdlib_strided_ssorthp( const CBLAS_INT N, const float order, float *X, const CBLAS_INT strideX );
```

<!--lint disable maximum-heading-length-->

#### stdlib_strided_ssorthp_ndarray( N, order, \*X, strideX, offsetX )

<!--lint enable maximum-heading-length-->

Sorts a single-precision floating-point strided array using heapsort and alternative indexing semantics.

```c
float x[] = { 1.0f, -2.0f, 3.0f, -4.0f };

stdlib_strided_ssorthp_ndarray( 4, 1.0f, x, 1, 0 );
```

The function accepts the following arguments:

- **N**: `[in] CBLAS_INT` number of indexed elements.
- **order**: `[in] float` sort order. If `order < 0.0`, the input strided array is sorted in **decreasing** order. If `order > 0.0`, the input strided array is sorted in **increasing** order. If `order == 0.0`, the input strided array is left unchanged.
- **X**: `[inout] float*` input array.
- **strideX**: `[in] CBLAS_INT` stride length.
- **offsetX**: `[in] CBLAS_INT` starting index.

```c
stdlib_strided_ssorthp_ndarray( const CBLAS_INT N, const float order, float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX );
```

</section>

<!-- /.usage -->

<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="notes">

</section>

<!-- /.notes -->

<!-- C API usage examples. -->

<section class="examples">

### Examples

```c
#include "stdlib/blas/ext/base/ssorthp.h"
#include <stdio.h>

int main( void ) {
// Create a strided array:
float x[] = { 1.0f, -2.0f, 3.0f, -4.0f, 5.0f, -6.0f, 7.0f, -8.0f };

// Specify the number of elements:
int N = 8;

// Specify a stride:
int strideX = 1;

// Sort the array:
stdlib_strided_ssorthp( N, 1.0f, x, strideX );

// Print the result:
for ( int i = 0; i < 8; i++ ) {
printf( "x[ %i ] = %f\n", i, x[ i ] );
}
}
```

</section>

<!-- /.examples -->

</section>

<!-- /.c -->

<section class="references">

## References
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var pow = require( '@stdlib/math/base/special/pow' );
var floor = require( '@stdlib/math/base/special/floor' );
var Float32Array = require( '@stdlib/array/float32' );
var scopy = require( '@stdlib/blas/base/scopy' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var ssorthp = require( './../lib/ssorthp.js' );

Expand Down Expand Up @@ -119,7 +120,7 @@ function main() {
opts = {
'iterations': iter
};
bench( pkg+'::mostly_sorted,few_uniques:len='+len, opts, f );
bench( format( '%s::mostly_sorted,few_uniques:len=%d', pkg, len ), opts, f );
iter = floor( pow( iter, 3.0/4.0 ) );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var pow = require( '@stdlib/math/base/special/pow' );
var floor = require( '@stdlib/math/base/special/floor' );
var Float32Array = require( '@stdlib/array/float32' );
var scopy = require( '@stdlib/blas/base/scopy' );
var format = require( '@stdlib/string/format' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;

Expand Down Expand Up @@ -129,7 +130,7 @@ function main() {
'skip': opts.skip,
'iterations': iter
};
bench( pkg+'::native,mostly_sorted,few_uniques:len='+len, bopts, f );
bench( format( '%s::native,mostly_sorted,few_uniques:len=%d', pkg, len ), bopts, f );
iter = floor( pow( iter, 3.0/4.0 ) );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var pow = require( '@stdlib/math/base/special/pow' );
var floor = require( '@stdlib/math/base/special/floor' );
var Float32Array = require( '@stdlib/array/float32' );
var scopy = require( '@stdlib/blas/base/scopy' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var ssorthp = require( './../lib/ndarray.js' );

Expand Down Expand Up @@ -119,7 +120,7 @@ function main() {
opts = {
'iterations': iter
};
bench( pkg+'::mostly_sorted,few_uniques:ndarray:len='+len, opts, f );
bench( format( '%s::mostly_sorted,few_uniques:ndarray:len=%d', pkg, len ), opts, f );
iter = floor( pow( iter, 3.0/4.0 ) );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var pow = require( '@stdlib/math/base/special/pow' );
var floor = require( '@stdlib/math/base/special/floor' );
var Float32Array = require( '@stdlib/array/float32' );
var scopy = require( '@stdlib/blas/base/scopy' );
var format = require( '@stdlib/string/format' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;

Expand Down Expand Up @@ -129,7 +130,7 @@ function main() {
'skip': opts.skip,
'iterations': iter
};
bench( pkg+'::native,mostly_sorted,few_uniques:ndarray:len='+len, bopts, f );
bench( format( '%s::native,mostly_sorted,few_uniques:ndarray:len=%d', pkg, len ), bopts, f );
iter = floor( pow( iter, 3.0/4.0 ) );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var pow = require( '@stdlib/math/base/special/pow' );
var floor = require( '@stdlib/math/base/special/floor' );
var Float32Array = require( '@stdlib/array/float32' );
var scopy = require( '@stdlib/blas/base/scopy' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var ssorthp = require( './../lib/ssorthp.js' );

Expand Down Expand Up @@ -110,7 +111,7 @@ function main() {
opts = {
'iterations': iter
};
bench( pkg+'::mostly_sorted,random:len='+len, opts, f );
bench( format( '%s::mostly_sorted,random:len=%d', pkg, len ), opts, f );
iter = floor( pow( iter, 3.0/4.0 ) );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var pow = require( '@stdlib/math/base/special/pow' );
var floor = require( '@stdlib/math/base/special/floor' );
var Float32Array = require( '@stdlib/array/float32' );
var scopy = require( '@stdlib/blas/base/scopy' );
var format = require( '@stdlib/string/format' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;

Expand Down Expand Up @@ -120,7 +121,7 @@ function main() {
'skip': opts.skip,
'iterations': iter
};
bench( pkg+'::native,mostly_sorted,random:len='+len, bopts, f );
bench( format( '%s::native,mostly_sorted,random:len=%d', pkg, len ), bopts, f );
iter = floor( pow( iter, 3.0/4.0 ) );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var pow = require( '@stdlib/math/base/special/pow' );
var floor = require( '@stdlib/math/base/special/floor' );
var Float32Array = require( '@stdlib/array/float32' );
var scopy = require( '@stdlib/blas/base/scopy' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var ssorthp = require( './../lib/ndarray.js' );

Expand Down Expand Up @@ -110,7 +111,7 @@ function main() {
opts = {
'iterations': iter
};
bench( pkg+'::mostly_sorted,random:ndarray:len='+len, opts, f );
bench( format( '%s::mostly_sorted,random:ndarray:len=%d', pkg, len ), opts, f );
iter = floor( pow( iter, 3.0/4.0 ) );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var pow = require( '@stdlib/math/base/special/pow' );
var floor = require( '@stdlib/math/base/special/floor' );
var Float32Array = require( '@stdlib/array/float32' );
var scopy = require( '@stdlib/blas/base/scopy' );
var format = require( '@stdlib/string/format' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;

Expand Down Expand Up @@ -120,7 +121,7 @@ function main() {
'skip': opts.skip,
'iterations': iter
};
bench( pkg+'::native,mostly_sorted,random:ndarray:len='+len, bopts, f );
bench( format( '%s::native,mostly_sorted,random:ndarray:len=%d', pkg, len ), bopts, f );
iter = floor( pow( iter, 3.0/4.0 ) );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var pow = require( '@stdlib/math/base/special/pow' );
var floor = require( '@stdlib/math/base/special/floor' );
var Float32Array = require( '@stdlib/array/float32' );
var scopy = require( '@stdlib/blas/base/scopy' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var ssorthp = require( './../lib/ssorthp.js' );

Expand Down Expand Up @@ -119,7 +120,7 @@ function main() {
opts = {
'iterations': iter
};
bench( pkg+'::reverse_mostly_sorted,few_uniques:len='+len, opts, f );
bench( format( '%s::reverse_mostly_sorted,few_uniques:len=%d', pkg, len ), opts, f );
iter = floor( pow( iter, 3.0/4.0 ) );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var pow = require( '@stdlib/math/base/special/pow' );
var floor = require( '@stdlib/math/base/special/floor' );
var Float32Array = require( '@stdlib/array/float32' );
var scopy = require( '@stdlib/blas/base/scopy' );
var format = require( '@stdlib/string/format' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;

Expand Down Expand Up @@ -129,7 +130,7 @@ function main() {
'skip': opts.skip,
'iterations': iter
};
bench( pkg+'::native,reverse_mostly_sorted,few_uniques:len='+len, bopts, f );
bench( format( '%s::native,reverse_mostly_sorted,few_uniques:len=%d', pkg, len ), bopts, f );
iter = floor( pow( iter, 3.0/4.0 ) );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var pow = require( '@stdlib/math/base/special/pow' );
var floor = require( '@stdlib/math/base/special/floor' );
var Float32Array = require( '@stdlib/array/float32' );
var scopy = require( '@stdlib/blas/base/scopy' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var ssorthp = require( './../lib/ndarray.js' );

Expand Down Expand Up @@ -119,7 +120,7 @@ function main() {
opts = {
'iterations': iter
};
bench( pkg+'::reverse_mostly_sorted,few_uniques:ndarray:len='+len, opts, f );
bench( format( '%s::reverse_mostly_sorted,few_uniques:ndarray:len=%d', pkg, len ), opts, f );
iter = floor( pow( iter, 3.0/4.0 ) );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var pow = require( '@stdlib/math/base/special/pow' );
var floor = require( '@stdlib/math/base/special/floor' );
var Float32Array = require( '@stdlib/array/float32' );
var scopy = require( '@stdlib/blas/base/scopy' );
var format = require( '@stdlib/string/format' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;

Expand Down Expand Up @@ -129,7 +130,7 @@ function main() {
'skip': opts.skip,
'iterations': iter
};
bench( pkg+'::native,reverse_mostly_sorted,few_uniques:ndarray:len='+len, bopts, f );
bench( format( '%s::native,reverse_mostly_sorted,few_uniques:ndarray:len=%d', pkg, len ), bopts, f );
iter = floor( pow( iter, 3.0/4.0 ) );
}
}
Expand Down
Loading