@@ -24,6 +24,7 @@ var tape = require( 'tape' );
24
24
var isndarrayLike = require ( '@stdlib/assert/is-ndarray-like' ) ;
25
25
var ndarray = require ( '@stdlib/ndarray/ctor' ) ;
26
26
var zeros = require ( '@stdlib/ndarray/zeros' ) ;
27
+ var Int32Array = require ( '@stdlib/array/int32' ) ;
27
28
var ndarray2array = require ( '@stdlib/ndarray/to-array' ) ;
28
29
var scalar2ndarray = require ( '@stdlib/ndarray/from-scalar' ) ;
29
30
var getDType = require ( '@stdlib/ndarray/dtype' ) ;
@@ -384,6 +385,32 @@ tape( 'the function throws an error if provided a first argument which is not an
384
385
}
385
386
} ) ;
386
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
+ indexOf ( value , scalar2ndarray ( 2.0 ) , scalar2ndarray ( 0 , opts ) , { } ) ; // eslint-disable-line max-len
410
+ } ;
411
+ }
412
+ } ) ;
413
+
387
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 ) {
388
415
var values ;
389
416
var x ;
@@ -987,6 +1014,74 @@ tape( 'the function supports specifying the operation dimension (column-major)',
987
1014
t . end ( ) ;
988
1015
} ) ;
989
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 = indexOf ( 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 = indexOf ( 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 ] , [ 1 , 2 ] , 0 , 'column-major' ) ;
1059
+
1060
+ actual = indexOf ( x , 2.0 , {
1061
+ 'keepdims' : true
1062
+ } ) ;
1063
+ expected = [ [ 0 ] , [ 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 = indexOf ( x , 2.0 , 0 , {
1072
+ 'keepdims' : true
1073
+ } ) ;
1074
+ expected = [ [ 0 ] , [ 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
+
990
1085
tape ( 'the function supports specifying the output array data type' , function test ( t ) {
991
1086
var expected ;
992
1087
var actual ;
@@ -1325,3 +1420,39 @@ tape( 'the function supports providing a from index (0d ndarray, broadcasted)',
1325
1420
1326
1421
t . end ( ) ;
1327
1422
} ) ;
1423
+
1424
+ tape ( 'the function supports providing a from index (1d ndarray)' , function test ( t ) {
1425
+ var searchElement ;
1426
+ var expected ;
1427
+ var fromIdx ;
1428
+ var actual ;
1429
+ var xbuf ;
1430
+ var x ;
1431
+
1432
+ /*
1433
+ * [
1434
+ * 1.0, -2.0,
1435
+ * 2.0, -3.0,
1436
+ * 3.0, -4.0,
1437
+ * 2.0, -3.0,
1438
+ * 5.0, -6.0
1439
+ * ]
1440
+ */
1441
+ xbuf = [ 1.0 , - 2.0 , 2.0 , - 3.0 , 3.0 , - 4.0 , 2.0 , - 3.0 , 5.0 , - 6.0 ] ;
1442
+ x = new ndarray ( 'generic' , xbuf , [ 5 , 2 ] , [ 2 , 1 ] , 0 , 'row-major' ) ;
1443
+
1444
+ fromIdx = new ndarray ( 'int32' , new Int32Array ( [ 2 , 2 ] ) , [ 2 ] , [ 1 ] , 0 , 'row-major' ) ;
1445
+ searchElement = new ndarray ( 'generic' , [ 2.0 , - 3.0 ] , [ 2 ] , [ 1 ] , 0 , 'row-major' ) ;
1446
+ actual = indexOf ( x , searchElement , fromIdx , {
1447
+ 'dim' : 0
1448
+ } ) ;
1449
+ expected = [ 3 , 3 ] ;
1450
+
1451
+ t . strictEqual ( isndarrayLike ( actual ) , true , 'returns expected value' ) ;
1452
+ t . strictEqual ( getDType ( actual ) , 'generic' , 'returns expected value' ) ;
1453
+ t . deepEqual ( getShape ( actual ) , [ 2 ] , 'returns expected value' ) ;
1454
+ t . strictEqual ( getOrder ( actual ) , getOrder ( x ) , 'returns expected value' ) ;
1455
+ t . deepEqual ( ndarray2array ( actual ) , expected , 'returns expected value' ) ;
1456
+
1457
+ t . end ( ) ;
1458
+ } ) ;
0 commit comments