Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: update blas/ext/base/ssortins to follow current project conventions #2917

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
Open
34 changes: 7 additions & 27 deletions lib/node_modules/@stdlib/blas/ext/base/ssortins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,34 +50,30 @@ The function has the following parameters:
- **x**: input [`Float32Array`][@stdlib/array/float32].
- **stride**: index increment.

The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to sort every other element
The `N` and stride parameters determine which elements in the strided array 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 N = floor( x.length / 2 );

ssortins( N, -1.0, x, 2 );
ssortins( 2, -1.0, x, 2 );
// x => <Float32Array>[ 3.0, -2.0, 1.0, -4.0 ]
```

Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views.

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

// Initial array...
var x0 = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] );

// Create an offset view...
var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
var N = floor( x0.length/2 );

// Sort every other element...
ssortins( N, -1.0, x1, 2 );
ssortins( 2, -1.0, x1, 2 );
// x0 => <Float32Array>[ 1.0, 4.0, 3.0, 2.0 ]
```

Expand All @@ -98,7 +94,7 @@ The function has the following additional parameters:

- **offset**: 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 Expand Up @@ -136,27 +132,11 @@ ssortins.ndarray( 3, 1.0, x, 1, x.length-3 );
<!-- eslint no-undef: "error" -->

```javascript
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 ssortins = require( '@stdlib/blas/ext/base/ssortins' );

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

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

ssortins( x.length, -1.0, x, -1 );
Expand Down
24 changes: 12 additions & 12 deletions lib/node_modules/@stdlib/blas/ext/base/ssortins/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@

{{alias}}( N, order, x, stride )
Sorts a single-precision floating-point strided array using insertion sort.
Sorts a single-precision floating-point strided array
using insertion sort.

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

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

Examples
--------
Expand All @@ -59,27 +61,26 @@
> {{alias}}( x.length, 1, x, 1 )
<Float32Array>[ -4.0, -2.0, 1.0, 3.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 ] );
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
> {{alias}}( N, -1, x, 2 )
> {{alias}}( 2, -1, x, 2 )
<Float32Array>[ 3.0, -2.0, 1.0, -4.0 ]

// Using view offsets:
> var x0 = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, -4.0 ] );
> var x1 = new {{alias:@stdlib/array/float32}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 );
> N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 );
> {{alias}}( N, 1, x1, 2 )
> {{alias}}( 2, 1, x1, 2 )
<Float32Array>[ -4.0, 3.0, -2.0 ]
> x0
<Float32Array>[ 1.0, -4.0, 3.0, -2.0 ]


{{alias}}.ndarray( N, order, x, stride, offset )
Sorts a single-precision floating-point strided 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 All @@ -103,7 +104,7 @@
Returns
-------
x: Float32Array
Input array `x`.
Input array.

Examples
--------
Expand All @@ -114,8 +115,7 @@

// Using an index offset:
> x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, -4.0 ] );
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
> {{alias}}.ndarray( N, 1, x, 2, 1 )
> {{alias}}.ndarray( 2, 1, x, 2, 1 )
<Float32Array>[ 1.0, -4.0, 3.0, -2.0 ]

See Also
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ interface Routine {
* @param order - sort order
* @param x - input array
* @param stride - stride length
* @returns `x`
* @returns input array
*
* @example
* var Float32Array = require( '@stdlib/array/float32' );
Expand All @@ -49,7 +49,7 @@ interface Routine {
* @param x - input array
* @param stride - stride length
* @param offset - starting index
* @returns `x`
* @returns input array
*
* @example
* var Float32Array = require( '@stdlib/array/float32' );
Expand All @@ -69,7 +69,7 @@ interface Routine {
* @param order - sort order
* @param x - input array
* @param stride - stride length
* @returns `x`
* @returns input array
*
* @example
* var Float32Array = require( '@stdlib/array/float32' );
Expand Down
26 changes: 3 additions & 23 deletions lib/node_modules/@stdlib/blas/ext/base/ssortins/examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,11 @@

'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 ssortins = require( './../lib' );

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

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

ssortins( x.length, -1.0, x, -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( './ssortins.native.js' );


Expand All @@ -45,12 +46,10 @@ var addon = require( './ssortins.native.js' );
*/
function ssortins( N, order, x, stride, offset ) {
var view;
if ( stride < 0 ) {
order *= -1.0;
stride *= -1;
offset -= (N-1) * stride;
}
view = new Float32Array( x.buffer, x.byteOffset+(x.BYTES_PER_ELEMENT*offset), x.length-offset ); // eslint-disable-line max-len

offset = minViewBufferIndex( N, stride, offset );
view = offsetView( x, offset );

addon( N, order, view, stride );
return x;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@
"libpath": [],
"dependencies": [
"@stdlib/math/base/assert/is-nanf",
"@stdlib/math/base/assert/is-negative-zerof"
"@stdlib/math/base/assert/is-negative-zerof",
"@stdlib/napi/export",
"@stdlib/napi/argv",
"@stdlib/napi/argv-double",
"@stdlib/napi/argv-float",
"@stdlib/napi/argv-int64",
"@stdlib/napi/argv-strided-float32array"
]
}
]
Expand Down
4 changes: 3 additions & 1 deletion lib/node_modules/@stdlib/blas/ext/base/ssortins/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,7 @@
"single",
"float32array"
],
"__stdlib__": {}
"__stdlib__": {
"wasm": false
}
}
44 changes: 44 additions & 0 deletions lib/node_modules/@stdlib/blas/ext/base/ssortins/src/addon.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* @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/ssortins.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_float32array.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, 4 );
STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 );
STDLIB_NAPI_ARGV_DOUBLE( env, order, argv, 1 );
STDLIB_NAPI_ARGV_INT64( env, stride, argv, 3 );
STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, stride, argv, 2 );
c_ssortins( N, order, X, stride );
return NULL;
}

STDLIB_NAPI_MODULE_EXPORT_FCN( addon )
Loading
Loading