Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion R/DelayedUnaryIsoOpWithArgs-class.R
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,13 @@ setMethod("extract_sparse_array", "DelayedUnaryIsoOpWithArgs",
Largs <- subset_args(x@Largs, x@Lalong, index)
Rargs <- subset_args(x@Rargs, x@Ralong, index)

## SparseArray does not support all operations between an
## SVT_SparseArray and a vector-like argument (e.g. addition with a
## vector). Since 'is_sparse(x)' guarantees that the dense result is
## structurally sparse, realize this block and convert it back.
if (length(Largs) != 0L || length(Rargs) != 0L)
return(as(extract_array(x, index), "SVT_SparseArray"))

ans <- do.call(x@OP, c(Largs, list(svt), Rargs))
}
)

13 changes: 11 additions & 2 deletions inst/unitTests/test_DelayedUnaryIsoOpWithArgs-class.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ test_DelayedUnaryIsoOpWithArgs_constructor <- function(silent=FALSE)
#checkIdentical(FALSE, is_noop(x))
}

### TODO: Also test for extract_sparse_array().
test_DelayedUnaryIsoOpWithArgs_API <- function()
{
## 1. Ordinary array seed -- no-op
Expand Down Expand Up @@ -131,5 +130,15 @@ test_DelayedUnaryIsoOpWithArgs_API <- function()
.basic_checks_on_DelayedOp_with_DIM3(a4, x4)

checkIdentical(FALSE, is_sparse(x4))
}

## 5. Sparse seed with a vector-like argument

x5 <- new_DelayedUnaryIsoOpWithArgs(
ConstantArraySeed(c(2, 4), value=0), `+`,
Rargs=list(e2=c(0, 0)), Ralong=1L
)
checkTrue(is_sparse(x5))
a5 <- matrix(0, nrow=2, ncol=4)
checkIdentical(a5, as.array(x5))
checkIdentical(a5, as.array(as(x5, "SVT_SparseArray")))
}