Skip to content

Commit 8ddc5d5

Browse files
committed
Bug fix
1 parent 5fa3d52 commit 8ddc5d5

6 files changed

Lines changed: 51 additions & 12 deletions

File tree

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: spatstat.sparse
2-
Version: 3.0-1
3-
Date: 2023-03-12
2+
Version: 3.0-1.001
3+
Date: 2023-06-23
44
Title: Sparse Three-Dimensional Arrays and Linear Algebra Utilities
55
Authors@R: c(person("Adrian", "Baddeley",
66
role = c("aut", "cre", "cph"),

NEWS

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
11

2+
CHANGES IN spatstat.sparse VERSION 3.0-1.001
3+
4+
OVERVIEW
5+
6+
o We thank Joey Arthur for contributions.
7+
8+
o Bug fix.
9+
10+
BUG FIXES
11+
12+
o marginSumsSparse
13+
If the result of marginSumsSparse was a one-dimensional sparse vector,
14+
the entries were incorrectly rearranged so that the non-zero entries
15+
were all at the beginning of the vector.
16+
[Spotted by Joey Arthur.]
17+
Fixed.
18+
219
CHANGES IN spatstat.sparse VERSION 3.0-1
320

421
OVERVIEW

R/sparse3Darray.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#' Copyright (c) Adrian Baddeley, Ege Rubak and Rolf Turner 2016-2020
77
#' GNU Public Licence >= 2.0
88
#'
9-
#' $Revision: 1.44 $ $Date: 2021/03/04 07:42:18 $
9+
#' $Revision: 1.45 $ $Date: 2023/06/23 02:26:26 $
1010
#'
1111

1212
sparse3Darray <- function(i=integer(0), j=integer(0), k=integer(0),
@@ -911,7 +911,7 @@ EntriesToSparse <- function(df, dims) {
911911
first <- !dup
912912
newi <- cumsum(first)
913913
newx <- as(tapply(df$x, newi, sum), typeof(df$x))
914-
df <- data.frame(i=newi[first], x=newx)
914+
df <- data.frame(i=df$i[first], x=newx)
915915
}
916916
result <- with(df, sparseVector(i=i, x=x, length=dims))
917917
} else if(nd == 2) {

inst/doc/packagesizes.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ date version nhelpfiles nobjects ndatasets Rlines srclines
1717
"2021-03-16" "2.0-0" 14 48 0 2059 733
1818
"2022-10-19" "3.0-0" 15 48 0 2092 740
1919
"2023-03-12" "3.0-1" 15 48 0 2092 740
20+
"2023-06-23" "3.0-1.001" 15 48 0 2092 740

man/macros/defns.Rd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
\newcommand{\Martin}{\ifelse{latex}{\out{Mart\'{\i}n}}{Martin}}
3333
\newcommand{\Dominguez}{\ifelse{latex}{\out{Dom\'{\i}nguez}}{Dominguez}}
3434
\newcommand{\Rodriguez}{\ifelse{latex}{\out{Rodr\'{\i}guez}}{Rodriguez}}
35+
\newcommand{\Gonzalez}{\ifelse{latex}{\out{Gonz\'{a}lez}}{Gonzalez}}
3536
%% List of all Gibbs interactions
3637
\newcommand{\GibbsInteractionsList}{\code{\link[MPKG]{AreaInter}}, \code{\link[MPKG]{BadGey}}, \code{\link[MPKG]{Concom}}, \code{\link[MPKG]{DiggleGatesStibbard}}, \code{\link[MPKG]{DiggleGratton}}, \code{\link[MPKG]{Fiksel}}, \code{\link[MPKG]{Geyer}}, \code{\link[MPKG]{Hardcore}}, \code{\link[MPKG]{HierHard}}, \code{\link[MPKG]{HierStrauss}}, \code{\link[MPKG]{HierStraussHard}}, \code{\link[MPKG]{Hybrid}}, \code{\link[MPKG]{LennardJones}}, \code{\link[MPKG]{MultiHard}}, \code{\link[MPKG]{MultiStrauss}}, \code{\link[MPKG]{MultiStraussHard}}, \code{\link[MPKG]{OrdThresh}}, \code{\link[MPKG]{Ord}}, \code{\link[MPKG]{Pairwise}}, \code{\link[MPKG]{PairPiece}}, \code{\link[MPKG]{Penttinen}}, \code{\link[MPKG]{Poisson}}, \code{\link[MPKG]{Saturated}}, \code{\link[MPKG]{SatPiece}}, \code{\link[MPKG]{Softcore}}, \code{\link[MPKG]{Strauss}}, \code{\link[MPKG]{StraussHard}} and \code{\link[MPKG]{Triplets}}}
3738
%% List of interactions recognised by RMH code

tests/sparse3Darrays.R

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ require(spatstat.sparse)
55
ALWAYS <- 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

1010
if(!exists("ALWAYS")) ALWAYS <- TRUE
1111
if(!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

Comments
 (0)