summaryrefslogtreecommitdiff
path: root/examples/vector.hs
blob: 855c6b4bfd43229d69d75b364ecb8b7053125aaa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
-- conversion to/from Data.Vector.Storable
-- from Roman Leshchinskiy "vector" package
--
-- In the future Data.Packed.Vector will be replaced by Data.Vector.Storable

-------------------------------------------

import Data.Packed as H
import Data.Packed.Development(unsafeFromForeignPtr, unsafeToForeignPtr)
import Foreign.Storable
import qualified Data.Vector.Storable as V

fromVector :: Storable t => V.Vector t -> H.Vector t
fromVector v = unsafeFromForeignPtr p i n where
    (p,i,n) = V.unsafeToForeignPtr v

toVector :: H.Vector t -> V.Vector t
toVector v = V.unsafeFromForeignPtr p i n where
    (p,i,n) = unsafeToForeignPtr v

-------------------------------------------

v = V.slice 5 10 (V.fromList [1 .. 10::Double] V.++ V.replicate 10 7)

w = subVector 2 3 (linspace 10 (0,2))

main = do
    print v
    print $ fromVector v
    print w
    print $ toVector w