diff options
author | Justin Le <justin@jle.im> | 2016-05-25 02:20:49 -0700 |
---|---|---|
committer | Justin Le <justin@jle.im> | 2016-05-25 02:20:49 -0700 |
commit | 5623e4d4e613b89786a225265a4d8373680096f3 (patch) | |
tree | 4ea79f2ed7a8199b80ae6eea3b272822fb569e35 | |
parent | 42a88fbcb6bd1d2c4dc18fae5e962bd34fb316a1 (diff) |
re-implemented exactDim and exactLength in terms of the native GHC TypeLits API with sameNat
-rw-r--r-- | packages/base/src/Numeric/LinearAlgebra/Static.hs | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/packages/base/src/Numeric/LinearAlgebra/Static.hs b/packages/base/src/Numeric/LinearAlgebra/Static.hs index 3e772b2..a55ae44 100644 --- a/packages/base/src/Numeric/LinearAlgebra/Static.hs +++ b/packages/base/src/Numeric/LinearAlgebra/Static.hs | |||
@@ -78,6 +78,7 @@ import Data.Proxy(Proxy(..)) | |||
78 | import Internal.Static | 78 | import Internal.Static |
79 | import Control.Arrow((***)) | 79 | import Control.Arrow((***)) |
80 | import Text.Printf | 80 | import Text.Printf |
81 | import Data.Type.Equality ((:~:)(Refl)) | ||
81 | 82 | ||
82 | ud1 :: R n -> Vector ℝ | 83 | ud1 :: R n -> Vector ℝ |
83 | ud1 (R (Dim v)) = v | 84 | ud1 (R (Dim v)) = v |
@@ -444,11 +445,9 @@ exactLength | |||
444 | :: forall n m . (KnownNat n, KnownNat m) | 445 | :: forall n m . (KnownNat n, KnownNat m) |
445 | => R m | 446 | => R m |
446 | -> Maybe (R n) | 447 | -> Maybe (R n) |
447 | exactLength v | 448 | exactLength v = do |
448 | | natVal (Proxy :: Proxy n) == natVal (Proxy :: Proxy m) | 449 | Refl <- sameNat (Proxy :: Proxy n) (Proxy :: Proxy m) |
449 | = Just (mkR (unwrap v)) | 450 | return $ mkR (unwrap v) |
450 | | otherwise | ||
451 | = Nothing | ||
452 | 451 | ||
453 | withMatrix | 452 | withMatrix |
454 | :: forall z | 453 | :: forall z |
@@ -470,12 +469,10 @@ exactDims | |||
470 | :: forall n m j k . (KnownNat n, KnownNat m, KnownNat j, KnownNat k) | 469 | :: forall n m j k . (KnownNat n, KnownNat m, KnownNat j, KnownNat k) |
471 | => L m n | 470 | => L m n |
472 | -> Maybe (L j k) | 471 | -> Maybe (L j k) |
473 | exactDims m | 472 | exactDims m = do |
474 | | natVal (Proxy :: Proxy m) == natVal (Proxy :: Proxy j) | 473 | Refl <- sameNat (Proxy :: Proxy m) (Proxy :: Proxy j) |
475 | && natVal (Proxy :: Proxy n) == natVal (Proxy :: Proxy k) | 474 | Refl <- sameNat (Proxy :: Proxy n) (Proxy :: Proxy k) |
476 | = Just (mkL (unwrap m)) | 475 | return $ mkL (unwrap m) |
477 | | otherwise | ||
478 | = Nothing | ||
479 | 476 | ||
480 | randomVector | 477 | randomVector |
481 | :: forall n . KnownNat n | 478 | :: forall n . KnownNat n |