Skip to content
Prev 37571 / 63424 Next

Is it safe not to coerce matrices with as.double() in .C()?

On Aug 27, 2010, at 2:44 PM, Liaw, Andy wrote:

            
In a word: yes. It is safe as long as you are absolutely sure that the argument has the right mode. The unsafeness comes in when people might unwittingly use, say, an integer vector where a double was expected, causing memory overruns and general mayhem. 

Notice, BTW, that if you switch to .Call or .External, then you have much more scope for handling such details on the C-side. E.g. you could coerce only if the object has the wrong mode, avoid duplicating things you won't be modifying anyway, etc.