File: test-matrixPower.R

package info (click to toggle)
r-cran-lavasearch2 2.0.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,832 kB
  • sloc: cpp: 28; sh: 13; makefile: 2
file content (45 lines) | stat: -rw-r--r-- 1,223 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
### test-matrixPower.R --- 
#----------------------------------------------------------------------
## author: Brice Ozenne
## created: okt 24 2017 (09:21) 
## Version: 
## last-updated: Jan 12 2022 (14:47) 
##           By: Brice Ozenne
##     Update #: 19
#----------------------------------------------------------------------
## 
### Commentary: 
## 
### Change Log:
#----------------------------------------------------------------------
## 
### Code:

## * header
## rm(list = ls())
if(FALSE){ ## already called in test-all.R
    library(testthat)
    library(lavaSearch2)    
}

lava.options(symbols = c("~","~~"))

context("matrixPower")
matrixPower <- lavaSearch2:::matrixPower

## * tests
M <- matrix(rnorm(2e2),20,10)
Sigma <- var(M)

test_that("square root", {
    Sigma.half <- matrixPower(Sigma, power = 1/2, symmetric = FALSE)
    expect_true(all(abs(crossprod(Sigma.half)-Sigma) < 1e-12))
})
 
test_that("inverse", {
    Sigma.m1 <- matrixPower(Sigma, power = -1, symmetric = FALSE)
    expect_equal(Sigma.m1 %*% Sigma,diag(1,NROW(Sigma),NCOL(Sigma)))
})

##----------------------------------------------------------------------
### test-matrixPower.R ends here