packages feed

hmatrix-vector-sized 0.1.0.0 → 0.1.1.0

raw patch · 4 files changed

+118/−6 lines, 4 filesdep +ghc-typelits-knownnatPVP ok

version bump matches the API change (PVP)

Dependencies added: ghc-typelits-knownnat

API changes (from Hackage documentation)

+ Numeric.LinearAlgebra.Static.Vector: lVec :: forall m n. () => L m n -> Vector (m * n) ℝ
+ Numeric.LinearAlgebra.Static.Vector: mVec :: forall m n. () => M m n -> Vector (m * n) ℂ
+ Numeric.LinearAlgebra.Static.Vector: vecL :: forall m n. KnownNat n => Vector (m * n) ℝ -> L m n
+ Numeric.LinearAlgebra.Static.Vector: vecM :: forall m n. KnownNat n => Vector (m * n) ℂ -> M m n

Files

CHANGELOG.md view
@@ -1,6 +1,15 @@ Changelog ========= +Version 0.1.1.0+---------------++*Feb 11, 2018*++<https://github.com/mstksg/hmatrix-vector-sized/releases/tag/v0.1.1.0>++*   Conversions to and from flattened versions of matrices.+ Version 0.1.0.0 --------------- 
hmatrix-vector-sized.cabal view
@@ -2,10 +2,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 70aa6c0a47ec2f24e7aa0c898db148bf6e298635849cef213bfdd866941396e3+-- hash: 599f43d91e14ba43a882f7ef47d4b638ecdab3da7eae3da1c0e744565c61b14d  name:           hmatrix-vector-sized-version:        0.1.0.0+version:        0.1.1.0 synopsis:       Conversions between hmatrix and vector-sized types description:    Conversions between statically sized types in hmatrix and vector-sized.                 .@@ -52,6 +52,7 @@   ghc-options: -Wall -Wcompat -Wincomplete-record-updates -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N   build-depends:       base >=4.7 && <5+    , ghc-typelits-knownnat     , hedgehog     , hmatrix >=0.18     , hmatrix-vector-sized
src/Numeric/LinearAlgebra/Static/Vector.hs view
@@ -1,4 +1,6 @@ {-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TypeApplications    #-}+{-# LANGUAGE TypeOperators       #-}  -- | -- Module      : Numeric.LinearAlgebra.Static.Vector@@ -33,14 +35,20 @@   , rowsL   , lCols   , colsL+  , lVec+  , vecL   -- ** Complex   , mRows   , rowsM   , mCols   , colsM+  , mVec+  , vecM   ) where  import           Data.Foldable+import           Data.Proxy+import           GHC.TypeLits import           Unsafe.Coerce import qualified Data.Vector                  as UV import qualified Data.Vector.Sized            as V@@ -158,3 +166,44 @@       . HU.fromColumns       . map (unsafeCoerce :: H.C m -> HU.Vector H.ℂ)       . toList++-- | Shape a /vector-sized/ storable vector of elements into an /hmatrix/+-- matrix.+vecL+    :: forall m n. KnownNat n+    => VS.Vector (m * n) H.ℝ+    -> H.L m n+vecL = (unsafeCoerce :: HU.Matrix H.ℝ -> H.L m n)+     . HU.reshape (fromIntegral (natVal (Proxy @n)))+     . unsafeCoerce++-- | Flatten an /hmatrix/ matrix into a /vector-sized/ storable vector of+-- its items.+lVec+    :: forall m n. ()+    => H.L m n+    -> VS.Vector (m * n) H.ℝ+lVec = unsafeCoerce+     . HU.flatten+     . (unsafeCoerce :: H.L m n -> HU.Matrix H.ℝ)++-- | Shape a /vector-sized/ storable vector of elements into an /hmatrix/+-- complex matrix.+vecM+    :: forall m n. KnownNat n+    => VS.Vector (m * n) H.ℂ+    -> H.M m n+vecM = (unsafeCoerce :: HU.Matrix H.ℂ -> H.M m n)+     . HU.reshape (fromIntegral (natVal (Proxy @n)))+     . unsafeCoerce++-- | Flatten an /hmatrix/ complex matrix into a /vector-sized/ storable+-- vector of its items.+mVec+    :: forall m n. ()+    => H.M m n+    -> VS.Vector (m * n) H.ℂ+mVec = unsafeCoerce+     . HU.flatten+     . (unsafeCoerce :: H.M m n -> HU.Matrix H.ℂ)+
test/Spec.hs view
@@ -1,7 +1,9 @@-{-# LANGUAGE ScopedTypeVariables  #-}-{-# LANGUAGE TemplateHaskell      #-}-{-# LANGUAGE TypeApplications     #-}-{-# OPTIONS_GHC -fno-warn-orphans #-}+{-# LANGUAGE ScopedTypeVariables                      #-}+{-# LANGUAGE TemplateHaskell                          #-}+{-# LANGUAGE TypeApplications                         #-}+{-# LANGUAGE TypeOperators                            #-}+{-# OPTIONS_GHC -fno-warn-orphans                     #-}+{-# OPTIONS_GHC -fplugin GHC.TypeLits.KnownNat.Solver #-}  import           Control.Monad import           Data.Complex@@ -117,6 +119,31 @@                ((* 2) . H.colsL @m @n)                (Identity . V.map (/ 2) . H.lCols) +prop_vecL :: Property+prop_vecL = property $ do+    ( SomeNat (Proxy :: Proxy m)+     , SomeNat (Proxy :: Proxy n)+     , xs+     ) <- forAll $ genMatList genDouble+    let v :: VS.Vector (m * n) Double+        v = fromJust $ VS.fromList @_ @(m * n) (concat xs)+    tripping v ((* 2) . H.vecL @m @n)+              (Identity . VS.map (/ 2) . H.lVec)++prop_lVec :: Property+prop_lVec = property $ do+    ( SomeNat (pM@Proxy :: Proxy m)+     , SomeNat (pN@Proxy :: Proxy n)+     , xs+     ) <- forAll $ genMatList genDouble+    let m :: H.L m n+        m = fromJust+          . H.create+          . (fromIntegral (natVal pM) HU.>< fromIntegral (natVal pN))+          $ concat xs+    tripping m (VS.map (* 2) . H.lVec)+              (Identity . (/ 2) . H.vecL)+ prop_mRows :: Property prop_mRows = property $ do     ( SomeNat (Proxy :: Proxy m)@@ -152,6 +179,32 @@       tripping (V.map (fromJust . H.create . HU.fromList) v)                ((* 2) . H.colsM @m @n)                (Identity . V.map (/ 2) . H.mCols)++prop_vecM :: Property+prop_vecM = property $ do+    ( SomeNat (Proxy :: Proxy m)+     , SomeNat (Proxy :: Proxy n)+     , xs+     ) <- forAll $ genMatList genComplex+    let v :: VS.Vector (m * n) (Complex Double)+        v = fromJust $ VS.fromList @_ @(m * n) (concat xs)+    tripping v ((* 2) . H.vecM @m @n)+              (Identity . VS.map (/ 2) . H.mVec)++prop_mVec :: Property+prop_mVec = property $ do+    ( SomeNat (pM@Proxy :: Proxy m)+     , SomeNat (pN@Proxy :: Proxy n)+     , xs+     ) <- forAll $ genMatList genComplex+    let m :: H.M m n+        m = fromJust+          . H.create+          . (fromIntegral (natVal pM) HU.>< fromIntegral (natVal pN))+          $ concat xs+    tripping m (VS.map (* 2) . H.mVec)+               (Identity . (/ 2) . H.vecM)+  main :: IO () main = do