module Data.Packed.Repa (
vectorToRepa
, repaToVector
, matrixToRepa
, repaToMatrix
) where
import qualified Data.Packed.Vector as HV
import qualified Data.Packed.Matrix as HM
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
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 RV.fromVector (RA.Z RA.:. ln) $ convert v
repaToVector :: (GV.Vector HV.Vector e)
=> RV.Array RV.V RA.DIM1 e -> HV.Vector e
repaToVector = convert . RV.toVector
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 RV.fromVector (RA.Z RA.:. r RA.:. c) $ convert $ HM.flatten m
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