kaneplusplus / bigmemory

126 stars 24 forks source link

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

Open privefl opened 8 years ago

privefl commented 8 years ago

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

adamryczkowski commented 8 years ago

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 commented 8 years ago

Now your code work as expected.

Thank you for testing my patch :-)

cdeterman commented 8 years ago

Hence the perpetual need for more unit tests :)

adamryczkowski commented 8 years ago

So here it is :-)

privefl commented 8 years ago

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

kaneplusplus commented 8 years ago

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

privefl commented 7 years ago

@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 commented 1 month ago

@adamryczkowski More on this:

X <- bigmemory::big.matrix(1, 1, type = "raw", init = 0)
testthat::expect_identical(X[1, 1], as.raw(0))
testthat::expect_identical(X[1], 0L)  # should be 00, but okay..

While X[1, 1] works fine, X[1] returns an integer instead of a raw (not really a major issue but still). However, one major issue is that X[1] now returns NA on new Macs.