From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 89813BC57 for ; Thu, 4 Mar 2010 12:07:58 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApoCACIjj0tIDtyei2dsb2JhbACPMoFtiW8IFQEBAQoLCgcRBR+nLYFehSMtiEkBAQMFhHcEi0o X-IronPort-AV: E=Sophos;i="4.49,580,1262559600"; d="scan'208";a="54008938" Received: from fg-out-1718.google.com ([72.14.220.158]) by mail1-smtp-roc.national.inria.fr with ESMTP; 04 Mar 2010 12:07:58 +0100 Received: by fg-out-1718.google.com with SMTP id 19so644038fgg.9 for ; Thu, 04 Mar 2010 03:07:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:reply-to:date:message-id :subject:from:to:content-type; bh=0b6v/xRmywv5ByILyUIEUnL8eVMTrfdZ4sK5LP53ry4=; b=xanW4ns0w3zb4Gv6o5eASXWwDRUDsNFTkHAnsC9c3yduGpozJN4KQNW66KXNUWKBlF Zsc0+0lOhnbw1fKtjzCj/gwt/oZTx4dLwB7KbhUm2VjxVN2HqaMXSKOzMFcjDCGPVB9a UE00RYmb1+Yn6tWnvlLY7+RPLw5ntUM5FEzvg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:reply-to:date:message-id:subject:from:to:content-type; b=hvyy1DaGLATM0rjfHSS4mrd5kjJecv1XrO1DW9WZjRT+DrdavyNtdjR6lgG/O7yS9x yv+zuzEvpH74R863+/JbZlfWBQR6VBFaidueRvIV1fmMMkNudT2rneJG/7dZ6UnqxlA5 thnbrp04uAyUelawqlaTm/v0MQF41IU29+3Ac= MIME-Version: 1.0 Received: by 10.239.181.78 with SMTP id l14mr905802hbg.156.1267700877843; Thu, 04 Mar 2010 03:07:57 -0800 (PST) Reply-To: odalric.maillard@inria.fr Date: Thu, 4 Mar 2010 12:07:57 +0100 Message-ID: <406c33611003040307v2195e006qfe273bf85c7f2c95@mail.gmail.com> Subject: [Ocaml and C] Passing Arrays and Matrices of floats from Ocaml to C and back From: Odalric-Ambrym Maillard To: caml-list@inria.fr Content-Type: multipart/alternative; boundary=001485f45454815fa90480f79cae X-Spam: no; 0.00; ocaml:01 arrays:01 matrices:01 ocaml:01 solver:01 coefficients:01 stub:01 camlparam:01 camlreturn:01 vectors:01 matrices:01 integers:01 arrays:01 solver:01 coefficients:01 --001485f45454815fa90480f79cae Content-Type: text/plain; charset=ISO-8859-1 , 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...) { CAMLparam... 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, Odalric-Ambrym --001485f45454815fa90480f79cae Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable <caml-list@inria.fr>,
<= br>
Hello, I have the following problem : I wan to use a Least-squares R= egression solver written in C in a program written in OCaml.

I have = something like this in the Ocaml program,

let beta =3D solve_olsr psi_matrix y_train in ...


where p= si_matrix is built using=A0 Array.make_matrix and y_train by Array.make The dimensions are KxN for psi_matrix and N for y_train, and the output be= ta should be a vector of length K (built with Array.make etc).

I have a C function with the following signature :

void=A0 ol= sr(int rows, int columns,
=A0=A0=A0 =A0=A0=A0 =A0double **matrix_of_dat= a,
=A0=A0=A0 =A0=A0=A0 =A0double *vector_of_data,
=A0=A0=A0 =A0=A0= =A0 =A0double ** vector_of_coefficients)


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

= CAMLValue solve_olsr(value ...,value...) {
=A0CAMLparam...

=A0= CAMLReturn ...
}


My problem is the following : how do=A0 proc= eed 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,
Odalric-A= mbrym

--001485f45454815fa90480f79cae--