Skip to content

Commit d6325f4

Browse files
committed
Auto-generated commit
1 parent 88b3c85 commit d6325f4

File tree

108 files changed

+6292
-378
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+6292
-378
lines changed

.editorconfig

-5
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,6 @@ indent_size = 2
148148
indent_style = space
149149
indent_size = 2
150150

151-
# Set properties for `tslint.json` files:
152-
[tslint.json]
153-
indent_style = space
154-
indent_size = 2
155-
156151
# Set properties for `tsconfig.json` files:
157152
[tsconfig.json]
158153
indent_style = space

array/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ The function accepts the following `options`:
114114
- **mode**: specifies how to handle indices which exceed array dimensions.
115115

116116
- `throw`: specifies that an [`ndarray`][@stdlib/ndarray/ctor] instance should throw an error when an index exceeds array dimensions.
117+
- `normalize`: specifies that an [`ndarray`][@stdlib/ndarray/ctor] instance should normalize negative indices and throw an error when an index exceeds array dimensions.
117118
- `wrap`: specifies that an [`ndarray`][@stdlib/ndarray/ctor] instance should wrap around an index exceeding array dimensions using modulo arithmetic.
118119
- `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.
119120

array/docs/repl.txt

+4
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@
101101

102102
- 'throw': an ndarray instance throws an error when an index exceeds
103103
array dimensions.
104+
- 'normalize': an ndarray instance normalizes negative indices and
105+
throws an error when an index exceeds array dimensions.
104106
- 'wrap': an ndarray instance wraps around indices exceeding array
105107
dimensions using modulo arithmetic.
106108
- 'clamp', an ndarray instance sets an index exceeding array dimensions
@@ -114,6 +116,8 @@
114116

115117
- 'throw': an ndarray instance throws an error when a subscript exceeds
116118
array dimensions.
119+
- 'normalize': an ndarray instance normalizes negative subscripts and
120+
throws an error when a subscript exceeds array dimensions.
117121
- 'wrap': an ndarray instance wraps around subscripts exceeding array
118122
dimensions using modulo arithmetic.
119123
- 'clamp': an ndarray instance sets a subscript exceeding array

base/assert/is-index-mode/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ Tests if an input `value` is a supported ndarray index mode.
4848
var bool = isIndexMode( 'throw' );
4949
// returns true
5050

51+
bool = isIndexMode( 'normalize' );
52+
// returns true
53+
5154
bool = isIndexMode( 'clamp' );
5255
// returns true
5356

base/assert/is-index-mode/lib/main.js

+4-15
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,17 @@
2020

2121
// MODULES //
2222

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

2526

26-
// VARIABLES //
27-
28-
var MODES = modes();
29-
var len = MODES.length;
30-
31-
3227
// MAIN //
3328

3429
/**
3530
* Tests whether an input value is a supported ndarray index mode.
3631
*
32+
* @name isIndexMode
33+
* @type {Function}
3734
* @param {*} v - value to test
3835
* @returns {boolean} boolean indicating whether an input value is a supported ndarray index mode
3936
*
@@ -50,15 +47,7 @@ var len = MODES.length;
5047
* bool = isIndexMode( 'foo' );
5148
* // returns false
5249
*/
53-
function isIndexMode( v ) {
54-
var i;
55-
for ( i = 0; i < len; i++ ) {
56-
if ( v === MODES[ i ] ) {
57-
return true;
58-
}
59-
}
60-
return false;
61-
}
50+
var isIndexMode = contains( modes() );
6251

6352

6453
// EXPORTS //

base/assert/is-index-mode/test/test.js

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ tape( 'the function returns `true` if provided a supported ndarray index mode',
3939

4040
values = [
4141
'throw',
42+
'normalize',
4243
'wrap',
4344
'clamp'
4445
];
@@ -56,6 +57,7 @@ tape( 'the function returns `false` if not provided a supported ndarray index mo
5657

5758
values = [
5859
'throws',
60+
'normalizes',
5961
'wraps',
6062
'clamps',
6163
'clip',

base/bind2vind/README.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,12 @@ var idx = bind2vind( shape, strides, offset, order, 7, 'throw' );
5454
// returns 1
5555
```
5656

57-
The function supports the following `modes`:
57+
The function supports the following modes:
5858

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

