This bugzilla service is closed. All entries have been migrated to https://gitlab.com/libeigen/eigen
Bug 1322 - PermutationMatrix<>::transpose() product causes compilation error
Summary: PermutationMatrix<>::transpose() product causes compilation error
Status: CONFIRMED
Alias: None
Product: Eigen
Classification: Unclassified
Component: Core - expression templates (show other bugs)
Version: 3.3 (current stable)
Hardware: All Windows
: Normal Compilation Problem
Assignee: Nobody
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-10-08 20:54 UTC by Sergiu Deitsch
Modified: 2019-12-04 16:24 UTC (History)
4 users (show)



Attachments

Description Sergiu Deitsch 2016-10-08 20:54:01 UTC
I have encountered a very strange (probably compiler related) issue for which I was not able to create a minimal working example. The code below I extracted to demonstrate the problem compiles just fine in a standalone project.

Nevertheless, I hope someone from the devs knows what is happening here.

I have a piece of code that looks as follows:

#include <Eigen/Core>
#include <Eigen/Eigenvalues>

int main()
{
    Eigen::SelfAdjointEigenSolver<Eigen::Matrix3d> solver;
    // ...
    const Eigen::PermutationMatrix<3, 3> p(Eigen::Vector3i::LinSpaced(0, 2).reverse());
    // Works!
    p.transpose().operator*(solver.eigenvalues());
    // However, the following expression fails:
    // p.transpose() * solver.eigenvalues();
}

In Eigen 3.2.x the product of the permutation matrix transpose and a vector compiled without any errors. In Eigen 3.3, however, MSVC issues the following error:

2>d:\projects\eigen\eigen\src/Geometry/Transform.h(1443): error C2039: 'Scalar': is not a member of 'Eigen::Inverse<Derived>'
2>          with
2>          [
2>              Derived=Eigen::PermutationMatrix<3,3,int>
2>          ]
2>  d:\projects\eigen\eigen\src/Core/PermutationMatrix.h(68): note: see declaration of 'Eigen::Inverse<Derived>'
2>          with
2>          [
2>              Derived=Eigen::PermutationMatrix<3,3,int>
2>          ]
2>  C:\Users\Sergiu\Projects\Tracker\include\vision/calibration.hpp(412): note: see reference to class template instantiation 'Eigen::internal::transform_left_product_impl<Eigen::Inverse<Derived>,2,0,3,4,3,3>' being compiled
2>          with
2>          [
2>              Derived=Eigen::PermutationMatrix<3,3,int>
2>          ]

If I explicitly call PermutationMatrix<>::operator*, the code compiles (see above example).

It seems that a wrong operator* overload is picked up causing the problem. I also include Eigen/Geometry in my project (the module from which the operator* is falsely chosen, as it seems), but not in the header containing the PermutationMatrix<>::transpose product.

Any ideas?
Comment 1 Sergiu Deitsch 2016-10-08 20:56:20 UTC
This happens with 97c1ebe6ccc2.
Comment 2 Gael Guennebaud 2016-10-12 11:57:52 UTC
I cannot find any revision starting with 97c1. Please, could you try with the head of the default (3.3) branch to make sure the issue has not been already fixed?
Comment 3 Gael Guennebaud 2016-10-12 12:01:07 UTC
Sorry, I forgot to update my repo, rev 97c1ebe6ccc2 is indeed very recent.
Comment 4 Gael Guennebaud 2016-10-12 12:11:12 UTC
Your error message is a complete non sense to me:

1 - it tries to instantiate transform_left_product_impl<>, but this class is returned only by Transform::operator*, no free operator*.

2 - this means it first converted a Vector3d to a Transform, but the only non explicit Transform ctors are from Transform objects.

So really, I clueless about how MSVC managed to instantiate this code. Is it the full error message?
Comment 5 Sergiu Deitsch 2016-10-12 13:14:21 UTC
It's pretty much the full error message. I left out the remaining log output which provides only the stack trace of template instantiations specific to my code.

I will try to further investigate the problem. Any pointers where I should start are highly appreciated.
Comment 6 Gael Guennebaud 2016-10-12 13:58:15 UTC
Some idea to try:

1 - in file src/Core/Inverse.h, add:

using Base::operator*

to class InversE.

2 - You could try to comment some ctors of Transform to identify which one is instantiated (without breaking the rest of your code!).
Comment 7 Sergiu Deitsch 2016-10-16 10:54:53 UTC
Thanks for your suggestions. I was able to isolate the code that causes compilation errors, and this is getting really weird. The above example is mostly unchanged:

#include <Eigen/Core>
#include <Eigen/Eigenvalues>
#include <Eigen/Geometry>

int main()
{
    Eigen::Affine3d t; // Remove to compile.

    Eigen::SelfAdjointEigenSolver<Eigen::Matrix3d> solver;
    // ...
    const Eigen::PermutationMatrix<3, 3> p(Eigen::Vector3i::LinSpaced(0, 2).reverse());
    p.transpose() * solver.eigenvalues();
}


The code fails to compile with the additional Eigen::Affine3d variable definition.

The command-line and the full error:

D:\Projects\eigen>cl test.cpp -I. /EHsc
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24215.1 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

test.cpp
d:\projects\eigen\eigen\src/Geometry/Transform.h(1443): error C2039: 'Scalar': is not a member of 'Eigen::Inverse<Derived>'
        with
        [
            Derived=Eigen::PermutationMatrix<3,3,int>
        ]
d:\projects\eigen\eigen\src/Core/PermutationMatrix.h(68): note: see declaration of 'Eigen::Inverse<Derived>'
        with
        [
            Derived=Eigen::PermutationMatrix<3,3,int>
        ]
test.cpp(12): note: see reference to class template instantiation 'Eigen::internal::transform_left_product_impl<Eigen::Inverse<Derived>,2,0,3,4,3,3>' being compiled
        with
        [
            Derived=Eigen::PermutationMatrix<3,3,int>
        ]
d:\projects\eigen\eigen\src/Geometry/Transform.h(1443): error C2146: syntax error: missing '>' before identifier 'Scalar'

If you remove the Eigen::Affine3d variable, the code compiles.
Comment 8 Gael Guennebaud 2016-10-25 15:16:09 UTC
This is worth reporting to MSVC developers.

On Eigen's side it will take time to find a workaround, if any.

On your side, you can split the code in two different cpp file (admittedly, this might be really inconvenient).
Comment 9 Sergiu Deitsch 2019-05-24 08:28:59 UTC
I've reported the issue 2 years ago: https://developercommunity.visualstudio.com/content/problem/50644/eigen-333-code-not-compile.html. No resolution as of today.
Comment 10 Nobody 2019-12-04 16:24:19 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/1322.

Note You need to log in before you can comment on or make changes to this bug.