From f6ba7be1733d99eb767bb38b30533ac70e179676 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Tue, 15 Jan 2008 17:33:19 +0000 Subject: [PATCH] Changed various uses of the maximum function to make sure they always succeed --- transformations/ArrayUsageCheck.hs | 4 ++-- transformations/ArrayUsageCheckTest.hs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/transformations/ArrayUsageCheck.hs b/transformations/ArrayUsageCheck.hs index a302b12..5b50090 100644 --- a/transformations/ArrayUsageCheck.hs +++ b/transformations/ArrayUsageCheck.hs @@ -357,7 +357,7 @@ makeEquations es high = makeEquations' >>* (\(s,v,lh) -> [(s,squareEquations eqI mapToArray :: (IArray a v, Num v, Num k, Ord k, Ix k) => Map.Map k v -> a k v mapToArray m = accumArray (+) 0 (0, highest') . Map.assocs $ m where - highest' = maximum $ Map.keys m + highest' = maximum $ 0 : Map.keys m -- | Given a pair of equation sets, makes all the equations in the lists be the length -- of the longest equation. All missing elements are of course given value zero. @@ -368,7 +368,7 @@ makeEquations es high = makeEquations' >>* (\(s,v,lh) -> [(s,squareEquations eqI makeSize :: (Show i, Show e,IArray a e, Ix i, Enum i) => (i,i) -> e -> a i e -> a i e makeSize size def arr = array size [(i,arrayLookupWithDefault def arr i) | i <- [fst size .. snd size]] - highest = maximum $ concatMap indices $ eqs ++ ineqs + highest = maximum $ 0 : (concatMap indices $ eqs ++ ineqs) type CoeffIndex = Int type EqualityConstraintEquation = Array CoeffIndex Integer diff --git a/transformations/ArrayUsageCheckTest.hs b/transformations/ArrayUsageCheckTest.hs index 4fb5cf2..c4ee671 100644 --- a/transformations/ArrayUsageCheckTest.hs +++ b/transformations/ArrayUsageCheckTest.hs @@ -175,7 +175,7 @@ makeConsistent eqs ineqs = (map ensure eqs', map ensure ineqs') ineqs' = map (\(Ineq e) -> e) ineqs ensure = accumArray (+) 0 (0, largestIndex) - largestIndex = maximum $ map (maximum . map fst) $ eqs' ++ ineqs' + largestIndex = maximum $ map (maximum . map fst) $ [[(0,0)]] ++ eqs' ++ ineqs' -- | Returns Nothing if there is definitely no solution, or (Just ineq) if