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/sapx to follow current project conventions #1824

Merged
merged 14 commits into from
Mar 21, 2024
Merged
38 changes: 10 additions & 28 deletions lib/node_modules/@stdlib/blas/ext/base/sapx/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 add a constant to every other element
The `N` and `stride` parameters determine which elements in the strided array are accessed at runtime. For example, to add a constant to every other element
kgryte marked this conversation as resolved.
Show resolved Hide resolved

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

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

sapx( N, 5.0, x, 2 );
sapx( 4, 5.0, x, 2 );
// x => <Float32Array>[ 3.0, 1.0, 8.0, -5.0, 9.0, 0.0, 4.0, -3.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, 5.0, -6.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 );

// Add a constant to every other element...
sapx( N, 5.0, x1, 2 );
sapx( 3, 5.0, x1, 2 );
// x0 => <Float32Array>[ 1.0, 3.0, 3.0, 1.0, 5.0, -1.0 ]
```

kgryte marked this conversation as resolved.
Show resolved Hide resolved
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 the strided array

```javascript
var Float32Array = require( '@stdlib/array/float32' );
Expand All @@ -117,7 +113,7 @@ sapx.ndarray( 3, 5.0, x, 1, x.length-3 );

## Notes

- If `N <= 0`, both functions return `x` unchanged.
- If `N <= 0`, both functions return the input array unchanged.
rxbryan marked this conversation as resolved.
Show resolved Hide resolved

</section>

