@@ -385,6 +385,32 @@ tape( 'the function throws an error if provided a first argument which is not an
385
385
}
386
386
} ) ;
387
387
388
+ tape ( 'the function throws an error if provided a first argument which is a zero-dimensional ndarray' , function test ( t ) {
389
+ var values ;
390
+ var opts ;
391
+ var i ;
392
+
393
+ opts = {
394
+ 'dtype' : 'generic'
395
+ } ;
396
+
397
+ values = [
398
+ scalar2ndarray ( 10.0 ) ,
399
+ scalar2ndarray ( - 3.0 ) ,
400
+ scalar2ndarray ( 0.0 )
401
+ ] ;
402
+ for ( i = 0 ; i < values . length ; i ++ ) {
403
+ t . throws ( badValue ( values [ i ] ) , RangeError , 'throws an error when provided ' + values [ i ] ) ;
404
+ }
405
+ t . end ( ) ;
406
+
407
+ function badValue ( value ) {
408
+ return function badValue ( ) {
409
+ lastIndexOf ( value , scalar2ndarray ( 2.0 ) , scalar2ndarray ( 0 , opts ) , { } ) ; // eslint-disable-line max-len
410
+ } ;
411
+ }
412
+ } ) ;
413
+
388
414
tape ( 'the function throws an error if provided a third argument which is not an ndarray-like object, an integer or an object' , function test ( t ) {
389
415
var values ;
390
416
var x ;
@@ -988,6 +1014,74 @@ tape( 'the function supports specifying the operation dimension (column-major)',
988
1014
t . end ( ) ;
989
1015
} ) ;
990
1016
1017
+ tape ( 'the function supports specifying the `keepdims` option (row-major)' , function test ( t ) {
1018
+ var expected ;
1019
+ var actual ;
1020
+ var xbuf ;
1021
+ var x ;
1022
+
1023
+ xbuf = [ - 1.0 , 2.0 , - 3.0 , 2.0 ] ;
1024
+ x = new ndarray ( 'generic' , xbuf , [ 2 , 2 ] , [ 2 , 1 ] , 0 , 'row-major' ) ;
1025
+
1026
+ actual = lastIndexOf ( x , 2.0 , {
1027
+ 'keepdims' : true
1028
+ } ) ;
1029
+ expected = [ [ - 1 ] , [ - 1 ] ] ;
1030
+
1031
+ t . strictEqual ( isndarrayLike ( actual ) , true , 'returns expected value' ) ;
1032
+ t . strictEqual ( getDType ( actual ) , 'generic' , 'returns expected value' ) ;
1033
+ t . deepEqual ( getShape ( actual ) , [ 2 , 1 ] , 'returns expected value' ) ;
1034
+ t . strictEqual ( getOrder ( actual ) , getOrder ( x ) , 'returns expected value' ) ;
1035
+ t . deepEqual ( ndarray2array ( actual ) , expected , 'returns expected value' ) ;
1036
+
1037
+ actual = lastIndexOf ( x , 2.0 , 0 , {
1038
+ 'keepdims' : true
1039
+ } ) ;
1040
+ expected = [ [ - 1 ] , [ - 1 ] ] ;
1041
+
1042
+ t . strictEqual ( isndarrayLike ( actual ) , true , 'returns expected value' ) ;
1043
+ t . strictEqual ( getDType ( actual ) , 'generic' , 'returns expected value' ) ;
1044
+ t . deepEqual ( getShape ( actual ) , [ 2 , 1 ] , 'returns expected value' ) ;
1045
+ t . strictEqual ( getOrder ( actual ) , getOrder ( x ) , 'returns expected value' ) ;
1046
+ t . deepEqual ( ndarray2array ( actual ) , expected , 'returns expected value' ) ;
1047
+
1048
+ t . end ( ) ;
1049
+ } ) ;
1050
+
1051
+ tape ( 'the function supports specifying the `keepdims` option (column-major)' , function test ( t ) {
1052
+ var expected ;
1053
+ var actual ;
1054
+ var xbuf ;
1055
+ var x ;
1056
+
1057
+ xbuf = [ - 1.0 , 2.0 , - 3.0 , 2.0 ] ;
1058
+ x = new ndarray ( 'generic' , xbuf , [ 2 , 2 ] , [ 2 , 1 ] , 0 , 'column-major' ) ;
1059
+
1060
+ actual = lastIndexOf ( x , 2.0 , {
1061
+ 'keepdims' : true
1062
+ } ) ;
1063
+ expected = [ [ - 1 ] , [ - 1 ] ] ;
1064
+
1065
+ t . strictEqual ( isndarrayLike ( actual ) , true , 'returns expected value' ) ;
1066
+ t . strictEqual ( getDType ( actual ) , 'generic' , 'returns expected value' ) ;
1067
+ t . deepEqual ( getShape ( actual ) , [ 2 , 1 ] , 'returns expected value' ) ;
1068
+ t . strictEqual ( getOrder ( actual ) , getOrder ( x ) , 'returns expected value' ) ;
1069
+ t . deepEqual ( ndarray2array ( actual ) , expected , 'returns expected value' ) ;
1070
+
1071
+ actual = lastIndexOf ( x , 2.0 , 0 , {
1072
+ 'keepdims' : true
1073
+ } ) ;
1074
+ expected = [ [ - 1 ] , [ - 1 ] ] ;
1075
+
1076
+ t . strictEqual ( isndarrayLike ( actual ) , true , 'returns expected value' ) ;
1077
+ t . strictEqual ( getDType ( actual ) , 'generic' , 'returns expected value' ) ;
1078
+ t . deepEqual ( getShape ( actual ) , [ 2 , 1 ] , 'returns expected value' ) ;
1079
+ t . strictEqual ( getOrder ( actual ) , getOrder ( x ) , 'returns expected value' ) ;
1080
+ t . deepEqual ( ndarray2array ( actual ) , expected , 'returns expected value' ) ;
1081
+
1082
+ t . end ( ) ;
1083
+ } ) ;
1084
+
991
1085
tape ( 'the function supports specifying the output array data type' , function test ( t ) {
992
1086
var expected ;
993
1087
var actual ;
0 commit comments