summaryrefslogtreecommitdiff
path: root/lib/Data/Packed/Internal/Vector.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Data/Packed/Internal/Vector.hs')
-rw-r--r--lib/Data/Packed/Internal/Vector.hs27
1 files changed, 22 insertions, 5 deletions
diff --git a/lib/Data/Packed/Internal/Vector.hs b/lib/Data/Packed/Internal/Vector.hs
index f2646a4..0d9dc70 100644
--- a/lib/Data/Packed/Internal/Vector.hs
+++ b/lib/Data/Packed/Internal/Vector.hs
@@ -21,6 +21,28 @@ import Complex
21import Control.Monad(when) 21import Control.Monad(when)
22import Data.List(transpose) 22import Data.List(transpose)
23import Debug.Trace(trace) 23import Debug.Trace(trace)
24import Foreign.C.String(peekCString)
25import Foreign.C.Types
26
27
28data Vector t = V { dim :: Int
29 , fptr :: ForeignPtr t
30 , ptr :: Ptr t
31 }
32
33check :: String -> [Vector a] -> IO Int -> IO ()
34check msg ls f = do
35 err <- f
36 when (err/=0) $ if err > 999 -- FIXME, it should be 1024
37 then (error (msg++": "++errorCode err))
38 else do
39 ps <- gsl_strerror err
40 s <- peekCString ps
41 error (msg++": "++s)
42 mapM_ (touchForeignPtr . fptr) ls
43 return ()
44
45foreign import ccall "aux.h gsl_strerror" gsl_strerror :: Int -> IO (Ptr CChar)
24 46
25type Vc t s = Int -> Ptr t -> s 47type Vc t s = Int -> Ptr t -> s
26-- not yet admitted by my haddock version 48-- not yet admitted by my haddock version
@@ -30,8 +52,6 @@ type Vc t s = Int -> Ptr t -> s
30vec :: Vector t -> (Vc t s) -> s 52vec :: Vector t -> (Vc t s) -> s
31vec v f = f (dim v) (ptr v) 53vec v f = f (dim v) (ptr v)
32 54
33--baseOf v = (v `at` 0)
34
35createVector :: Storable a => Int -> IO (Vector a) 55createVector :: Storable a => Int -> IO (Vector a)
36createVector n = do 56createVector n = do
37 when (n <= 0) $ error ("trying to createVector of dim "++show n) 57 when (n <= 0) $ error ("trying to createVector of dim "++show n)
@@ -86,8 +106,6 @@ infixl 9 @>
86(@>) = at 106(@>) = at
87 107
88 108
89
90
91-- | creates a new Vector by joining a list of Vectors 109-- | creates a new Vector by joining a list of Vectors
92join :: Storable t => [Vector t] -> Vector t 110join :: Storable t => [Vector t] -> Vector t
93join [] = error "joining zero vectors" 111join [] = error "joining zero vectors"
@@ -111,7 +129,6 @@ asReal v = V { dim = 2*dim v, fptr = castForeignPtr (fptr v), ptr = castPtr (pt
111asComplex :: Vector Double -> Vector (Complex Double) 129asComplex :: Vector Double -> Vector (Complex Double)
112asComplex v = V { dim = dim v `div` 2, fptr = castForeignPtr (fptr v), ptr = castPtr (ptr v) } 130asComplex v = V { dim = dim v `div` 2, fptr = castForeignPtr (fptr v), ptr = castPtr (ptr v) }
113 131
114
115---------------------------------------------------------------- 132----------------------------------------------------------------
116 133
117liftVector :: (Storable a, Storable b) => (a-> b) -> Vector a -> Vector b 134liftVector :: (Storable a, Storable b) => (a-> b) -> Vector a -> Vector b