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-- 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 mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id E6B26BC57 for ; Thu, 4 Mar 2010 14:08:37 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AkYIADJAj0vRVdvWimdsb2JhbACDCY4WghiHVwgVAQEBCgkMBxEFH6Z2NoFehSotiEkBAQMFgTCCXWoE X-IronPort-AV: E=Sophos;i="4.49,581,1262559600"; d="scan'208";a="45978643" Received: from mail-ew0-f214.google.com ([209.85.219.214]) by mail3-smtp-sop.national.inria.fr with ESMTP; 04 Mar 2010 14:08:37 +0100 Received: by ewy6 with SMTP id 6so1757611ewy.17 for ; Thu, 04 Mar 2010 05:08:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :from:date:message-id:subject:to:content-type; bh=pFwJsaDHKxnAvSUpiT1Lbon4daaFWlfmFYSnkB4KF/0=; b=mt/fB4gE80OQCXpvMIjA8UiDzNw3f/+R+9wphlC65G3ZWFHfsPlAAw4LCjR/tstJK6 UlGx1PMXwu3S1XJikf1PViZ3UBoUuj8V+cURRhyvgi8EtYzSqeP+jr1mQGvQfoIEbA7o CB6034SjhCpNPUD7hWzfcDxfSJrX8nkmoMW74= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; b=FJf0Qv1ms4jlSP7tF5Oa+3P0wDP6YsZqQt4RMFQDNPzYlEo4c496TgGmgcvPHGtYyO 7D03rpGU54qTbxPepatEmAYe02m2Ad8HGL/LqNu+R4c+5kezlArtu5aTh+fUbDNVMDUd j9cB4zpP4193PvGZa8t9MScPvTKee3kNWW73E= MIME-Version: 1.0 Received: by 10.213.65.138 with SMTP id j10mr811596ebi.23.1267708117151; Thu, 04 Mar 2010 05:08:37 -0800 (PST) In-Reply-To: <406c33611003040307v2195e006qfe273bf85c7f2c95@mail.gmail.com> References: <406c33611003040307v2195e006qfe273bf85c7f2c95@mail.gmail.com> From: Paolo Donadeo Date: Thu, 4 Mar 2010 14:08:17 +0100 Message-ID: <4b5157c31003040508u98111adkc485f89c319f129c@mail.gmail.com> Subject: Re: [Caml-list] [Ocaml and C] Passing Arrays and Matrices of floats from Ocaml to C and back To: caml-list@inria.fr Content-Type: text/plain; charset=UTF-8 X-Spam: no; 0.00; ocaml:01 arrays:01 matrices:01 ocaml:01 bigarray:01 caml-list:01 caml:02 floats:02 library:03 passing:05 manual:06 inria:06 docs:07 consider:09 using:15 Did you consider using the bigarray library? http://caml.inria.fr/pub/docs/manual-ocaml/manual043.html -- Paolo 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 mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 898A0BC57 for ; Thu, 4 Mar 2010 14:52:30 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvIAABdKj0vBvsFKmWdsb2JhbACbVQEBAQEBCAsKBxMitzCEfAQ X-IronPort-AV: E=Sophos;i="4.49,581,1262559600"; d="scan'208";a="45906687" Received: from dnsp.umh.ac.be (HELO hermes1.umh.ac.be) ([193.190.193.74]) by mail2-smtp-roc.national.inria.fr with ESMTP; 04 Mar 2010 14:52:30 +0100 Received: from poincare.swapping.umh.ac.be (poincare.swapping.umh.ac.be [10.102.100.81]) by hermes1.umh.ac.be (8.14.2/8.13.6) with ESMTP id o24DpmIL794626; Thu, 4 Mar 2010 14:51:48 +0100 Received: from localhost ([127.0.0.1] ident=trch) by poincare.swapping.umh.ac.be with esmtp (Exim 4.71) (envelope-from ) id 1NnBTX-0005kd-6T; Thu, 04 Mar 2010 14:52:27 +0100 Date: Thu, 04 Mar 2010 14:52:27 +0100 (CET) Message-Id: <20100304.145227.906513221350493012.Christophe.Troestler+ocaml@umons.ac.be> To: odalric.maillard@inria.fr, odalricambrym.maillard@gmail.com Cc: caml-list@inria.fr Subject: Re: [Caml-list] [Ocaml and C] Passing Arrays and Matrices of floats from Ocaml to C and back From: Christophe TROESTLER In-Reply-To: <406c33611003040307v2195e006qfe273bf85c7f2c95@mail.gmail.com> References: <406c33611003040307v2195e006qfe273bf85c7f2c95@mail.gmail.com> X-Face: #2fb%mPx>rRL@4ff~TVgZ"<[:,oL"`TUEGK/[8/qb58~C>jR(x4A+v/n)7BgpEtIph_neoLKJBq0JBY9:}8v|j Organization: University of Mons Return-Receipt-To: Christophe.Troestler@umons.ac.be Disposition-Notification-To: Christophe.Troestler@umons.ac.be X-Mailer: Mew version 7.0.50 on Emacs 23.1 / Mule 6.0 (HANACHIRUSATO) Mime-Version: 1.0 Content-Type: Text/Plain; charset=iso-8859-15 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.64 on 193.190.193.76 X-Spam: no; 0.00; ocaml:01 arrays:01 matrices:01 ocaml:01 christophe:01 troestler:01 christophe:01 troestler:01 0100,:01 solver:01 lacaml:01 lapack:01 lacaml:01 solver:01 bigarrays:01 On Thu, 4 Mar 2010 12:07:57 +0100, Odalric-Ambrym Maillard wrote: > > Hello, I have the following problem : I wan to use a Least-squares > Regression solver written in C in a program written in OCaml. Aren't the Lacaml/LAPACK least square enough ? http://www.ocaml.info/home/ocaml_sources.html#lacaml If you want to bind your very own solver, the recommended route is to use bigarrays : http://caml.inria.fr/pub/docs/manual-ocaml/manual043.html#toc143 My 0.02¤, C. 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 mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 8B2F5BC57 for ; Thu, 4 Mar 2010 15:04:35 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AuEBAGRMj0vRVdrhkGdsb2JhbACPLAeBbYoYCBUBAQEBCQkMBxMDH6cxgV6FLS2ISQEBAwWEdwSLSg X-IronPort-AV: E=Sophos;i="4.49,581,1262559600"; d="scan'208";a="58201466" Received: from mail-bw0-f225.google.com ([209.85.218.225]) by mail4-smtp-sop.national.inria.fr with ESMTP; 04 Mar 2010 15:04:35 +0100 Received: by bwz25 with SMTP id 25so591324bwz.17 for ; Thu, 04 Mar 2010 06:04:34 -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:in-reply-to :references:date:message-id:subject:from:to:cc:content-type; bh=bHg6HLGRhyff6ccvgwBHyoqv/kWOJe2tO6u58Pqtv5Y=; b=WIHBQOIKY3Av8KDyTnXF2ODEUNdHwM5qupANUGWGmgQqTCrdmqpPu3fAyK9Pv08vba oZv/WI0KKYdet198Vd0vpTkrTbfIw9L2J8I2Z5xe5PoucTeAwVwcAMd4Kst1r2ZJrflQ 4izZXP626g6qCWks7e+WTw0SB50Qoa5DIpGvc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:reply-to:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; b=Xc2kCoCWqexGaDmU6jZMra+cDlf+EqSqPTYF+fiyWRVJHEb0HUN5w3P1g3Qbz5b05K DGkc9bqKX/bo7IUk4ukX7xFCHEt7LBPEFn3wFcuWlcEhYrZ+ZWaxv2ZDgefUhpaqCMnp WKwKVa07LTSwKi5v+5JAQwjUZ0CB4hfe9FFQA= MIME-Version: 1.0 Received: by 10.239.185.137 with SMTP id c9mr979387hbh.69.1267711474509; Thu, 04 Mar 2010 06:04:34 -0800 (PST) Reply-To: odalric.maillard@inria.fr In-Reply-To: <4b5157c31003040508u98111adkc485f89c319f129c@mail.gmail.com> References: <406c33611003040307v2195e006qfe273bf85c7f2c95@mail.gmail.com> <4b5157c31003040508u98111adkc485f89c319f129c@mail.gmail.com> Date: Thu, 4 Mar 2010 15:04:34 +0100 Message-ID: <406c33611003040604y25517b4bmd34f137708ce5b37@mail.gmail.com> Subject: Re: [Caml-list] [Ocaml and C] Passing Arrays and Matrices of floats from Ocaml to C and back From: Odalric-Ambrym Maillard To: Paolo Donadeo Cc: caml-list@inria.fr Content-Type: multipart/alternative; boundary=001485f5ce461da74f0480fa149f X-Spam: no; 0.00; ocaml:01 arrays:01 matrices:01 ocaml:01 bigarrays:01 bigarray:01 beginner's:01 bug:01 bigarrays:01 bigarray:01 beginner's:01 bug:01 beginners:01 beginners:01 caml-list:01 --001485f5ce461da74f0480fa149f Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Thanks, I was not aware of this relation between Bigarrays and C. I will try to use this and tell you of it works as I want. Odalric 2010/3/4 Paolo Donadeo > Did you consider using the bigarray library? > > http://caml.inria.fr/pub/docs/manual-ocaml/manual043.html > > > -- > Paolo > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > --=20 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Odalric-Ambrym Maillard, Phd student INRIA Lille - Nord Europe, - Sequential Learning Project Institut de Math=E9matiques de Toulouse, - Equipe de Statistique et Probabilit=E9s Odalric.maillard@inria.fr, +33 6.43.71.70.48 (cell) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --001485f5ce461da74f0480fa149f Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Thanks, I was not aware of this relation between Bigarrays and C.
I wil= l try to use this and tell you of it works as I want.

