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 0fc3ca4 commit 3f9f311
Show file tree
Hide file tree
Showing 16 changed files with 507 additions and 66 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: 0 additions & 1 deletion .github/.keepalive

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ jobs:
# For all dependencies, check in all *.js files if they are still used; if not, remove them:
jq -r '.dependencies | keys[]' ./package.json | while read -r dep; do
dep=$(echo "$dep" | xargs)
if ! grep -q "$dep" lib/** && ! grep -q -s "$dep" manifest.json && ! grep -q -s "$dep" include.gypi; then
if ! find lib -name "*.js" -exec grep -q "$dep" {} + && ! grep -q -s "$dep" manifest.json && ! grep -q -s "$dep" include.gypi; then
jq --indent 2 "del(.dependencies[\"$dep\"])" ./package.json > ./package.json.tmp
mv ./package.json.tmp ./package.json
fi
Expand All @@ -129,7 +129,7 @@ jobs:
continue
fi
dep=$(echo "$dep" | xargs)
if ! grep -q "$dep" lib/** && ! grep -q -s "$dep" manifest.json && ! grep -q -s "$dep" include.gypi; then
if ! find lib -name "*.js" -exec grep -q "$dep" {} + && ! grep -q -s "$dep" manifest.json && ! grep -q -s "$dep" include.gypi; then
jq --indent 2 "del(.devDependencies[\"$dep\"])" ./package.json > ./package.json.tmp
mv ./package.json.tmp ./package.json
fi
Expand Down
3 changes: 2 additions & 1 deletion CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Brendan Graetz <bguiz@users.noreply.github.com>
Bruno Fenzl <brunofenzl@gmail.com>
Christopher Dambamuromo <chridam@gmail.com>
Dan Rose <danoftheroses@gmail.com>
Daniel Killenberger <daniel.killenberger@gmail.com>
Dominik Moritz <domoritz@gmail.com>
Dorrin Sotoudeh <dorrinsotoudeh123@gmail.com>
Frank Kovacs <fran70kk@gmail.com>
Expand All @@ -29,6 +30,7 @@ Ognjen Jevremović <ognjenjevremovic@users.noreply.github.com>
Philipp Burckhardt <pburckhardt@outlook.com>
Pranav Goswami <goswami.4@iitj.ac.in>
Ricky Reusser <rsreusser@gmail.com>
Robert Gislason <gztown2216@yahoo.com>
Roman Stetsyk <25715951+romanstetsyk@users.noreply.github.com>
Ryan Seal <splrk@users.noreply.github.com>
Seyyed Parsa Neshaei <spneshaei@users.noreply.github.com>
Expand All @@ -37,4 +39,3 @@ Stephannie Jiménez Gacha <steff456@hotmail.com>
Yernar Yergaziyev <yernar.yergaziyev@erg.kz>
orimiles5 <97595296+orimiles5@users.noreply.github.com>
rei2hu <reimu@reimu.ws>
Robert Gislason <gztown2216@yahoo.com>
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,12 @@ var idx = vind2bind( shape, strides, offset, order, 1, 'throw' );
// returns 7
```

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 linear indices and 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 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 = vind2bind( 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 = vind2bind( 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 = vind2bind( 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 = vind2bind( 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 3f9f311

Please sign in to comment.