hmatrix-repa (empty) → 0.1
raw patch · 7 files changed
+148/−0 lines, 7 filesdep +basedep +hmatrixdep +repasetup-changed
Dependencies added: base, hmatrix, repa, vector
Files
- CHANGES +2/−0
- INSTALL +17/−0
- LICENSE +10/−0
- README +12/−0
- Setup.lhs +5/−0
- hmatrix-repa.cabal +46/−0
- lib/Data/Packed/Repa.hs +56/−0
+ CHANGES view
@@ -0,0 +1,2 @@+0.1:+ initial version
+ INSTALL view
@@ -0,0 +1,17 @@+\-----------------------------------------------+ A Repa/hmatrix adaptor library for Haskell+-----------------------------------------------++INSTALLATION++cabal install hmatrix-repa++OR++tar xzf hmatrix-repa-x.y.z.tar.gz+cd hmatrix-repa+runhaskell Setup.lhs configure+runhaskell Setup.lhs build+runhaskell Setup.lhs haddock+runhaskell Setup.lhs install+
+ LICENSE view
@@ -0,0 +1,10 @@+Copyright (c) 2011, A.V.H. McPhail+All rights reserved.++Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.+ * Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README view
@@ -0,0 +1,12 @@+-------------------------------------------+ A Repa/hmatrix adaptor library for Haskell+-------------------------------------------++INSTALLATION++See the INSTALL file.++ACKNOWLEDGEMENTS -----------------------------------------------------++I thank ALberto Ruiz for hmatrix, especially for setup files which I+have shamelessly copied and modified
+ Setup.lhs view
@@ -0,0 +1,5 @@+#! /usr/bin/env runhaskell++> import Distribution.Simple++> main = defaultMain
+ hmatrix-repa.cabal view
@@ -0,0 +1,46 @@+Name: hmatrix-repa+Version: 0.1+License: BSD3+License-file: LICENSE+Copyright: (c) A.V.H. McPhail 2011+Author: Vivian McPhail+Maintainer: haskell.vivian.mcphail <at> gmail <dot> com+Stability: provisional+Homepage: http://code.haskell.org/hmatrix-repa+Synopsis: Adaptors for interoperability between hmatrix and repa+Description: + Adaptors for interoperability between hmatrix and repa+Category: Math, Data+tested-with: GHC ==7.0.1++cabal-version: >=1.8++build-type: Simple++extra-source-files: README INSTALL CHANGES+extra-tmp-files: hmatrix-repa.buildinfo++library++ Build-Depends: base >= 4 && < 5,+ vector >= 0.7,+ hmatrix >= 0.10.0.4,+ repa >= 2++ Extensions: ++ hs-source-dirs: lib+ Exposed-modules: Data.Packed.Repa+ other-modules: + C-sources: ++ ghc-prof-options: -auto++ ghc-options: -Wall -fno-warn-missing-signatures+ -fno-warn-orphans+ -fno-warn-unused-binds++source-repository head+ type: darcs+ location: http://code.haskell.org/hmatrix-repa+
+ lib/Data/Packed/Repa.hs view
@@ -0,0 +1,56 @@+-----------------------------------------------------------------------------+-- |+-- Module : Data.Packed.Repa+-- Copyright : (c) Alexander Vivian Hugh McPhail 2011+-- License : BSD3+--+-- Maintainer : haskell.vivian.mcphail <at> gmail <dot> com+-- Stability : provisional+-- Portability : portable+--+-- Repa / hmatrix conversion functions+--+-----------------------------------------------------------------------------++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.Array.Repa as RA++-- | convert a Storable vector to a DIM1 repa array+vectorToRepa :: (Storable a, RA.Elt a)+ => HV.Vector a+ -> RA.Array RA.DIM1 a+vectorToRepa v = let ln = HV.dim v+ in RA.fromVector (RA.Z RA.:. ln) $ convert v++-- | 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++-- | 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 m = let (r,c) = (HM.rows m,HM.cols m) + in RA.fromVector (RA.Z RA.:. r RA.:. c) $ convert $ HM.flatten m++-- | 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