Re: [eigen] unpleasant surprise mit math functions

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


thank you Christoph and Karli, that makes perfect sense. So I thought
the solution would simply to put the "internal" base classes into
their own namespace. That worked for some expressions, but not for
all. Typically if a template class Expr<Func> defined in namespace A
is instantiated with a class defined in internal then, all the generic
functions of internal become readily available for the class Expr.
That's more clear on an example:

namespace A {

  struct Matrix { float x; };

  namespace internal {
    template<typename T> T bar(const T& x) { return x; }
    struct func1 {};
  }
  struct func2 {};

  template<typename Func>
  struct Expr
  {
    Expr(const Matrix&) {}
  };

}

int main()
{
  A::Matrix m;
  bar(A::Expr<A::internal::func1>(m)); // does compile
  bar(A::Expr<A::func2>(m)); // does not compile
}

Did anyone be aware of such a rule? It does not make sense to me, and
looks rather dangerous.


cheers,
gael

On Sun, Sep 23, 2012 at 11:09 AM, Helmut Jarausch
<jarausch@xxxxxxxxxxxxxxxxxxx> wrote:
> Hi,
>
> then what about declaring the math functions - applicable to Matrix/Vector
> classes - as  private!
> Just an idea,
> Helmut.
>
>
> On 09/22/2012 10:21:11 PM, Gael Guennebaud wrote:
>>
>> Hi,
>>
>> there is indeed something very strange happening. I've no idea why
>> sin(t) with t a VectorXd does compile. It seems it manages to directly
>> found Eigen::internal::sin even though VectorXd is defined in the
>> Eigen namespace, not Eigen::internal. This can be shown more clearly
>> in the following test:
>>
>> #include <Eigen/Core>
>>
>> namespace A {
>>
>>   struct Matrix { float x; };
>>
>>   namespace internal {
>>     template<typename T> T bar(const T& x) { return x; }
>>   }
>>
>> }
>>
>> namespace Eigen {
>>   namespace internal {
>>     template<typename T> T foo(const T& x) { return x; }
>>   }
>> }
>>
>> int main()
>> {
>>   A::Matrix m;
>>   bar(m); // does not compile (as expected)
>>
>>   Eigen::MatrixXd b;
>>   foo(b); // does compile (does not make sense to me)
>> }
>>
>>
>> I tried with both g++ and clang++. I've no clue...
>>
>>
>> gael
>>
>>
>> On Wed, Sep 19, 2012 at 3:28 PM, Christoph Hertzberg
>> <chtz@xxxxxxxxxxxxxxxxxxxxxxxx> wrote:
>> > On 18.09.2012 20:25, Helmut Jarausch wrote:
>> >>
>> >> int main() {
>> >>    int N= 5,  m= 2;
>> >>    VectorXd t(N);
>> >>    MatrixXd A(N,m);
>> >>
>> >>    A.col(0).fill(0);
>> >>    t << 10, 20, 30, 40, 50;
>> >>    double F = 8*atan(1.0)/50;
>> >>    A.col(1)= sin(F*t);
>> >>    cout << A << endl;
>> >> }
>> >
>> >
>> > IIRC, sin(t) is only supposed to work for array expressions, so
>> > sin(F*t.array()) should work. However, your example should give a
>> > compile-time error, so this seems to be a bug.
>> >
>> > Christoph
>> >
>> >
>> >
>> >
>> > --
>> > ----------------------------------------------
>> > Dipl.-Inf. Christoph Hertzberg
>> > Cartesium 0.049
>> > Universität Bremen
>> > Enrique-Schmidt-Straße 5
>> > 28359 Bremen
>> >
>> > Tel: +49 (421) 218-64252
>> > ----------------------------------------------
>> >
>> >
>>
>>
>>
>>
>>
>
>
>



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/