diff options
author | Alberto Ruiz <aruiz@um.es> | 2015-05-25 09:23:39 +0200 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2015-05-25 09:23:39 +0200 |
commit | e803d45acc0fd3202af9ea3844c554a9b807bade (patch) | |
tree | ee8982d68735e54c7ce6c8db7f843df18065dc5f /packages | |
parent | 11095a22c59bed6a011723641dfb782415e2c02b (diff) |
At range, idxs
Diffstat (limited to 'packages')
-rw-r--r-- | packages/base/src/Data/Packed/Internal/Numeric.hs | 24 | ||||
-rw-r--r-- | packages/base/src/Numeric/LinearAlgebra/Data.hs | 4 |
2 files changed, 16 insertions, 12 deletions
diff --git a/packages/base/src/Data/Packed/Internal/Numeric.hs b/packages/base/src/Data/Packed/Internal/Numeric.hs index 60dd167..cda9429 100644 --- a/packages/base/src/Data/Packed/Internal/Numeric.hs +++ b/packages/base/src/Data/Packed/Internal/Numeric.hs | |||
@@ -39,7 +39,7 @@ module Data.Packed.Internal.Numeric ( | |||
39 | roundVector, fromInt, | 39 | roundVector, fromInt, |
40 | RealOf, ComplexOf, SingleOf, DoubleOf, | 40 | RealOf, ComplexOf, SingleOf, DoubleOf, |
41 | IndexOf, | 41 | IndexOf, |
42 | CInt, Extractor(..), (??), range, | 42 | CInt, Extractor(..), (??), range, idxs, |
43 | module Data.Complex | 43 | module Data.Complex |
44 | ) where | 44 | ) where |
45 | 45 | ||
@@ -70,12 +70,13 @@ type instance ArgOf Matrix a = a -> a -> a | |||
70 | data Extractor | 70 | data Extractor |
71 | = All | 71 | = All |
72 | | Range Int Int | 72 | | Range Int Int |
73 | | At [Int] | 73 | | At Idxs |
74 | | AtCyc [Int] | 74 | | AtCyc Idxs |
75 | | Take Int | 75 | | Take Int |
76 | | Drop Int | 76 | | Drop Int |
77 | deriving Show | 77 | deriving Show |
78 | 78 | ||
79 | idxs :: [Int] -> Idxs | ||
79 | idxs js = fromList (map fromIntegral js) :: Idxs | 80 | idxs js = fromList (map fromIntegral js) :: Idxs |
80 | 81 | ||
81 | infixl 9 ?? | 82 | infixl 9 ?? |
@@ -86,8 +87,9 @@ extractError m e = error $ printf "can't extract %s from matrix %dx%d" (show e) | |||
86 | 87 | ||
87 | m ?? e@(Range a b,_) | a < 0 || b >= rows m = extractError m e | 88 | m ?? e@(Range a b,_) | a < 0 || b >= rows m = extractError m e |
88 | m ?? e@(_,Range a b) | a < 0 || b >= cols m = extractError m e | 89 | m ?? e@(_,Range a b) | a < 0 || b >= cols m = extractError m e |
89 | m ?? e@(At ps,_) | minimum ps < 0 || maximum ps >= rows m = extractError m e | 90 | |
90 | m ?? e@(_,At ps) | minimum ps < 0 || maximum ps >= cols m = extractError m e | 91 | m ?? e@(At vs,_) | minElement vs < 0 || maxElement vs >= fromIntegral (rows m) = extractError m e |
92 | m ?? e@(_,At vs) | minElement vs < 0 || maxElement vs >= fromIntegral (cols m) = extractError m e | ||
91 | 93 | ||
92 | m ?? (All,All) = m | 94 | m ?? (All,All) = m |
93 | 95 | ||
@@ -112,9 +114,11 @@ m ?? (er,ec) = extractR m moder rs modec cs | |||
112 | (moder,rs) = mkExt (rows m) er | 114 | (moder,rs) = mkExt (rows m) er |
113 | (modec,cs) = mkExt (cols m) ec | 115 | (modec,cs) = mkExt (cols m) ec |
114 | ran a b = (0, idxs [a,b]) | 116 | ran a b = (0, idxs [a,b]) |
115 | pos ks = (1, idxs ks) | 117 | pos ks = (1, ks) |
116 | mkExt _ (At ks) = pos ks | 118 | mkExt _ (At ks) = pos ks |
117 | mkExt n (AtCyc ks) = pos (map (`mod` n) ks) | 119 | mkExt n (AtCyc ks) |
120 | | n == 0 = mkExt n (Take 0) | ||
121 | | otherwise = pos (cmod n ks) | ||
118 | mkExt n All = ran 0 (n-1) | 122 | mkExt n All = ran 0 (n-1) |
119 | mkExt _ (Range mn mx) = ran mn mx | 123 | mkExt _ (Range mn mx) = ran mn mx |
120 | mkExt n (Take k) | 124 | mkExt n (Take k) |
@@ -420,8 +424,8 @@ scale = scale' | |||
420 | arctan2 :: (Fractional e, Container c e) => c e -> c e -> c e | 424 | arctan2 :: (Fractional e, Container c e) => c e -> c e -> c e |
421 | arctan2 = arctan2' | 425 | arctan2 = arctan2' |
422 | 426 | ||
423 | cmod :: (Integral e, Container c e) => e -> c e -> c e | 427 | cmod :: (Integral e, Container c e) => Int -> c e -> c e |
424 | cmod = cmod' | 428 | cmod m = cmod' (fromIntegral m) |
425 | 429 | ||
426 | fromInt :: (Container c e) => c CInt -> c e | 430 | fromInt :: (Container c e) => c CInt -> c e |
427 | fromInt = fromInt' | 431 | fromInt = fromInt' |
diff --git a/packages/base/src/Numeric/LinearAlgebra/Data.hs b/packages/base/src/Numeric/LinearAlgebra/Data.hs index b40054c..8a0b9a2 100644 --- a/packages/base/src/Numeric/LinearAlgebra/Data.hs +++ b/packages/base/src/Numeric/LinearAlgebra/Data.hs | |||
@@ -28,7 +28,7 @@ module Numeric.LinearAlgebra.Data( | |||
28 | Indexable(..), | 28 | Indexable(..), |
29 | 29 | ||
30 | -- * Construction | 30 | -- * Construction |
31 | scalar, Konst(..), Build(..), assoc, accum, linspace, range,-- ones, zeros, | 31 | scalar, Konst(..), Build(..), assoc, accum, linspace, range, idxs, -- ones, zeros, |
32 | 32 | ||
33 | -- * Diagonal | 33 | -- * Diagonal |
34 | ident, diag, diagl, diagRect, takeDiag, | 34 | ident, diag, diagl, diagRect, takeDiag, |
@@ -82,6 +82,6 @@ import Numeric.LinearAlgebra.Util hiding ((&),(#)) | |||
82 | import Data.Complex | 82 | import Data.Complex |
83 | import Numeric.Sparse | 83 | import Numeric.Sparse |
84 | import Data.Packed.Internal.Vector(Idxs) | 84 | import Data.Packed.Internal.Vector(Idxs) |
85 | import Data.Packed.Internal.Numeric(CInt,Extractor(..),(??),fromInt,range) | 85 | import Data.Packed.Internal.Numeric(CInt,Extractor(..),(??),fromInt,range,idxs) |
86 | 86 | ||
87 | 87 | ||