From 05a7df70fcba1f8a78ab072da99ea055149ddb17 Mon Sep 17 00:00:00 2001 From: Joe Crayne Date: Sat, 10 Aug 2019 04:20:40 -0400 Subject: Fixed modulo-CInt specialization. --- packages/base/src/Internal/Specialized.hs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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 , rowOp , gemm , reorderV + , specialize ) where import Control.Monad @@ -104,6 +105,9 @@ data IntegralRep t a = IntegralRep , modulo :: Maybe t } +instance Show (IntegralRep t a) where + show _ = "IntegralRep" + idint :: Storable t => IntegralRep t t idint = IntegralRep id id id id id Nothing @@ -116,6 +120,8 @@ modint r = IntegralRep i2f i2fM f2i f2iM unMod (Just n) n = read . show $ r -- XXX: Hack to get nat value from Type.Reflection -- n = fromIntegral . natVal $ (undefined :: Proxy n) +coercerep :: Coercible s t => IntegralRep s a -> IntegralRep t a +coercerep = coerce typeRepOf :: Typeable a => proxy a -> TypeRep a typeRepOf proxy = typeRep @@ -127,6 +133,7 @@ data Specialized a | SpCDouble !(a :~: Complex Double) | SpInt32 !(IntegralRep Int32 a) | SpInt64 !(IntegralRep Int64 a) + deriving Show specialize :: forall m a. Typeable a => m a -> Maybe (Specialized a) specialize x = foldr1 mplus @@ -140,7 +147,8 @@ specialize x = foldr1 mplus , case typeRepOf x of App (App modtyp n) inttyp -> do HRefl <- eqTypeRep (typeRep :: TypeRep (Mod :: Nat -> * -> *)) modtyp - mplus (eqTypeRep (typeRep :: TypeRep Int32) inttyp <&> \HRefl -> SpInt32 $ modint n) + mplus (mplus (eqTypeRep (typeRep :: TypeRep Int32) inttyp <&> \HRefl -> SpInt32 $ modint n) + (eqTypeRep (typeRep :: TypeRep CInt) inttyp <&> \HRefl -> SpInt32 $ coercerep $ modint n)) (eqTypeRep (typeRep :: TypeRep Int64) inttyp <&> \HRefl -> SpInt64 $ modint n) _ -> Nothing ] -- cgit v1.2.3