6364
```javascript
6465
var shape = [ 2, 2 ];

base/bind2vind/benchmark/benchmark.js

+130
Original file line numberDiff line numberDiff line change
@@ -422,3 +422,133 @@ bench( pkg+':mode=clamp,offset=0,order=column-major', function benchmark( b ) {
422422
b.pass( 'benchmark finished' );
423423
b.end();
424424
});
425+
426+
bench( pkg+':mode=normalize,order=row-major', function benchmark( b ) {
427+
var strides;
428+
var offset;
429+
var shape;
430+
var order;
431+
var out;
432+
var len;
433+
var idx;
434+
var i;
435+
436+
shape = [ 10, 10, 10 ];
437+
order = 'row-major';
438+
strides = shape2strides( shape, order );
439+
strides[ 1 ] *= -1;
440+
offset = strides2offset( shape, strides );
441+
len = numel( shape );
442+
443+
b.tic();
444+
for ( i = 0; i < b.iterations; i++ ) {
445+
idx = floor( randu()*len*2.0 ) - len;
446+
out = bind2vind( shape, strides, offset, order, idx, 'normalize' );
447+
if ( out !== out ) {
448+
b.fail( 'should not return NaN' );
449+
}
450+
}
451+
b.toc();
452+
if ( !isInteger( out ) ) {
453+
b.fail( 'should return an integer' );
454+
}
455+
b.pass( 'benchmark finished' );
456+
b.end();
457+
});
458+
459+
bench( pkg+':mode=normalize,order=column-major', function benchmark( b ) {
460+
var strides;
461+
var offset;
462+
var shape;
463+
var order;
464+
var out;
465+
var len;
466+
var idx;
467+
var i;
468+
469+
shape = [ 10, 10, 10 ];
470+
order = 'column-major';
471+
strides = shape2strides( shape, order );
472+
strides[ 1 ] *= -1;
473+
offset = strides2offset( shape, strides );
474+
len = numel( shape );
475+
476+
b.tic();
477+
for ( i = 0; i < b.iterations; i++ ) {
478+
idx = floor( randu()*len*2.0 ) - len;
479+
out = bind2vind( shape, strides, offset, order, idx, 'normalize' );
480+
if ( out !== out ) {
481+
b.fail( 'should not return NaN' );
482+
}
483+
}
484+
b.toc();
485+
if ( !isInteger( out ) ) {
486+
b.fail( 'should return an integer' );
487+
}
488+
b.pass( 'benchmark finished' );
489+
b.end();
490+
});
491+
492+
bench( pkg+':mode=normalize,offset=0,order=row-major', function benchmark( b ) {
493+
var strides;
494+
var offset;
495+
var shape;
496+
var order;
497+
var out;
498+
var len;
499+
var idx;
500+
var i;
501+
502+
shape = [ 10, 10, 10 ];
503+
order = 'row-major';
504+
strides = shape2strides( shape, order );
505+
offset = strides2offset( shape, strides );
506+
len = numel( shape );
507+
508+
b.tic();
509+
for ( i = 0; i < b.iterations; i++ ) {
510+
idx = floor( randu()*len*2.0 ) - len;
511+
out = bind2vind( shape, strides, offset, order, idx, 'normalize' );
512+
if ( out !== out ) {
513+
b.fail( 'should not return NaN' );
514+
}
515+
}
516+
b.toc();
517+
if ( !isInteger( out ) ) {
518+
b.fail( 'should return an integer' );
519+
}
520+
b.pass( 'benchmark finished' );
521+
b.end();
522+
});
523+
524+
bench( pkg+':mode=normalize,offset=0,order=column-major', function benchmark( b ) {
525+
var strides;
526+
var offset;
527+
var shape;
528+
var order;
529+
var out;
530+
var len;
531+
var idx;
532+
var i;
533+
534+
shape = [ 10, 10, 10 ];
535+
order = 'column-major';
536+
strides = shape2strides( shape, order );
537+
offset = strides2offset( shape, strides );
538+
len = numel( shape );
539+
540+
b.tic();
541+
for ( i = 0; i < b.iterations; i++ ) {
542+
idx = floor( randu()*len*2.0 ) - len;
543+
out = bind2vind( shape, strides, offset, order, idx, 'normalize' );
544+
if ( out !== out ) {
545+
b.fail( 'should not return NaN' );
546+
}
547+
}
548+
b.toc();
549+
if ( !isInteger( out ) ) {
550+
b.fail( 'should return an integer' );
551+
}
552+
b.pass( 'benchmark finished' );
553+
b.end();
554+
});

0 commit comments

Comments
 (0)