{-# LANGUAGE CPP #-}
module Numeric.GSL.Polynomials (
polySolve
) where
import Numeric.LinearAlgebra.HMatrix
import Numeric.GSL.Internal
import System.IO.Unsafe (unsafePerformIO)
#if __GLASGOW_HASKELL__ >= 704
import Foreign.C.Types (CInt(..))
#endif
polySolve :: [Double] -> [Complex Double]
polySolve :: [Double] -> [Complex Double]
polySolve = Vector (Complex Double) -> [Complex Double]
forall a. Storable a => Vector a -> [a]
toList (Vector (Complex Double) -> [Complex Double])
-> ([Double] -> Vector (Complex Double))
-> [Double]
-> [Complex Double]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector Double -> Vector (Complex Double)
polySolve' (Vector Double -> Vector (Complex Double))
-> ([Double] -> Vector Double)
-> [Double]
-> Vector (Complex Double)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Double] -> Vector Double
forall a. Storable a => [a] -> Vector a
fromList
polySolve' :: Vector Double -> Vector (Complex Double)
polySolve' :: Vector Double -> Vector (Complex Double)
polySolve' v :: Vector Double
v | Vector Double -> IndexOf Vector
forall (c :: * -> *) t. Container c t => c t -> IndexOf c
size Vector Double
v Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> 1 = IO (Vector (Complex Double)) -> Vector (Complex Double)
forall a. IO a -> a
unsafePerformIO (IO (Vector (Complex Double)) -> Vector (Complex Double))
-> IO (Vector (Complex Double)) -> Vector (Complex Double)
forall a b. (a -> b) -> a -> b
$ do
Vector (Complex Double)
r <- Int -> IO (Vector (Complex Double))
forall a. Storable a => Int -> IO (Vector a)
createVector (Vector Double -> IndexOf Vector
forall (c :: * -> *) t. Container c t => c t -> IndexOf c
size Vector Double
vInt -> Int -> Int
forall a. Num a => a -> a -> a
-1)
(Vector Double
v Vector Double
-> ((CInt -> Ptr (Complex Double) -> IO CInt) -> IO CInt)
-> TransRaw
(Vector Double) (CInt -> Ptr (Complex Double) -> IO CInt)
-> IO CInt
forall c b r.
TransArray c =>
c -> (b -> IO r) -> TransRaw c b -> IO r
`applyRaw` (Vector (Complex Double)
r Vector (Complex Double)
-> (IO CInt -> IO CInt)
-> TransRaw (Vector (Complex Double)) (IO CInt)
-> IO CInt
forall c b r.
TransArray c =>
c -> (b -> IO r) -> TransRaw c b -> IO r
`applyRaw` IO CInt -> IO CInt
forall a. a -> a
id)) TransRaw (Vector Double) (CInt -> Ptr (Complex Double) -> IO CInt)
TV (CInt -> Ptr (Complex Double) -> IO CInt)
c_polySolve IO CInt -> String -> IO ()
#| "polySolve"
Vector (Complex Double) -> IO (Vector (Complex Double))
forall (m :: * -> *) a. Monad m => a -> m a
return Vector (Complex Double)
r
| Bool
otherwise = String -> Vector (Complex Double)
forall a. HasCallStack => String -> a
error "polySolve on a polynomial of degree zero"
foreign import ccall unsafe "gsl-aux.h polySolve" c_polySolve:: TV (TCV Res)