caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* bigarray & int24
@ 2008-03-31  9:58 Christoph Bauer
  2008-03-31 10:30 ` [Caml-list] " Berke Durak
  2008-03-31 11:27 ` Sylvain Le Gall
  0 siblings, 2 replies; 3+ messages in thread
From: Christoph Bauer @ 2008-03-31  9:58 UTC (permalink / raw)
  To: caml-list

Hi,

my program should read unaligned 3 byte integers. (A real world
example for such a format would be an RGB image). What is
the best approach?

  - extend bigarray for the int24 format and send the patch to INRIA
  - write a C-function, which converts the data to an int32-array
  - read an 1-byte-bigarray and construct an int-bigarray
  - ???

It should be a bigarray solution, because my program reads other
(supported)
formats as well.

Speed matters, because there are a lot of data.

Thanks,

Christoph Bauer
--  
c++; /* this makes c bigger but returns the old value */ (Unknown)


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] bigarray & int24
  2008-03-31  9:58 bigarray & int24 Christoph Bauer
@ 2008-03-31 10:30 ` Berke Durak
  2008-03-31 11:27 ` Sylvain Le Gall
  1 sibling, 0 replies; 3+ messages in thread
From: Berke Durak @ 2008-03-31 10:30 UTC (permalink / raw)
  To: Christoph Bauer; +Cc: caml-list List

Christoph Bauer a écrit :
> Hi,
> 
> my program should read unaligned 3 byte integers. (A real world
> example for such a format would be an RGB image). What is
> the best approach?
> 
>   - extend bigarray for the int24 format and send the patch to INRIA
>   - write a C-function, which converts the data to an int32-array
>   - read an 1-byte-bigarray and construct an int-bigarray
>   - ???
> 
> It should be a bigarray solution, because my program reads other
> (supported)
> formats as well.
> 
> Speed matters, because there are a lot of data.
> 
> Thanks,
> 
> Christoph Bauer

Last time I did this, I used a (m x n x 3) byte bigarray, also known
pendantically as a rank 3 tensor, where m is the number of rows and
n the number of columns.  Should work reasonably well.

-- 
Berke DURAK


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: bigarray & int24
  2008-03-31  9:58 bigarray & int24 Christoph Bauer
  2008-03-31 10:30 ` [Caml-list] " Berke Durak
@ 2008-03-31 11:27 ` Sylvain Le Gall
  1 sibling, 0 replies; 3+ messages in thread
From: Sylvain Le Gall @ 2008-03-31 11:27 UTC (permalink / raw)
  To: caml-list

Hello,

On 31-03-2008, Christoph Bauer <Christoph.Bauer@lmsintl.com> wrote:
> Hi,
>
> my program should read unaligned 3 byte integers. (A real world
> example for such a format would be an RGB image). What is
> the best approach?
>
>   - extend bigarray for the int24 format and send the patch to INRIA
>   - write a C-function, which converts the data to an int32-array
>   - read an 1-byte-bigarray and construct an int-bigarray
>   - ???
>
> It should be a bigarray solution, because my program reads other
> (supported)
> formats as well.
>
> Speed matters, because there are a lot of data.
>

If speed matters, you could use an alternate approach that can give you
a very efficient way of processing:
* keep an int32/int64 bigarray (use native int format -- the one which is the
  more efficient)
* use a number of row that allow you to fit a x 24 bit data in b x
 (32/64) bit data (least common multiplicator / 32 or 64)
* create a layer that allow you to process your packed data 

This is a way to minimize the number of unaligned access, being fully
compatible with your raw format.

You will still have an issue with conversion to Nativeint when
extracting data. 

So i recommend you to write your abstract layer in C (gaining full speed
for extraction of packed-aligned data and conversion) and to return
OCaml int (which is possible since your data are only 24 bits long). 

This is not very OCaml friendly -- but allow you to get the best in term
of speed.

Regards,
Sylvain Le Gall


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-03-31 11:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-31  9:58 bigarray & int24 Christoph Bauer
2008-03-31 10:30 ` [Caml-list] " Berke Durak
2008-03-31 11:27 ` Sylvain Le Gall

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).