Odalric
2010/3/4 Paolo Donadeo <p.donadeo@gmail.com>
Did you consider = using the bigarray library?

http://caml.inria.fr/pub/docs/manual-ocaml/manual043.html<= br>

--
Paolo

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list Archives: http://caml.in= ria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



--
~~~~~~~~~~~~~~~~~~~~~~~= ~~~~~~~~~~
Odalric-Ambrym Maillard, Phd student
INRIA Lille - Nord Eu= rope,
- Sequential Learning Project
Institut de Math=E9matiques de To= ulouse,
- Equipe de Statistique et Probabilit=E9s
Odalric.maillard@inria.fr,
+33 6.43.71.70.48 (cell)~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--001485f5ce461da74f0480fa149f-- 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 54AA8BC57 for ; Thu, 4 Mar 2010 18:02:53 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AuEBAFd2j0vRVdrhkGdsb2JhbACPLAeBbYoXCBUBAQEBCQkMBxMDH6hSgV6FLC2ISQEBAwWEdwSLSg X-IronPort-AV: E=Sophos;i="4.49,582,1262559600"; d="scan'208";a="54035597" Received: from mail-bw0-f225.google.com ([209.85.218.225]) by mail1-smtp-roc.national.inria.fr with ESMTP; 04 Mar 2010 18:02:53 +0100 Received: by bwz25 with SMTP id 25so793886bwz.17 for ; Thu, 04 Mar 2010 09:02:52 -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:in-reply-to :references:date:message-id:subject:from:to:cc:content-type; bh=JiLCQj033Pj2lKAyWmDGX54BX9uRyXMrclJYTZ3hvNk=; b=C1pCOGqIJQRqPeeOp2w0L0I/bzuF4Z/X4/yUN+tQ9PnJK2c2I40tMKWv7EfA8jFP6S Yf4R+ldaQUnCsquUH/DSXr412zVjlgfiZjLz2iaMGX894Uq11FzVyIpqeb/dpumlnj4s Yi6uT+8fIUnowBCccnRzFJjcwdU8jEbNr0nB0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:reply-to:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; b=vfxc36pXT4RJTfavGO+MPvngHcbepNc9E1OAnw9FQsRMEx3gpg/olElhirY0hXClmS Uk8S/O3IuwfzRgnqkX0ZFpr8zFmEg2mGhWxjOtGVLeNNZsfz0kcM2YdBwTve9Hhf4x7z g9aoNUXb1zSn6OINBNJI05HZHxbbiYAp6XaYQ= MIME-Version: 1.0 Received: by 10.239.164.80 with SMTP id s16mr1136389hbd.54.1267722172354; Thu, 04 Mar 2010 09:02:52 -0800 (PST) Reply-To: odalric.maillard@inria.fr In-Reply-To: <406c33611003040604y25517b4bmd34f137708ce5b37@mail.gmail.com> References: <406c33611003040307v2195e006qfe273bf85c7f2c95@mail.gmail.com> <4b5157c31003040508u98111adkc485f89c319f129c@mail.gmail.com> <406c33611003040604y25517b4bmd34f137708ce5b37@mail.gmail.com> Date: Thu, 4 Mar 2010 18:02:50 +0100 Message-ID: <406c33611003040902o897243cled850c2e8184334e@mail.gmail.com> Subject: Re: [Caml-list] [Ocaml and C] Passing Arrays and Matrices of floats from Ocaml to C and back From: Odalric-Ambrym Maillard To: Paolo Donadeo Cc: caml-list@inria.fr Content-Type: multipart/alternative; boundary=001485f1ec2ac1d40e0480fc91a5 X-Spam: no; 0.00; ocaml:01 arrays:01 matrices:01 ocaml:01 bigarrays:01 bigarray:01 bigarray:01 stub:01 camlparam:01 val:01 val:01 bigarrays:01 beginner's:01 bug:01 stub:01 --001485f1ec2ac1d40e0480fc91a5 Content-Type: text/plain; charset=ISO-8859-1 Using Bigarrays, most of the problem seems to be solved. However, I still have an important problem: Now I define in the Ocaml code a matrix (Bigarray.Array2) "bpsi" and a vector (Bigarray.Array1) "by". Both are defined using the kind Bigarray.float32 and the layout Bigarray.c_layout. If I print them in Ocaml, they contains the good values. Now I call my stub function from Ocaml, written in C: (definef with * external* ...etc) *let beta = solve_olsr bpsi by* In C, I have: *value solve_olsr(value bpsi, value by){ CAMLparam2(bpsi,by); int rows = Bigarray_val(bpsi)->dim[0]; int cols = Bigarray_val(bpsi)->dim[1]; ... double * vec_data = Data_bigarray_val(by); double ** mat_data = Data_bigarray_val(bpsi); ... print_vector(rows, vec_data); print_matrix(rows,cols,mat_data); ....* There are two problems : - First, I need to have a matrix defined with type double **, due to the function I call next, which takes as input a matrix of type double ** and an array of type double *. I guess that *Data_bigarray_val only* outputs a flat array corresponding to an Array of any dimension. If this is the case, this is not what I want (it seems more difficult to allocate a such a contiguous block in memory when it is big). So is there another function that does the job, i.e. maps a Bigarray.Array2 to double ** with the right allocation ? Now, when I print the matrix, the programs crashes (Segmentation fault), which seems coherent with the previous interpretation. - When I print the vector *vec_data*, it has the right number of elements, but unfortunately all values are 0. Thus I guess there is some problem with the Bigarray.float32 thing. Is it that ? Thanks, Odalric 2010/3/4 Odalric-Ambrym Maillard > Thanks, I was not aware of this relation between Bigarrays and C. > I will try to use this and tell you of it works as I want. > > Odalric > > 2010/3/4 Paolo Donadeo > > Did you consider using the bigarray library? >> >> http://caml.inria.fr/pub/docs/manual-ocaml/manual043.html >> >> >> -- >> Paolo >> >> _______________________________________________ >> Caml-list mailing list. Subscription management: >> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list >> Archives: http://caml.inria.fr >> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners >> Bug reports: http://caml.inria.fr/bin/caml-bugs >> > > > --001485f1ec2ac1d40e0480fc91a5 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Using Bigarrays, most of the problem seems to be solved.
However, I stil= l have an important problem:

