dkahle / dkahle/mpoly

Speedup with c++ using Rcpp

Open
#11 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
HTML
Stars
12
Forks
12
PR merge metrics
No merged PRs in 30d

Description

Have you thought about implementing (the bulk of) the code using [Rcpp](https://cran.r-project.org/web/packages/Rcpp/index.html) (nice intro [here](http://adv-r.had.co.nz/Rcpp.html))? As that's C++ code, it would be quite faster than the current implementation.

In my [fork of the repo](https://github.com/Blaza/mpoly/tree/rcpp/) I rewrote the `mpoly` function, the main workhorse, and some mpoly arithmetic functions (`*` and `^`) using Rcpp. The code basically follows your algorithm almost exactly, just in C++. It is relatively straightforward to implement the current code (at least the `mpoly` function and arithmetic) in Rcpp, and the speed gains are 4-5 fold.

I made a quick benchmark, which you can see [here](https://blaza.github.io/bench.html). The implementation is quite straightforward, so there may well be room for more optimization, as I'm not really an expert C++ coder.

I am making a package which would make use of (multivariate) Lagrange polynomial, so I'm using mpoly to generate the polynomial (the reduced polynomial that mpoly gives is easy to vectorize to give quick evaluation), and the number of collocation points, and thus the degree of the poly, can get quite high, so the speed of generation of the polynomial (the `mpoly` function being the main workhorse) is very important to me, so that brought me to try and implement it in Rcpp and the results have been satisfying for now.

I'd love to hear what you have to say and where we could go from here. Maybe the package could go the Rcpp route (I don't know if you'd like to add another dependency?). Or perhaps I may, in parallel, work on the, let's say, "Rcppmpoly" package which focuses a bit more on speed?

Sorry for the long post :)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.