[Coin-discuss] possible error in CoinPackedVector.hpp

Sven de Vries devries at ma.tum.de
Wed May 26 12:33:11 EDT 2004


Hi,

we noticed the "feature" that when an empty and a nonempty
coinpackedvector are added, then the resulting vector is always the empty
vector.

looking at the source:

template <class BinaryFunction> inline void
binaryOp(CoinPackedVector& retVal,
	 double value, const CoinPackedVectorBase& op2,
	 BinaryFunction bf)
{
   binaryOp(retVal, op2, value, bf);
}

template <class BinaryFunction> void
binaryOp(CoinPackedVector& retVal,
	 const CoinPackedVectorBase& op1, const CoinPackedVectorBase& op2,
	 BinaryFunction bf)
{
   retVal.clear();
   const int s1 = op1.getNumElements();
   const int s2 = op2.getNumElements();
   if (s1 == 0 || s2 == 0)
      return;


...

it seems to me, that the last if-statement is the culprit (at least if
bf=addition).

for a second (thinking of bf= +) the following looked like a fix,
 if (s1 == 0){
	retVal=s2;
      return; }
 elseif (s2==0){
	retVal=s1;
	return;}

BUT this is only correct for bf= + and false if bf is multiplication.

Hence I think the only remedy is to remove this if-statement entirely.

sven



More information about the Coin-discuss mailing list