From 49a3d719221cd9484a64688ffcdbeb13cb8e55a0 Mon Sep 17 00:00:00 2001 From: Alberto Ruiz Date: Fri, 5 Jun 2009 18:53:07 +0000 Subject: check dim in root function --- lib/Numeric/GSL/Root.hs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/Numeric/GSL/Root.hs b/lib/Numeric/GSL/Root.hs index ad1b72c..d674fad 100644 --- a/lib/Numeric/GSL/Root.hs +++ b/lib/Numeric/GSL/Root.hs @@ -76,7 +76,7 @@ root method epsabs maxit fun xinit = rootGen (fi (fromEnum method)) fun xinit ep rootGen m f xi epsabs maxit = unsafePerformIO $ do let xiv = fromList xi n = dim xiv - fp <- mkVecVecfun (aux_vTov (fromList.f.toList)) + fp <- mkVecVecfun (aux_vTov (fromList . checkdim n f . toList)) rawpath <- withVector xiv $ \xiv' -> createMIO maxit (2*n+1) (c_root m fp epsabs (fi maxit) // xiv') @@ -115,3 +115,9 @@ createMIO r c fun msg = do res <- createMatrix RowMajor r c app1 fun mat res msg return res + +checkdim n f x + | length y /= n = error $ "Error: "++ show n + ++ " results expected in the function supplied to root" + | otherwise = y + where y = f x -- cgit v1.2.3