summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Le <justin@jle.im>2016-05-25 02:20:49 -0700
committerJustin Le <justin@jle.im>2016-05-25 02:20:49 -0700
commit5623e4d4e613b89786a225265a4d8373680096f3 (patch)
tree4ea79f2ed7a8199b80ae6eea3b272822fb569e35
parent42a88fbcb6bd1d2c4dc18fae5e962bd34fb316a1 (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.hs19
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(..))
78import Internal.Static 78import Internal.Static
79import Control.Arrow((***)) 79import Control.Arrow((***))
80import Text.Printf 80import Text.Printf
81import Data.Type.Equality ((:~:)(Refl))
81 82
82ud1 :: R n -> Vector ℝ 83ud1 :: R n -> Vector ℝ
83ud1 (R (Dim v)) = v 84ud1 (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)
447exactLength v 448exactLength 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
453withMatrix 452withMatrix
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)
473exactDims m 472exactDims 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
480randomVector 477randomVector
481 :: forall n . KnownNat n 478 :: forall n . KnownNat n