diff options
Diffstat (limited to 'lib/Data/Packed/Internal/Common.hs')
-rw-r--r-- | lib/Data/Packed/Internal/Common.hs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/Data/Packed/Internal/Common.hs b/lib/Data/Packed/Internal/Common.hs index c3a733c..dc1c2b4 100644 --- a/lib/Data/Packed/Internal/Common.hs +++ b/lib/Data/Packed/Internal/Common.hs | |||
@@ -23,6 +23,8 @@ import Debug.Trace | |||
23 | import Data.List(transpose,intersperse) | 23 | import Data.List(transpose,intersperse) |
24 | import Data.Typeable | 24 | import Data.Typeable |
25 | import Data.Maybe(fromJust) | 25 | import Data.Maybe(fromJust) |
26 | import Foreign.C.String(peekCString) | ||
27 | import Foreign.C.Types | ||
26 | 28 | ||
27 | ---------------------------------------------------------------------- | 29 | ---------------------------------------------------------------------- |
28 | instance (Storable a, RealFloat a) => Storable (Complex a) where -- | 30 | instance (Storable a, RealFloat a) => Storable (Complex a) where -- |
@@ -65,6 +67,13 @@ ww2 w1 o1 w2 o2 f = w1 o1 $ \a1 -> w2 o2 $ \a2 -> f a1 a2 | |||
65 | ww3 w1 o1 w2 o2 w3 o3 f = w1 o1 $ \a1 -> ww2 w2 o2 w3 o3 (f a1) | 67 | ww3 w1 o1 w2 o2 w3 o3 f = w1 o1 $ \a1 -> ww2 w2 o2 w3 o3 (f a1) |
66 | ww4 w1 o1 w2 o2 w3 o3 w4 o4 f = w1 o1 $ \a1 -> ww3 w2 o2 w3 o3 w4 o4 (f a1) | 68 | ww4 w1 o1 w2 o2 w3 o3 w4 o4 f = w1 o1 $ \a1 -> ww3 w2 o2 w3 o3 w4 o4 (f a1) |
67 | 69 | ||
70 | app1 f w1 o1 s = w1 o1 $ \a1 -> f // a1 // check s | ||
71 | app2 f w1 o1 w2 o2 s = ww2 w1 o1 w2 o2 $ \a1 a2 -> f // a1 // a2 // check s | ||
72 | app3 f w1 o1 w2 o2 w3 o3 s = ww3 w1 o1 w2 o2 w3 o3 $ | ||
73 | \a1 a2 a3 -> f // a1 // a2 // a3 // check s | ||
74 | app4 f w1 o1 w2 o2 w3 o3 w4 o4 s = ww4 w1 o1 w2 o2 w3 o3 w4 o4 $ | ||
75 | \a1 a2 a3 a4 -> f // a1 // a2 // a3 // a4 // check s | ||
76 | |||
68 | -- GSL error codes are <= 1024 | 77 | -- GSL error codes are <= 1024 |
69 | -- | error codes for the auxiliary functions required by the wrappers | 78 | -- | error codes for the auxiliary functions required by the wrappers |
70 | errorCode :: Int -> String | 79 | errorCode :: Int -> String |
@@ -78,6 +87,22 @@ errorCode 2006 = "the input matrix is not positive definite" | |||
78 | errorCode 2007 = "not yet supported in this OS" | 87 | errorCode 2007 = "not yet supported in this OS" |
79 | errorCode n = "code "++show n | 88 | errorCode n = "code "++show n |
80 | 89 | ||
90 | -- | check the error code | ||
91 | check :: String -> IO Int -> IO () | ||
92 | check msg f = do | ||
93 | err <- f | ||
94 | when (err/=0) $ if err > 1024 | ||
95 | then (error (msg++": "++errorCode err)) -- our errors | ||
96 | else do -- GSL errors | ||
97 | ps <- gsl_strerror err | ||
98 | s <- peekCString ps | ||
99 | error (msg++": "++s) | ||
100 | return () | ||
101 | |||
102 | -- | description of GSL error codes | ||
103 | foreign import ccall "auxi.h gsl_strerror" gsl_strerror :: Int -> IO (Ptr CChar) | ||
104 | |||
105 | |||
81 | {- | conversion of Haskell functions into function pointers that can be used in the C side | 106 | {- | conversion of Haskell functions into function pointers that can be used in the C side |
82 | -} | 107 | -} |
83 | foreign import ccall "wrapper" mkfun:: (Double -> Ptr() -> Double) -> IO( FunPtr (Double -> Ptr() -> Double)) | 108 | foreign import ccall "wrapper" mkfun:: (Double -> Ptr() -> Double) -> IO( FunPtr (Double -> Ptr() -> Double)) |