diff options
author | Don Stewart <dons@galois.com> | 2008-06-10 00:53:03 +0000 |
---|---|---|
committer | Don Stewart <dons@galois.com> | 2008-06-10 00:53:03 +0000 |
commit | 9cb72979acc7bcd9df2fa8eab05169d9c5ca84f5 (patch) | |
tree | 52cb0810dc6fbcd199d40146df1f7afebb2171ef /lib/Data/Packed/Internal/Vector.hs | |
parent | 8fdd2158ab7a122e9c72a7f41c8bac1a794cf53c (diff) |
Unpack Matrix type, and add -funsafe flag
-funsafe optionally compiles out the bounds checks on indexing matrices
and vectors. Yields good speedups on tight loops. Not enabled by default.
Diffstat (limited to 'lib/Data/Packed/Internal/Vector.hs')
-rw-r--r-- | lib/Data/Packed/Internal/Vector.hs | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/Data/Packed/Internal/Vector.hs b/lib/Data/Packed/Internal/Vector.hs index 8723367..6274e48 100644 --- a/lib/Data/Packed/Internal/Vector.hs +++ b/lib/Data/Packed/Internal/Vector.hs | |||
@@ -100,10 +100,24 @@ n |> l = if length l == n then fromList l else error "|> with wrong size" | |||
100 | at' :: Storable a => Vector a -> Int -> a | 100 | at' :: Storable a => Vector a -> Int -> a |
101 | at' v n = safeRead v $ flip peekElemOff n | 101 | at' v n = safeRead v $ flip peekElemOff n |
102 | 102 | ||
103 | -- | ||
104 | -- turn off bounds checking with -funsafe at configure time. | ||
105 | -- ghc will optimise away the salways true case at compile time. | ||
106 | -- | ||
107 | #if defined(UNSAFE) | ||
108 | safe :: Bool | ||
109 | safe = False | ||
110 | #else | ||
111 | safe = True | ||
112 | #endif | ||
113 | |||
103 | -- | access to Vector elements with range checking. | 114 | -- | access to Vector elements with range checking. |
104 | at :: Storable a => Vector a -> Int -> a | 115 | at :: Storable a => Vector a -> Int -> a |
105 | at v n | n >= 0 && n < dim v = at' v n | 116 | at v n |
106 | | otherwise = error "vector index out of range" | 117 | | safe = if n >= 0 && n < dim v |
118 | then at' v n | ||
119 | else error "vector index out of range" | ||
120 | | otherwise = at' v n | ||
107 | {-# INLINE at #-} | 121 | {-# INLINE at #-} |
108 | 122 | ||
109 | {- | takes a number of consecutive elements from a Vector | 123 | {- | takes a number of consecutive elements from a Vector |