summaryrefslogtreecommitdiff
path: root/R/src
diff options
context:
space:
mode:
authorJustin Bedo <cu@cua0.org>2023-02-07 16:09:06 +1100
committerJustin Bedo <cu@cua0.org>2023-02-07 17:08:50 +1100
commitb555b36b5c14f7a4342b10bcea8374bfe5e0fac8 (patch)
treea08064479c101d33ea350382b1cc56e748ce40c2 /R/src
parenta0b5f58d8d2040306006a8b9deded629692ed8f3 (diff)
add R bindings
Diffstat (limited to 'R/src')
-rw-r--r--R/src/Makevars1
-rw-r--r--R/src/wrapper.c27
2 files changed, 28 insertions, 0 deletions
diff --git a/R/src/Makevars b/R/src/Makevars
new file mode 100644
index 0000000..ca122c3
--- /dev/null
+++ b/R/src/Makevars
@@ -0,0 +1 @@
+PKG_LIBS = -lcodapca
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);
+
+}