Summation of ConstantArray of 0 with vector of 0's fails

Open
#123 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
r
Domain
data

Research direction

Reproduce the zero-valued case starting with DelayedArray::ConstantArray and the HDF5Array::writeHDF5Array entry point, then compare it with the working combinations shown in the report. Done means the zero ConstantArray plus zero vector can be written successfully, with the existing examples serving as regression checks.

Written by the indexing model from the issue text.

Description

Hi,

I ran into a curious edge case, where summing a ConstantArray with a vector fails if both are zero and then writing it with HDF5Array::writeHDF5Array, but not in any other combination:

mat <- DelayedArray::ConstantArray(c(2, 4), value = 0)
res <- mat + rep(0, 2)
res
#> <2 x 4> sparse DelayedMatrix object of type "double":
#>      [,1] [,2] [,3] [,4]
#> [1,]    0    0    0    0
#> [2,]    0    0    0    0
HDF5Array::writeHDF5Array(res)
#> Error in .Arith_SVT1_v2(.Generic, e1, e2): "+" is not supported between a SparseArray object and a numeric vector
#>   (result wouldn't be sparse in general)

# All other combination seems to work
mat <- DelayedArray::ConstantArray(c(2, 4), value = 0)
res <- mat + rep(3, 2)
HDF5Array::writeHDF5Array(res)
#> <2 x 4> HDF5Matrix object of type "double":
#>      [,1] [,2] [,3] [,4]
#> [1,]    3    3    3    3
#> [2,]    3    3    3    3

mat <- DelayedArray::ConstantArray(c(2, 4), value = 17)
res <- mat + rep(0, 2)
HDF5Array::writeHDF5Array(res)
#> <2 x 4> HDF5Matrix object of type "double":
#>      [,1] [,2] [,3] [,4]
#> [1,]   17   17   17   17
#> [2,]   17   17   17   17

mat <- DelayedArray::ConstantArray(c(2, 4), value = 0)
res <- mat + 0
HDF5Array::writeHDF5Array(res)
#> <2 x 4> sparse HDF5Matrix object of type "double":
#>      [,1] [,2] [,3] [,4]
#> [1,]    0    0    0    0
#> [2,]    0    0    0    0

Created on 2025-03-05 with reprex v2.1.1

I am not actually 100% this is an DelayedArray issue or if it might rather need to be moved to HDF5Array.

Best,
Constantin

Dominant language
R
Stars
29
Forks
12
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Bioconductor/DelayedArray

All issues in Bioconductor/DelayedArray

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.