bigmemory icon indicating copy to clipboard operation
bigmemory copied to clipboard

as.big.matrix() with type "raw"

Open privefl opened this issue 9 years ago • 8 comments

I tried:

> x <- matrix(as.raw(sample(0:255, 100)), 10, 10)
> class(x)
[1] "matrix"
> typeof(x)
[1] "raw"
> as.big.matrix(x, type = "raw")
Error in SetMatrixElements(x@address, as.double(j), as.double(i), value) : 
  RAW() can only be applied to a 'raw', not a 'double'
In addition: Warning messages:
1: In as.big.matrix(x, type = "raw") : Casting to numeric type
2: In SetElements.bm(x, i, j, value) :
  Assignment will down cast from double to raw
Hint: To remove this warning type:  options(bigmemory.typecast.warning=FALSE)

Am I doing something wrong or is it a missing implementation?

@adamryczkowski

privefl avatar Sep 15 '16 14:09 privefl

No, it is a bug. What works (and what I have been doing) is:

x <- matrix(as.raw(sample(0:255, 100)), 10, 10)
m<-big.matrix(10,10,type='raw')
m[,]<-x

I'll look at it.

adamryczkowski avatar Sep 15 '16 14:09 adamryczkowski

Now your code work as expected.

Thank you for testing my patch :-)

adamryczkowski avatar Sep 15 '16 14:09 adamryczkowski

Hence the perpetual need for more unit tests :)

cdeterman avatar Sep 15 '16 14:09 cdeterman

So here it is :-)

adamryczkowski avatar Sep 15 '16 14:09 adamryczkowski

Thanks for https://github.com/kaneplusplus/bigmemory/pull/48

privefl avatar Sep 15 '16 15:09 privefl

Thanks @adamryczkowski. I've merged the pull request.

kaneplusplus avatar Sep 15 '16 18:09 kaneplusplus

@adamryczkowski I'll continue here, because this is about "raw" big.matrices. This is only a minor bug, but subsetting with a matrix is returning numeric elements, not raw ones.

Example:

x <- matrix(as.raw(sample(0:255, 100)), 10, 10)
X <- as.big.matrix(x, type = "raw") # so this now works :-)
ind <- cbind(1, 2:3)
ind
X[ind]
X[1, 2:3]

privefl avatar Feb 26 '17 17:02 privefl