From 1bdc3af98f098f45e97e9c1a3225c5dcb64e3119 Mon Sep 17 00:00:00 2001 From: Alberto Ruiz Date: Tue, 22 Jan 2008 10:08:07 +0000 Subject: CInt in GSL args --- lib/Numeric/GSL/Minimization.hs | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'lib/Numeric/GSL/Minimization.hs') diff --git a/lib/Numeric/GSL/Minimization.hs b/lib/Numeric/GSL/Minimization.hs index 98c0ca9..65705cc 100644 --- a/lib/Numeric/GSL/Minimization.hs +++ b/lib/Numeric/GSL/Minimization.hs @@ -24,6 +24,7 @@ module Numeric.GSL.Minimization ( import Data.Packed.Internal import Data.Packed.Matrix import Foreign +import Foreign.C.Types(CInt) ------------------------------------------------------------------------- @@ -85,7 +86,7 @@ minimizeNMSimplex f xi sz tol maxit = unsafePerformIO $ do fp <- mkVecfun (iv (f.toList)) rawpath <- ww2 withVector xiv withVector szv $ \xiv' szv' -> createMIO maxit (n+3) - (c_minimizeNMSimplex fp tol maxit // xiv' // szv') + (c_minimizeNMSimplex fp tol (fromIntegral maxit) // xiv' // szv') "minimizeNMSimplex" let it = round (rawpath @@> (maxit-1,0)) path = takeRows it rawpath @@ -95,7 +96,7 @@ minimizeNMSimplex f xi sz tol maxit = unsafePerformIO $ do foreign import ccall "gsl-aux.h minimize" - c_minimizeNMSimplex:: FunPtr (Int -> Ptr Double -> Double) -> Double -> Int + c_minimizeNMSimplex:: FunPtr (CInt -> Ptr Double -> Double) -> Double -> CInt -> TVVM ---------------------------------------------------------------------------------- @@ -151,7 +152,7 @@ minimizeConjugateGradient istep minimpar tol maxit f df xi = unsafePerformIO $ d dfp <- mkVecVecfun (aux_vTov df') rawpath <- withVector xiv $ \xiv' -> createMIO maxit (n+2) - (c_minimizeConjugateGradient fp dfp istep minimpar tol maxit // xiv') + (c_minimizeConjugateGradient fp dfp istep minimpar tol (fromIntegral maxit) // xiv') "minimizeDerivV" let it = round (rawpath @@> (maxit-1,0)) path = takeRows it rawpath @@ -162,36 +163,36 @@ minimizeConjugateGradient istep minimpar tol maxit f df xi = unsafePerformIO $ d foreign import ccall "gsl-aux.h minimizeWithDeriv" - c_minimizeConjugateGradient :: FunPtr (Int -> Ptr Double -> Double) - -> FunPtr (Int -> Ptr Double -> Ptr Double -> IO ()) - -> Double -> Double -> Double -> Int + c_minimizeConjugateGradient :: FunPtr (CInt -> Ptr Double -> Double) + -> FunPtr (CInt -> Ptr Double -> Ptr Double -> IO ()) + -> Double -> Double -> Double -> CInt -> TVM --------------------------------------------------------------------- -iv :: (Vector Double -> Double) -> (Int -> Ptr Double -> Double) -iv f n p = f (createV n copy "iv") where +iv :: (Vector Double -> Double) -> (CInt -> Ptr Double -> Double) +iv f n p = f (createV (fromIntegral n) copy "iv") where copy n' q = do copyArray q p n' return 0 -- | conversion of Haskell functions into function pointers that can be used in the C side foreign import ccall "wrapper" - mkVecfun :: (Int -> Ptr Double -> Double) - -> IO( FunPtr (Int -> Ptr Double -> Double)) + mkVecfun :: (CInt -> Ptr Double -> Double) + -> IO( FunPtr (CInt -> Ptr Double -> Double)) -- | another required conversion foreign import ccall "wrapper" - mkVecVecfun :: (Int -> Ptr Double -> Ptr Double -> IO ()) - -> IO (FunPtr (Int -> Ptr Double -> Ptr Double->IO())) + mkVecVecfun :: (CInt -> Ptr Double -> Ptr Double -> IO ()) + -> IO (FunPtr (CInt -> Ptr Double -> Ptr Double->IO())) -aux_vTov :: (Vector Double -> Vector Double) -> (Int -> Ptr Double -> Ptr Double -> IO()) +aux_vTov :: (Vector Double -> Vector Double) -> (CInt -> Ptr Double -> Ptr Double -> IO()) aux_vTov f n p r = g where V {fptr = pr} = f x - x = createV n copy "aux_vTov" + x = createV (fromIntegral n) copy "aux_vTov" copy n' q = do copyArray q p n' return 0 - g = withForeignPtr pr $ \p' -> copyArray r p' n + g = withForeignPtr pr $ \p' -> copyArray r p' (fromIntegral n) -------------------------------------------------------------------- -- cgit v1.2.3