Moved various functions from the where clause of checkArrayUsage up to the top level
This commit is contained in:
parent
56a10b403f
commit
95d25c3dbc
|
@ -119,15 +119,14 @@ checkArrayUsage (m,p) = mapM_ (checkIndexes m) $ Map.toList $
|
||||||
++ "(\"" ++ cx ++ "\" and \"" ++ cy ++ "\") could overlap"
|
++ "(\"" ++ cx ++ "\" and \"" ++ cy ++ "\") could overlap"
|
||||||
++ if sol /= "" then " when: " ++ sol else ""
|
++ if sol /= "" then " when: " ++ sol else ""
|
||||||
|
|
||||||
-- Solves the problem and munges the arguments and results into a useful order
|
-- TODO this is surely defined elsewhere already?
|
||||||
solve :: (labels,vm,(EqualityProblem,InequalityProblem)) -> Maybe (labels,vm,VariableMapping,(EqualityProblem,InequalityProblem))
|
getRealName :: A.Name -> m String
|
||||||
solve (ls,vm,(eq,ineq)) = case solveProblem eq ineq of
|
getRealName n = lookupName n >>* A.ndOrigName
|
||||||
Nothing -> Nothing
|
|
||||||
Just vm' -> Just (ls,vm,vm',(eq,ineq))
|
|
||||||
|
|
||||||
-- Formats an entire problem ready to print it out half-legibly for debugging purposes
|
|
||||||
formatProblem :: VarMap -> (EqualityProblem, InequalityProblem) -> m String
|
-- | Formats an entire problem ready to print it out half-legibly for debugging purposes
|
||||||
formatProblem varToIndex (eq, ineq)
|
formatProblem :: forall m. CSMR m => VarMap -> (EqualityProblem, InequalityProblem) -> m String
|
||||||
|
formatProblem varToIndex (eq, ineq)
|
||||||
= do feqs <- mapM (showWithConst "=") $ eq
|
= do feqs <- mapM (showWithConst "=") $ eq
|
||||||
fineqs <- mapM (showWithConst ">=") $ ineq
|
fineqs <- mapM (showWithConst ">=") $ ineq
|
||||||
return $ concat $ intersperse "\n" $ feqs ++ fineqs
|
return $ concat $ intersperse "\n" $ feqs ++ fineqs
|
||||||
|
@ -151,19 +150,24 @@ checkArrayUsage (m,p) = mapM_ (checkIndexes m) $ Map.toList $
|
||||||
-1 -> "-"
|
-1 -> "-"
|
||||||
_ -> show a ++ "*"
|
_ -> show a ++ "*"
|
||||||
|
|
||||||
-- Formats a solution (not a problem, just the solution) ready to print it out for the user
|
-- | Solves the problem and munges the arguments and results into a useful order
|
||||||
formatSolution :: VarMap -> Map.Map CoeffIndex Integer -> m String
|
solve :: (labels,vm,(EqualityProblem,InequalityProblem)) ->
|
||||||
formatSolution varToIndex indexToConst = do names <- mapM valOfVar $ Map.assocs varToIndex
|
Maybe (labels,vm,VariableMapping,(EqualityProblem,InequalityProblem))
|
||||||
return $ concat $ intersperse " , " $ catMaybes names
|
solve (ls,vm,(eq,ineq)) = case solveProblem eq ineq of
|
||||||
|
Nothing -> Nothing
|
||||||
|
Just vm' -> Just (ls,vm,vm',(eq,ineq))
|
||||||
|
|
||||||
|
-- | Formats a solution (not a problem, just the solution) ready to print it out for the user
|
||||||
|
formatSolution :: (CSMR m, Monad m) => VarMap -> Map.Map CoeffIndex Integer -> m String
|
||||||
|
formatSolution varToIndex indexToConst
|
||||||
|
= do names <- mapM valOfVar $ Map.assocs varToIndex
|
||||||
|
return $ concat $ intersperse " , " $ catMaybes names
|
||||||
where
|
where
|
||||||
valOfVar (varExp,k) = case Map.lookup k indexToConst of
|
valOfVar (varExp,k) = case Map.lookup k indexToConst of
|
||||||
Nothing -> return Nothing
|
Nothing -> return Nothing
|
||||||
Just val -> do varExp' <- showFlattenedExp showCode varExp
|
Just val -> do varExp' <- showFlattenedExp showCode varExp
|
||||||
return $ Just $ varExp' ++ " = " ++ show val
|
return $ Just $ varExp' ++ " = " ++ show val
|
||||||
|
|
||||||
-- TODO this is surely defined elsewhere already?
|
|
||||||
getRealName :: A.Name -> m String
|
|
||||||
getRealName n = lookupName n >>* A.ndOrigName
|
|
||||||
|
|
||||||
showFlattenedExpSet :: Monad m => (A.Expression -> m String) -> Set.Set FlattenedExp -> m String
|
showFlattenedExpSet :: Monad m => (A.Expression -> m String) -> Set.Set FlattenedExp -> m String
|
||||||
showFlattenedExpSet showExp s = liftM concat $ sequence $ intersperse (return " + ") $ map (showFlattenedExp showExp) $ Set.toList s
|
showFlattenedExpSet showExp s = liftM concat $ sequence $ intersperse (return " + ") $ map (showFlattenedExp showExp) $ Set.toList s
|
||||||
|
|
Loading…
Reference in New Issue
Block a user