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: updated blas/ext/base/ssort2sh to follow current project conventions #2957

Merged
merged 11 commits into from
Sep 29, 2024
18 changes: 6 additions & 12 deletions lib/node_modules/@stdlib/blas/ext/base/ssort2sh/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,15 @@ 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 );

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

console.log( x );
// => <Float32Array>[ 3.0, -2.0, 1.0, -4.0 ]
Expand All @@ -81,7 +79,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 +87,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...
ssort2sh( N, -1.0, x1, 2, y1, 2 );
ssort2sh( 2, -1.0, x1, 2, y1, 2 );

console.log( x0 );
// => <Float32Array>[ 1.0, 4.0, 3.0, 2.0 ]
Expand Down Expand Up @@ -126,7 +122,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 Expand Up @@ -177,12 +173,10 @@ var ssort2sh = require( '@stdlib/blas/ext/base/ssort2sh' );

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

x = new Float32Array( 10 );
y = new Float32Array( 10 ); // index array
var x = new Float32Array( 10 );
var y = new Float32Array( 10 ); // index array
for ( i = 0; i < x.length; i++ ) {
rand = round( randu()*100.0 );
sign = randu();
Expand Down
20 changes: 9 additions & 11 deletions lib/node_modules/@stdlib/blas/ext/base/ssort2sh/docs/repl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
Simultaneously sorts two single-precision floating-point strided arrays
based on the sort order of the first array using Shellsort.

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 @@ -67,11 +67,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 @@ -81,22 +80,22 @@
> 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 Shellsort 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 parameter supports indexing semantics based on a starting
index.

Parameters
----------
Expand Down Expand Up @@ -143,8 +142,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 @@ -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 - first stride length
* @param y - second input array
* @param strideY - `y` stride length
* @param strideY - second stride length
* @returns `x`
*
* @example
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@ var ssort2sh = require( './../lib' );

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

x = new Float32Array( 10 );
y = new Float32Array( 10 ); // index array
var x = new Float32Array( 10 );
var y = new Float32Array( 10 ); // index array
for ( i = 0; i < x.length; i++ ) {
if ( randu() < 0.2 ) {
x[ i ] = NaN;
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
124 changes: 83 additions & 41 deletions lib/node_modules/@stdlib/blas/ext/base/ssort2sh/manifest.json
Original file line number Diff line number Diff line change
@@ -1,43 +1,85 @@
{
"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/ssort2sh.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/ssort2sh.c"
],
"include": [
"./include"
],
"libraries": [
"-lm"
],
"libpath": [],
"dependencies": [
"@stdlib/math/base/assert/is-nanf",
"@stdlib/math/base/assert/is-negative-zerof",
"@stdlib/napi/export",
"@stdlib/napi/argv",
"@stdlib/napi/argv-float",
"@stdlib/napi/argv-int64",
"@stdlib/napi/argv-strided-float32array"
]
},
{
"task": "benchmark",
"src": [
"./src/ssort2sh.c"
],
"include": [
"./include"
],
"libraries": [
"-lm"
],
"libpath": [],
"dependencies": [
"@stdlib/math/base/assert/is-nanf",
"@stdlib/math/base/assert/is-negative-zerof"
]
},
{
"task": "examples",
"src": [
"./src/ssort2sh.c"
],
"include": [
"./include"
],
"libraries": [
"-lm"
],
"libpath": [],
"dependencies": [
"@stdlib/math/base/assert/is-nanf",
"@stdlib/math/base/assert/is-negative-zerof"
]
}
]
}
4 changes: 3 additions & 1 deletion lib/node_modules/@stdlib/blas/ext/base/ssort2sh/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,7 @@
"single",
"float32array"
],
"__stdlib__": {}
"__stdlib__": {
"wasm": false
}
}
46 changes: 46 additions & 0 deletions lib/node_modules/@stdlib/blas/ext/base/ssort2sh/src/addon.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* @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/ssort2sh.h"
#include "stdlib/napi/export.h"
#include "stdlib/napi/argv.h"
#include "stdlib/napi/argv_int64.h"
#include "stdlib/napi/argv_float.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, 6 );
STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 );
STDLIB_NAPI_ARGV_FLOAT( env, order, argv, 1 );
STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 );
STDLIB_NAPI_ARGV_INT64( env, strideY, argv, 5 );
STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 2 );
STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, Y, N, strideY, argv, 4 );
c_ssort2sh( N, order, X, strideX, Y, strideY );
return NULL;
}

STDLIB_NAPI_MODULE_EXPORT_FCN( addon )
Loading
Loading