diff options
Diffstat (limited to 'packages/base/src')
-rw-r--r-- | packages/base/src/Internal/Matrix.hs | 3 | ||||
-rw-r--r-- | packages/base/src/Internal/Modular.hs | 16 | ||||
-rw-r--r-- | packages/base/src/Internal/Static.hs | 18 |
3 files changed, 18 insertions, 19 deletions
diff --git a/packages/base/src/Internal/Matrix.hs b/packages/base/src/Internal/Matrix.hs index f9b02ca..c47c625 100644 --- a/packages/base/src/Internal/Matrix.hs +++ b/packages/base/src/Internal/Matrix.hs | |||
@@ -6,8 +6,7 @@ | |||
6 | {-# LANGUAGE TypeFamilies #-} | 6 | {-# LANGUAGE TypeFamilies #-} |
7 | {-# LANGUAGE ViewPatterns #-} | 7 | {-# LANGUAGE ViewPatterns #-} |
8 | {-# LANGUAGE DeriveGeneric #-} | 8 | {-# LANGUAGE DeriveGeneric #-} |
9 | 9 | {-# LANGUAGE ConstrainedClassMethods #-} | |
10 | |||
11 | 10 | ||
12 | -- | | 11 | -- | |
13 | -- Module : Internal.Matrix | 12 | -- Module : Internal.Matrix |
diff --git a/packages/base/src/Internal/Modular.hs b/packages/base/src/Internal/Modular.hs index 239c742..f3c59a8 100644 --- a/packages/base/src/Internal/Modular.hs +++ b/packages/base/src/Internal/Modular.hs | |||
@@ -72,7 +72,7 @@ instance (Ord t, KnownNat m) => Ord (Mod m t) | |||
72 | where | 72 | where |
73 | compare a b = compare (unMod a) (unMod b) | 73 | compare a b = compare (unMod a) (unMod b) |
74 | 74 | ||
75 | instance (Real t, KnownNat m, Integral (Mod m t)) => Real (Mod m t) | 75 | instance (Integral t, Real t, KnownNat m, Integral (Mod m t)) => Real (Mod m t) |
76 | where | 76 | where |
77 | toRational x = toInteger x % 1 | 77 | toRational x = toInteger x % 1 |
78 | 78 | ||
@@ -114,7 +114,7 @@ instance Show t => Show (Mod n t) | |||
114 | where | 114 | where |
115 | show = show . unMod | 115 | show = show . unMod |
116 | 116 | ||
117 | instance forall n t . (Integral t, KnownNat n) => Num (Mod n t) | 117 | instance (Integral t, KnownNat n) => Num (Mod n t) |
118 | where | 118 | where |
119 | (+) = l2 (\m a b -> (a + b) `mod` (fromIntegral m)) | 119 | (+) = l2 (\m a b -> (a + b) `mod` (fromIntegral m)) |
120 | (*) = l2 (\m a b -> (a * b) `mod` (fromIntegral m)) | 120 | (*) = l2 (\m a b -> (a * b) `mod` (fromIntegral m)) |
@@ -159,11 +159,11 @@ instance KnownNat m => Element (Mod m Z) | |||
159 | m' = fromIntegral . natVal $ (undefined :: Proxy m) | 159 | m' = fromIntegral . natVal $ (undefined :: Proxy m) |
160 | 160 | ||
161 | 161 | ||
162 | instance forall m . KnownNat m => CTrans (Mod m I) | 162 | instance KnownNat m => CTrans (Mod m I) |
163 | instance forall m . KnownNat m => CTrans (Mod m Z) | 163 | instance KnownNat m => CTrans (Mod m Z) |
164 | 164 | ||
165 | 165 | ||
166 | instance forall m . KnownNat m => Container Vector (Mod m I) | 166 | instance KnownNat m => Container Vector (Mod m I) |
167 | where | 167 | where |
168 | conj' = id | 168 | conj' = id |
169 | size' = dim | 169 | size' = dim |
@@ -203,7 +203,7 @@ instance forall m . KnownNat m => Container Vector (Mod m I) | |||
203 | fromZ' = vmod . fromZ' | 203 | fromZ' = vmod . fromZ' |
204 | toZ' = toZ' . f2i | 204 | toZ' = toZ' . f2i |
205 | 205 | ||
206 | instance forall m . KnownNat m => Container Vector (Mod m Z) | 206 | instance KnownNat m => Container Vector (Mod m Z) |
207 | where | 207 | where |
208 | conj' = id | 208 | conj' = id |
209 | size' = dim | 209 | size' = dim |
@@ -311,7 +311,7 @@ lift2 f a b = vmod (f (f2i a) (f2i b)) | |||
311 | 311 | ||
312 | lift2m f a b = liftMatrix vmod (f (f2iM a) (f2iM b)) | 312 | lift2m f a b = liftMatrix vmod (f (f2iM a) (f2iM b)) |
313 | 313 | ||
314 | instance forall m . KnownNat m => Num (Vector (Mod m I)) | 314 | instance KnownNat m => Num (Vector (Mod m I)) |
315 | where | 315 | where |
316 | (+) = lift2 (+) | 316 | (+) = lift2 (+) |
317 | (*) = lift2 (*) | 317 | (*) = lift2 (*) |
@@ -321,7 +321,7 @@ instance forall m . KnownNat m => Num (Vector (Mod m I)) | |||
321 | negate = lift1 negate | 321 | negate = lift1 negate |
322 | fromInteger x = fromInt (fromInteger x) | 322 | fromInteger x = fromInt (fromInteger x) |
323 | 323 | ||
324 | instance forall m . KnownNat m => Num (Vector (Mod m Z)) | 324 | instance KnownNat m => Num (Vector (Mod m Z)) |
325 | where | 325 | where |
326 | (+) = lift2 (+) | 326 | (+) = lift2 (+) |
327 | (*) = lift2 (*) | 327 | (*) = lift2 (*) |
diff --git a/packages/base/src/Internal/Static.hs b/packages/base/src/Internal/Static.hs index 0ad2cad..1e9a5a3 100644 --- a/packages/base/src/Internal/Static.hs +++ b/packages/base/src/Internal/Static.hs | |||
@@ -207,7 +207,7 @@ singleV v = LA.size v == 1 | |||
207 | singleM m = rows m == 1 && cols m == 1 | 207 | singleM m = rows m == 1 && cols m == 1 |
208 | 208 | ||
209 | 209 | ||
210 | instance forall n. KnownNat n => Sized ℂ (C n) Vector | 210 | instance KnownNat n => Sized ℂ (C n) Vector |
211 | where | 211 | where |
212 | size _ = fromIntegral . natVal $ (undefined :: Proxy n) | 212 | size _ = fromIntegral . natVal $ (undefined :: Proxy n) |
213 | konst x = mkC (LA.scalar x) | 213 | konst x = mkC (LA.scalar x) |
@@ -223,7 +223,7 @@ instance forall n. KnownNat n => Sized ℂ (C n) Vector | |||
223 | r = mkC v :: C n | 223 | r = mkC v :: C n |
224 | 224 | ||
225 | 225 | ||
226 | instance forall n. KnownNat n => Sized ℝ (R n) Vector | 226 | instance KnownNat n => Sized ℝ (R n) Vector |
227 | where | 227 | where |
228 | size _ = fromIntegral . natVal $ (undefined :: Proxy n) | 228 | size _ = fromIntegral . natVal $ (undefined :: Proxy n) |
229 | konst x = mkR (LA.scalar x) | 229 | konst x = mkR (LA.scalar x) |
@@ -240,7 +240,7 @@ instance forall n. KnownNat n => Sized ℝ (R n) Vector | |||
240 | 240 | ||
241 | 241 | ||
242 | 242 | ||
243 | instance forall m n . (KnownNat m, KnownNat n) => Sized ℝ (L m n) Matrix | 243 | instance (KnownNat m, KnownNat n) => Sized ℝ (L m n) Matrix |
244 | where | 244 | where |
245 | size _ = ((fromIntegral . natVal) (undefined :: Proxy m) | 245 | size _ = ((fromIntegral . natVal) (undefined :: Proxy m) |
246 | ,(fromIntegral . natVal) (undefined :: Proxy n)) | 246 | ,(fromIntegral . natVal) (undefined :: Proxy n)) |
@@ -258,7 +258,7 @@ instance forall m n . (KnownNat m, KnownNat n) => Sized ℝ (L m n) Matrix | |||
258 | r = mkL x :: L m n | 258 | r = mkL x :: L m n |
259 | 259 | ||
260 | 260 | ||
261 | instance forall m n . (KnownNat m, KnownNat n) => Sized ℂ (M m n) Matrix | 261 | instance (KnownNat m, KnownNat n) => Sized ℂ (M m n) Matrix |
262 | where | 262 | where |
263 | size _ = ((fromIntegral . natVal) (undefined :: Proxy m) | 263 | size _ = ((fromIntegral . natVal) (undefined :: Proxy m) |
264 | ,(fromIntegral . natVal) (undefined :: Proxy n)) | 264 | ,(fromIntegral . natVal) (undefined :: Proxy n)) |
@@ -316,7 +316,7 @@ isDiagg (Dim (Dim x)) | |||
316 | 316 | ||
317 | -------------------------------------------------------------------------------- | 317 | -------------------------------------------------------------------------------- |
318 | 318 | ||
319 | instance forall n . KnownNat n => Show (R n) | 319 | instance KnownNat n => Show (R n) |
320 | where | 320 | where |
321 | show s@(R (Dim v)) | 321 | show s@(R (Dim v)) |
322 | | singleV v = "("++show (v!0)++" :: R "++show d++")" | 322 | | singleV v = "("++show (v!0)++" :: R "++show d++")" |
@@ -324,7 +324,7 @@ instance forall n . KnownNat n => Show (R n) | |||
324 | where | 324 | where |
325 | d = size s | 325 | d = size s |
326 | 326 | ||
327 | instance forall n . KnownNat n => Show (C n) | 327 | instance KnownNat n => Show (C n) |
328 | where | 328 | where |
329 | show s@(C (Dim v)) | 329 | show s@(C (Dim v)) |
330 | | singleV v = "("++show (v!0)++" :: C "++show d++")" | 330 | | singleV v = "("++show (v!0)++" :: C "++show d++")" |
@@ -332,7 +332,7 @@ instance forall n . KnownNat n => Show (C n) | |||
332 | where | 332 | where |
333 | d = size s | 333 | d = size s |
334 | 334 | ||
335 | instance forall m n . (KnownNat m, KnownNat n) => Show (L m n) | 335 | instance (KnownNat m, KnownNat n) => Show (L m n) |
336 | where | 336 | where |
337 | show (isDiag -> Just (z,y,(m',n'))) = printf "(diag %s %s :: L %d %d)" (show z) (drop 9 $ show y) m' n' | 337 | show (isDiag -> Just (z,y,(m',n'))) = printf "(diag %s %s :: L %d %d)" (show z) (drop 9 $ show y) m' n' |
338 | show s@(L (Dim (Dim x))) | 338 | show s@(L (Dim (Dim x))) |
@@ -341,7 +341,7 @@ instance forall m n . (KnownNat m, KnownNat n) => Show (L m n) | |||
341 | where | 341 | where |
342 | (m',n') = size s | 342 | (m',n') = size s |
343 | 343 | ||
344 | instance forall m n . (KnownNat m, KnownNat n) => Show (M m n) | 344 | instance (KnownNat m, KnownNat n) => Show (M m n) |
345 | where | 345 | where |
346 | show (isDiagC -> Just (z,y,(m',n'))) = printf "(diag %s %s :: M %d %d)" (show z) (drop 9 $ show y) m' n' | 346 | show (isDiagC -> Just (z,y,(m',n'))) = printf "(diag %s %s :: M %d %d)" (show z) (drop 9 $ show y) m' n' |
347 | show s@(M (Dim (Dim x))) | 347 | show s@(M (Dim (Dim x))) |
@@ -352,7 +352,7 @@ instance forall m n . (KnownNat m, KnownNat n) => Show (M m n) | |||
352 | 352 | ||
353 | -------------------------------------------------------------------------------- | 353 | -------------------------------------------------------------------------------- |
354 | 354 | ||
355 | instance forall n t . (Num (Vector t), Numeric t )=> Num (Dim n (Vector t)) | 355 | instance (Num (Vector t), Numeric t )=> Num (Dim n (Vector t)) |
356 | where | 356 | where |
357 | (+) = lift2F (+) | 357 | (+) = lift2F (+) |
358 | (*) = lift2F (*) | 358 | (*) = lift2F (*) |