how to combine multiple DelayedArray to a high dimension array
1
0
Entering edit mode
Ou, Jianhong ★ 1.3k
@ou-jianhong-4539
Last seen 12 hours ago
United States

What is the best way to combine two or more DelayedArray to a high dimension DelayedArray with low cost of memory?

for example:

a <- array(runif(1500000), dim=c(10000, 30, 5))
A <- DelayedArray(a)
b <- array(runif(1500000), dim=c(10000, 30, 5))
B <- DelayedArray(b)
DelayedArray(arrayc(A, B), dim=c(10000, 30, 5, 2))

Thank you!

delayedarray • 1.4k views
ADD COMMENT
2
Entering edit mode
Peter Hickey ▴ 740
@petehaitch
Last seen 4 weeks ago
WEHI, Melbourne, Australia

There's no general abind() method for DelayedArray at this time. However, for your particular example, you can achieve it with some trickery using aperm() with arbind():

suppressPackageStartupMessages(library(DelayedArray))

# NOTE: I add a 4th dimension to the array
a <- array(runif(1500000), dim=c(10000, 30, 5, 1))
A <- DelayedArray(a)
b <- array(runif(1500000), dim=c(10000, 30, 5, 1))
B <- DelayedArray(b)
C <- aperm(arbind(aperm(A, 4:1), aperm(B, 4:1)), 4:1)
dim(C)
#> [1] 10000    30     5     2

Created on 2018-03-16 by the reprex package (v0.2.0).

This is memory-efficient asĀ aperm() only permutes some index variables and not the data itself.

ADD COMMENT
0
Entering edit mode

Thank you! very helpful.

ADD REPLY

Login before adding your answer.

Traffic: 719 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6