tests/testthat/test_vclMatrix_chol.R

library(gpuR)
context("vclMatrix chol decomposition")

if(detectGPUs() >= 1){
    current_context <- set_device_context("gpu")    
}else{
    current_context <- currentContext()
}

# set seed
set.seed(123)

ORDER <- 10

# Base R objects
X <- matrix(rnorm(ORDER^2), nrow=ORDER, ncol=ORDER)
X <- X %*% t(X)
# X <- matrix(c(5,1,1,3),2,2)
nsqA <- matrix(rnorm(20), nrow = 4)

D <- chol(X)

test_that("vclMatrix Single Precision Matrix Cholesky Decomposition",
          {
              
              has_gpu_skip()
              
              fgpuX <- vclMatrix(X, type="float")
              fgpuA <- vclMatrix(nsqA, type = "float")
              
              C <- chol(fgpuX)
              
              # print(C[])
              
              expect_is(C, "fvclMatrix")
              expect_equal(C[], D, tolerance=1e-05, 
                           info="float cholesky decomposition not equivalent")  
              expect_error(chol(fgpuA), "'x' must be a square matrix",
                           info = "chol shouldn't accept non-square matrices")
          })

test_that("vclMatrix Double Precision Matrix Cholesky Decomposition",
          {
              
              has_gpu_skip()
              has_double_skip()
              
              fgpuX <- vclMatrix(X, type="double")
              fgpuA <- gpuMatrix(nsqA, type = "double")
              
              C <- chol(fgpuX)
              
              expect_is(C, "dvclMatrix")
              expect_equal(C[], D, tolerance=.Machine$double.eps^0.5, 
                           info="double cholesky decomposition not equivalent")  
              expect_error(chol(fgpuA), "'x' must be a square matrix",
                           info = "chol shouldn't accept non-square matrices")
          })

setContext(current_context)

Try the gpuR package in your browser

Any scripts or data that you put into this service are public.

gpuR documentation built on May 30, 2019, 1:02 a.m.