Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Export fftw c++ methods for use in other packages #5

Open
jkennel opened this issue Jun 29, 2022 · 3 comments
Open

feature: Export fftw c++ methods for use in other packages #5

jkennel opened this issue Jun 29, 2022 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@jkennel
Copy link

jkennel commented Jun 29, 2022

I've been looking for some nice wrappers for fftw for quite some time and it looks like you have done a great job with it! I have a desire to use the functions inside of some C++ code and was wondering if you would be willing export them from your package. I could generate a pull request for this if you are interested. I followed the instructions here and it worked great. Thanks for the nice package!

@dipterix
Copy link
Owner

dipterix commented Jul 7, 2022

Hi, @jkennel, thanks. A pull request is of course welcome. In the meanwhile, I'll try to export and make sure the function generates expected results in the https://github.com/dipterix/ravetools/tree/test branch

  • Export cpp functions to inst/includes so users can dynamically link to ravetools
  • remove the ambiguous argument (inplace) from cpp functions and make sure FFTW flags are respected
  • Make sure FFTW plans are correctly scheduled to avoid data pollution (also add unit tests)
    • r2c
    • c2r
    • c2c
    • mv-r2c
    • mv-c2r
    • mv-c2c
    • r2c-2D, 3D, XD
    • c2r-2D, 3D, XD
    • c2c-2D, 3D, XD

@dipterix
Copy link
Owner

dipterix commented Sep 11, 2022

Hi, @jkennel , sorry for the late reply. I was busy working on other projects these days so there is a delay on this issue. Currently I have exposed some C++ functions so that you can dynamically link to my package. I'll gradually release other functions (I have to test them to make sure they comply with the FFTW documentation and produce the correct results in most cases).

Here are some examples to link those functions in C++ code:

library(Rcpp)

# --- FFTW r2c ----------------
test_fftw_r2c <- cppFunction(
  depends = "ravetools",
  'SEXP test_fftw_r2c(SEXP data, int HermConj = 1, int fftwplanopt = 0, SEXP ret = R_NilValue) {
    SEXP re = PROTECT(ravetools::fftw_r2c(data, HermConj, fftwplanopt, ret));
    // Do something
    UNPROTECT(1);
    return re;
  }')

data <- rnorm(1000)
ret <- complex(1000)
invisible(test_fftw_r2c(data, ret = ret))
ret

# --- Filter signals, agrees with Matlab filter function ----------
test_filter <- cppFunction(
  depends = "ravetools",
  'SEXP test(SEXP b, SEXP a, SEXP x, SEXP z) {
    SEXP re = PROTECT(ravetools::cpp_filter(b, a, x, z));
    // Do something
    UNPROTECT(1);
    return re;
  }')

t <- seq(0, 1, by = 0.01)
x <- sin(2 * pi * t * 2.3)
bf <- signal::butter(2, c(0.15, 0.3))

test_filter(bf$b, bf$a, x, rep(0, 4))

I'm trying to update ravetools package on CRAN on the monthly basis. However if you want to use the most recent features, there is a auto-builder that compiles changes on the hourly basis:

# Enable repository from dipterix
options(repos = c(
  dipterix = 'https://dipterix.r-universe.dev',
  CRAN = 'https://cloud.r-project.org'))
# Download and install ravetools in R
install.packages('ravetools')

@jkennel
Copy link
Author

jkennel commented Sep 13, 2022

This is great! Thank you for all your efforts on this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants