Skip to content

matrix computations with __float128

Summary

Eigen does not work for quadmath.h

I really think this is a bug because most matrix computations in eigen should work for any number type with well-defined operations for =,+,-,*,/.

Environment

  • Operating System : Windows10
  • Architecture : x64
  • Eigen Version : 3.7
  • Compiler Version : GCC 8.2.0
  • Compile Flags : no flags
  • Vector Extension : no extensions

Minimal Example

The following minimum example exposes two kinds of issues:

  1. Eigen uses cout in a way that cannot handle operator<<(__float128) in a non-ambiguous way.
  2. Eigen requires functions like epsilon() and other functions that usually do not need to exist for general number types.
#include<quadmath.h>
#include<iostream>
#include<Eigen>

//typedef double  num;
typedef __float128  num;

int main(){
    //
    Eigen::Matrix<num,Eigen::Dynamic,Eigen::Dynamic> A,R;
    Eigen::HouseholderQR<Eigen::Matrix<num,Eigen::Dynamic,Eigen::Dynamic>> solver_dense_QR;
    //
    int m=10,n=5;
    A = Eigen::Matrix<num,Eigen::Dynamic,Eigen::Dynamic>::Random(m,n);
    R = Eigen::Matrix<num,Eigen::Dynamic,Eigen::Dynamic>::Zero  (n,n);
    //
    solver_dense_QR.compute(A);
    int k = A.cols();
    A.setIdentity(); A.applyOnTheLeft(solver_dense_QR.householderQ());
    R = solver_dense_QR.matrixQR().block(0,0,k,k).template triangularView<Eigen::Upper>();
    std::cout << "A:\n" << A << "\n\nR:\n" << R << "\n\n";
    return 0;
}

Steps to reproduce

run g++ main.cpp on command line. A battery of errors will arise.

What is the current bug behavior?

The code cannot be compiled unless changing the type of num back to double.

What is the expected correct behavior?

That it compiles in either case and runs and prints out the QR factorization with 128 bits of precision.

Relevant logs

There is no program output because the program cannot even be compiled.

Anything else that might help: Compiler Errors

.../eigen_M3_m7/Eigen/src/Core/IO.h:175:14: error: ambiguous overload for 'operator<<' (operand types are 'std::stringstream' {aka 'std::__cxx11::basic_stringstream'} and 'const Scalar' {aka 'const __float128'}) sstr << m.coeff(i,j); In file included from c:\mingw\lib\gcc\mingw32\8.2.0\include\c++\iostream:39, from .\minimum.cpp:3:

.../eigen_M3_m7/Eigen/src/Core/IO.h:186:7: error: ambiguous overload for 'operator<<' (operand types are 'std::ostream' {aka 'std::basic_ostream'} and 'const Scalar' {aka 'const __float128'}) s << m.coeff(i, 0); In file included from c:\mingw\lib\gcc\mingw32\8.2.0\include\c++\iostream:39, from .\minimum.cpp:3:

.../eigen_M3_m7/Eigen/src/Core/NumTraits.h:34:27: error: call of overloaded 'log10(Eigen::GenericNumTraits<__float128>::Real)' is ambiguous return int(ceil(-log10(NumTraits::epsilon()))); ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~

.../eigen_M3_m7/Eigen/src/Householder/Householder.h:88:16: error: call of overloaded 'sqrt(Eigen::internal::abs2_retval<__float128>::type)' is ambiguous beta = sqrt(numext::abs2(c0) + tailSqNorm); ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~