
p <- c(3L, 5L, 2L, 5L)
A <- array(rnorm(prod(p)), p)

eps <- 1
Gs <- TTSVD(A, eps = eps)

B <- Reduce(function(L, R)
    ttt(L, R, length(dim(L)), 1)
, Gs)

stopifnot(sqrt(sum((A - B)^2)) <= eps * sqrt(sum(A^2)))

unlist(Map(function(M) qr(M)$rank, Map(function(k) mat(A, k), seq_along(dim(A)))))
attr(Gs, "TT.rank")
