toon-members
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Toon-members] GCC bug?


From: Edward Rosten
Subject: Re: [Toon-members] GCC bug?
Date: Mon, 4 Aug 2008 15:03:02 -0600 (MDT)

On Fri, 1 Aug 2008, Ethan Eade wrote:

Using gcc 4.3.1, the following code does not give correct output if using -02 optimization or greater. Turning down the optimization (or even adding more lines) will make it work. Is this a compiler bug?

It's looking like it. I've attached some debugging code below. Note the function b0rk(). When compiled as -O3 or -O, it gets called the correct number of times (4). However, the output seems to come out differently.

-Ed


///////////////////////////////////////////////////////
// bug.cc

int C=0;
#include <iostream>
using namespace std;

double& b0rk(double& d)
{
        C++;
        return d;
}


#include <TooN/TooN.h>
using namespace TooN;

Matrix<2,1> dup(const Matrix<2,1>& m)
{
        return m;
}

int main()
{
   Vector<2> x;
   x[0] = 1;
   x[1] = 2;

   Matrix<2> o = dup(x.as_col()) * x.as_row();

   cerr << o << endl;
   cerr << C << endl;
}


//////////////////////////////////////////////////////////
//
// linoperators.hh
//
template <int Rows, int Inter, int Cols, class LMAccessor, class RMAccessor>
inline Matrix<Rows,Cols> operator*(const FixedMatrix<Rows,Inter,LMAccessor>& 
lhs,
                                   const FixedMatrix<Inter,Cols,RMAccessor>& 
rhs){

  Matrix<Rows, Cols> ret;

  for(int i=0; i < Rows; i++)
  {
        TooN::util::MatrixProductRow<Cols>::eval(lhs,rhs.T(),ret[i],i);
  }

  return ret;
}


///////////////////////////////////////////////////////
//
// util.h
//
namespace TooN {
    namespace util {

        template <bool Cond> struct Assert;
        template <> struct Assert<true> {};

        template <int B, int Col=0> struct MatrixProductRow {
            template <class M1, class M2, class V> static inline void eval(const M1& a, 
const M2& b, V& v, int row) {
                //Perform a dot product
                v[Col] = 0;
                for(int i=0; i < b[Col].size(); i++)
                        b0rk(v[Col]) = (a[row][i] * b[Col][i]);

                MatrixProductRow<B,Col+1>::eval(a,b,v, row);
            }
        };

        template <int B> struct MatrixProductRow<B,B> {
            template <class M1, class M2, class V> static inline void eval(const M1&, 
const M2&, V&, int) {
            }
        };

    }
}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]