This bugzilla service is closed. All entries have been migrated to https://gitlab.com/libeigen/eigen

Bug 1424

Summary: Eigen::Matrix< unsigned int >::setLinSpaced
Product: Eigen Reporter: simon.floery
Component: Core - generalAssignee: Nobody <eigen.nobody>
Status: RESOLVED FIXED    
Severity: Compilation Problem CC: chtz, fl.gagliardi, gael.guennebaud, jacob.benoit.1
Priority: Normal    
Version: 3.3 (current stable)   
Hardware: All   
OS: Windows   
Whiteboard:

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)
Comment 3 Nobody 2019-12-04 16:58:43 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to gitlab.com's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.com/libeigen/eigen/issues/1424.