1# 2# Copyright (C) 2012 - 2013 Douglas Bates, Dirk Eddelbuettel and Romain Francois 3# 4# This file is part of RcppEigen. 5# 6# RcppEigen is free software: you can redistribute it and/or modify it 7# under the terms of the GNU General Public License as published by 8# the Free Software Foundation, either version 2 of the License, or 9# (at your option) any later version. 10# 11# RcppEigen is distributed in the hope that it will be useful, but 12# WITHOUT ANY WARRANTY; without even the implied warranty of 13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14# GNU General Public License for more details. 15# 16# You should have received a copy of the GNU General Public License 17# along with Rcpp. If not, see <http://www.gnu.org/licenses/>. 18 19Rcpp::sourceCpp("cpp/wrap.cpp") 20 21#test.wrapVectors <- function() { 22res <- wrap_vectors() 23 24expect_equal(res[[1]][[1]], complex(5)) 25expect_equal(res[[1]][[2]], double(5)) 26expect_equal(res[[1]][[3]], double(5)) 27expect_equal(res[[1]][[4]], integer(5)) 28expect_equal(res[[1]][[5]], integer(5)) 29 30expect_equal(res[[2]][[1]], (1+0i) * diag(nr=3L)) 31expect_equal(res[[2]][[2]], diag(nr=3L)) 32expect_equal(res[[2]][[3]], diag(nr=3L)) 33expect_equal(res[[2]][[4]], matrix(as.integer((diag(nr=3L))),nr=3L)) 34expect_equal(res[[2]][[5]], matrix(as.integer((diag(nr=3L))),nr=3L)) 35 36expect_equal(res[[3]][[1]], matrix(complex(5), nr=1L)) 37expect_equal(res[[3]][[2]], matrix(numeric(5), nr=1L)) 38expect_equal(res[[3]][[3]], matrix(numeric(5), nr=1L)) 39expect_equal(res[[3]][[4]], matrix(integer(5), nr=1L)) 40expect_equal(res[[3]][[5]], matrix(integer(5), nr=1L)) 41 42expect_equal(res[[4]][[1]], as.matrix(complex(5))) 43expect_equal(res[[4]][[2]], as.matrix(numeric(5))) 44expect_equal(res[[4]][[3]], as.matrix(numeric(5))) 45expect_equal(res[[4]][[4]], as.matrix(integer(5))) 46expect_equal(res[[4]][[5]], as.matrix(integer(5))) 47 48expect_equal(res[[5]][[1]], matrix(complex(9L), nc=3L)) 49expect_equal(res[[5]][[2]], matrix(numeric(9L), nc=3L)) 50expect_equal(res[[5]][[3]], matrix(numeric(9L), nc=3L)) 51expect_equal(res[[5]][[4]], matrix(integer(9L), nc=3L)) 52expect_equal(res[[5]][[5]], matrix(integer(9L), nc=3L)) 53 54expect_equal(res[[6]][[1]], complex(5)) 55expect_equal(res[[6]][[2]], double(5)) 56expect_equal(res[[6]][[3]], double(5)) 57expect_equal(res[[6]][[4]], integer(5)) 58expect_equal(res[[6]][[5]], integer(5)) 59 60oneTen <- seq(1, 10, length.out=6L) 61 62expect_equal(res[[7]][[1]], oneTen) 63expect_equal(res[[7]][[2]], log(oneTen)) 64expect_equal(res[[7]][[3]], exp(oneTen)) 65expect_equal(res[[7]][[4]], sqrt(oneTen)) 66expect_equal(res[[7]][[5]], cos(oneTen)) 67 68 69#test.asVec <- function() { 70res <- as_Vec(list(1:10, as.numeric(1:10))) 71expect_equal(unlist(res), rep.int(55, 10L)) 72 73#test.asArray <- function() { 74res <- as_Array(list(1:10, as.numeric(1:10))) 75expect_equal(unlist(res), rep.int(55, 10L)) 76 77#test.asMat <- function() { 78integer_mat <- matrix(as.integer(diag(nrow = 5L))) 79numeric_mat <- diag(nrow = 5L) 80res <- as_Mat(list(integer_mat, numeric_mat)) 81expect_equal(unlist(res), rep.int(5, 6L)) 82 83#test.asArray2D <- function() { 84integer_mat <- matrix(as.integer(diag(nrow = 5L))) 85numeric_mat <- diag(nrow = 5L) 86res <- as_Array2D(list(integer_mat, numeric_mat)) 87expect_equal(unlist(res), rep.int(5, 6L)) 88