File: test_complex.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 (56 lines) | stat: -rw-r--r-- 2,147 bytes parent folder | download | duplicates (5)
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
52
53
54
55
56
#!/usr/bin/r -t
#
# Copyright (C) 2013 - 2019 Baptiste Auguie and Dirk Eddelbuettel
# Copyright (C) 2019 - 2020 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)

## It now (Apr 2020) appears to fail on 32-bit Windows
.onWindows <- .Platform$OS.type == "windows"
.is32bit <- .Platform$r_arch == "i386"

if (.onWindows && .is32bit) exit_file("Do not bother on 32-bit Windows")

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

set.seed(123)

## create variables

A <- matrix(rnorm(9), 3)
B <- matrix(rnorm(9), 3)
C <- A + 1i * B

V <- rnorm(3) + 1i * rnorm(3)
S <- matrix(rnorm(5*3), nrow=3)

## Basic operations

rl <- complexCppTests(A, B, V, S)   # returns results list from C++

expect_equal(rl[["C"]],     C)#,          msg="complex matrix")
expect_equal(rl[["Cst"]],   t(C))#,       msg="complex matrix transpose")
expect_equal(rl[["Ct"]],    Conj(t(C)))#, msg="complex matrix transpose conjugated")
expect_equal(rl[["conjC"]], Conj(C))#,    msg="complex matrix conjugated")
expect_equal(rl[["absC"]],  Mod(C))#,     msg="complex matrix mod")
expect_equal(rl[["CV"]],    C %*% V)#,    msg="complex matrix product")
expect_equal(rl[["CS"]],    C %*% S)#,    msg="complex matrix times vector")
expect_equal(rl[["CC"]],    C * C)#,      msg="complex matrix ops mult")
expect_equal(rl[["CdC"]],   C / C)#,      msg="complex matrix ops div")
expect_equal(rl[["CpC"]],   C + C)#,      msg="complex matrix ops plus")
expect_equal(rl[["CmC"]],   C - C)#,      msg="complex matrix ops minus")