forked from RcppCore/RcppEigen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_solution.R
More file actions
48 lines (40 loc) · 1.39 KB
/
test_solution.R
File metadata and controls
48 lines (40 loc) · 1.39 KB
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
#
# Copyright (C) 2012 - 2019 Douglas Bates, Dirk Eddelbuettel and Romain Francois
#
# This file is part of RcppEigen.
#
# RcppEigen 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.
#
# RcppEigen 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 Rcpp. If not, see <http://www.gnu.org/licenses/>.
Rcpp::sourceCpp("cpp/solution.cpp")
#test.smallDense <- function() {
A <- matrix(c(1,2,3,4), nrow=2L)
B <- matrix(c(5,6,7,8), nrow=2L)
b <- c(1,1)
## solutions to dense systems
res <- dense_PPLU(A, b)
expect_equal(res$Ainv, solve(A))
expect_equal(res$x, solve(A, b))
res <- dense_CPQR(A, b)
expect_equal(res$Ainv, solve(A))
expect_equal(res$x, solve(A, b))
#test.largeDense <- function() {
set.seed(1234321)
N <- 100L
AA <- matrix(rnorm(N * N), nrow=N)
bb <- rnorm(N)
res <- dense_PPLU(AA, bb)
expect_equal(res$Ainv, solve(AA))
expect_equal(res$x, solve(AA, bb))
res <- dense_CPQR(AA, bb)
expect_equal(res$Ainv, solve(AA))
expect_equal(res$x, solve(AA, bb))