@@ -5,7 +5,7 @@ require(spatstat.sparse)
55ALWAYS <- FULLTEST <- TRUE
66# ' tests/sparse3Darrays.R
77# ' Basic tests of code in sparse3Darray.R and sparsecommon.R
8- # ' $Revision: 1.28 $ $Date: 2021/03/07 07:39:44 $
8+ # ' $Revision: 1.32 $ $Date: 2023/06/23 02:34:57 $
99
1010if (! exists(" ALWAYS" )) ALWAYS <- TRUE
1111if (! exists(" FULLTEST" )) FULLTEST <- ALWAYS
@@ -46,14 +46,19 @@ local({
4646 A11 <- A [,1 ,1 ]
4747 AA11 <- as.sparse3Darray(A11 )
4848 # ' NULL with warning
49- as.sparse3Darray(list ())
49+ suppressWarnings( Niets <- as.sparse3Darray(list () ))
5050
5151 # '
5252 dim(AA ) <- dim(AA ) + 1
5353
5454 I1 <- SparseIndices(A1 )
5555 I11 <- SparseIndices(A11 )
5656
57+ BB <- evalSparse3Dentrywise(AA + AA / 2 )
58+
59+ MM <- bind.sparse3Darray(M , M , along = 1 )
60+ MM <- bind.sparse3Darray(M , M , along = 2 )
61+
5762 if (require(Matrix )) {
5863 # ' sparse matrices from Matrix package
5964 A1 <- as(A1 , " sparseMatrix" )
@@ -75,19 +80,33 @@ local({
7580 bb <- EntriesToSparse(df , 7 )
7681 cc <- EntriesToSparse(df , c(7 , 4 ))
7782 dd <- EntriesToSparse(df , c(7 , 4 , 3 ))
83+
7884 # ' duplicated entries
7985 dfdup <- df [c(1 : 3 , 2 ), ]
8086 aa <- EntriesToSparse(dfdup , NULL )
8187 bb <- EntriesToSparse(dfdup , 7 )
8288 cc <- EntriesToSparse(dfdup , c(7 , 4 ))
8389 dd <- EntriesToSparse(dfdup , c(7 , 4 , 3 ))
84- }
85-
86- BB <- evalSparse3Dentrywise(AA + AA / 2 )
87-
88- MM <- bind.sparse3Darray(M , M , along = 1 )
89- MM <- bind.sparse3Darray(M , M , along = 2 )
90+
91+ # ' example from Joey Arthur (bug in EntriesToSparse)
92+ joey <- as.sparse3Darray(
93+ list (
94+ as(matrix (rep(1 , 9 ), 3 , 3 ), ' dgCMatrix' ),
95+ as(matrix (rep(0 , 9 ), 3 , 3 ), ' dgCMatrix' ),
96+ as(matrix (rep(2 , 9 ), 3 , 3 ), ' dgCMatrix' )
97+ )
98+ )
99+ answer <- marginSumsSparse(joey , 3 )
100+ rightanswer <- marginSums(as.array(joey ), 3 ) # [1] 9 0 18
101+ if (! all(as.vector(answer ) == rightanswer )) {
102+ cat(" Result of marginSumsSparse:\n " )
103+ print(answer )
104+ cat(" Right answer:\n " )
105+ print(rightanswer )
106+ stop(" Incorrect answer from marginSumsSparse" )
107+ }
90108
109+ }
91110})
92111
93112
@@ -333,3 +352,4 @@ local({
333352})
334353
335354}
355+
0 commit comments