Skip to content

Change to array indicies to prevent overflow. - #25

Open
gumeo wants to merge 1 commit into
leelabsg:masterfrom
gumeo:master
Open

Change to array indicies to prevent overflow.#25
gumeo wants to merge 1 commit into
leelabsg:masterfrom
gumeo:master

Conversation

@gumeo

@gumeo gumeo commented Apr 14, 2025

Copy link
Copy Markdown

Hi

This is a small contribution which is a fix to a problem I ran into.

I had an issue with the SKAT package on TTN with 500K rows and 10K columns. The index returned from the which function can exceed the maximum length of an underlying C array, resulting in an overflow. Using array indices fixes this problem.

Best regards,
Guðmundur Einarsson

@gumeo

gumeo commented Apr 22, 2025

Copy link
Copy Markdown
Author

Hi again,

Here is a simple example to illustrate the problem:

library(Matrix)

# Create an empty sparse matrix
m <- Matrix(0, nrow = 500000, ncol = 10000, sparse = TRUE)

# Set one element to 10 at a high index position
m[5, 6000] <- 10

# Index error:
ind <- which(m == 10)
m[ind] <- 5

# Fix:
ind <- which(m == 10, arr.ind = TRUE)
m[ind] <- 5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant