Skip to content

Commit

Permalink
Auto-generated commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stdlib-bot committed Nov 25, 2023
1 parent 88b3c85 commit d6325f4
Show file tree
Hide file tree
Showing 108 changed files with 6,292 additions and 378 deletions.
5 changes: 0 additions & 5 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,6 @@ indent_size = 2
indent_style = space
indent_size = 2

# Set properties for `tslint.json` files:
[tslint.json]
indent_style = space
indent_size = 2

# Set properties for `tsconfig.json` files:
[tsconfig.json]
indent_style = space
Expand Down
1 change: 1 addition & 0 deletions array/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ The function accepts the following `options`:
- **mode**: specifies how to handle indices which exceed array dimensions.

- `throw`: specifies that an [`ndarray`][@stdlib/ndarray/ctor] instance should throw an error when an index exceeds array dimensions.
- `normalize`: specifies that an [`ndarray`][@stdlib/ndarray/ctor] instance should normalize negative indices and throw an error when an index exceeds array dimensions.
- `wrap`: specifies that an [`ndarray`][@stdlib/ndarray/ctor] instance should wrap around an index exceeding array dimensions using modulo arithmetic.
- `clamp`: specifies that an [`ndarray`][@stdlib/ndarray/ctor] instance should set an index exceeding array dimensions to either `0` (minimum index) or the maximum index.

Expand Down
4 changes: 4 additions & 0 deletions array/docs/repl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@

- 'throw': an ndarray instance throws an error when an index exceeds
array dimensions.
- 'normalize': an ndarray instance normalizes negative indices and
throws an error when an index exceeds array dimensions.
- 'wrap': an ndarray instance wraps around indices exceeding array
dimensions using modulo arithmetic.
- 'clamp', an ndarray instance sets an index exceeding array dimensions
Expand All @@ -114,6 +116,8 @@

- 'throw': an ndarray instance throws an error when a subscript exceeds
array dimensions.
- 'normalize': an ndarray instance normalizes negative subscripts and
throws an error when a subscript exceeds array dimensions.
- 'wrap': an ndarray instance wraps around subscripts exceeding array
dimensions using modulo arithmetic.
- 'clamp': an ndarray instance sets a subscript exceeding array
Expand Down
3 changes: 3 additions & 0 deletions base/assert/is-index-mode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ Tests if an input `value` is a supported ndarray index mode.
var bool = isIndexMode( 'throw' );
// returns true

bool = isIndexMode( 'normalize' );
// returns true

bool = isIndexMode( 'clamp' );
// returns true

Expand Down
19 changes: 4 additions & 15 deletions base/assert/is-index-mode/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,17 @@

// MODULES //

var contains = require( '@stdlib/array/base/assert/contains' ).factory;
var modes = require( './../../../../index-modes' );


// VARIABLES //

var MODES = modes();
var len = MODES.length;


// MAIN //

/**
* Tests whether an input value is a supported ndarray index mode.
*
* @name isIndexMode
* @type {Function}
* @param {*} v - value to test
* @returns {boolean} boolean indicating whether an input value is a supported ndarray index mode
*
Expand All @@ -50,15 +47,7 @@ var len = MODES.length;
* bool = isIndexMode( 'foo' );
* // returns false
*/
function isIndexMode( v ) {
var i;
for ( i = 0; i < len; i++ ) {
if ( v === MODES[ i ] ) {
return true;
}
}
return false;
}
var isIndexMode = contains( modes() );


// EXPORTS //
Expand Down
2 changes: 2 additions & 0 deletions base/assert/is-index-mode/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ tape( 'the function returns `true` if provided a supported ndarray index mode',

values = [
'throw',
'normalize',
'wrap',
'clamp'
];
Expand All @@ -56,6 +57,7 @@ tape( 'the function returns `false` if not provided a supported ndarray index mo

values = [
'throws',
'normalizes',
'wraps',
'clamps',
'clip',
Expand Down
9 changes: 5 additions & 4 deletions base/bind2vind/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@ var idx = bind2vind( shape, strides, offset, order, 7, 'throw' );
// returns 1
```

The function supports the following `modes`:
The function supports the following modes:

- `throw`: specifies that the function should throw an error when a linear index exceeds array dimensions.
- `wrap`: specifies that the function should wrap around a linear index exceeding array dimensions using modulo arithmetic.
- `clamp`: specifies that the function should set a linear index exceeding array dimensions to either `0` (minimum linear index) or the maximum linear index.
- **throw**: specifies that the function should throw an error when a linear index exceeds array dimensions.
- **normalize**: specifies that the function should normalize negative indices and should throw an error when a linear index exceeds array dimensions.
- **wrap**: specifies that the function should wrap around a linear index exceeding array dimensions using modulo arithmetic.
- **clamp**: specifies that the function should set a linear index exceeding array dimensions to either `0` (minimum linear index) or the maximum linear index.

```javascript
var shape = [ 2, 2 ];
Expand Down
130 changes: 130 additions & 0 deletions base/bind2vind/benchmark/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,3 +422,133 @@ bench( pkg+':mode=clamp,offset=0,order=column-major', function benchmark( b ) {
b.pass( 'benchmark finished' );
b.end();
});

bench( pkg+':mode=normalize,order=row-major', function benchmark( b ) {
var strides;
var offset;
var shape;
var order;
var out;
var len;
var idx;
var i;

shape = [ 10, 10, 10 ];
order = 'row-major';
strides = shape2strides( shape, order );
strides[ 1 ] *= -1;
offset = strides2offset( shape, strides );
len = numel( shape );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
idx = floor( randu()*len*2.0 ) - len;
out = bind2vind( shape, strides, offset, order, idx, 'normalize' );
if ( out !== out ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( !isInteger( out ) ) {
b.fail( 'should return an integer' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( pkg+':mode=normalize,order=column-major', function benchmark( b ) {
var strides;
var offset;
var shape;
var order;
var out;
var len;
var idx;
var i;

shape = [ 10, 10, 10 ];
order = 'column-major';
strides = shape2strides( shape, order );
strides[ 1 ] *= -1;
offset = strides2offset( shape, strides );
len = numel( shape );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
idx = floor( randu()*len*2.0 ) - len;
out = bind2vind( shape, strides, offset, order, idx, 'normalize' );
if ( out !== out ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( !isInteger( out ) ) {
b.fail( 'should return an integer' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( pkg+':mode=normalize,offset=0,order=row-major', function benchmark( b ) {
var strides;
var offset;
var shape;
var order;
var out;
var len;
var idx;
var i;

shape = [ 10, 10, 10 ];
order = 'row-major';
strides = shape2strides( shape, order );
offset = strides2offset( shape, strides );
len = numel( shape );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
idx = floor( randu()*len*2.0 ) - len;
out = bind2vind( shape, strides, offset, order, idx, 'normalize' );
if ( out !== out ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( !isInteger( out ) ) {
b.fail( 'should return an integer' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( pkg+':mode=normalize,offset=0,order=column-major', function benchmark( b ) {
var strides;
var offset;
var shape;
var order;
var out;
var len;
var idx;
var i;

shape = [ 10, 10, 10 ];
order = 'column-major';
strides = shape2strides( shape, order );
offset = strides2offset( shape, strides );
len = numel( shape );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
idx = floor( randu()*len*2.0 ) - len;
out = bind2vind( shape, strides, offset, order, idx, 'normalize' );
if ( out !== out ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( !isInteger( out ) ) {
b.fail( 'should return an integer' );
}
b.pass( 'benchmark finished' );
b.end();
});
Loading

0 comments on commit d6325f4

Please sign in to comment.