multiprecision -- eigen matrices using dynamically allocated variable-precision mpfr_float
I'd like to use the variable-precision mpfr_float type offered by the
Boost.Multiprecision library, with the templated Eigen linear algebra
library. I observe that if I make an identity matrix created with
dynamically-allocated variable-precision mpfr_floats, and multiply it
against itself, every other row is populated with nan's. Here is some code:
int main(){
int size = 9;
typedef boost::multiprecision::mpfr_float_backend<0,
boost::multiprecision::allocate_dynamic> mybackend;
typedef boost::multiprecision::number
I have been able to pin it down to the allocate_dynamic switch; if I select allocate_stack, the product computes correctly; allocate_dynamic reliably generates nans. Fixed-precision numbers work just fine, and expression templates on/off make no difference. I'd like to use the dynamic allocation, as I expect to use thousands of digits at times.
I am using clang++, with c++11, on OSX, Boost 1.57.0, Eigen 3.2.4. Same behaviour in 1.56 / 3.2.3.
It seems like maybe an offset issue, but I just can't get there by myself. I've also played with defining the NumTraits in Eigen various ways, but nothing affects the nan behaviour. Does anyone have any ideas?
Well that's weird. The only difference between dynamic and static allocation that I can think of at present is in the way they handle move semantics - dynamically allocated values have destructive moves - which is to say the moved-from-value is left uninitialized. Can you try building with BOOST_NO_CXX11_RVALUE_REFERENCES defined and see if that fixes the issue? If it does, I'll have to investigate what Eigen is doing in this case. John.
Hi John,
Can you try building with BOOST_NO_CXX11_RVALUE_REFERENCES defined and see if that fixes the issue?
I assumed you meant to compile my executable, not all of boost and then my executable. I have attempted to compile my program with #define BOOST_NO_CXX11_RVALUE_REFERENCES, defined prior to my #inclusions, and I get two compiler errors. I'm using clang-600.0.57. Here are the errors: In file included from src/nameomitted/nameomitted.cpp:10: In file included from /usr/local/include/boost/multiprecision/number.hpp:22: In file included from /usr/local/include/boost/multiprecision/detail/generic_interconvert.hpp:9: In file included from /usr/local/include/boost/multiprecision/detail/default_ops.hpp:9: In file included from /usr/local/include/boost/math/policies/error_handling.hpp:31: In file included from /usr/local/include/boost/format.hpp:38: In file included from /usr/local/include/boost/format/internals.hpp:20: In file included from /usr/local/include/boost/optional.hpp:15: /usr/local/include/boost/optional/optional.hpp:1010:5: error: unknown type name 'reference_type_of_temporary_wrapper' reference_type_of_temporary_wrapper operator *() && { return boost::move(this->get()) ; } ^ /usr/local/include/boost/optional/optional.hpp:1033:5: error: unknown type name 'reference_type_of_temporary_wrapper' reference_type_of_temporary_wrapper value() && I looked everywhere I could for solutions to this problem, and came up with only one relevant post: http://stackoverflow.com/questions/27449993/boost-unknown-type-name-referenc... I hope this compiler error helps. If I misunderstood and was supposed to rebuild boost with that definition, I apologize. I'm using the Homebrew-installed Boost with all default flags and compilation options. Thanks a lot for helping me out! Daniel
On 15/04/2015 19:35, Daniel Brake wrote:
Hi John,
Can you try building with BOOST_NO_CXX11_RVALUE_REFERENCES defined and see if that fixes the issue?
I assumed you meant to compile my executable, not all of boost and then my executable. I have attempted to compile my program with #define BOOST_NO_CXX11_RVALUE_REFERENCES, defined prior to my #inclusions, and I get two compiler errors. I'm using clang-600.0.57. Here are the errors:
Never mind, false lead anyway - there's a bug in the assignment operator of mpfr_float_backend - the operator: mpfr_float_backend& operator=(const mpfr_float_backend& o) Needs to be a no-op in the case of self-assignment, otherwise the call to mpfr_set_prec sets the value to NaN, even though the precision and value doesn't actually change in this case :( There'll be an official patch shortly, but I need to wait for the revised tests to complete first (to make sure they catch this). John.
Never mind, false lead anyway - there's a bug in the assignment operator of mpfr_float_backend - the operator:
thanks for researching this, John!
mpfr_float_backend& operator=(const mpfr_float_backend& o)
Needs to be a no-op in the case of self-assignment, otherwise the call to mpfr_set_prec sets the value to NaN, even though the precision and value doesn't actually change in this case :(
There'll be an official patch shortly, but I need to wait for the revised tests to complete first (to make sure they catch this).
I have four questions regarding a patch. Please pardon if they are trivial, but this seems like the quickest way to receive answers, and searches didn't reveal the answers for me. 1) Do I need to do anything to report this bug, or has a report on this one been filed? 2) Will the patch be contained in the 1.58 release? 3) If not, once a patch for this bug is released, will the patch show up in http://www.boost.org/patches/ ? And one last question -- 4) Is there a way to detect whether a patch has been applied, and refuse to compile my program if it hasn't? Thanks a ton for the help, I truly appreciate it. Daniel
I have four questions regarding a patch. Please pardon if they are trivial, but this seems like the quickest way to receive answers, and searches didn't reveal the answers for me.
1) Do I need to do anything to report this bug, or has a report on this one been filed?
I've just filed one so the issue is known: https://svn.boost.org/trac/boost/ticket/11193
2) Will the patch be contained in the 1.58 release?
No that ship has sailed I'm afraid.
3) If not, once a patch for this bug is released, will the patch show up in http://www.boost.org/patches/ ? And one last question --
Embarrassingly I didn't realise that page existed - I'll try and find out what needs to be done to get a patch on there - although in some ways Github may replace this?
4) Is there a way to detect whether a patch has been applied, and refuse to compile my program if it hasn't?
I guess check for boost-1.59 in boost/version.hpp - of that's a way off yet :( Here's the patch on Github: https://github.com/boostorg/multiprecision/commit/c36e15bd292d3a6aa97091f4ee... HTH, John.
participants (2)
-
Daniel Brake
-
John Maddock