diff options
author | Alberto Ruiz <aruiz@um.es> | 2014-05-06 08:50:50 +0200 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2014-05-06 08:50:50 +0200 |
commit | c9914d694d3b86ece46fa0c76e0466c6cd394d14 (patch) | |
tree | 7fa1c5a95b204912f5d560c843ae6045ee8d2780 /lib/Numeric/Container.hs | |
parent | 4078cf44c98b42960be27843782f6983bb66017f (diff) |
extend conformability to empty arrays
Diffstat (limited to 'lib/Numeric/Container.hs')
-rw-r--r-- | lib/Numeric/Container.hs | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/Numeric/Container.hs b/lib/Numeric/Container.hs index b145a26..dea8a79 100644 --- a/lib/Numeric/Container.hs +++ b/lib/Numeric/Container.hs | |||
@@ -86,15 +86,19 @@ constant = constantD-- about 2x faster | |||
86 | 86 | ||
87 | {- | Creates a real vector containing a range of values: | 87 | {- | Creates a real vector containing a range of values: |
88 | 88 | ||
89 | >>> linspace 5 (-3,7) | 89 | >>> linspace 5 (-3,7::Double) |
90 | fromList [-3.0,-0.5,2.0,4.5,7.0]@ | 90 | fromList [-3.0,-0.5,2.0,4.5,7.0]@ |
91 | 91 | ||
92 | >>> linspace 5 (8,2+i) :: Vector (Complex Double) | ||
93 | fromList [8.0 :+ 0.0,6.5 :+ 0.25,5.0 :+ 0.5,3.5 :+ 0.75,2.0 :+ 1.0] | ||
94 | |||
92 | Logarithmic spacing can be defined as follows: | 95 | Logarithmic spacing can be defined as follows: |
93 | 96 | ||
94 | @logspace n (a,b) = 10 ** linspace n (a,b)@ | 97 | @logspace n (a,b) = 10 ** linspace n (a,b)@ |
95 | -} | 98 | -} |
96 | linspace :: (Enum e, Container Vector e) => Int -> (e, e) -> Vector e | 99 | linspace :: (Container Vector e) => Int -> (e, e) -> Vector e |
97 | linspace n (a,b) = addConstant a $ scale s $ fromList [0 .. fromIntegral n-1] | 100 | linspace 0 (a,b) = fromList[(a+b)/2] |
101 | linspace n (a,b) = addConstant a $ scale s $ fromList $ map fromIntegral [0 .. n-1] | ||
98 | where s = (b-a)/fromIntegral (n-1) | 102 | where s = (b-a)/fromIntegral (n-1) |
99 | 103 | ||
100 | -- | dot product: @cdot u v = 'udot' ('conj' u) v@ | 104 | -- | dot product: @cdot u v = 'udot' ('conj' u) v@ |