File: test_Rlapack.R

package info (click to toggle)
r-cran-rcpparmadillo 14.6.0-1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,436 kB
  • sloc: cpp: 134,812; sh: 22; makefile: 2
file content (51 lines) | stat: -rw-r--r-- 1,939 bytes parent folder | download | duplicates (4)
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
46
47
48
49
50
51
#!/usr/bin/r -t
#
# Copyright (C) 2018 - 2022  Keith O'Hara and Dirk Eddelbuettel
# Copyright (C) 2019 - 2022  Dirk Eddelbuettel
#
# This file is part of RcppArmadillo.
#
# RcppArmadillo is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# RcppArmadillo is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with RcppArmadillo.  If not, see <http://www.gnu.org/licenses/>.

library(RcppArmadillo)

if (isFALSE(tryCatch({svd(matrix(complex(1, 1, 1),1,1)); TRUE}, error=function(e) FALSE)))
    exit_file("Skipping for lack of Fortran complex functions in this R build")

Rcpp::sourceCpp("cpp/Rlapack.cpp")

set.seed(123)

## create variables

n <- 5 # size the of matrices generated in tests
n_tri <- 50 # size the of matrices generated in tridiagonal tests

## Basic operations

rl1 <- norm(cx_eig_pair_test(n),"2")
rl2 <- norm(cx_qz_test(n),"2")
rl3 <- cx_rank_test(n)                # should equal n
rl4 <- norm(cx_solve_test(n),"2")
rl5 <- norm(cx_solve_band_test(n_tri),"2")
rl6 <- norm(cx_pinv_test(n),"2")      # should be (approx) an identity matrix
rl7 <- norm(cx_schur_test(n),"2")

expect_equal(rl1,  0)#,  msg="eig_pair for complex matrices")
expect_equal(rl2,  0)#,  msg="qz for complex matrices")
expect_equal(rl3,  n)#,  msg="rank complex matrices")
expect_equal(rl4,  0)#,  msg="solve for complex matrices")
expect_equal(rl5,  0)#,  msg="solve for band complex matrices")
expect_equal(rl6,  1)#,  msg="pinv for complex matrices")
expect_equal(rl7,  0)#,  msg="schur for complex matrices")