Error: expecting a single value when indexing a vector with a vector in gpuR
Hi,
Will there be functionality for subsetting vclVectors and vclMatrices using other vclVectors or normal R vectors and matrices as indices?
Since this is a fundamental functionality in R, I think this issue should be considered as a bug.
Best regards, Venelin
Quite possibly. Could you provide some examples to demonstrate all the functionality you would like? This would be useful for me setting up more unit tests in addition to making sure I understand you correctly. I also will file this as a feature request as it is something I simply haven't implemented as opposed to a bug.
As far as I know the R-vector interface supports subsetting by logical or integer vectors or arrays of higher order (i.e. when indexing a matrix or an array). Here is some example code for vectors but the same principles should work for matrices and higher order arrays:
vec <- rnorm(1000) vec <- as.vclVector(vec, type="float") # if no double type available
subsetting using integer vectors as indices
set the elements from 20 to 30 to 0
vec[20:30] <- 0
All elements except the elements 20:30
length(vecMinus) should be 1000 - 11 = 989
vecMinus <- vec[-(20:30)]
One should also be able to do this using non-contiguous indices
vecMinus2 <- vec[-c(20:30, 120:130)]
... or using logical mask-vectors:
mask <- rep(FALSE, 1000) mask[c(20:30, 120:130)] <- TRUE vec[mask] # should have length 22. vec[ !mask ] # should have length 978.
In the ideal case, all functionality described on the page https://stat.ethz.ch/R-manual/R-devel/library/base/html/Extract.html should be implemented with minimal performance overhead. This is the only way to guarantee that one can port his R-code to gpuR by changing R-native types with vcl/gpu types.
2017-01-17 14:30 GMT+01:00 Charles Determan [email protected]:
Quite possibly. Could you provide some examples to demonstrate all the functionality you would like? This would be useful for me setting up more unit tests in addition to making sure I understand you correctly. I also will file this as a feature request as it is something I simply haven't implemented as opposed to a bug.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/cdeterman/gpuR/issues/62#issuecomment-273157026, or mute the thread https://github.com/notifications/unsubscribe-auth/AOVgsV3ShW3DRIxuUxqqxPQPWxPzKV3iks5rTMJ-gaJpZM4Lkihs .
-- Venelin MITOV
@venelin sorry for the lack of activity lately, I have been otherwise occupied. Looking at this again I believe most of these can be implemented. However, anything non-contiguous is not supported by the ViennaCL backend upon which the gpuR package is based. The only workaround is to create a new vector and copy the required elements from the old. This would likely have some overhead but how much is to be determined. I likely will try to have sections copied that are contiguous to try and keep things as efficient as possible.
Hi Charles,
I see very well what you are meaning. If you are interested in the concrete application of the functionality I was having in mind, you can have a look at my recently submitted manuscript at http://biorxiv.org/content/early/2017/03/08/115089. This is a good example of an application where most of the operations can be done on contiguous indices.
Meanwhile I've implemented my R-algorithm in C++ using the Armadillo library for vector element-wise operations. I've also reordered the elements of the vectors so that most of the operations are done on contiguous index-spans. This already benefits from vectorized operations on normal CPUs, but parallelization can become interesting once I extend this algorithm to a multitrait (multivariate) setting.
I saw that ViennaCL tries to provide a common interface to normal CPUs as well as GPUs. If not already there, it would be cool if your package allows to decide which backend one wants to use :).
Cheers, Venelin
2017-03-16 19:03 GMT+01:00 Charles Determan [email protected]:
@venelin https://github.com/venelin sorry for the lack of activity lately, I have been otherwise occupied. Looking at this again I believe most of these can be implemented. However, anything non-contiguous is not supported by the ViennaCL backend upon which the gpuR package is based. The only workaround is to create a new vector and copy the required elements from the old. This would likely have some overhead but how much is to be determined. I likely will try to have sections copied that are contiguous to try and keep things as efficient as possible.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/cdeterman/gpuR/issues/62#issuecomment-287142793, or mute the thread https://github.com/notifications/unsubscribe-auth/AOVgsXgqK8PfinFfvmirJOuCivkEpLLEks5rmXl6gaJpZM4Lkihs .
-- Venelin MITOV
@venelin Technically it does at this point by using OpenCL. OpenCL can be used on a CPU or GPU. I have run the functions within this package with the device set as the CPU and it works just fine. However, I don't believe it is taking advantage of the OpenMP parallelization that is possible. That is likely outside the scope of this package though as the primary intent is to leverage GPU devices. Perhaps a future version could allow the build to define which backend to use (OpenCL or OpenMP, CUDA is a whole different animal). However, there are likely other/better implementations of the BLAS functions that better utilize the CPU than this package would so it would be a very low priority.
A task list of features to make sure working correctly:
vclVector
- [x]
scalar return - [x]
scalar assignment - [x]
contiguous numeric subset- (seeslicemethod) - [x]
contiguous numeric assignment- see (slicemethod) - [ ]
non-contiguous numeric subset - [ ]
non-contiguous numeric assignment - [ ]
negative (drop) contiguous numeric subset - [ ]
negative (drop) non-contiguous numeric subset - [ ]
contiguous integer subset - [ ]
contiguous integer assignment - [ ]
non-contiguous integer subset - [ ]
non-contiguous integer assignment - [ ]
negative (drop) contiguous integer subset - [ ]
negative (drop) non-contiguous integer subset - [ ]
logical subset (same length) - [ ]
logical subset (recycle rule) - [ ]
logical assignment (same length) - [ ]
logical assignment (recycle rule)
gpuVector
- [x]
scalar return - [x]
scalar assignment - [x]
contiguous numeric subset- see (slicemethod) - [x]
contiguous numeric assignment- see (slicemethod) - [ ]
non-contiguous numeric subset - [ ]
non-contiguous numeric assignment - [ ]
negative (drop) contiguous numeric subset - [ ]
negative (drop) non-contiguous numeric subset - [ ]
contiguous integer subset - [ ]
contiguous integer assignment - [ ]
non-contiguous integer subset - [ ]
non-contiguous integer assignment - [ ]
negative (drop) contiguous integer subset - [ ]
negative (drop) non-contiguous integer subset - [ ]
logical subset (same length) - [ ]
logical subset (recycle rule) - [ ]
logical assignment (same length) - [ ]
logical assignment (recycle rule)
vclMatrix
- [x]
scalar return - [x]
scalar assignment - [x]
matrix element return - [x]
matrix element assignment - [x]
contiguous numeric subset- (seeblockmethod) - [x]
contiguous numeric assignment- (seeblockmethod) - [ ]
non-contiguous numeric subset - [ ]
non-contiguous numeric assignment - [ ]
negative (drop) contiguous numeric subset - [ ]
negative (drop) non-contiguous numeric subset - [ ]
contiguous integer subset - [ ]
contiguous integer assignment - [ ]
non-contiguous integer subset - [ ]
non-contiguous integer assignment - [ ]
negative (drop) contiguous integer subset - [ ]
negative (drop) non-contiguous integer subset - [ ]
logical subset (same length) - [ ]
logical subset (recycle rule) - [ ]
logical assignment (same length) - [ ]
logical assignment (recycle rule)
gpuMatrix
- [x]
scalar return - [x]
scalar assignment - [x]
matrix element return - [x]
matrix element assignment - [x]
contiguous numeric subset- (seeblockmethod) - [x]
contiguous numeric assignment- (seeblockmethod) - [ ]
non-contiguous numeric subset - [ ]
non-contiguous numeric assignment - [ ]
negative (drop) contiguous numeric subset - [ ]
negative (drop) non-contiguous numeric subset - [ ]
contiguous integer subset - [ ]
contiguous integer assignment - [ ]
non-contiguous integer subset - [ ]
non-contiguous integer assignment - [ ]
negative (drop) contiguous integer subset - [ ]
negative (drop) non-contiguous integer subset - [ ]
logical subset (same length) - [ ]
logical subset (recycle rule) - [ ]
logical assignment (same length) - [ ]
logical assignment (recycle rule)
@venelin sorry for the silence on this issue but I will need to push it to the next release. There are so many changes already implemented that most people are being directed to using the develop branch here instead of CRAN. I hope to get to this issue in the near future.
@charles thanks for the news! No time pressure from my side.
2017-08-31 17:23 GMT+02:00 Charles Determan [email protected]:
@venelin https://github.com/venelin sorry for the silence on this issue but I will need to push it to the next release. There are so many changes already implemented that most people are being directed to using the develop branch here instead of CRAN. I hope to get to this issue in the near future.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/cdeterman/gpuR/issues/62#issuecomment-326330283, or mute the thread https://github.com/notifications/unsubscribe-auth/AOVgsQTn7xU-RWomg6IK9Vy6_nyIuKfhks5sdtACgaJpZM4Lkihs .
-- Venelin MITOV