diff options
Diffstat (limited to 'packages/base/src/Internal/Numeric.hs')
-rw-r--r-- | packages/base/src/Internal/Numeric.hs | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/packages/base/src/Internal/Numeric.hs b/packages/base/src/Internal/Numeric.hs index 879daf8..85594cc 100644 --- a/packages/base/src/Internal/Numeric.hs +++ b/packages/base/src/Internal/Numeric.hs | |||
@@ -24,7 +24,7 @@ import Internal.Element | |||
24 | import Internal.ST as ST | 24 | import Internal.ST as ST |
25 | import Internal.Conversion | 25 | import Internal.Conversion |
26 | import Internal.Vectorized | 26 | import Internal.Vectorized |
27 | import Internal.LAPACK(multiplyR,multiplyC,multiplyF,multiplyQ,multiplyI) | 27 | import Internal.LAPACK(multiplyR,multiplyC,multiplyF,multiplyQ,multiplyI,multiplyL) |
28 | import Data.List.Split(chunksOf) | 28 | import Data.List.Split(chunksOf) |
29 | 29 | ||
30 | -------------------------------------------------------------------------------- | 30 | -------------------------------------------------------------------------------- |
@@ -129,6 +129,45 @@ instance Container Vector I | |||
129 | fromInt' = id | 129 | fromInt' = id |
130 | toInt' = id | 130 | toInt' = id |
131 | 131 | ||
132 | |||
133 | instance Container Vector Z | ||
134 | where | ||
135 | conj' = id | ||
136 | size' = dim | ||
137 | scale' = vectorMapValL Scale | ||
138 | addConstant = vectorMapValL AddConstant | ||
139 | add = vectorZipL Add | ||
140 | sub = vectorZipL Sub | ||
141 | mul = vectorZipL Mul | ||
142 | equal u v = dim u == dim v && maxElement' (vectorMapL Abs (sub u v)) == 0 | ||
143 | scalar' x = fromList [x] | ||
144 | konst' = constantD | ||
145 | build' = buildV | ||
146 | cmap' = mapVector | ||
147 | atIndex' = (@>) | ||
148 | minIndex' = emptyErrorV "minIndex" (fromIntegral . toScalarL MinIdx) | ||
149 | maxIndex' = emptyErrorV "maxIndex" (fromIntegral . toScalarL MaxIdx) | ||
150 | minElement' = emptyErrorV "minElement" (toScalarL Min) | ||
151 | maxElement' = emptyErrorV "maxElement" (toScalarL Max) | ||
152 | sumElements' = sumL | ||
153 | prodElements' = prodL | ||
154 | step' = stepL | ||
155 | find' = findV | ||
156 | assoc' = assocV | ||
157 | accum' = accumV | ||
158 | ccompare' = compareCV compareV | ||
159 | cselect' = selectCV selectV | ||
160 | scaleRecip = undefined -- cannot match | ||
161 | divide = undefined | ||
162 | arctan2' = undefined | ||
163 | cmod' m x | ||
164 | | m /= 0 = vectorMapValL ModVS m x | ||
165 | | otherwise = error $ "cmod 0 on vector of size "++(show $ dim x) | ||
166 | fromInt' = int2longV | ||
167 | toInt' = long2intV | ||
168 | |||
169 | |||
170 | |||
132 | instance Container Vector Float | 171 | instance Container Vector Float |
133 | where | 172 | where |
134 | conj' = id | 173 | conj' = id |
@@ -540,6 +579,13 @@ instance Product I where | |||
540 | normInf = emptyVal (maxElement . vectorMapI Abs) | 579 | normInf = emptyVal (maxElement . vectorMapI Abs) |
541 | multiply = emptyMul multiplyI | 580 | multiply = emptyMul multiplyI |
542 | 581 | ||
582 | instance Product Z where | ||
583 | norm2 = undefined | ||
584 | absSum = emptyVal (sumElements . vectorMapL Abs) | ||
585 | norm1 = absSum | ||
586 | normInf = emptyVal (maxElement . vectorMapL Abs) | ||
587 | multiply = emptyMul multiplyL | ||
588 | |||
543 | 589 | ||
544 | emptyMul m a b | 590 | emptyMul m a b |
545 | | x1 == 0 && x2 == 0 || r == 0 || c == 0 = konst' 0 (r,c) | 591 | | x1 == 0 && x2 == 0 || r == 0 || c == 0 = konst' 0 (r,c) |
@@ -676,6 +722,7 @@ type instance RealOf Float = Float | |||
676 | type instance RealOf (Complex Float) = Float | 722 | type instance RealOf (Complex Float) = Float |
677 | 723 | ||
678 | type instance RealOf I = I | 724 | type instance RealOf I = I |
725 | type instance RealOf Z = Z | ||
679 | 726 | ||
680 | type family ComplexOf x | 727 | type family ComplexOf x |
681 | 728 | ||