summaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2015-05-25 09:23:39 +0200
committerAlberto Ruiz <aruiz@um.es>2015-05-25 09:23:39 +0200
commite803d45acc0fd3202af9ea3844c554a9b807bade (patch)
treeee8982d68735e54c7ce6c8db7f843df18065dc5f /packages
parent11095a22c59bed6a011723641dfb782415e2c02b (diff)
At range, idxs
Diffstat (limited to 'packages')
-rw-r--r--packages/base/src/Data/Packed/Internal/Numeric.hs24
-rw-r--r--packages/base/src/Numeric/LinearAlgebra/Data.hs4
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
70data Extractor 70data 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
79idxs :: [Int] -> Idxs
79idxs js = fromList (map fromIntegral js) :: Idxs 80idxs js = fromList (map fromIntegral js) :: Idxs
80 81
81infixl 9 ?? 82infixl 9 ??
@@ -86,8 +87,9 @@ extractError m e = error $ printf "can't extract %s from matrix %dx%d" (show e)
86 87
87m ?? e@(Range a b,_) | a < 0 || b >= rows m = extractError m e 88m ?? e@(Range a b,_) | a < 0 || b >= rows m = extractError m e
88m ?? e@(_,Range a b) | a < 0 || b >= cols m = extractError m e 89m ?? e@(_,Range a b) | a < 0 || b >= cols m = extractError m e
89m ?? e@(At ps,_) | minimum ps < 0 || maximum ps >= rows m = extractError m e 90
90m ?? e@(_,At ps) | minimum ps < 0 || maximum ps >= cols m = extractError m e 91m ?? e@(At vs,_) | minElement vs < 0 || maxElement vs >= fromIntegral (rows m) = extractError m e
92m ?? e@(_,At vs) | minElement vs < 0 || maxElement vs >= fromIntegral (cols m) = extractError m e
91 93
92m ?? (All,All) = m 94m ?? (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'
420arctan2 :: (Fractional e, Container c e) => c e -> c e -> c e 424arctan2 :: (Fractional e, Container c e) => c e -> c e -> c e
421arctan2 = arctan2' 425arctan2 = arctan2'
422 426
423cmod :: (Integral e, Container c e) => e -> c e -> c e 427cmod :: (Integral e, Container c e) => Int -> c e -> c e
424cmod = cmod' 428cmod m = cmod' (fromIntegral m)
425 429
426fromInt :: (Container c e) => c CInt -> c e 430fromInt :: (Container c e) => c CInt -> c e
427fromInt = fromInt' 431fromInt = 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 ((&),(#))
82import Data.Complex 82import Data.Complex
83import Numeric.Sparse 83import Numeric.Sparse
84import Data.Packed.Internal.Vector(Idxs) 84import Data.Packed.Internal.Vector(Idxs)
85import Data.Packed.Internal.Numeric(CInt,Extractor(..),(??),fromInt,range) 85import Data.Packed.Internal.Numeric(CInt,Extractor(..),(??),fromInt,range,idxs)
86 86
87 87