0

I'm doing a package using 'Rcpp' and it contains this function:

Eigen::MatrixXcd matricesToMatrixXcd(const Eigen::MatrixXd& Re,
                                     const Eigen::MatrixXd& Im) {
  return Re.cast<std::complex<double>>() + 1i * Im.cast<std::complex<double>>();
}

Here, 1i is the unit imaginary number.

I submitted the package to CRAN but the R CHECK on Debian generates this warning:

* checking whether package ‘EigenR’ can be installed ... [297s/297s] WARNING
Found the following significant warnings:
  EigenR.cpp:10:44: warning: imaginary constants are a GCC extension

Would you know what should I do?

Stéphane Laurent
  • 75,186
  • 15
  • 119
  • 225
  • I'm going to try `std::complex I {0, 1};` and check on R-hub... – Stéphane Laurent Nov 23 '20 at 12:26
  • Please make a _reproducible_ example. The error is from a line 10, your example does not have that many lines. – Dirk Eddelbuettel Nov 23 '20 at 13:05
  • @DirkEddelbuettel Sorry, line 10 is the one with `1i`. – Stéphane Laurent Nov 23 '20 at 13:11
  • And it is a column 44 so this is the guilty. – Stéphane Laurent Nov 23 '20 at 13:15
  • I still do not see a [minimally complete and verifable example](https://stackoverflow.com/help/minimal-reproducible-example). Then again the warning message is quite clear and you may just want to try removing `const` ... – Dirk Eddelbuettel Nov 23 '20 at 14:19
  • @DirkEddelbuettel The previous lines are just some comments. I don't think that `const` causes this issue. The "imaginary constant" is `1i`: *GCC provides a non-portable extension that allows imaginary constants to be specified with the suffix i on integer literals: 1.0fi, 1.0i, and 1.0li are imaginary units in GNU C*. I tried to check on r-hub but my internet connection sucks. – Stéphane Laurent Nov 23 '20 at 14:33
  • Maybe the Eigen docs have pointers. It's not really a Rcpp question _per se_ as we're really just the glue you use to get to Eigen headers. – Dirk Eddelbuettel Nov 23 '20 at 14:55
  • @DirkEddelbuettel I was right, `1i` was the smoking gun. The CRAN check has not complained with the code of my answer. Thanks for pointing attention to my problems. – Stéphane Laurent Nov 23 '20 at 16:29

1 Answers1

0

Yeah, this has worked:

Eigen::MatrixXcd matricesToMatrixXcd(const Eigen::MatrixXd& Re,
                                     const Eigen::MatrixXd& Im) {
  const std::complex<double> I_ {0.0, 1.0};
  return Re.cast<std::complex<double>>() + I_ * Im.cast<std::complex<double>>();
}
Stéphane Laurent
  • 75,186
  • 15
  • 119
  • 225