Expand All @@ -130,27 +126,13 @@ sapx.ndarray( 3, 5.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 uniform = require( '@stdlib/random/base/uniform' ).factory;
var filledarrayBy = require( '@stdlib/array/filled-by' );
var sapx = require( '@stdlib/blas/ext/base/sapx' );

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 rand = uniform( -100.0, 100.0 );

kgryte marked this conversation as resolved.
Show resolved Hide resolved
var x = filledarrayBy( 10, 'float32', rand );
console.log( x );

sapx( x.length, 5.0, x, 1 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,19 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/base/uniform' ).factory;
var filledarrayBy = require( '@stdlib/array/filled-by' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var Float32Array = require( '@stdlib/array/float32' );
var pkg = require( './../package.json' ).name;
var sapx = require( './../lib/sapx.js' );


// VARIABLES //

var rand = uniform( -100.0, 100.0 );


// FUNCTIONS //

/**
Expand All @@ -39,13 +44,7 @@ var sapx = require( './../lib/sapx.js' );
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var x;
var i;

x = new Float32Array( len );
for ( i = 0; i < len; i++ ) {
x[ i ] = ( randu()*20.0 ) - 10.0;
}
var x = filledarrayBy( len, 'float32', rand );
return benchmark;

function benchmark( b ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@

var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/base/uniform' ).factory;
var filledarrayBy = require( '@stdlib/array/filled-by' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var Float32Array = require( '@stdlib/array/float32' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;

Expand All @@ -36,6 +36,7 @@ var sapx = tryRequire( resolve( __dirname, './../lib/sapx.native.js' ) );
var opts = {
'skip': ( sapx instanceof Error )
};
var rand = uniform( -100.0, 100.0 );


// FUNCTIONS //
Expand All @@ -48,13 +49,7 @@ var opts = {
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var x;
var i;

x = new Float32Array( len );
for ( i = 0; i < len; i++ ) {
x[ i ] = ( randu()*20.0 ) - 10.0;
}
var x = filledarrayBy( len, 'float32', rand );
return benchmark;

function benchmark( b ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,19 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/base/uniform' ).factory;
var filledarrayBy = require( '@stdlib/array/filled-by' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var Float32Array = require( '@stdlib/array/float32' );
var pkg = require( './../package.json' ).name;
var sapx = require( './../lib/ndarray.js' );


// VARIABLES //

var rand = uniform( -100.0, 100.0 );


// FUNCTIONS //

/**
Expand All @@ -39,13 +44,7 @@ var sapx = require( './../lib/ndarray.js' );
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var x;
var i;

x = new Float32Array( len );
for ( i = 0; i < len; i++ ) {
x[ i ] = ( randu()*20.0 ) - 10.0;
}
var x = filledarrayBy( len, 'float32', rand );
return benchmark;

function benchmark( b ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@

var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/base/uniform' ).factory;
var filledarrayBy = require( '@stdlib/array/filled-by' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var Float32Array = require( '@stdlib/array/float32' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;

Expand All @@ -36,6 +36,7 @@ var sapx = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) );
var opts = {
'skip': ( sapx instanceof Error )
};
var rand = uniform( -100.0, 100.0 );


// FUNCTIONS //
Expand All @@ -48,13 +49,7 @@ var opts = {
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var x;
var i;

x = new Float32Array( len );
for ( i = 0; i < len; i++ ) {
x[ i ] = ( randu()*20.0 ) - 10.0;
}
var x = filledarrayBy( len, 'float32', rand );
return benchmark;

function benchmark( b ) {
Expand Down
23 changes: 5 additions & 18 deletions lib/node_modules/@stdlib/blas/ext/base/sapx/examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,14 @@

'use strict';

var round = require( '@stdlib/math/base/special/round' );
var randu = require( '@stdlib/random/base/randu' );
var Float32Array = require( '@stdlib/array/float32' );
var uniform = require( '@stdlib/random/base/uniform' ).factory;
var filledarrayBy = require( '@stdlib/array/filled-by' );
var sapx = require( './../lib' );

var rand;
var sign;
var x;
var i;
var rand = uniform( -100.0, 100.0 );

var x = filledarrayBy( 10, 'float32', rand );
kgryte marked this conversation as resolved.
Show resolved Hide resolved

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;
}
console.log( x );

sapx( x.length, 5.0, x, 1 );
Expand Down
2 changes: 1 addition & 1 deletion lib/node_modules/@stdlib/blas/ext/base/sapx/include.gypi
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( './sapx.native.js' );


Expand All @@ -47,10 +48,9 @@ var addon = require( './sapx.native.js' );
*/
function sapx( N, alpha, x, stride, offset ) {
var view;
if ( stride < 0 ) {
offset += (N-1) * stride;
}
view = new Float32Array( x.buffer, x.byteOffset+(x.BYTES_PER_ELEMENT*offset), x.length-offset ); // eslint-disable-line max-len

kgryte marked this conversation as resolved.
Show resolved Hide resolved
offset = minViewBufferIndex( N, stride, offset );
view = offsetView( x, offset );
addon( N, alpha, view, stride );
return x;
}
Expand Down
82 changes: 44 additions & 38 deletions lib/node_modules/@stdlib/blas/ext/base/sapx/manifest.json
Original file line number Diff line number Diff line change
@@ -1,40 +1,46 @@
{
"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/sapx.c"
],
"include": [
"./include"
],
"libraries": [
"-lm"
],
"libpath": [],
"dependencies": []
}
]
"options": {},
kgryte marked this conversation as resolved.
Show resolved Hide resolved
kgryte marked this conversation as resolved.
Show resolved Hide resolved
"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/sapx.c"
],
"include": [
"./include"
],
"libraries": [
"-lm"
],
"libpath": [],
"dependencies": [
"@stdlib/napi/export",
"@stdlib/napi/argv",
"@stdlib/napi/argv-int64",
"@stdlib/napi/argv-double",
kgryte marked this conversation as resolved.
Show resolved Hide resolved
"@stdlib/napi/argv-strided-float32array"
]
}
]
}
4 changes: 3 additions & 1 deletion lib/node_modules/@stdlib/blas/ext/base/sapx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,7 @@
"single",
"float32array"
],
"__stdlib__": {}
"__stdlib__": {
"wasm": false
}
}
Loading
Loading