[clean-list] Re: clean-list digest, Vol 1 #161 - 1 msg

Siegfried Gonzi siegfried.gonzi@kfunigraz.ac.at
Tue, 25 Sep 2001 10:04:04 +0200


From: Shivkumar Chandrasekaran <shiv@ece.ucsb.edu>

 
> Can someone please tell me how to do this efficiently? I hate to fake 2D
> arrays with 1D arrays. Thanks,


This version takes on my old Sun 0.12sec for creating an array of
1000x1000:

module test
import StdEnv

createUnboxedRealArr2D :: !Int !Int !Real -> *{#*{#Real}}
createUnboxedRealArr2D m n x = {createUnboxedRealArr n x \\ i <- r}
where
     r = [0..m-1]
 
createUnboxedRealArr :: !Int !Real -> *{#Real}       
createUnboxedRealArr n x = { x \\ j <- [0..n-1] }

Start :: !Real
Start = TakeFirst (createUnboxedRealArr2D 1000 1000 2.34)
where
	TakeFirst:: *{#*{#Real}} -> !Real
	TakeFirst m = m.[0,0]



But this version -- without the "#" in the strictness information:

module test
import StdEnv

createUnboxedRealArr2D :: !Int !Int !Real -> *{*{#Real}}
createUnboxedRealArr2D m n x = {createUnboxedRealArr n x \\ i <- r}
where
     r = [0..m-1]
 
createUnboxedRealArr :: !Int !Real -> *{#Real}       
createUnboxedRealArr n x = { x \\ j <- [0..n-1] }

Start :: !Real
Start = TakeFirst (createUnboxedRealArr2D 1000 1000 2.34)
where
	TakeFirst:: *{*{#Real}} -> !Real
	TakeFirst m = m.[0,0]


takes 0.01sec for creating the same array as above.


Your report of execution times (an user system) due to the 2 different
versions would be of interest.


S. Gonzi