summaryrefslogtreecommitdiff
path: root/packages/base/src/Internal/Modular.hs
diff options
context:
space:
mode:
Diffstat (limited to 'packages/base/src/Internal/Modular.hs')
-rw-r--r--packages/base/src/Internal/Modular.hs43
1 files changed, 39 insertions, 4 deletions
diff --git a/packages/base/src/Internal/Modular.hs b/packages/base/src/Internal/Modular.hs
index 1289a21..824fc57 100644
--- a/packages/base/src/Internal/Modular.hs
+++ b/packages/base/src/Internal/Modular.hs
@@ -111,18 +111,46 @@ instance forall n t . (Integral t, KnownNat n) => Num (Mod n t)
111 fromInteger = l0 (\m x -> fromInteger x `mod` (fromIntegral m)) 111 fromInteger = l0 (\m x -> fromInteger x `mod` (fromIntegral m))
112 112
113 113
114instance KnownNat m => Element (Mod m I)
115 where
116 transdata n v m = i2f (transdata n (f2i v) m)
117 constantD x n = i2f (constantD (unMod x) n)
118 extractR m mi is mj js = i2fM <$> extractR (f2iM m) mi is mj js
119 sortI = sortI . f2i
120 sortV = i2f . sortV . f2i
121 compareV u v = compareV (f2i u) (f2i v)
122 selectV c l e g = i2f (selectV c (f2i l) (f2i e) (f2i g))
123 remapM i j m = i2fM (remap i j (f2iM m))
124 rowOp c a i1 i2 j1 j2 x = rowOpAux (c_rowOpMI m') c (unMod a) i1 i2 j1 j2 (f2iM x)
125 where
126 m' = fromIntegral . natVal $ (undefined :: Proxy m)
114 127
115instance (Ord t, Element t) => Element (Mod n t) 128instance KnownNat m => Element (Mod m Z)
116 where 129 where
117 transdata n v m = i2f (transdata n (f2i v) m) 130 transdata n v m = i2f (transdata n (f2i v) m)
118 constantD x n = i2f (constantD (unMod x) n) 131 constantD x n = i2f (constantD (unMod x) n)
119 extractR m mi is mj js = i2fM (extractR (f2iM m) mi is mj js) 132 extractR m mi is mj js = i2fM <$> extractR (f2iM m) mi is mj js
120 sortI = sortI . f2i 133 sortI = sortI . f2i
121 sortV = i2f . sortV . f2i 134 sortV = i2f . sortV . f2i
122 compareV u v = compareV (f2i u) (f2i v) 135 compareV u v = compareV (f2i u) (f2i v)
123 selectV c l e g = i2f (selectV c (f2i l) (f2i e) (f2i g)) 136 selectV c l e g = i2f (selectV c (f2i l) (f2i e) (f2i g))
124 remapM i j m = i2fM (remap i j (f2iM m)) 137 remapM i j m = i2fM (remap i j (f2iM m))
138 rowOp c a i1 i2 j1 j2 x = rowOpAux (c_rowOpML m') c (unMod a) i1 i2 j1 j2 (f2iM x)
139 where
140 m' = fromIntegral . natVal $ (undefined :: Proxy m)
125 141
142{-
143instance (Ord t, Element t) => Element (Mod m t)
144 where
145 transdata n v m = i2f (transdata n (f2i v) m)
146 constantD x n = i2f (constantD (unMod x) n)
147 extractR m mi is mj js = i2fM <$> extractR (f2iM m) mi is mj js
148 sortI = sortI . f2i
149 sortV = i2f . sortV . f2i
150 compareV u v = compareV (f2i u) (f2i v)
151 selectV c l e g = i2f (selectV c (f2i l) (f2i e) (f2i g))
152 remapM i j m = i2fM (remap i j (f2iM m))
153-}
126 154
127instance forall m . KnownNat m => Container Vector (Mod m I) 155instance forall m . KnownNat m => Container Vector (Mod m I)
128 where 156 where
@@ -205,12 +233,10 @@ instance forall m . KnownNat m => Container Vector (Mod m Z)
205 toZ' = f2i 233 toZ' = f2i
206 234
207 235
208
209instance (Storable t, Indexable (Vector t) t) => Indexable (Vector (Mod m t)) (Mod m t) 236instance (Storable t, Indexable (Vector t) t) => Indexable (Vector (Mod m t)) (Mod m t)
210 where 237 where
211 (!) = (@>) 238 (!) = (@>)
212 239
213
214type instance RealOf (Mod n I) = I 240type instance RealOf (Mod n I) = I
215type instance RealOf (Mod n Z) = Z 241type instance RealOf (Mod n Z) = Z
216 242
@@ -270,6 +296,15 @@ instance forall m . KnownNat m => Num (Vector (Mod m I))
270 negate = lift1 negate 296 negate = lift1 negate
271 fromInteger x = fromInt (fromInteger x) 297 fromInteger x = fromInt (fromInteger x)
272 298
299instance forall m . KnownNat m => Num (Vector (Mod m Z))
300 where
301 (+) = lift2 (+)
302 (*) = lift2 (*)
303 (-) = lift2 (-)
304 abs = lift1 abs
305 signum = lift1 signum
306 negate = lift1 negate
307 fromInteger x = fromZ (fromInteger x)
273 308
274-------------------------------------------------------------------------------- 309--------------------------------------------------------------------------------
275 310