Skip to content

Commit 84616ed

Browse files
authored
Merge pull request #299 from alexmccreight/master
Matrix symmetry check with mismatching row/col names bug fix
2 parents dbb69cb + 52f94a0 commit 84616ed

4 files changed

Lines changed: 40 additions & 4 deletions

File tree

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Description: Implements methods for variable selection in linear
1616
and fast, allowing the SuSiE model be fit to large data sets
1717
(thousands of samples and hundreds of thousands of variables).
1818
Date: 2026-03-09
19-
Version: 0.15.56
19+
Version: 0.15.57
2020
Authors@R: c(person("Gao","Wang",role="aut",email="wang.gao@columbia.edu"),
2121
person("Yuxin","Zou",role="aut"),
2222
person("Alexander","McCreight",role="aut"),

R/susie_constructors.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -950,8 +950,9 @@ rss_lambda_constructor <- function(z, R = NULL, X = NULL, n = NULL,
950950
length(z), ")."
951951
))
952952
}
953-
if (!isSymmetric(R)) {
954-
stop("R is not a symmetric matrix.")
953+
if (!is_symmetric_matrix(R)) {
954+
warning_message("R not symmetric; using (R + t(R))/2.")
955+
R <- (R + t(R)) / 2
955956
}
956957
if (!(is.double(R) & is.matrix(R)) & !inherits(R, "sparseMatrix")) {
957958
stop("Input R must be a double-precision matrix or a sparse matrix.")

R/susie_utils.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ is_symmetric_matrix <- function(x) {
116116
requireNamespace("Rfast", quietly = TRUE)) {
117117
return(Rfast::is.symmetric(x))
118118
} else {
119-
return(Matrix::isSymmetric(x))
119+
return(Matrix::isSymmetric(x, check.attributes = FALSE))
120120
}
121121
}
122122

tests/testthat/test_susie_constructors.R

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,41 @@ test_that("rss_lambda_constructor rejects non-symmetric R", {
11371137
)
11381138
})
11391139

1140+
test_that("rss_lambda_constructor accepts R with mismatched rownames and colnames", {
1141+
p <- 10
1142+
z <- rnorm(p)
1143+
R <- diag(p)
1144+
rownames(R) <- paste0("row_", 1:p)
1145+
colnames(R) <- paste0("col_", 1:p)
1146+
1147+
# Should succeed despite mismatched dimnames (values are symmetric)
1148+
result <- rss_lambda_constructor(z, R, lambda = 0.5)
1149+
expect_equal(result$data$p, p)
1150+
expect_s3_class(result$data, "rss_lambda")
1151+
})
1152+
1153+
test_that("rss_lambda_constructor accepts R with matching rownames and colnames", {
1154+
p <- 10
1155+
z <- rnorm(p)
1156+
R <- diag(p)
1157+
rownames(R) <- paste0("SNP", 1:p)
1158+
colnames(R) <- paste0("SNP", 1:p)
1159+
1160+
result <- rss_lambda_constructor(z, R, lambda = 0.5)
1161+
expect_equal(result$data$p, p)
1162+
expect_s3_class(result$data, "rss_lambda")
1163+
})
1164+
1165+
test_that("rss_lambda_constructor accepts R with no dimnames", {
1166+
p <- 10
1167+
z <- rnorm(p)
1168+
R <- diag(p)
1169+
1170+
result <- rss_lambda_constructor(z, R, lambda = 0.5)
1171+
expect_equal(result$data$p, p)
1172+
expect_s3_class(result$data, "rss_lambda")
1173+
})
1174+
11401175
test_that("rss_lambda_constructor rejects integer matrix R", {
11411176
R <- matrix(1:25, 5, 5)
11421177
R <- R + t(R) # Make it symmetric

0 commit comments

Comments
 (0)