Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: native code compiler and exceptions
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jocelyn Serot <Jocelyn.Serot@l...>
Subject: Re: native code compiler and exceptions

Thanks for your enlightments about efficiency concerns in Caml.
Seems like i have re-discovered an evidence: efficiency AND abstraction
do not live well together in the world of programs :-)
For example, i do agree with your optimisation of the conv fn:

> let conv im =
>  let nr = nb_rows im and nc = nb_cols im in
>  let im' = create nr nc in
>  for y = 0 to pred nr do for x = 0 to pred nc do
>   let p1 = if x = 0 then 0 else im.(x - 1).(y) in
>   let p2 = if y = 0 then 0 else im.(x).(y - 1) in
>   let p3 = if x = nc - 1 then 0 else im.(x + 1).(y) in
>   let p4 = if y = nr - 1 then 0 else im.(x).(y + 1) in
>   im'.(y).(x) <- ((p1 + p2 + p3 + p4) / 4) done done;
>  m'
> 

But in my code, conv is in fact a generalized "map" fn implemented as a higher
order fn, sth with a signature like:

#    val conv : (coord -> coord array) ->
#               (pixel array -> pixel) -> (coord -> pixel) -> t -> t
#            (* [conv g f clp im] is [im']
#                where im'@@(y,x) = f [|p1;..;pk|]
#                    where pi = im@@(yi,xi)   ,if in_bounds m (yi,xi),
#                               clp (yi,xi)  ,otherwise
#                        where [|(y1,x1);...;(yk,xk)|] = g (y,x) *)
#            (* 
#             * [g] is the "neighboorhing fn"
#             * [f] is the "combining fn"
#             * [clp] is the "clipping fn" *)

This level of abstraction - that may be useful if you dont want to spend to
time writing "for" loops on image representations - clearly precludes the sort
of optimisation you suggest ...

So i am on my own now, speed or abstraction: this is the question ;-)

Thanks for your help,

	Jocelyn
--
E-mail: Jocelyn.Serot@lasmea.univ-bpclermont.fr .............................
S-mail: LASMEA - URA 1793 CNRS, Universite Blaise Pascal, 63177 Aubiere cedex
Tel: (33) 73.40.73.30 - Fax: (33) 73.40.72.62 ...............................
.... http://wwwlasmea.univ-bpclermont.fr/Personnel/Jocelyn.Serot/Welcome.html