Skip to content

Summing DelayedArray and Matrix #60

@const-ae

Description

@const-ae

Hi Hervé,
I have recently started to play around with the DelayedArray package and it is just great to handle datasets that are too big to be kept in memory.

However, I recently tried to sum a classical matrix with a DelayedArray of the same dimension. To my surprise this gave the following error:

suppressPackageStartupMessages({
  library(DelayedArray)
})
# Standard Matrix
mat1 <- matrix(1:12, nrow = 3, ncol = 4)
mat2 <- matrix(3, nrow = 3, ncol = 4)
mat1 + mat2
#>      [,1] [,2] [,3] [,4]
#> [1,]    4    7   10   13
#> [2,]    5    8   11   14
#> [3,]    6    9   12   15

# Operations with DelayedArray
dmat1 <- DelayedArray(mat1)
dmat2 <- DelayedArray(mat2)
dmat1 + dmat2
#> <3 x 4> DelayedMatrix object of type "double":
#>      [,1] [,2] [,3] [,4]
#> [1,]    4    7   10   13
#> [2,]    5    8   11   14
#> [3,]    6    9   12   15

# Mixed
dmat1 + mat2
#> Error in .check_Ops_vector_arg_length(e, x_nrow, e_what = e_what, x_what = x_what): right object is longer than first dimension of left object

Created on 2020-01-23 by the reprex package (v0.3.0)

My question is: is this the intended behavior?

I realize that this is not the most realistic scenario because if dmat1 is too big for the memory, mat2 would probably be as well. However, I expected this to work because now, if I write a generic function, I will have to check the classes of the input arguments and make sure that they match.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions