gsl-ocaml / mlgsl_qrng.c

/* ocamlgsl - OCaml interface to GSL                        */
/* Copyright (©) 2002-2005 - Olivier Andrieu                */
/* distributed under the terms of the GPL version 2         */


#include <gsl/gsl_qrng.h>

#include "wrappers.h"

static inline const gsl_qrng_type *qrngtype_val(value v)
{
  const gsl_qrng_type *qrng_type[] = {
    gsl_qrng_niederreiter_2,
    gsl_qrng_sobol };
  return qrng_type[Int_val(v)];
}

#define Qrng_val(v) (gsl_qrng *)Field((v), 0)

CAMLprim value ml_gsl_qrng_alloc(value type, value dim)
{
  value r;
  Abstract_ptr(r, gsl_qrng_alloc(qrngtype_val(type), Int_val(dim)));
  return r;
}

ML1(gsl_qrng_free, Qrng_val, Unit)
ML1(gsl_qrng_init, Qrng_val, Unit)

CAMLprim value ml_gsl_qrng_dimension(value qrng)
{
  return Val_int((Qrng_val(qrng))->dimension);
}

CAMLprim value ml_gsl_qrng_get(value qrng, value x)
{
  if(Double_array_length(x) != (Qrng_val(qrng))->dimension)
    GSL_ERROR("wrong array size", GSL_EBADLEN);
  gsl_qrng_get(Qrng_val(qrng), Double_array_val(x));
  return Val_unit;
}

CAMLprim value ml_gsl_qrng_sample(value qrng)
{
  gsl_qrng * q = Qrng_val(qrng);
  value arr = alloc(q->dimension * Double_wosize, Double_array_tag);
  gsl_qrng_get(q, Double_array_val(arr));
  return arr;
}

ML1(gsl_qrng_name, Qrng_val, copy_string)

CAMLprim value ml_gsl_qrng_memcpy(value src, value dst)
{
  gsl_qrng_memcpy(Qrng_val(dst), Qrng_val(src));
  return Val_unit;
}

CAMLprim value ml_gsl_qrng_clone(value qrng)
{
  value r;
  Abstract_ptr(r, gsl_qrng_clone(Qrng_val(qrng))); 
  return r;
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.