From c9914d694d3b86ece46fa0c76e0466c6cd394d14 Mon Sep 17 00:00:00 2001 From: Alberto Ruiz Date: Tue, 6 May 2014 08:50:50 +0200 Subject: extend conformability to empty arrays --- lib/Numeric/Container.hs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'lib/Numeric/Container.hs') 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 {- | Creates a real vector containing a range of values: ->>> linspace 5 (-3,7) +>>> linspace 5 (-3,7::Double) fromList [-3.0,-0.5,2.0,4.5,7.0]@ +>>> linspace 5 (8,2+i) :: Vector (Complex Double) +fromList [8.0 :+ 0.0,6.5 :+ 0.25,5.0 :+ 0.5,3.5 :+ 0.75,2.0 :+ 1.0] + Logarithmic spacing can be defined as follows: @logspace n (a,b) = 10 ** linspace n (a,b)@ -} -linspace :: (Enum e, Container Vector e) => Int -> (e, e) -> Vector e -linspace n (a,b) = addConstant a $ scale s $ fromList [0 .. fromIntegral n-1] +linspace :: (Container Vector e) => Int -> (e, e) -> Vector e +linspace 0 (a,b) = fromList[(a+b)/2] +linspace n (a,b) = addConstant a $ scale s $ fromList $ map fromIntegral [0 .. n-1] where s = (b-a)/fromIntegral (n-1) -- | dot product: @cdot u v = 'udot' ('conj' u) v@ -- cgit v1.2.3