This seems entirely avoidable, given that there is a relatively simple formula for converting 2-ary indices [i,j] of S to 1-ary indices k of S[lower.tri(S, TRUE)]:

k <- i + round(0.5 * (2L * n - j) * (j - 1L)) # for i >= j

I ought to be slightly more precise here: _coercion_ is avoidable, because we can always map [i,j] to [k], but memory limits are not. Certainly S@x[k] cannot be arbitrarily long...

At the very least, it would be convenient if the subset were performed efficiently whenever dimensions would be dropped anyway:

* S[i, ] and S[, j] where i and j are vectors indexing exactly zero or one rows/columns
* S[i] where i is a matrix of the form cbind(i, j)

This would support, e.g., a memory-efficient 'apply' analogue without any need for MARGIN...

applySymmetric <- function(X, FUN, ..., simplify = TRUE, check = TRUE) {
  if (check && !isSymmetric(X)) {
    stop("'X' is not a symmetric matrix.")
  }
  ## preprocessing
  ans <- vector("list", n)
  for (i in seq_len(n)) {
    ans[[i]] <- forceAndCall(1L, FUN, S[i, ], ...)
  }
  ## postprocessing
  ans
}

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to