module Data.Packed.Repa (
vectorToRepa
, repaToVector
, matrixToRepa
, repaToMatrix
) where
import qualified Numeric.LinearAlgebra as H
import qualified Numeric.LinearAlgebra.Data as HV
import qualified Numeric.LinearAlgebra.Data 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, H.Container Vector e)
=> HV.Vector e
-> RV.Array RV.V RA.DIM1 e
vectorToRepa v = let ln = HV.size 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 :: (H.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