diff options
Diffstat (limited to 'packages')
-rw-r--r-- | packages/base/src/Internal/Specialized.hs | 10 |
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 | ||
40 | import Control.Monad | 41 | import Control.Monad |
@@ -104,6 +105,9 @@ data IntegralRep t a = IntegralRep | |||
104 | , modulo :: Maybe t | 105 | , modulo :: Maybe t |
105 | } | 106 | } |
106 | 107 | ||
108 | instance Show (IntegralRep t a) where | ||
109 | show _ = "IntegralRep" | ||
110 | |||
107 | idint :: Storable t => IntegralRep t t | 111 | idint :: Storable t => IntegralRep t t |
108 | idint = IntegralRep id id id id id Nothing | 112 | idint = 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 | ||
123 | coercerep :: Coercible s t => IntegralRep s a -> IntegralRep t a | ||
124 | coercerep = coerce | ||
119 | 125 | ||
120 | typeRepOf :: Typeable a => proxy a -> TypeRep a | 126 | typeRepOf :: Typeable a => proxy a -> TypeRep a |
121 | typeRepOf proxy = typeRep | 127 | typeRepOf 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 | ||
131 | specialize :: forall m a. Typeable a => m a -> Maybe (Specialized a) | 138 | specialize :: forall m a. Typeable a => m a -> Maybe (Specialized a) |
132 | specialize x = foldr1 mplus | 139 | specialize 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 | ] |