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
25 write.sparse2 <- function(m, to) {
26 stopifnot(inherits(m, "dgCMatrix"))
27 fh <- file(to, open="w")
29 wl <- function(...) cat(..., "\n", file=fh)
30 wl(dim(m), length(m@x))
34 print('FIXME : svdpath hardcoded !!')
35 my.svd <- function(x, nu, nv) {
37 rc <- system(paste("/usr/bin/svd -o /tmp/sout -d", nu, "/tmp/sparse.m"))
39 stop("Couldn't run external svd code")
40 d <- scan("/tmp/sout-S", skip=1)
41 #FIXME : sometimes, svdlibc doesn't find solution with 2 dimensions, but does with 3
44 rc <- system(paste("/usr/bin/svd -o /tmp/sout -d", nu, "/tmp/sparse.m"))
45 d <- scan("/tmp/sout-S", skip=1)
47 ut <- matrix(scan('/tmp/sout-Ut',skip=1),nrow=nu,byrow=TRUE)
52 list(d=d, u=-t(ut), v=vt)