From b555b36b5c14f7a4342b10bcea8374bfe5e0fac8 Mon Sep 17 00:00:00 2001 From: Justin Bedo Date: Tue, 7 Feb 2023 16:09:06 +1100 Subject: add R bindings --- R/src/wrapper.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 R/src/wrapper.c (limited to 'R/src/wrapper.c') diff --git a/R/src/wrapper.c b/R/src/wrapper.c new file mode 100644 index 0000000..dd7bce1 --- /dev/null +++ b/R/src/wrapper.c @@ -0,0 +1,27 @@ +#include "pca.h" + +void +pca_wrapper(int *n, int *d, double *q, int *k, double *X, double *B, double *U, double *l) { + + struct futhark_context_config *cfg = futhark_context_config_new(); + struct futhark_context *ctx = futhark_context_new(cfg); + + struct futhark_f64_2d *Xf = futhark_new_f64_2d(ctx, X, *n, *d); + struct futhark_f64_2d *Yf; + struct futhark_f64_2d *Bf; + struct futhark_f64_2d *Uf; + + futhark_entry_pcaWithQuantile(ctx, &Bf, &Uf, &Yf, l, *q, *k, Xf); + futhark_context_sync(ctx); + futhark_values_f64_2d(ctx, Bf, B); + futhark_values_f64_2d(ctx, Uf, U); + futhark_values_f64_2d(ctx, Yf, X); + + futhark_free_f64_2d(ctx, Xf); + futhark_free_f64_2d(ctx, Bf); + futhark_free_f64_2d(ctx, Uf); + futhark_free_f64_2d(ctx, Yf); + futhark_context_free(ctx); + futhark_context_config_free(cfg); + +} -- cgit v1.2.3