[clean-list] help, update in place, two dimensional array.

Carlos Aya carlosayam at yahoo.com.au
Tue Jun 22 23:09:44 MEST 2010


Dear Clean team,

I'm trying a two-dimensional array update in-place... and got lost.

I have this utility function I did a while ago for update in place for one-dimensional arrays...

// updates first parameter (array) in place with values from a function that takes as parameters the value at 
// index p and p itself
updateInPlace :: *(a e) (e Int -> e) Int -> *(a e) | Array a e
updateInPlace arr1 f maxPos = updateLoop_ arr1 f 0 maxPos
where
    updateLoop_ :: *(a e) (e Int -> e) Int Int -> *(a e) | Array a e
    updateLoop_ arr1 f pos maxPos
    | pos == maxPos  = arr1
    # (v, arr1) = arr1![pos]
    = {(updateLoop_ arr1 f (pos+1) maxPos) & [pos] = f v pos}

If not the best implementation, at least worked for me.


I'm now trying to port the following element-wise matrix multiplication (for the sake of a simple example)

times :: {{#Int}} {{#Int}} -> {{#Int}}
times m1 m2 = {{m1.[i,j] * m2.[i,j] \\ j <- [0..MAX_INDEX]} \\ i <- [0..MAX_INDEX]}

into an efficient update in place in the first parameter... but this throws a compilation error

times :: *{{#Int}} {{#Int}} -> *{{#Int}}
times m1 m2 = updateInPlace m1 rowUpdate SIZE
where
    rowUpdate :: *{#Int} Int -> *{#Int}
    rowUpdate row i = updateInPlace row (\v j = v * m2.[i,j]) SIZE

And the error refers to rowUpdate, I believe, but refers to it curried, [i.e. like A -> (B -> C) instead of A B -> C]... and says that (B -> C) must be unique, I'm lost.

Am I missing something?

Kind regards
Carlos
p.s. attached test2.icl with extracted code above



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/clean-list/attachments/20100622/1947e7a0/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test2.icl
Type: application/octet-stream
Size: 818 bytes
Desc: not available
URL: <http://mailman.science.ru.nl/pipermail/clean-list/attachments/20100622/1947e7a0/attachment.obj>


More information about the clean-list mailing list