summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2019-08-10 04:20:40 -0400
committerJoe Crayne <joe@jerkface.net>2019-08-10 04:20:40 -0400
commit05a7df70fcba1f8a78ab072da99ea055149ddb17 (patch)
treee590ca905c153461dacfca235bd86c2d6899356d
parent8ce80f6d8a38d67e9781f4a361e5c904bb73c7cd (diff)
Fixed modulo-CInt specialization.
-rw-r--r--packages/base/src/Internal/Specialized.hs10
1 files changed, 9 insertions, 1 deletions
diff --git a/packages/base/src/Internal/Specialized.hs b/packages/base/src/Internal/Specialized.hs
index 19a62d1..3738f79 100644
--- a/packages/base/src/Internal/Specialized.hs
+++ b/packages/base/src/Internal/Specialized.hs
@@ -35,6 +35,7 @@ module Internal.Specialized
35 , rowOp 35 , rowOp
36 , gemm 36 , gemm
37 , reorderV 37 , reorderV
38 , specialize
38 ) where 39 ) where
39 40
40import Control.Monad 41import Control.Monad
@@ -104,6 +105,9 @@ data IntegralRep t a = IntegralRep
104 , modulo :: Maybe t 105 , modulo :: Maybe t
105 } 106 }
106 107
108instance Show (IntegralRep t a) where
109 show _ = "IntegralRep"
110
107idint :: Storable t => IntegralRep t t 111idint :: Storable t => IntegralRep t t
108idint = IntegralRep id id id id id Nothing 112idint = IntegralRep id id id id id Nothing
109 113
@@ -116,6 +120,8 @@ modint r = IntegralRep i2f i2fM f2i f2iM unMod (Just n)
116 n = read . show $ r -- XXX: Hack to get nat value from Type.Reflection 120 n = read . show $ r -- XXX: Hack to get nat value from Type.Reflection
117 -- n = fromIntegral . natVal $ (undefined :: Proxy n) 121 -- n = fromIntegral . natVal $ (undefined :: Proxy n)
118 122
123coercerep :: Coercible s t => IntegralRep s a -> IntegralRep t a
124coercerep = coerce
119 125
120typeRepOf :: Typeable a => proxy a -> TypeRep a 126typeRepOf :: Typeable a => proxy a -> TypeRep a
121typeRepOf proxy = typeRep 127typeRepOf proxy = typeRep
@@ -127,6 +133,7 @@ data Specialized a
127 | SpCDouble !(a :~: Complex Double) 133 | SpCDouble !(a :~: Complex Double)
128 | SpInt32 !(IntegralRep Int32 a) 134 | SpInt32 !(IntegralRep Int32 a)
129 | SpInt64 !(IntegralRep Int64 a) 135 | SpInt64 !(IntegralRep Int64 a)
136 deriving Show
130 137
131specialize :: forall m a. Typeable a => m a -> Maybe (Specialized a) 138specialize :: forall m a. Typeable a => m a -> Maybe (Specialized a)
132specialize x = foldr1 mplus 139specialize x = foldr1 mplus
@@ -140,7 +147,8 @@ specialize x = foldr1 mplus
140 , case typeRepOf x of 147 , case typeRepOf x of
141 App (App modtyp n) inttyp 148 App (App modtyp n) inttyp
142 -> do HRefl <- eqTypeRep (typeRep :: TypeRep (Mod :: Nat -> * -> *)) modtyp 149 -> do HRefl <- eqTypeRep (typeRep :: TypeRep (Mod :: Nat -> * -> *)) modtyp
143 mplus (eqTypeRep (typeRep :: TypeRep Int32) inttyp <&> \HRefl -> SpInt32 $ modint n) 150 mplus (mplus (eqTypeRep (typeRep :: TypeRep Int32) inttyp <&> \HRefl -> SpInt32 $ modint n)
151 (eqTypeRep (typeRep :: TypeRep CInt) inttyp <&> \HRefl -> SpInt32 $ coercerep $ modint n))
144 (eqTypeRep (typeRep :: TypeRep Int64) inttyp <&> \HRefl -> SpInt64 $ modint n) 152 (eqTypeRep (typeRep :: TypeRep Int64) inttyp <&> \HRefl -> SpInt64 $ modint n)
145 _ -> Nothing 153 _ -> Nothing
146 ] 154 ]