hmatrix-repa 0.1.0.1 → 0.1.1
raw patch · 3 files changed
+29/−21 lines, 3 filesdep ~repa
Dependency ranges changed: repa
Files
- THANKS +3/−0
- hmatrix-repa.cabal +4/−4
- lib/Data/Packed/Repa.hs +22/−17
+ THANKS view
@@ -0,0 +1,3 @@+Joachim Fasting + * updated for repa 3+ * minor fixes
hmatrix-repa.cabal view
@@ -1,5 +1,5 @@ Name: hmatrix-repa-Version: 0.1.0.1+Version: 0.1.1 License: BSD3 License-file: LICENSE Copyright: (c) A.V.H. McPhail 2011@@ -11,13 +11,13 @@ Description: Adaptors for interoperability between hmatrix and repa Category: Math, Data-tested-with: GHC ==7.0.1+tested-with: GHC ==7.4.1 cabal-version: >=1.8 build-type: Simple -extra-source-files: README INSTALL CHANGES+extra-source-files: README INSTALL CHANGES THANKS extra-tmp-files: hmatrix-repa.buildinfo library@@ -25,7 +25,7 @@ Build-Depends: base >= 4 && < 5, vector >= 0.7, hmatrix >= 0.10.0.4,- repa >= 2+ repa >= 3 && < 4 Extensions:
lib/Data/Packed/Repa.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE FlexibleContexts #-}+ ----------------------------------------------------------------------------- -- | -- Module : Data.Packed.Repa@@ -25,32 +27,35 @@ import Foreign.Storable import Data.Vector.Storable+import qualified Data.Vector.Generic as GV import qualified Data.Array.Repa as RA+import qualified Data.Array.Repa.Repr.Vector as RV -- | convert a Storable vector to a DIM1 repa array-vectorToRepa :: (Storable a, RA.Elt a)- => HV.Vector a- -> RA.Array RA.DIM1 a+vectorToRepa :: (Storable e, GV.Vector HV.Vector e)+ => HV.Vector e+ -> RV.Array RV.V RA.DIM1 e vectorToRepa v = let ln = HV.dim v- in RA.fromVector (RA.Z RA.:. ln) $ convert v+ in RV.fromVector (RA.Z RA.:. ln) $ convert v +-- XXX: note that this type could be made shape polymorhphic. -- | convert a 1d repa array to a Storable vector-repaToVector :: (Storable a, RA.Elt a)- => RA.Array RA.DIM1 a- -> HV.Vector a-repaToVector = convert . RA.toVector+repaToVector :: (GV.Vector HV.Vector e)+ => RV.Array RV.V RA.DIM1 e -> HV.Vector e+repaToVector = convert . RV.toVector -- | convert a Storable matrix to a DIM2 repa array-matrixToRepa :: (Storable a, HM.Element a, RA.Elt a)- => HM.Matrix a- -> RA.Array RA.DIM2 a+matrixToRepa :: (HM.Element e, GV.Vector HV.Vector e)+ => HM.Matrix e+ -> RV.Array RV.V RA.DIM2 e matrixToRepa m = let (r,c) = (HM.rows m,HM.cols m) - in RA.fromVector (RA.Z RA.:. r RA.:. c) $ convert $ HM.flatten m+ in RV.fromVector (RA.Z RA.:. r RA.:. c) $ convert $ HM.flatten m +-- XXX: note that this could be made shape polymorphic -- | convert a 2d repa array to a Storable matrix-repaToMatrix :: (Storable a, RA.Elt a)- => RA.Array RA.DIM2 a- -> HM.Matrix a-repaToMatrix a = let (RA.Z RA.:. r RA.:. c) = RA.extent a- in HM.reshape c $ convert $ RA.toVector a+repaToMatrix :: (Storable e, GV.Vector HV.Vector e)+ => RV.Array RV.V RA.DIM2 e+ -> HM.Matrix e+repaToMatrix a = let (RA.Z RA.:. _ RA.:. c) = RA.extent a+ in HM.reshape c $ convert $ RV.toVector a