diff options
author | Alberto Ruiz <aruiz@um.es> | 2010-02-24 12:01:07 +0000 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2010-02-24 12:01:07 +0000 |
commit | aae45de54aca92c5f0f013e46c6d6f65508d76f5 (patch) | |
tree | 3a3bbc11b6c87e6b7d469b046dff1a13df15561e /examples/vector.hs | |
parent | ded908e2a222f902b41e500eea5272700db75699 (diff) |
conversion from/to Data.Vector.Storable
Diffstat (limited to 'examples/vector.hs')
-rw-r--r-- | examples/vector.hs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/examples/vector.hs b/examples/vector.hs new file mode 100644 index 0000000..12cbc42 --- /dev/null +++ b/examples/vector.hs | |||
@@ -0,0 +1,29 @@ | |||
1 | -- conversion to/from Data.Vector.Storable | ||
2 | -- from Roman Leshchinskiy "vector" package | ||
3 | -- | ||
4 | -- In the future Data.Packed.Vector will be replaced by Data.Vector.Storable | ||
5 | |||
6 | ------------------------------------------- | ||
7 | |||
8 | import Data.Packed as H | ||
9 | import Data.Packed.Development(unsafeFromForeignPtr, unsafeToForeignPtr) | ||
10 | import Foreign.Storable | ||
11 | import qualified Data.Vector.Storable as V | ||
12 | |||
13 | fromVector :: Storable t => V.Vector t -> H.Vector t | ||
14 | fromVector v = unsafeFromForeignPtr p i n where | ||
15 | (p,i,n) = V.unsafeToForeignPtr (V.copy v) | ||
16 | |||
17 | toVector :: H.Vector t -> V.Vector t | ||
18 | toVector v = V.unsafeFromForeignPtr p i n where | ||
19 | (p,i,n) = unsafeToForeignPtr v | ||
20 | |||
21 | ------------------------------------------- | ||
22 | |||
23 | v = V.slice 5 10 (V.fromList [1 .. 10::Double] V.++ V.replicate 10 7) | ||
24 | |||
25 | w = linspace 5 (0,2) | ||
26 | |||
27 | main = do | ||
28 | print $ fromVector v | ||
29 | print $ toVector w | ||