Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Ocaml and C] Passing Arrays and Matrices of floats from Ocaml to C and back
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2010-03-04 (11:07)
From: Odalric-Ambrym Maillard <odalricambrym.maillard@g...>
Subject: [Ocaml and C] Passing Arrays and Matrices of floats from Ocaml to C and back

Hello, I have the following problem : I wan to use a Least-squares
Regression solver written in C in a program written in OCaml.

I have something like this in the Ocaml program,
let beta = solve_olsr psi_matrix y_train in ...*

where psi_matrix is built using  Array.make_matrix and y_train by Array.make

The dimensions are KxN for psi_matrix and N for y_train, and the output beta
should be a vector of length K (built with Array.make etc).

I have a C function with the following signature :
void  olsr(int rows, int columns,
         double **matrix_of_data,
         double *vector_of_data,
         double ** vector_of_coefficients)*

Thus, I need to create a stub function, that will lok like this

*CAMLValue solve_olsr(value ...,value...) {

 CAMLReturn ...

My problem is the following : how do  proceed since the parameters I need to
transmt are vectors or matrices of float (for Caml, i.e. double for C), and
not just integers or floats ? I really do not know how to transfer arrays
and matrix of floats from Caml to C, and back.

It would be great to have an answer.

Thank you,