1 #http://www.mail-archive.com/rcpp-devel@lists.r-forge.r-project.org/msg01513.html
3 write.sparse <- function (m, to) {
4 ## Writes in a format that SVDLIBC can read
5 stopifnot(inherits(m, "dgCMatrix"))
6 fh <- file(to, open="w")
8 wl <- function(...) cat(..., "\n", file=fh)
11 wl(dim(m), length(m@x))
16 wl(nper[i]) ## Number of entries in this column
19 wl(m@i[globalCount], m@x[m@p[i]+j])
20 globalCount <- globalCount+1
24 my.svd <- function(x, nu, nv) {
26 rc <- system(paste("/usr/bin/svd -o /tmp/sout -d", nu, "/tmp/sparse.m"))
28 stop("Couldn't run external svd code")
29 d <- scan("/tmp/sout-S", skip=1)
30 #FIXME : sometimes, libsvdc doesn't find solution with 2 dimensions, but does with 3
33 rc <- system(paste("/usr/bin/svd -o /tmp/sout -d", nu, "/tmp/sparse.m"))
34 d <- scan("/tmp/sout-S", skip=1)
36 ut <- matrix(scan('/tmp/sout-Ut',skip=1),nrow=nu,byrow=TRUE)
41 list(d=d, u=-t(ut), v=vt)