Skip to content
Back to formatted view

Raw Message

Message-ID: <CADpnMoWqYKn7_CktfY+ZyMQ52t6+vStWvQQxAAxOeRsnCUszYg@mail.gmail.com>
Date: 2016-08-07T11:00:27Z
From: Kaspar Märtens
Subject: [Rcpp-devel] type mismatch between NumericMatrix and IntegerMatrix

Hi,

When experimenting with the following toy function,

// [[Rcpp::export]]
void modify_matrix(NumericMatrix A){
  A(0, 0) = 5;
}

and applying this on matrices defined in R, I occasionally noticed
unexpected behaviour (as it turns out, on integer matrices).

### Example 1 (works as expected)

A = matrix(0, 2, 2)
modify_matrix(A)
A

##      [,1] [,2]
## [1,]    5    0
## [2,]    0    0

### Example 2 (does not modify the matrix)

A = matrix(1:4, 2, 2)
modify_matrix(A)
A

##      [,1] [,2]
## [1,]    1    3
## [2,]    2    4

I realised that in the latter case, A consists of integers, so I guess I
should be using an IntegerMatrix version of my function instead. However,
shouldn't Rcpp detect the type mismatch between NumericMatrix and
IntegerMatrix?

Best,
Kaspar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20160807/5d3ce18c/attachment.html>