This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Ambiguous overload between real and complex version function

Tags: None
(comma "," separated)
abachrac
Registered Member
Posts
8
Karma
0
OS
Hi there,
I'm trying to write overload a function to take either a real MatrixXd/MatrixXf, or a complex valued MatrixXcd/MatrixXcf.

However, the compiler is complaining that the call is ambiguous...

/home/abachrac/stuff/pods_stuff/LR-Planning/externals/common_utils/eigen-utils/src/test-eigen/test_fft.cpp: In function ‘int main(int, char**)’:
/home/abachrac/stuff/pods_stuff/LR-Planning/externals/common_utils/eigen-utils/src/test-eigen/test_fft.cpp:195:57: error: call of overloaded ‘fftw_fwd2(Eigen::MatrixBase<Eigen::Matrix<std::complex<double>, -0x00000000000000001, -0x00000000000000001> >::NonConstRealReturnType)’ is ambiguous
/home/abachrac/stuff/pods_stuff/LR-Planning/externals/common_utils/eigen-utils/src/test-eigen/test_fft.cpp:195:57: note: candidates are:
/home/abachrac/stuff/pods_stuff/LR-Planning/externals/common_utils/eigen-utils/src/test-eigen/../eigen_fftw.hpp:8:18: note: Eigen::MatrixXcd eigen_utils::fftw_fwd2(const MatrixXcd&)
/home/abachrac/stuff/pods_stuff/LR-Planning/externals/common_utils/eigen-utils/src/test-eigen/../eigen_fftw.hpp:9:18: note: Eigen::MatrixXcf eigen_utils::fftw_fwd2(const MatrixXcf&)
/home/abachrac/stuff/pods_stuff/LR-Planning/externals/common_utils/eigen-utils/src/test-eigen/../eigen_fftw.hpp:11:18: note: Eigen::MatrixXcd eigen_utils::fftw_fwd2(const MatrixXd&)
/home/abachrac/stuff/pods_stuff/LR-Planning/externals/common_utils/eigen-utils/src/test-eigen/../eigen_fftw.hpp:16:18: note: Eigen::MatrixXcf eigen_utils::fftw_fwd2(const MatrixXf&)



The function prototypes are:
Code: Select all
Eigen::MatrixXcd fftw_fwd2(const Eigen::MatrixXcd &timeM);
Eigen::MatrixXcf fftw_fwd2(const Eigen::MatrixXcf &timeM);

Eigen::MatrixXcd fftw_fwd2(const Eigen::MatrixXd &timeM)
{
  Eigen::MatrixXcd ctimeM = timeM.cast<std::complex<double> >();
  return fftw_fwd2(ctimeM);
}
Eigen::MatrixXcf fftw_fwd2(const Eigen::MatrixXf &timeM)
{
  Eigen::MatrixXcf ctimeM = timeM.cast<std::complex<float> >();
  return fftw_fwd2(ctimeM);
}



Any ideas as to why the compiler is complaining?

thanks,
-=Abe
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
I think the problem is that you are not calling fft_fwd2 with a Matrix** object but with an expression, here .real() I guess. It would be better to have a very generic fft_fwd2 function that will call an helper function specialized on the scalar type of the expression, e.g.:

template<typename T>
typename fftw_fwd2_helper<typename T::Scalar>::return_type
fft_fwd2(const T& A)
{
return fftw_fwd2_helper<typename T::Scalar>::run(A);
}


where fftw_fwd2_helper is a little struct with a typedef and a static function.


Bookmarks



Who is online

Registered users: Bing [Bot], claydoh, Google [Bot], rblackwell, Yahoo [Bot]