Now I define in the Ocaml code a matrix= (Bigarray.Array2)=A0 "bpsi" and=A0 a vector (Bigarray.Array1) &q= uot;by".
Both are defined using the kind Bigarray.float32 and the layout Bigarray.c_= layout.
If I print them in Ocaml, they contains the good values.

= Now I call my stub function from Ocaml, written in C: (definef with exte= rnal ...etc)
let beta =3D solve_olsr bpsi by

In C, I have:

value= solve_olsr(value bpsi, value by){
CAMLparam2(bpsi,by);
int rows =3D = Bigarray_val(bpsi)->dim[0];
int cols =3D Bigarray_val(bpsi)->dim[1= ];
...
double * vec_data =3D Data_bigarray_val(by);
double ** mat_data = =3D Data_bigarray_val(bpsi);
...
print_vector(rows, vec_data);
pri= nt_matrix(rows,cols,mat_data);
....


There are two problems : =
=A0- First, I need to have a matrix defined with type double **, due to the= function I call next, which takes as input a matrix of type double ** and = an array of type double *. I guess that Data_bigarray_val only outpu= ts a flat array corresponding to an Array of any dimension. If this is the = case, this is not what I want (it seems more difficult to allocate a such a= contiguous block in memory when it is big). So is there another function t= hat does the job, i.e. maps a Bigarray.Array2 to double ** with the right a= llocation ?
Now, when I print the matrix, the programs crashes (Segmentation fault), wh= ich seems coherent with the previous interpretation.
=A0- When I print t= he vector vec_data, it has the right number of elements, but unfortu= nately all values are 0. Thus I guess there is some problem with the Bigarr= ay.float32 thing. Is it that ?

Thanks,
Odalric


2010/3/4 Odalr= ic-Ambrym Maillard <odalricambrym.maillard@gmail.com>
Thanks, I was not aware of this relation between Bigarrays and C.
I wil= l try to use this and tell you of it works as I want.

Odalric
2010/3/4 Paolo Donadeo <p.donadeo@gmail.com<= /a>>

Did you consider = using the bigarray library?

http://caml.inria.fr/pub/docs/manual-ocaml/manual043.html<= br>

--
Paolo

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list Archives: http://caml.in= ria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


--001485f1ec2ac1d40e0480fc91a5--