bluescarni / mppp

Multiprecision for modern C++
Mozilla Public License 2.0
305 stars 26 forks source link

Use mp++ types in armadillo (proof of concept) #207

Open chatziko opened 4 years ago

chatziko commented 4 years ago

The following repo shows that armadillo can be monkey-patched to support mp++ types as elements (integer and rational, but others could be easily added).

https://github.com/chatziko/arma-mppp

A variety of basic operations are supported, and I'm sure others could be added.

Of course I wouldn't expect performance similar to BLAS, but using armadillo to do linear algebra with mp++'s exact arithmetic could be super useful. I'd love to see something like this included in mp++, I think it's a natural fit for armadillo!

bluescarni commented 4 years ago

Hi @chatziko, that is indeed a good suggestion. I would be willing to incorporate explicit support for armadillo's types directly within mp++, perhaps in the form of a header in the extra/ subdirectory.

I have never used armadillo myself however, so probably the best way to proceed would be if you could open a PR and then we could work on it together.

chatziko commented 4 years ago

Ok, I'll try to open a PR when I find some time.

Quick question: one problem I found in supporting more armadillo operations is that it sometimes uses 0 as a default argument, assuming that its element type accepts it, like:

template<typename T>
void foo(T a = 0) {
    ...
}

My understanding is that mp++ doesn't allow implicit conversions, so this will fail when T = int_t. Is that because they are error prone? Do you see any way to optionally/conditionally/... enable them or something?

bluescarni commented 4 years ago

Yes, disallowing implicit conversions was a conscious design decision from the very beginning. I find them complex to reason about and generally speaking I try not to rely on/use them in my code. It is unfortunate that initialization in the form T a = 0; is dependent upon the availability of implicit conversions, but there's nothing that can be done about it.

I don't see an easy way out of this situation, apart from some hacky preprocessor logic to shut off the explicit keyword in a few key places. The only sane option I can see at the moment is to change the armadillo source code to use void foo(T a = T(0)) instead, but I can see how this is a hard sell.

chatziko commented 4 years ago

I made a PR to armadillo, let's see how this goes :smile:

https://gitlab.com/conradsnicta/armadillo-code/merge_requests/93

bluescarni commented 4 years ago

Great, thanks! I'll follow the discussion there.