
Ublas : 
From: Michael Stevens (mail_at_[hidden])
Date: 20050825 05:53:13
On Wednesday 24 August 2005 21:40, Darin DeForest wrote:
> I'm trying to understand the difference betwen these too snippets of code
>
> snippet #1
>
> const int numberOfPoints = 4
> ublas::vector<int> processed( zero_vector<int>(numberOfPoints ) );
>
> snippet #2
>
> const int numberOfPoints = 4
> ublas::vector<int> processed( scalar_vector<int>(numberOfPoints, 0) );
>
>
> The problem is when I perform the following
>
> processed[ 0 ] = 3;
>
> I get an compiler error for code snippet #1, i.e.
> error C2109: subscript requires array or pointer type
>
> I suspect that in snippet 1, processed is defining a function prototype
> with a parameter of zero_vector<int>, while in snippet #2, it is vector
> that is getting initialized to zero.
That does seem to be the cause. I have confirmed the same error on GCC 4.0 so
it is not just a VC problem. An example of the horrific syntax mess that C++
is!
> What makes this more interesting is when I change this to initialization by
> assignment
>
> ublas::vector<int> processed = ( zero_vector<int>(numberOfPoints, 0) );
>
> This error message goes away, but now I get error messages on these type of
> definitions
>
> ublas::vector<int> vector1;
I think that is cooincidence. The = syntax is correct. VC has a problem with
'int'. The assignment checks in uBLAS use a metric which requires a sqrt.
VC does not allow 'std::sqrt (1)'. This is VC specific, probably due to lack
of support for partial template ordering. There are 2 workaround for VC
Define std::sqrt(int).
OR
#define BOOST_UBLAS_TYPE_CHECK 0
to avoid uBLAS checking its assignments.
Michael
>
>
>
>
> error C2668: 'std::sqrt' : ambiguous call to overloaded function
> \ublas\boost\boost_1_33_0\boost\numeric\ublas\traits.hpp(94) :
> error C2668: 'std::sqrt' : ambiguous call to overloaded function C:\Program
> Files\Microsoft Visual Studio .NET 2003\Vc7\include\math.h(200): could be
> 'double sqrt(double)' C:\Program Files\Microsoft Visual Studio .NET
> 2003\Vc7\include\math.h(578): or 'float sqrt(float)' C:\Program
> Files\Microsoft Visual Studio .NET 2003\Vc7\include\math.h(626): or
> 'long double sqrt(long double)' while trying to match the argument list
> '(const int)'
> \ublas\boost\boost_1_33_0\boost\numeric\ublas\traits.hpp(93) : while
> compiling classtemplate member function
> 'boost::numeric::ublas::scalar_traits<T>::value_type
> boost::numeric::ublas::scalar_traits<T>::sqrt(boost::numeric::ublas::scalar
>_traits<T>::const_reference)' with
> [
> T=int
> ]
> \ublas\boost\boost_1_33_0\boost\numeric\ublas\traits.hpp(125) : see
> reference to class template instantiation
> 'boost::numeric::ublas::scalar_traits<T>' being compiled with
> [
> T=int
> ]
> \boost\boost_1_33_0\boost\numeric\ublas\vector.hpp(43) : see
> reference to class template instantiation
> 'boost::numeric::ublas::type_traits<T>' being compiled with
> [
> T=int
> ]
>
>
> If I remove the "processed" variable declaration/initialization, these
> error messages go away indicating nothing is wrong with the definition of
> vector1.
>
> So the moral of this story is that zero_vector seems to be treated funny
> for other vector constructors, and that using it as an rvalue in
> assignment causes other weird things to happen, which isn't obvious. Using
> scalar_vector these problems don't occur, and I still can use "vector<int>
> vector1; " constructors
 ___________________________________ Michael Stevens Systems Engineering 34128 Kassel, Germany Phone/Fax: +49 561 5218038 Navigation Systems, Estimation and Bayesian Filtering http://bayesclasses.sf.net ___________________________________