From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id q355vpgP004914 for ; Thu, 5 Apr 2012 07:57:51 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AjwBAMMzfU9KfVI0imdsb2JhbAApGq9uAYhvCCIBAQEKCQ0HEgYjgiICExkBGx4DEgkHXQERAQUBUAeHXQEDCwspnh+CXQqMFoJxhGwKGScNV4EOAQULkEQEiFmND4ERjUI9hCk X-IronPort-AV: E=Sophos;i="4.75,374,1330902000"; d="scan'208,217";a="152778538" Received: from mail-wg0-f52.google.com ([74.125.82.52]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 05 Apr 2012 07:57:46 +0200 Received: by mail-wg0-f52.google.com with SMTP id gn7so1043419wgb.9 for ; Wed, 04 Apr 2012 22:57:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=CGIQ1l97RmTQ84jMOK6zG3lyDXhZxjeE0PovTekmL3I=; b=odjUnkwp81a8JNRKlm4dU/vWFSN2n38PoAAJu2Xgs6kOSieMFRh6n25ngotMe+QK6y YUwWmczZoTy5N6Wmc0OIQM36SzzNRg9snQFKmGKb0c8eHJhoUCCjTRxvg88R1HeNWT1P IjGSKhRK27qpUeacdlrDVW/nkVkCVbRXVV15T0EAkx0nyRmIXfY1oUwEakUJw76hXzl3 Q8PvI2BgXISV0KLzxEfcRxmT8OD4HC02iXJLM9VEO00OjnXr451lD4mJfpIIJqEtq8qV teQGWoQ4lvF5J6kmT73uv8GWyUoh45O0d+RhLMVoiadEVqm2PNCHx1J5CNopNOpjCaQf 4E7A== MIME-Version: 1.0 Received: by 10.180.89.130 with SMTP id bo2mr1615386wib.17.1333605466222; Wed, 04 Apr 2012 22:57:46 -0700 (PDT) Received: by 10.223.6.25 with HTTP; Wed, 4 Apr 2012 22:57:45 -0700 (PDT) Date: Wed, 4 Apr 2012 23:57:45 -0600 Message-ID: From: Anthony Tavener To: caml-list@inria.fr Content-Type: multipart/alternative; boundary=e89a8f3bac5b15aeb604bce83882 Subject: [Caml-list] Size of Bigarray elements, or matching with 'kind'? --e89a8f3bac5b15aeb604bce83882 Content-Type: text/plain; charset=ISO-8859-1 I'm trying to determine the size of a Bigarray, in bytes. I've tried several things... ending up with this as the only solution: -------------------------- let ba_char = Hashtbl.hash Bigarray.char;; let ba_int8_signed = Hashtbl.hash int8_signed;; let ba_int8_unsigned = Hashtbl.hash int8_unsigned;; let ba_int16_signed = Hashtbl.hash int16_signed;; let ba_int16_unsigned = Hashtbl.hash int16_unsigned;; let ba_int32 = Hashtbl.hash Bigarray.int32;; let ba_float32 = Hashtbl.hash float32;; let ba_int64 = Hashtbl.hash Bigarray.int64;; let ba_float64 = Hashtbl.hash float64;; let ba_complex32 = Hashtbl.hash complex32;; let ba_complex64 = Hashtbl.hash complex64;; let ba_int = Hashtbl.hash Bigarray.int;; let ba_nativeint = Hashtbl.hash Bigarray.nativeint;; let bigarray_bytes ba = let elt_bytes = match Hashtbl.hash (Array1.kind ba) with | x when x=ba_char || x=ba_int8_signed || x=ba_int8_unsigned -> 1 | x when x=ba_int16_signed || x=ba_int16_unsigned -> 2 | x when x=ba_int32 || x=ba_float32 -> 4 | x when x=ba_int64 || x=ba_float64 || x=ba_complex32 -> 8 | x when x=ba_complex64 -> 16 | x when x=ba_int || x=ba_nativeint -> Nativeint.size lsr 8 | _ -> failwith "Unknown Bigarray kind." in (Array1.dim ba) * elt_bytes;; -------------------------- Which is a rather ugly hack! It feels dirty like Obj.magic, while being completely inelegant, and even has a fail case! Can't get much worse. :) Of course, internally, bigarray will know it's own size... sometimes the price of abstraction... *sigh* I found a related Mantis entry from 6 years back: http://caml.inria.fr/mantis/view.php?id=3962 Well... does anyone have some better suggestions? Please? :) Oh, I can make it look a little prettier by plugging in the constants eked out by Hashtbl.hash. ;D Why do I want this? Interfacing with OpenGL (glcaml). Thanks for looking, and more again if you have a good tip! -Tony --e89a8f3bac5b15aeb604bce83882 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable I'm trying to determine the size of a Bigarray, in bytes.

I've tried several things... ending up with this as the only solu= tion:

--------------------------
let ba_char =3D Hashtbl.hash Bigarray.char;;
let ba_int8_sig= ned =3D Hashtbl.hash int8_signed;;
let ba_int8_unsigned =3D Hasht= bl.hash int8_unsigned;;
let ba_int16_signed =3D Hashtbl.hash int1= 6_signed;;
let ba_int16_unsigned =3D Hashtbl.hash int16_unsigned;;
let = ba_int32 =3D Hashtbl.hash Bigarray.int32;;
let ba_float32 =3D Has= htbl.hash float32;;
let ba_int64 =3D Hashtbl.hash Bigarray.int64;= ;
let ba_float64 =3D Hashtbl.hash float64;;
let ba_complex32 = =3D Hashtbl.hash complex32;;
let ba_complex64 =3D Hashtbl.hash co= mplex64;;
let ba_int =3D Hashtbl.hash Bigarray.int;;
le= t ba_nativeint =3D Hashtbl.hash Bigarray.nativeint;;

let bigarray_bytes ba =3D
=A0 let elt_bytes = =3D match Hashtbl.hash (Array1.kind ba) with
=A0 =A0 | x when x= =3Dba_char || x=3Dba_int8_signed || x=3Dba_int8_unsigned -> 1
= =A0 =A0 | x when x=3Dba_int16_signed || x=3Dba_int16_unsigned =A0 =A0 =A0 = =A0 =A0 =A0-> 2
=A0 =A0 | x when x=3Dba_int32 || x=3Dba_float32 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0-> 4
=A0 =A0 | x when x=3Dba_in= t64 || x=3Dba_float64 || x=3Dba_complex32 =A0 =A0 =A0 =A0-> 8
= =A0 =A0 | x when x=3Dba_complex64 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0-> 16
=A0 =A0 | x when x=3Dba_int || x=3Dba_nativeint =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0-> Nativeint.size lsr 8
=A0 =A0= | _ -> failwith "Unknown Bigarray kind."
=A0 in (Ar= ray1.dim ba) * elt_bytes;;
--------------------------
=

Which is a rather ugly hack! It feels dirty like Obj.ma= gic, while being completely inelegant, and even has a fail case! Can't = get much worse. :)
Of course, internally, bigarray will know it's own size... sometim= es the price of abstraction... *sigh*

I found a re= lated Mantis entry from 6 years back:=A0http://caml.inria.fr/mantis/view.php?id=3D3962<= /div>

Well... does anyone have some better suggestions? Pleas= e? :)
Oh, I can make it look a little prettier by plugging in the= constants eked out by Hashtbl.hash. ;D

Why do I w= ant this? Interfacing with OpenGL (glcaml).

Thanks for looking, and more again if you have a good t= ip!

=A0-Tony

--e89a8f3bac5b15aeb604bce83882--