summaryrefslogtreecommitdiff
path: root/R/src/wrapper.c
blob: 5e258b80c9aea3ede015cdfc844d5281b73552c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include "pca.h"

void
pca_wrapper(int *nprocs, int *n, int *d, int *iters, double *q, int *k, double *X, double *B, double *U, double *l) {

  struct futhark_context_config *cfg = futhark_context_config_new();
  futhark_context_config_set_num_threads(cfg, *nprocs);
  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, *iters, *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);

}