@stdlib/blas-ext-base-ndarray-gsorthp
v0.1.1
Published
Sort a one-dimensional ndarray using heapsort.
Readme
gsorthp
Sort a one-dimensional ndarray using heapsort.
Installation
npm install @stdlib/blas-ext-base-ndarray-gsorthpUsage
var gsorthp = require( '@stdlib/blas-ext-base-ndarray-gsorthp' );gsorthp( arrays )
Sorts a one-dimensional ndarray using heapsort.
var scalar2ndarray = require( '@stdlib/ndarray-from-scalar' );
var ndarray2array = require( '@stdlib/ndarray-to-array' );
var ndarray = require( '@stdlib/ndarray-base-ctor' );
var xbuf = [ 1.0, -2.0, 3.0, -4.0 ];
var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' );
var order = scalar2ndarray( 1.0, {
'dtype': 'generic'
});
var out = gsorthp( [ x, order ] );
// returns <ndarray>
var arr = ndarray2array( out );
// returns [ -4.0, -2.0, 1.0, 3.0 ]The function has the following parameters:
- arrays: array-like object containing a one-dimensional input ndarray and a zero-dimensional ndarray specifying the sort order.
Notes
- The input ndarray is sorted in-place (i.e., the input ndarray is mutated).
- When the sort order is less than zero, the input ndarray is sorted in decreasing order. When the sort order is greater than zero, the input ndarray is sorted in increasing order. When the sort order is equal to zero, the input ndarray is left unchanged.
Examples
var discreteUniform = require( '@stdlib/random-array-discrete-uniform' );
var ndarray = require( '@stdlib/ndarray-base-ctor' );
var scalar2ndarray = require( '@stdlib/ndarray-from-scalar' );
var ndarray2array = require( '@stdlib/ndarray-to-array' );
var ndarraylike2scalar = require( '@stdlib/ndarray-base-ndarraylike2scalar' );
var gsorthp = require( '@stdlib/blas-ext-base-ndarray-gsorthp' );
var xbuf = discreteUniform( 10, -100, 100, {
'dtype': 'generic'
});
var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' );
console.log( ndarray2array( x ) );
var order = scalar2ndarray( 1.0, {
'dtype': 'generic'
});
console.log( 'Order:', ndarraylike2scalar( order ) );
gsorthp( [ x, order ] );
console.log( ndarray2array( x ) );Notice
This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
Community
License
See LICENSE.
Copyright
Copyright © 2016-2026. The Stdlib Authors.
