~ubuntu-branches/ubuntu/utopic/r-cran-rcpparmadillo/utopic

« back to all changes in this revision

Viewing changes to inst/unitTests/runit.complex.R

  • Committer: Package Import Robot
  • Author(s): Dirk Eddelbuettel
  • Date: 2013-12-09 18:13:21 UTC
  • mfrom: (1.1.9)
  • Revision ID: package-import@ubuntu.com-20131209181321-cc9ycvs53xfiz5ow
Tags: 0.3.930.1-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/r -t
 
2
#
 
3
# Copyright (C) 2013  Baptiste Auguie and Dirk Eddelbuettel
 
4
#
 
5
# This file is part of RcppArmadillo.
 
6
#
 
7
# RcppArmadillo is free software: you can redistribute it and/or modify it
 
8
# under the terms of the GNU General Public License as published by
 
9
# the Free Software Foundation, either version 2 of the License, or
 
10
# (at your option) any later version.
 
11
#
 
12
# RcppArmadillo is distributed in the hope that it will be useful, but
 
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
# GNU General Public License for more details.
 
16
#
 
17
# You should have received a copy of the GNU General Public License
 
18
# along with RcppArmadillo.  If not, see <http://www.gnu.org/licenses/>.
 
19
 
 
20
.setUp <- RcppArmadillo:::unit_test_setup("complex.cpp")
 
21
 
 
22
test.complex <- function() {
 
23
 
 
24
    set.seed(123)
 
25
 
 
26
    ## create variables
 
27
 
 
28
    A <- matrix(rnorm(9), 3)
 
29
    B <- matrix(rnorm(9), 3)
 
30
    C <- A + 1i * B
 
31
 
 
32
    V <- rnorm(3) + 1i * rnorm(3)
 
33
    S <- matrix(rnorm(5*3), nrow=3)
 
34
 
 
35
    ## Basic operations
 
36
 
 
37
    rl <- complexCppTests(A, B, V, S)   # returns results list from C++
 
38
 
 
39
    checkEquals(rl[["C"]],     C,          msg="complex matrix")
 
40
    checkEquals(rl[["Cst"]],   t(C),       msg="complex matrix transpose")
 
41
    checkEquals(rl[["Ct"]],    Conj(t(C)), msg="complex matrix transpose conjugated")
 
42
    checkEquals(rl[["conjC"]], Conj(C),    msg="complex matrix conjugated")
 
43
    checkEquals(rl[["absC"]],  Mod(C),     msg="complex matrix mod")
 
44
    checkEquals(rl[["CV"]],    C %*% V,    msg="complex matrix product")
 
45
    checkEquals(rl[["CS"]],    C %*% S,    msg="complex matrix times vector")
 
46
    checkEquals(rl[["CC"]],    C * C,      msg="complex matrix ops mult")
 
47
    checkEquals(rl[["CdC"]],   C / C,      msg="complex matrix ops div")
 
48
    checkEquals(rl[["CpC"]],   C + C,      msg="complex matrix ops plus")
 
49
    checkEquals(rl[["CmC"]],   C - C,      msg="complex matrix ops minus")
 
50
}