@@ -989,6 +989,29 @@ describe('Matrix', () => {
989
989
expect ( expidx ) . toEqual ( idx )
990
990
} )
991
991
992
+ test . each ( [ undefined , 0 ] ) ( 'row(%p) duplicate index' , axis => {
993
+ const n = 6
994
+ const org = Matrix . randn ( 3 , 5 )
995
+ const [ mat , idx ] = org . sample ( n , axis , true )
996
+ expect ( idx ) . toHaveLength ( n )
997
+
998
+ const expidx = [ ]
999
+ for ( let k = 0 ; k < n ; k ++ ) {
1000
+ for ( let i = 0 ; i < org . rows ; i ++ ) {
1001
+ let flg = true
1002
+ for ( let j = 0 ; j < org . cols ; j ++ ) {
1003
+ flg &= mat . at ( k , j ) === org . at ( i , j )
1004
+ }
1005
+ if ( flg ) {
1006
+ expidx . push ( i )
1007
+ break
1008
+ }
1009
+ }
1010
+ }
1011
+ expect ( expidx ) . toHaveLength ( n )
1012
+ expect ( expidx ) . toEqual ( idx )
1013
+ } )
1014
+
992
1015
test ( 'col index' , ( ) => {
993
1016
const n = 3
994
1017
const org = Matrix . randn ( 10 , 5 )
@@ -1012,6 +1035,34 @@ describe('Matrix', () => {
1012
1035
expect ( expidx ) . toEqual ( idx )
1013
1036
} )
1014
1037
1038
+ test ( 'col duplicate index' , ( ) => {
1039
+ const n = 6
1040
+ const org = Matrix . randn ( 3 , 5 )
1041
+ const [ mat , idx ] = org . sample ( n , 1 , true )
1042
+ expect ( idx ) . toHaveLength ( n )
1043
+
1044
+ const expidx = [ ]
1045
+ for ( let k = 0 ; k < n ; k ++ ) {
1046
+ for ( let j = 0 ; j < org . cols ; j ++ ) {
1047
+ let flg = true
1048
+ for ( let i = 0 ; i < org . rows ; i ++ ) {
1049
+ flg &= mat . at ( i , k ) === org . at ( i , j )
1050
+ }
1051
+ if ( flg ) {
1052
+ expidx . push ( j )
1053
+ break
1054
+ }
1055
+ }
1056
+ }
1057
+ expect ( expidx ) . toHaveLength ( n )
1058
+ expect ( expidx ) . toEqual ( idx )
1059
+ } )
1060
+
1061
+ test ( 'fail invalid sampled size %p' , ( ) => {
1062
+ const mat = Matrix . randn ( 5 , 10 )
1063
+ expect ( ( ) => mat . sample ( 6 , 0 ) ) . toThrow ( 'Invalid sampled size.' )
1064
+ } )
1065
+
1015
1066
test . each ( [ - 1 , 2 ] ) ( 'fail invalid axis %p' , axis => {
1016
1067
const mat = Matrix . randn ( 5 , 10 )
1017
1068
expect ( ( ) => mat . sample ( 4 , axis ) ) . toThrow ( 'Invalid axis.' )
0 commit comments