readArray is faster than unsafeRead

Mirko Rahn rahn at ira.uka.de
Tue May 29 10:36:36 EDT 2007


> instead of (!) (or readArray in stateful code) helped a lot. So then I
> went to optimize my gaussian elimination function and found just the
> opposite. unsafeRead is slower than readArray. This struck me as very

The functions gaussElimSafe and gaussElimUnsafe are different in their 
outputs (*). I guess you made a mistake during conversion from one 
version to the other.

BTW, the attached file contains an outline of a pure functional and 
indexless implementation. It calculates the inverse of a quadratic 
matrix in time O(n^3), so maybe you can get rid of all this exclamation 
marks and IO stuff...

BR,

(*) Try:

newStdGen >>= \ g -> flip mapM_ [gaussElimSafe,gaussElimUnsafe] $ \ f -> 
makeMatrix g >>= \ m -> printMatrix m >> f m >> printMatrix m

-- 
-- Mirko Rahn -- Tel +49-721 608 7504 --
--- http://liinwww.ira.uka.de/~rahn/ ---
-------------- next part --------------
A non-text attachment was scrubbed...
Name: GaussTestPure.hs
Type: text/x-haskell
Size: 1367 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/glasgow-haskell-users/attachments/20070529/58b47129/GaussTestPure.bin


More information about the Glasgow-haskell-users mailing list