New user self-registration is currently disabled. Please email eigen-core-team @ lists.tuxfamily.org if you need an account.
Bug 1424 - Eigen::Matrix< unsigned int >::setLinSpaced
Eigen::Matrix< unsigned int >::setLinSpaced
Status: RESOLVED FIXED
Product: Eigen
Classification: Unclassified
Component: Core - general
3.3 (current stable)
All Windows
: Normal Compilation Problem
Assigned To: Nobody
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2017-05-02 12:23 UTC by simon.floery
Modified: 2017-06-09 10:02 UTC (History)
4 users (show)



Attachments

Description simon.floery 2017-05-02 12:23:48 UTC
Dear all,

In both VS2015 and VS2017, the following code snippet fails to compile with eigen-3.3.3.:

	Eigen::Matrix< unsigned int, 1, 5 > m;
	m.setLinSpaced(0u, 7u);

VS2015 complains:
Severity	Code	Description	Project	File	Line
Error	C2668	'abs': ambiguous call to overloaded function	eigen_vs2015	c:\eigen-3.3.3\eigen\src\core\mathfunctions.h	1066

With eigen-3.2.8, we do not get any errors.

thanks, Simon
Comment 1 Flavio Gagliardi 2017-05-05 12:14:34 UTC
(In reply to simon.floery from comment #0)
> Dear all,
> 
> In both VS2015 and VS2017, the following code snippet fails to compile with
> eigen-3.3.3.:
> 
> 	Eigen::Matrix< unsigned int, 1, 5 > m;
> 	m.setLinSpaced(0u, 7u);
> 
> VS2015 complains:
> Severity	Code	Description	Project	File	Line
> Error	C2668	'abs': ambiguous call to overloaded function	eigen_vs2015
> c:\eigen-3.3.3\eigen\src\core\mathfunctions.h	1066
> 
> With eigen-3.2.8, we do not get any errors.
> 
> thanks, Simon

I am not an expert and I don't know if a better solution exists. Personally, I solved this problem in GCC 7.1 by adding a template specialization for unsigned int and long unsigned int in MathFunctions.h

after the function

template<typename T>
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
typename NumTraits<T>::Real abs(const T &x) {
  EIGEN_USING_STD_MATH(abs);
  return abs(x);
}


I added 

template<>
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
typename NumTraits<long unsigned int>::Real abs(const long unsigned int& x) {
  return x;
}

template<>
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
typename NumTraits<unsigned int>::Real abs(const unsigned int& x) {
  return x;
}
Comment 2 Gael Guennebaud 2017-06-09 10:02:01 UTC
Thank you for the report, fixed:

https://bitbucket.org/eigen/eigen/commits/cfb064a552e8/ (devel)
https://bitbucket.org/eigen/eigen/commits/15f6a8f430ab/ (3.3)

Note You need to log in before you can comment on or make changes to this bug.