    {-# LANGUAGE TypeOperators #-}
    {-# LANGUAGE TypeFamilies #-}

    -----------------------------------------------------------------------------
    -- |
    -- Module      :  Numeric.Vectorized
    -- Copyright   :  (c) Alberto Ruiz 2007-15
    -- License     :  BSD3
    -- Maintainer  :  Alberto Ruiz
    -- Stability   :  provisional
    --
    -- Low level interface to vector operations.
    --
    -----------------------------------------------------------------------------

    module Internal.Vectorized where

    import Internal.Vector
    import Internal.Devel
    import Data.Complex
    import Foreign.Marshal.Alloc(free,malloc)
    import Foreign.Marshal.Array(newArray,copyArray)
    import Foreign.Ptr(Ptr)
    import Foreign.Storable(peek,Storable)
    import Foreign.C.Types
    import Foreign.C.String
    import System.IO.Unsafe(unsafePerformIO)
    import Control.Monad(when)

    infixr 1 #
    (#) :: TransArray c => c -> (b -> IO r) -> TransRaw c b -> IO r
    c
    a # :: forall c b r.
    TransArray c =>
    c -> (b -> IO r) -> TransRaw c b -> IO r
    # b -> IO r
    b = c -> (b -> IO r) -> TransRaw c b -> IO r
    forall c b r.
    TransArray c =>
    c -> (b -> IO r) -> TransRaw c b -> IO r
    forall b r. c -> (b -> IO r) -> TransRaw c b -> IO r
    applyRaw c
    a b -> IO r
    b
    {-# INLINE (#) #-}

    (#!) :: (TransArray c, TransArray c1) => c1 -> c -> TransRaw c1 (TransRaw c (IO r)) -> IO r
    c1
    a #! :: forall c c1 r.
    (TransArray c, TransArray c1) =>
    c1 -> c -> TransRaw c1 (TransRaw c (IO r)) -> IO r
    #! c
    b = c1
    a c1
    -> (TransRaw c (IO r) -> IO r)
    -> TransRaw c1 (TransRaw c (IO r))
    -> IO r
    forall c b r.
    TransArray c =>
    c -> (b -> IO r) -> TransRaw c b -> IO r
    # c
    b c -> (IO r -> IO r) -> TransRaw c (IO r) -> IO r
    forall c b r.
    TransArray c =>
    c -> (b -> IO r) -> TransRaw c b -> IO r
    # IO r -> IO r
    forall a. a -> a
    id
    {-# INLINE (#!) #-}

    fromei :: Enum a => a -> CInt
    fromei :: forall a. Enum a => a -> CInt
    fromei a
    x = Int -> CInt
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral (a -> Int
    forall a. Enum a => a -> Int
    fromEnum a
    x) :: CInt

    data FunCodeV = Sin
                  | Cos
                  | Tan
                  | Abs
                  | ASin
                  | ACos
                  | ATan
                  | Sinh
                  | Cosh
                  | Tanh
                  | ASinh
                  | ACosh
                  | ATanh
                  | Exp
                  | Log
                  | Sign
                  | Sqrt
                  deriving Int -> FunCodeV
    FunCodeV -> Int
    FunCodeV -> [FunCodeV]
    FunCodeV -> FunCodeV
    FunCodeV -> FunCodeV -> [FunCodeV]
    FunCodeV -> FunCodeV -> FunCodeV -> [FunCodeV]
    (FunCodeV -> FunCodeV)
    -> (FunCodeV -> FunCodeV)
    -> (Int -> FunCodeV)
    -> (FunCodeV -> Int)
    -> (FunCodeV -> [FunCodeV])
    -> (FunCodeV -> FunCodeV -> [FunCodeV])
    -> (FunCodeV -> FunCodeV -> [FunCodeV])
    -> (FunCodeV -> FunCodeV -> FunCodeV -> [FunCodeV])
    -> Enum FunCodeV
    forall a.
    (a -> a)
    -> (a -> a)
    -> (Int -> a)
    -> (a -> Int)
    -> (a -> [a])
    -> (a -> a -> [a])
    -> (a -> a -> [a])
    -> (a -> a -> a -> [a])
    -> Enum a
    $csucc :: FunCodeV -> FunCodeV
    succ :: FunCodeV -> FunCodeV
    $cpred :: FunCodeV -> FunCodeV
    pred :: FunCodeV -> FunCodeV
    $ctoEnum :: Int -> FunCodeV
    toEnum :: Int -> FunCodeV
    $cfromEnum :: FunCodeV -> Int
    fromEnum :: FunCodeV -> Int
    $cenumFrom :: FunCodeV -> [FunCodeV]
    enumFrom :: FunCodeV -> [FunCodeV]
    $cenumFromThen :: FunCodeV -> FunCodeV -> [FunCodeV]
    enumFromThen :: FunCodeV -> FunCodeV -> [FunCodeV]
    $cenumFromTo :: FunCodeV -> FunCodeV -> [FunCodeV]
    enumFromTo :: FunCodeV -> FunCodeV -> [FunCodeV]
    $cenumFromThenTo :: FunCodeV -> FunCodeV -> FunCodeV -> [FunCodeV]
    enumFromThenTo :: FunCodeV -> FunCodeV -> FunCodeV -> [FunCodeV]
    Enum

    data FunCodeSV = Scale
                   | Recip
                   | AddConstant
                   | Negate
                   | PowSV
                   | PowVS
                   | ModSV
                   | ModVS
                   deriving Int -> FunCodeSV
    FunCodeSV -> Int
    FunCodeSV -> [FunCodeSV]
    FunCodeSV -> FunCodeSV
    FunCodeSV -> FunCodeSV -> [FunCodeSV]
    FunCodeSV -> FunCodeSV -> FunCodeSV -> [FunCodeSV]
    (FunCodeSV -> FunCodeSV)
    -> (FunCodeSV -> FunCodeSV)
    -> (Int -> FunCodeSV)
    -> (FunCodeSV -> Int)
    -> (FunCodeSV -> [FunCodeSV])
    -> (FunCodeSV -> FunCodeSV -> [FunCodeSV])
    -> (FunCodeSV -> FunCodeSV -> [FunCodeSV])
    -> (FunCodeSV -> FunCodeSV -> FunCodeSV -> [FunCodeSV])
    -> Enum FunCodeSV
    forall a.
    (a -> a)
    -> (a -> a)
    -> (Int -> a)
    -> (a -> Int)
    -> (a -> [a])
    -> (a -> a -> [a])
    -> (a -> a -> [a])
    -> (a -> a -> a -> [a])
    -> Enum a
    $csucc :: FunCodeSV -> FunCodeSV
    succ :: FunCodeSV -> FunCodeSV
    $cpred :: FunCodeSV -> FunCodeSV
    pred :: FunCodeSV -> FunCodeSV
    $ctoEnum :: Int -> FunCodeSV
    toEnum :: Int -> FunCodeSV
    $cfromEnum :: FunCodeSV -> Int
    fromEnum :: FunCodeSV -> Int
    $cenumFrom :: FunCodeSV -> [FunCodeSV]
    enumFrom :: FunCodeSV -> [FunCodeSV]
    $cenumFromThen :: FunCodeSV -> FunCodeSV -> [FunCodeSV]
    enumFromThen :: FunCodeSV -> FunCodeSV -> [FunCodeSV]
    $cenumFromTo :: FunCodeSV -> FunCodeSV -> [FunCodeSV]
    enumFromTo :: FunCodeSV -> FunCodeSV -> [FunCodeSV]
    $cenumFromThenTo :: FunCodeSV -> FunCodeSV -> FunCodeSV -> [FunCodeSV]
    enumFromThenTo :: FunCodeSV -> FunCodeSV -> FunCodeSV -> [FunCodeSV]
    Enum

    data FunCodeVV = Add
                   | Sub
                   | Mul
                   | Div
                   | Pow
                   | ATan2
                   | Mod
                   deriving Int -> FunCodeVV
    FunCodeVV -> Int
    FunCodeVV -> [FunCodeVV]
    FunCodeVV -> FunCodeVV
    FunCodeVV -> FunCodeVV -> [FunCodeVV]
    FunCodeVV -> FunCodeVV -> FunCodeVV -> [FunCodeVV]
    (FunCodeVV -> FunCodeVV)
    -> (FunCodeVV -> FunCodeVV)
    -> (Int -> FunCodeVV)
    -> (FunCodeVV -> Int)
    -> (FunCodeVV -> [FunCodeVV])
    -> (FunCodeVV -> FunCodeVV -> [FunCodeVV])
    -> (FunCodeVV -> FunCodeVV -> [FunCodeVV])
    -> (FunCodeVV -> FunCodeVV -> FunCodeVV -> [FunCodeVV])
    -> Enum FunCodeVV
    forall a.
    (a -> a)
    -> (a -> a)
    -> (Int -> a)
    -> (a -> Int)
    -> (a -> [a])
    -> (a -> a -> [a])
    -> (a -> a -> [a])
    -> (a -> a -> a -> [a])
    -> Enum a
    $csucc :: FunCodeVV -> FunCodeVV
    succ :: FunCodeVV -> FunCodeVV
    $cpred :: FunCodeVV -> FunCodeVV
    pred :: FunCodeVV -> FunCodeVV
    $ctoEnum :: Int -> FunCodeVV
    toEnum :: Int -> FunCodeVV
    $cfromEnum :: FunCodeVV -> Int
    fromEnum :: FunCodeVV -> Int
    $cenumFrom :: FunCodeVV -> [FunCodeVV]
    enumFrom :: FunCodeVV -> [FunCodeVV]
    $cenumFromThen :: FunCodeVV -> FunCodeVV -> [FunCodeVV]
    enumFromThen :: FunCodeVV -> FunCodeVV -> [FunCodeVV]
    $cenumFromTo :: FunCodeVV -> FunCodeVV -> [FunCodeVV]
    enumFromTo :: FunCodeVV -> FunCodeVV -> [FunCodeVV]
    $cenumFromThenTo :: FunCodeVV -> FunCodeVV -> FunCodeVV -> [FunCodeVV]
    enumFromThenTo :: FunCodeVV -> FunCodeVV -> FunCodeVV -> [FunCodeVV]
    Enum

    data FunCodeS = Norm2
                  | AbsSum
                  | MaxIdx
                  | Max
                  | MinIdx
                  | Min
                  deriving Int -> FunCodeS
    FunCodeS -> Int
    FunCodeS -> [FunCodeS]
    FunCodeS -> FunCodeS
    FunCodeS -> FunCodeS -> [FunCodeS]
    FunCodeS -> FunCodeS -> FunCodeS -> [FunCodeS]
    (FunCodeS -> FunCodeS)
    -> (FunCodeS -> FunCodeS)
    -> (Int -> FunCodeS)
    -> (FunCodeS -> Int)
    -> (FunCodeS -> [FunCodeS])
    -> (FunCodeS -> FunCodeS -> [FunCodeS])
    -> (FunCodeS -> FunCodeS -> [FunCodeS])
    -> (FunCodeS -> FunCodeS -> FunCodeS -> [FunCodeS])
    -> Enum FunCodeS
    forall a.
    (a -> a)
    -> (a -> a)
    -> (Int -> a)
    -> (a -> Int)
    -> (a -> [a])
    -> (a -> a -> [a])
    -> (a -> a -> [a])
    -> (a -> a -> a -> [a])
    -> Enum a
    $csucc :: FunCodeS -> FunCodeS
    succ :: FunCodeS -> FunCodeS
    $cpred :: FunCodeS -> FunCodeS
    pred :: FunCodeS -> FunCodeS
    $ctoEnum :: Int -> FunCodeS
    toEnum :: Int -> FunCodeS
    $cfromEnum :: FunCodeS -> Int
    fromEnum :: FunCodeS -> Int
    $cenumFrom :: FunCodeS -> [FunCodeS]
    enumFrom :: FunCodeS -> [FunCodeS]
    $cenumFromThen :: FunCodeS -> FunCodeS -> [FunCodeS]
    enumFromThen :: FunCodeS -> FunCodeS -> [FunCodeS]
    $cenumFromTo :: FunCodeS -> FunCodeS -> [FunCodeS]
    enumFromTo :: FunCodeS -> FunCodeS -> [FunCodeS]
    $cenumFromThenTo :: FunCodeS -> FunCodeS -> FunCodeS -> [FunCodeS]
    enumFromThenTo :: FunCodeS -> FunCodeS -> FunCodeS -> [FunCodeS]
    Enum

    ------------------------------------------------------------------

    -- | sum of elements
    sumF :: Vector Float -> Float
    sumF :: Vector Float -> Float
    sumF = TransRaw (Vector Float) (CInt -> Ptr Float -> IO CInt)
    -> Vector Float -> Float
    forall c a.
    (TransArray c, Storable a) =>
    TransRaw c (CInt -> Ptr a -> IO CInt) -> c -> a
    sumg TransRaw (Vector Float) (CInt -> Ptr Float -> IO CInt)
    TVV Float
    c_sumF

    -- | sum of elements
    sumR :: Vector Double -> Double
    sumR :: Vector Double -> Double
    sumR = TransRaw (Vector Double) (CInt -> Ptr Double -> IO CInt)
    -> Vector Double -> Double
    forall c a.
    (TransArray c, Storable a) =>
    TransRaw c (CInt -> Ptr a -> IO CInt) -> c -> a
    sumg TransRaw (Vector Double) (CInt -> Ptr Double -> IO CInt)
    TVV Double
    c_sumR

    -- | sum of elements
    sumQ :: Vector (Complex Float) -> Complex Float
    sumQ :: Vector (Complex Float) -> Complex Float
    sumQ = TransRaw
      (Vector (Complex Float)) (CInt -> Ptr (Complex Float) -> IO CInt)
    -> Vector (Complex Float) -> Complex Float
    forall c a.
    (TransArray c, Storable a) =>
    TransRaw c (CInt -> Ptr a -> IO CInt) -> c -> a
    sumg TransRaw
      (Vector (Complex Float)) (CInt -> Ptr (Complex Float) -> IO CInt)
    TVV (Complex Float)
    c_sumQ

    -- | sum of elements
    sumC :: Vector (Complex Double) -> Complex Double
    sumC :: Vector (Complex Double) -> Complex Double
    sumC = TransRaw
      (Vector (Complex Double)) (CInt -> Ptr (Complex Double) -> IO CInt)
    -> Vector (Complex Double) -> Complex Double
    forall c a.
    (TransArray c, Storable a) =>
    TransRaw c (CInt -> Ptr a -> IO CInt) -> c -> a
    sumg TransRaw
      (Vector (Complex Double)) (CInt -> Ptr (Complex Double) -> IO CInt)
    TVV (Complex Double)
    c_sumC

    sumI :: ( TransRaw c (CInt -> Ptr a -> IO CInt) ~ (CInt -> Ptr I -> I :> Ok)
            , TransArray c
            , Storable a
            )
         => I -> c -> a
    sumI :: forall c a.
    (TransRaw c (CInt -> Ptr a -> IO CInt)
     ~ (CInt -> Ptr CInt -> CInt :> IO CInt),
     TransArray c, Storable a) =>
    CInt -> c -> a
    sumI CInt
    m = TransRaw c (CInt -> Ptr a -> IO CInt) -> c -> a
    forall c a.
    (TransArray c, Storable a) =>
    TransRaw c (CInt -> Ptr a -> IO CInt) -> c -> a
    sumg (CInt -> CInt -> Ptr CInt -> CInt :> IO CInt
    c_sumI CInt
    m)

    sumL :: ( TransRaw c (CInt -> Ptr a -> IO CInt) ~ (CInt -> Ptr Z -> Z :> Ok)
            , TransArray c
            , Storable a
            ) => Z -> c -> a
    sumL :: forall c a.
    (TransRaw c (CInt -> Ptr a -> IO CInt)
     ~ (CInt -> Ptr Z -> Z :> IO CInt),
     TransArray c, Storable a) =>
    Z -> c -> a
    sumL Z
    m = TransRaw c (CInt -> Ptr a -> IO CInt) -> c -> a
    forall c a.
    (TransArray c, Storable a) =>
    TransRaw c (CInt -> Ptr a -> IO CInt) -> c -> a
    sumg (Z -> CInt -> Ptr Z -> Z :> IO CInt
    c_sumL Z
    m)

    sumg :: (TransArray c, Storable a) => TransRaw c (CInt -> Ptr a -> IO CInt) -> c -> a
    sumg :: forall c a.
    (TransArray c, Storable a) =>
    TransRaw c (CInt -> Ptr a -> IO CInt) -> c -> a
    sumg TransRaw c (CInt -> Ptr a -> IO CInt)
    f c
    x = IO a -> a
    forall a. IO a -> a
    unsafePerformIO (IO a -> a) -> IO a -> a
    forall a b. (a -> b) -> a -> b
    $ do
        r <- Int -> IO (Vector a)
    forall a. Storable a => Int -> IO (Vector a)
    createVector Int
    1
        (x #! r) f #| "sum"
        return $ r @> 0

    type TVV t = t :> t :> Ok

    foreign import ccall unsafe "sumF" c_sumF :: TVV Float
    foreign import ccall unsafe "sumR" c_sumR :: TVV Double
    foreign import ccall unsafe "sumQ" c_sumQ :: TVV (Complex Float)
    foreign import ccall unsafe "sumC" c_sumC :: TVV (Complex Double)
    foreign import ccall unsafe "sumI" c_sumI :: I -> TVV I
    foreign import ccall unsafe "sumL" c_sumL :: Z -> TVV Z

    -- | product of elements
    prodF :: Vector Float -> Float
    prodF :: Vector Float -> Float
    prodF = TransRaw (Vector Float) (CInt -> Ptr Float -> IO CInt)
    -> Vector Float -> Float
    forall c a.
    (TransArray c, Storable a) =>
    TransRaw c (CInt -> Ptr a -> IO CInt) -> c -> a
    prodg TransRaw (Vector Float) (CInt -> Ptr Float -> IO CInt)
    TVV Float
    c_prodF

    -- | product of elements
    prodR :: Vector Double -> Double
    prodR :: Vector Double -> Double
    prodR = TransRaw (Vector Double) (CInt -> Ptr Double -> IO CInt)
    -> Vector Double -> Double
    forall c a.
    (TransArray c, Storable a) =>
    TransRaw c (CInt -> Ptr a -> IO CInt) -> c -> a
    prodg TransRaw (Vector Double) (CInt -> Ptr Double -> IO CInt)
    TVV Double
    c_prodR

    -- | product of elements
    prodQ :: Vector (Complex Float) -> Complex Float
    prodQ :: Vector (Complex Float) -> Complex Float
    prodQ = TransRaw
      (Vector (Complex Float)) (CInt -> Ptr (Complex Float) -> IO CInt)
    -> Vector (Complex Float) -> Complex Float
    forall c a.
    (TransArray c, Storable a) =>
    TransRaw c (CInt -> Ptr a -> IO CInt) -> c -> a
    prodg TransRaw
      (Vector (Complex Float)) (CInt -> Ptr (Complex Float) -> IO CInt)
    TVV (Complex Float)
    c_prodQ

    -- | product of elements
    prodC :: Vector (Complex Double) -> Complex Double
    prodC :: Vector (Complex Double) -> Complex Double
    prodC = TransRaw
      (Vector (Complex Double)) (CInt -> Ptr (Complex Double) -> IO CInt)
    -> Vector (Complex Double) -> Complex Double
    forall c a.
    (TransArray c, Storable a) =>
    TransRaw c (CInt -> Ptr a -> IO CInt) -> c -> a
    prodg TransRaw
      (Vector (Complex Double)) (CInt -> Ptr (Complex Double) -> IO CInt)
    TVV (Complex Double)
    c_prodC

    prodI :: I-> Vector I -> I
    prodI :: CInt -> Vector CInt -> CInt
    prodI = TransRaw (Vector CInt) (CInt :> IO CInt) -> Vector CInt -> CInt
    (CInt -> Ptr CInt -> CInt :> IO CInt) -> Vector CInt -> CInt
    forall c a.
    (TransArray c, Storable a) =>
    TransRaw c (CInt -> Ptr a -> IO CInt) -> c -> a
    prodg ((CInt -> Ptr CInt -> CInt :> IO CInt) -> Vector CInt -> CInt)
    -> (CInt -> CInt -> Ptr CInt -> CInt :> IO CInt)
    -> CInt
    -> Vector CInt
    -> CInt
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . CInt -> CInt -> Ptr CInt -> CInt :> IO CInt
    c_prodI

    prodL :: Z-> Vector Z -> Z
    prodL :: Z -> Vector Z -> Z
    prodL = TransRaw (Vector Z) (Z :> IO CInt) -> Vector Z -> Z
    (CInt -> Ptr Z -> Z :> IO CInt) -> Vector Z -> Z
    forall c a.
    (TransArray c, Storable a) =>
    TransRaw c (CInt -> Ptr a -> IO CInt) -> c -> a
    prodg ((CInt -> Ptr Z -> Z :> IO CInt) -> Vector Z -> Z)
    -> (Z -> CInt -> Ptr Z -> Z :> IO CInt) -> Z -> Vector Z -> Z
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Z -> CInt -> Ptr Z -> Z :> IO CInt
    c_prodL

    prodg :: (TransArray c, Storable a)
          => TransRaw c (CInt -> Ptr a -> IO CInt) -> c -> a
    prodg :: forall c a.
    (TransArray c, Storable a) =>
    TransRaw c (CInt -> Ptr a -> IO CInt) -> c -> a
    prodg TransRaw c (CInt -> Ptr a -> IO CInt)
    f c
    x = IO a -> a
    forall a. IO a -> a
    unsafePerformIO (IO a -> a) -> IO a -> a
    forall a b. (a -> b) -> a -> b
    $ do
        r <- Int -> IO (Vector a)
    forall a. Storable a => Int -> IO (Vector a)
    createVector Int
    1
        (x #! r) f #| "prod"
        return $ r @> 0

    foreign import ccall unsafe "prodF" c_prodF :: TVV Float
    foreign import ccall unsafe "prodR" c_prodR :: TVV Double
    foreign import ccall unsafe "prodQ" c_prodQ :: TVV (Complex Float)
    foreign import ccall unsafe "prodC" c_prodC :: TVV (Complex Double)
    foreign import ccall unsafe "prodI" c_prodI :: I -> TVV I
    foreign import ccall unsafe "prodL" c_prodL :: Z -> TVV Z

    ------------------------------------------------------------------

    toScalarAux :: (Enum a, TransArray c, Storable a1)
                => (CInt -> TransRaw c (CInt -> Ptr a1 -> IO CInt)) -> a -> c -> a1
    toScalarAux :: forall a c a1.
    (Enum a, TransArray c, Storable a1) =>
    (CInt -> TransRaw c (CInt -> Ptr a1 -> IO CInt)) -> a -> c -> a1
    toScalarAux CInt -> TransRaw c (CInt -> Ptr a1 -> IO CInt)
    fun a
    code c
    v = IO a1 -> a1
    forall a. IO a -> a
    unsafePerformIO (IO a1 -> a1) -> IO a1 -> a1
    forall a b. (a -> b) -> a -> b
    $ do
        r <- Int -> IO (Vector a1)
    forall a. Storable a => Int -> IO (Vector a)
    createVector Int
    1
        (v #! r) (fun (fromei code)) #|"toScalarAux"
        return (r @> 0)

    vectorMapAux :: (Enum a, Storable t, Storable a1)
                 => (CInt -> CInt -> Ptr t -> CInt -> Ptr a1 -> IO CInt)
                 -> a -> Vector t -> Vector a1
    vectorMapAux :: forall a t a1.
    (Enum a, Storable t, Storable a1) =>
    (CInt -> CInt -> Ptr t -> CInt -> Ptr a1 -> IO CInt)
    -> a -> Vector t -> Vector a1
    vectorMapAux CInt -> CInt -> Ptr t -> CInt -> Ptr a1 -> IO CInt
    fun a
    code Vector t
    v = IO (Vector a1) -> Vector a1
    forall a. IO a -> a
    unsafePerformIO (IO (Vector a1) -> Vector a1) -> IO (Vector a1) -> Vector a1
    forall a b. (a -> b) -> a -> b
    $ do
        r <- Int -> IO (Vector a1)
    forall a. Storable a => Int -> IO (Vector a)
    createVector (Vector t -> Int
    forall t. Storable t => Vector t -> Int
    dim Vector t
    v)
        (v #! r) (fun (fromei code)) #|"vectorMapAux"
        return r

    vectorMapValAux :: (Enum a, Storable a2, Storable t, Storable a1)
                    => (CInt -> Ptr a2 -> CInt -> Ptr t -> CInt -> Ptr a1 -> IO CInt)
                    -> a -> a2 -> Vector t -> Vector a1
    vectorMapValAux :: forall a a2 t a1.
    (Enum a, Storable a2, Storable t, Storable a1) =>
    (CInt -> Ptr a2 -> CInt -> Ptr t -> CInt -> Ptr a1 -> IO CInt)
    -> a -> a2 -> Vector t -> Vector a1
    vectorMapValAux CInt -> Ptr a2 -> CInt -> Ptr t -> CInt -> Ptr a1 -> IO CInt
    fun a
    code a2
    val Vector t
    v = IO (Vector a1) -> Vector a1
    forall a. IO a -> a
    unsafePerformIO (IO (Vector a1) -> Vector a1) -> IO (Vector a1) -> Vector a1
    forall a b. (a -> b) -> a -> b
    $ do
        r <- Int -> IO (Vector a1)
    forall a. Storable a => Int -> IO (Vector a)
    createVector (Vector t -> Int
    forall t. Storable t => Vector t -> Int
    dim Vector t
    v)
        pval <- newArray [val]
        (v #! r) (fun (fromei code) pval) #|"vectorMapValAux"
        free pval
        return r

    vectorZipAux :: (Enum a, TransArray c, Storable t, Storable a1)
                 => (CInt -> CInt -> Ptr t -> TransRaw c (CInt -> Ptr a1 -> IO CInt))
                 -> a -> Vector t -> c -> Vector a1
    vectorZipAux :: forall a c t a1.
    (Enum a, TransArray c, Storable t, Storable a1) =>
    (CInt -> CInt -> Ptr t -> TransRaw c (CInt -> Ptr a1 -> IO CInt))
    -> a -> Vector t -> c -> Vector a1
    vectorZipAux CInt -> CInt -> Ptr t -> TransRaw c (CInt -> Ptr a1 -> IO CInt)
    fun a
    code Vector t
    u c
    v = IO (Vector a1) -> Vector a1
    forall a. IO a -> a
    unsafePerformIO (IO (Vector a1) -> Vector a1) -> IO (Vector a1) -> Vector a1
    forall a b. (a -> b) -> a -> b
    $ do
        r <- Int -> IO (Vector a1)
    forall a. Storable a => Int -> IO (Vector a)
    createVector (Vector t -> Int
    forall t. Storable t => Vector t -> Int
    dim Vector t
    u)
        (u # v #! r) (fun (fromei code)) #|"vectorZipAux"
        return r

    ---------------------------------------------------------------------

    -- | obtains different functions of a vector: norm1, norm2, max, min, posmax, posmin, etc.
    toScalarR :: FunCodeS -> Vector Double -> Double
    toScalarR :: FunCodeS -> Vector Double -> Double
    toScalarR FunCodeS
    oper =  (CInt -> TransRaw (Vector Double) (CInt -> Ptr Double -> IO CInt))
    -> CInt -> Vector Double -> Double
    forall a c a1.
    (Enum a, TransArray c, Storable a1) =>
    (CInt -> TransRaw c (CInt -> Ptr a1 -> IO CInt)) -> a -> c -> a1
    toScalarAux CInt -> TransRaw (Vector Double) (CInt -> Ptr Double -> IO CInt)
    CInt -> TVV Double
    c_toScalarR (FunCodeS -> CInt
    forall a. Enum a => a -> CInt
    fromei FunCodeS
    oper)

    foreign import ccall unsafe "toScalarR" c_toScalarR :: CInt -> TVV Double

    -- | obtains different functions of a vector: norm1, norm2, max, min, posmax, posmin, etc.
    toScalarF :: FunCodeS -> Vector Float -> Float
    toScalarF :: FunCodeS -> Vector Float -> Float
    toScalarF FunCodeS
    oper =  (CInt -> TransRaw (Vector Float) (CInt -> Ptr Float -> IO CInt))
    -> CInt -> Vector Float -> Float
    forall a c a1.
    (Enum a, TransArray c, Storable a1) =>
    (CInt -> TransRaw c (CInt -> Ptr a1 -> IO CInt)) -> a -> c -> a1
    toScalarAux CInt -> TransRaw (Vector Float) (CInt -> Ptr Float -> IO CInt)
    CInt -> TVV Float
    c_toScalarF (FunCodeS -> CInt
    forall a. Enum a => a -> CInt
    fromei FunCodeS
    oper)

    foreign import ccall unsafe "toScalarF" c_toScalarF :: CInt -> TVV Float

    -- | obtains different functions of a vector: only norm1, norm2
    toScalarC :: FunCodeS -> Vector (Complex Double) -> Double
    toScalarC :: FunCodeS -> Vector (Complex Double) -> Double
    toScalarC FunCodeS
    oper =  (CInt
     -> TransRaw
          (Vector (Complex Double)) (CInt -> Ptr Double -> IO CInt))
    -> CInt -> Vector (Complex Double) -> Double
    forall a c a1.
    (Enum a, TransArray c, Storable a1) =>
    (CInt -> TransRaw c (CInt -> Ptr a1 -> IO CInt)) -> a -> c -> a1
    toScalarAux CInt
    -> TransRaw
         (Vector (Complex Double)) (CInt -> Ptr Double -> IO CInt)
    CInt -> Complex Double :> (CInt -> Ptr Double -> IO CInt)
    c_toScalarC (FunCodeS -> CInt
    forall a. Enum a => a -> CInt
    fromei FunCodeS
    oper)

    foreign import ccall unsafe "toScalarC" c_toScalarC :: CInt -> Complex Double :> Double :> Ok

    -- | obtains different functions of a vector: only norm1, norm2
    toScalarQ :: FunCodeS -> Vector (Complex Float) -> Float
    toScalarQ :: FunCodeS -> Vector (Complex Float) -> Float
    toScalarQ FunCodeS
    oper =  (CInt
     -> TransRaw
          (Vector (Complex Float)) (CInt -> Ptr Float -> IO CInt))
    -> CInt -> Vector (Complex Float) -> Float
    forall a c a1.
    (Enum a, TransArray c, Storable a1) =>
    (CInt -> TransRaw c (CInt -> Ptr a1 -> IO CInt)) -> a -> c -> a1
    toScalarAux CInt
    -> TransRaw (Vector (Complex Float)) (CInt -> Ptr Float -> IO CInt)
    CInt -> Complex Float :> (CInt -> Ptr Float -> IO CInt)
    c_toScalarQ (FunCodeS -> CInt
    forall a. Enum a => a -> CInt
    fromei FunCodeS
    oper)

    foreign import ccall unsafe "toScalarQ" c_toScalarQ :: CInt -> Complex Float :> Float :> Ok

    -- | obtains different functions of a vector: norm1, norm2, max, min, posmax, posmin, etc.
    toScalarI :: FunCodeS -> Vector CInt -> CInt
    toScalarI :: FunCodeS -> Vector CInt -> CInt
    toScalarI FunCodeS
    oper =  (CInt -> TransRaw (Vector CInt) (CInt :> IO CInt))
    -> CInt -> Vector CInt -> CInt
    forall a c a1.
    (Enum a, TransArray c, Storable a1) =>
    (CInt -> TransRaw c (CInt -> Ptr a1 -> IO CInt)) -> a -> c -> a1
    toScalarAux CInt -> TransRaw (Vector CInt) (CInt :> IO CInt)
    CInt -> CInt -> Ptr CInt -> CInt :> IO CInt
    c_toScalarI (FunCodeS -> CInt
    forall a. Enum a => a -> CInt
    fromei FunCodeS
    oper)

    foreign import ccall unsafe "toScalarI" c_toScalarI :: CInt -> TVV CInt

    -- | obtains different functions of a vector: norm1, norm2, max, min, posmax, posmin, etc.
    toScalarL :: FunCodeS -> Vector Z -> Z
    toScalarL :: FunCodeS -> Vector Z -> Z
    toScalarL FunCodeS
    oper =  (CInt -> TransRaw (Vector Z) (Z :> IO CInt))
    -> CInt -> Vector Z -> Z
    forall a c a1.
    (Enum a, TransArray c, Storable a1) =>
    (CInt -> TransRaw c (CInt -> Ptr a1 -> IO CInt)) -> a -> c -> a1
    toScalarAux CInt -> TransRaw (Vector Z) (Z :> IO CInt)
    CInt -> CInt -> Ptr Z -> Z :> IO CInt
    c_toScalarL (FunCodeS -> CInt
    forall a. Enum a => a -> CInt
    fromei FunCodeS
    oper)

    foreign import ccall unsafe "toScalarL" c_toScalarL :: CInt -> TVV Z

    ------------------------------------------------------------------

    -- | map of real vectors with given function
    vectorMapR :: FunCodeV -> Vector Double -> Vector Double
    vectorMapR :: FunCodeV -> Vector Double -> Vector Double
    vectorMapR = (CInt -> TVV Double) -> FunCodeV -> Vector Double -> Vector Double
    forall a t a1.
    (Enum a, Storable t, Storable a1) =>
    (CInt -> CInt -> Ptr t -> CInt -> Ptr a1 -> IO CInt)
    -> a -> Vector t -> Vector a1
    vectorMapAux CInt -> TVV Double
    c_vectorMapR

    foreign import ccall unsafe "mapR" c_vectorMapR :: CInt -> TVV Double

    -- | map of complex vectors with given function
    vectorMapC :: FunCodeV -> Vector (Complex Double) -> Vector (Complex Double)
    vectorMapC :: FunCodeV -> Vector (Complex Double) -> Vector (Complex Double)
    vectorMapC FunCodeV
    oper = (CInt -> TVV (Complex Double))
    -> CInt -> Vector (Complex Double) -> Vector (Complex Double)
    forall a t a1.
    (Enum a, Storable t, Storable a1) =>
    (CInt -> CInt -> Ptr t -> CInt -> Ptr a1 -> IO CInt)
    -> a -> Vector t -> Vector a1
    vectorMapAux CInt -> TVV (Complex Double)
    c_vectorMapC (FunCodeV -> CInt
    forall a. Enum a => a -> CInt
    fromei FunCodeV
    oper)

    foreign import ccall unsafe "mapC" c_vectorMapC :: CInt -> TVV (Complex Double)

    -- | map of real vectors with given function
    vectorMapF :: FunCodeV -> Vector Float -> Vector Float
    vectorMapF :: FunCodeV -> Vector Float -> Vector Float
    vectorMapF = (CInt -> TVV Float) -> FunCodeV -> Vector Float -> Vector Float
    forall a t a1.
    (Enum a, Storable t, Storable a1) =>
    (CInt -> CInt -> Ptr t -> CInt -> Ptr a1 -> IO CInt)
    -> a -> Vector t -> Vector a1
    vectorMapAux CInt -> TVV Float
    c_vectorMapF

    foreign import ccall unsafe "mapF" c_vectorMapF :: CInt -> TVV Float

    -- | map of real vectors with given function
    vectorMapQ :: FunCodeV -> Vector (Complex Float) -> Vector (Complex Float)
    vectorMapQ :: FunCodeV -> Vector (Complex Float) -> Vector (Complex Float)
    vectorMapQ = (CInt -> TVV (Complex Float))
    -> FunCodeV -> Vector (Complex Float) -> Vector (Complex Float)
    forall a t a1.
    (Enum a, Storable t, Storable a1) =>
    (CInt -> CInt -> Ptr t -> CInt -> Ptr a1 -> IO CInt)
    -> a -> Vector t -> Vector a1
    vectorMapAux CInt -> TVV (Complex Float)
    c_vectorMapQ

    foreign import ccall unsafe "mapQ" c_vectorMapQ :: CInt -> TVV (Complex Float)

    -- | map of real vectors with given function
    vectorMapI :: FunCodeV -> Vector CInt -> Vector CInt
    vectorMapI :: FunCodeV -> Vector CInt -> Vector CInt
    vectorMapI = (CInt -> CInt -> Ptr CInt -> CInt :> IO CInt)
    -> FunCodeV -> Vector CInt -> Vector CInt
    forall a t a1.
    (Enum a, Storable t, Storable a1) =>
    (CInt -> CInt -> Ptr t -> CInt -> Ptr a1 -> IO CInt)
    -> a -> Vector t -> Vector a1
    vectorMapAux CInt -> CInt -> Ptr CInt -> CInt :> IO CInt
    c_vectorMapI

    foreign import ccall unsafe "mapI" c_vectorMapI :: CInt -> TVV CInt

    -- | map of real vectors with given function
    vectorMapL :: FunCodeV -> Vector Z -> Vector Z
    vectorMapL :: FunCodeV -> Vector Z -> Vector Z
    vectorMapL = (CInt -> CInt -> Ptr Z -> Z :> IO CInt)
    -> FunCodeV -> Vector Z -> Vector Z
    forall a t a1.
    (Enum a, Storable t, Storable a1) =>
    (CInt -> CInt -> Ptr t -> CInt -> Ptr a1 -> IO CInt)
    -> a -> Vector t -> Vector a1
    vectorMapAux CInt -> CInt -> Ptr Z -> Z :> IO CInt
    c_vectorMapL

    foreign import ccall unsafe "mapL" c_vectorMapL :: CInt -> TVV Z

    -------------------------------------------------------------------

    -- | map of real vectors with given function
    vectorMapValR :: FunCodeSV -> Double -> Vector Double -> Vector Double
    vectorMapValR :: FunCodeSV -> Double -> Vector Double -> Vector Double
    vectorMapValR FunCodeSV
    oper = (CInt -> Ptr Double -> TVV Double)
    -> CInt -> Double -> Vector Double -> Vector Double
    forall a a2 t a1.
    (Enum a, Storable a2, Storable t, Storable a1) =>
    (CInt -> Ptr a2 -> CInt -> Ptr t -> CInt -> Ptr a1 -> IO CInt)
    -> a -> a2 -> Vector t -> Vector a1
    vectorMapValAux CInt -> Ptr Double -> TVV Double
    c_vectorMapValR (FunCodeSV -> CInt
    forall a. Enum a => a -> CInt
    fromei FunCodeSV
    oper)

    foreign import ccall unsafe "mapValR" c_vectorMapValR :: CInt -> Ptr Double -> TVV Double

    -- | map of complex vectors with given function
    vectorMapValC :: FunCodeSV -> Complex Double -> Vector (Complex Double) -> Vector (Complex Double)
    vectorMapValC :: FunCodeSV
    -> Complex Double
    -> Vector (Complex Double)
    -> Vector (Complex Double)
    vectorMapValC = (CInt -> Ptr (Complex Double) -> TVV (Complex Double))
    -> FunCodeSV
    -> Complex Double
    -> Vector (Complex Double)
    -> Vector (Complex Double)
    forall a a2 t a1.
    (Enum a, Storable a2, Storable t, Storable a1) =>
    (CInt -> Ptr a2 -> CInt -> Ptr t -> CInt -> Ptr a1 -> IO CInt)
    -> a -> a2 -> Vector t -> Vector a1
    vectorMapValAux CInt -> Ptr (Complex Double) -> TVV (Complex Double)
    c_vectorMapValC

    foreign import ccall unsafe "mapValC" c_vectorMapValC :: CInt -> Ptr (Complex Double) -> TVV (Complex Double)

    -- | map of real vectors with given function
    vectorMapValF :: FunCodeSV -> Float -> Vector Float -> Vector Float
    vectorMapValF :: FunCodeSV -> Float -> Vector Float -> Vector Float
    vectorMapValF FunCodeSV
    oper = (CInt -> Ptr Float -> TVV Float)
    -> CInt -> Float -> Vector Float -> Vector Float
    forall a a2 t a1.
    (Enum a, Storable a2, Storable t, Storable a1) =>
    (CInt -> Ptr a2 -> CInt -> Ptr t -> CInt -> Ptr a1 -> IO CInt)
    -> a -> a2 -> Vector t -> Vector a1
    vectorMapValAux CInt -> Ptr Float -> TVV Float
    c_vectorMapValF (FunCodeSV -> CInt
    forall a. Enum a => a -> CInt
    fromei FunCodeSV
    oper)

    foreign import ccall unsafe "mapValF" c_vectorMapValF :: CInt -> Ptr Float -> TVV Float

    -- | map of complex vectors with given function
    vectorMapValQ :: FunCodeSV -> Complex Float -> Vector (Complex Float) -> Vector (Complex Float)
    vectorMapValQ :: FunCodeSV
    -> Complex Float
    -> Vector (Complex Float)
    -> Vector (Complex Float)
    vectorMapValQ FunCodeSV
    oper = (CInt -> Ptr (Complex Float) -> TVV (Complex Float))
    -> CInt
    -> Complex Float
    -> Vector (Complex Float)
    -> Vector (Complex Float)
    forall a a2 t a1.
    (Enum a, Storable a2, Storable t, Storable a1) =>
    (CInt -> Ptr a2 -> CInt -> Ptr t -> CInt -> Ptr a1 -> IO CInt)
    -> a -> a2 -> Vector t -> Vector a1
    vectorMapValAux CInt -> Ptr (Complex Float) -> TVV (Complex Float)
    c_vectorMapValQ (FunCodeSV -> CInt
    forall a. Enum a => a -> CInt
    fromei FunCodeSV
    oper)

    foreign import ccall unsafe "mapValQ" c_vectorMapValQ :: CInt -> Ptr (Complex Float) -> TVV (Complex Float)

    -- | map of real vectors with given function
    vectorMapValI :: FunCodeSV -> CInt -> Vector CInt -> Vector CInt
    vectorMapValI :: FunCodeSV -> CInt -> Vector CInt -> Vector CInt
    vectorMapValI FunCodeSV
    oper = (CInt -> Ptr CInt -> CInt -> Ptr CInt -> CInt :> IO CInt)
    -> CInt -> CInt -> Vector CInt -> Vector CInt
    forall a a2 t a1.
    (Enum a, Storable a2, Storable t, Storable a1) =>
    (CInt -> Ptr a2 -> CInt -> Ptr t -> CInt -> Ptr a1 -> IO CInt)
    -> a -> a2 -> Vector t -> Vector a1
    vectorMapValAux CInt -> Ptr CInt -> CInt -> Ptr CInt -> CInt :> IO CInt
    c_vectorMapValI (FunCodeSV -> CInt
    forall a. Enum a => a -> CInt
    fromei FunCodeSV
    oper)

    foreign import ccall unsafe "mapValI" c_vectorMapValI :: CInt -> Ptr CInt -> TVV CInt

    -- | map of real vectors with given function
    vectorMapValL :: FunCodeSV -> Z -> Vector Z -> Vector Z
    vectorMapValL :: FunCodeSV -> Z -> Vector Z -> Vector Z
    vectorMapValL FunCodeSV
    oper = (CInt -> Ptr Z -> CInt -> Ptr Z -> Z :> IO CInt)
    -> CInt -> Z -> Vector Z -> Vector Z
    forall a a2 t a1.
    (Enum a, Storable a2, Storable t, Storable a1) =>
    (CInt -> Ptr a2 -> CInt -> Ptr t -> CInt -> Ptr a1 -> IO CInt)
    -> a -> a2 -> Vector t -> Vector a1
    vectorMapValAux CInt -> Ptr Z -> CInt -> Ptr Z -> Z :> IO CInt
    c_vectorMapValL (FunCodeSV -> CInt
    forall a. Enum a => a -> CInt
    fromei FunCodeSV
    oper)

    foreign import ccall unsafe "mapValL" c_vectorMapValL :: CInt -> Ptr Z -> TVV Z

    -------------------------------------------------------------------

    type TVVV t = t :> t :> t :> Ok

    -- | elementwise operation on real vectors
    vectorZipR :: FunCodeVV -> Vector Double -> Vector Double -> Vector Double
    vectorZipR :: FunCodeVV -> Vector Double -> Vector Double -> Vector Double
    vectorZipR = (CInt
     -> CInt
     -> Ptr Double
     -> TransRaw (Vector Double) (CInt -> Ptr Double -> IO CInt))
    -> FunCodeVV -> Vector Double -> Vector Double -> Vector Double
    forall a c t a1.
    (Enum a, TransArray c, Storable t, Storable a1) =>
    (CInt -> CInt -> Ptr t -> TransRaw c (CInt -> Ptr a1 -> IO CInt))
    -> a -> Vector t -> c -> Vector a1
    vectorZipAux CInt
    -> CInt
    -> Ptr Double
    -> TransRaw (Vector Double) (CInt -> Ptr Double -> IO CInt)
    CInt -> CInt -> Ptr Double -> TVV Double
    c_vectorZipR

    foreign import ccall unsafe "zipR" c_vectorZipR :: CInt -> TVVV Double

    -- | elementwise operation on complex vectors
    vectorZipC :: FunCodeVV -> Vector (Complex Double) -> Vector (Complex Double) -> Vector (Complex Double)
    vectorZipC :: FunCodeVV
    -> Vector (Complex Double)
    -> Vector (Complex Double)
    -> Vector (Complex Double)
    vectorZipC = (CInt
     -> CInt
     -> Ptr (Complex Double)
     -> TransRaw
          (Vector (Complex Double))
          (CInt -> Ptr (Complex Double) -> IO CInt))
    -> FunCodeVV
    -> Vector (Complex Double)
    -> Vector (Complex Double)
    -> Vector (Complex Double)
    forall a c t a1.
    (Enum a, TransArray c, Storable t, Storable a1) =>
    (CInt -> CInt -> Ptr t -> TransRaw c (CInt -> Ptr a1 -> IO CInt))
    -> a -> Vector t -> c -> Vector a1
    vectorZipAux CInt
    -> CInt
    -> Ptr (Complex Double)
    -> TransRaw
         (Vector (Complex Double)) (CInt -> Ptr (Complex Double) -> IO CInt)
    CInt -> CInt -> Ptr (Complex Double) -> TVV (Complex Double)
    c_vectorZipC

    foreign import ccall unsafe "zipC" c_vectorZipC :: CInt -> TVVV (Complex Double)

    -- | elementwise operation on real vectors
    vectorZipF :: FunCodeVV -> Vector Float -> Vector Float -> Vector Float
    vectorZipF :: FunCodeVV -> Vector Float -> Vector Float -> Vector Float
    vectorZipF = (CInt
     -> CInt
     -> Ptr Float
     -> TransRaw (Vector Float) (CInt -> Ptr Float -> IO CInt))
    -> FunCodeVV -> Vector Float -> Vector Float -> Vector Float
    forall a c t a1.
    (Enum a, TransArray c, Storable t, Storable a1) =>
    (CInt -> CInt -> Ptr t -> TransRaw c (CInt -> Ptr a1 -> IO CInt))
    -> a -> Vector t -> c -> Vector a1
    vectorZipAux CInt
    -> CInt
    -> Ptr Float
    -> TransRaw (Vector Float) (CInt -> Ptr Float -> IO CInt)
    CInt -> CInt -> Ptr Float -> TVV Float
    c_vectorZipF

    foreign import ccall unsafe "zipF" c_vectorZipF :: CInt -> TVVV Float

    -- | elementwise operation on complex vectors
    vectorZipQ :: FunCodeVV -> Vector (Complex Float) -> Vector (Complex Float) -> Vector (Complex Float)
    vectorZipQ :: FunCodeVV
    -> Vector (Complex Float)
    -> Vector (Complex Float)
    -> Vector (Complex Float)
    vectorZipQ = (CInt
     -> CInt
     -> Ptr (Complex Float)
     -> TransRaw
          (Vector (Complex Float)) (CInt -> Ptr (Complex Float) -> IO CInt))
    -> FunCodeVV
    -> Vector (Complex Float)
    -> Vector (Complex Float)
    -> Vector (Complex Float)
    forall a c t a1.
    (Enum a, TransArray c, Storable t, Storable a1) =>
    (CInt -> CInt -> Ptr t -> TransRaw c (CInt -> Ptr a1 -> IO CInt))
    -> a -> Vector t -> c -> Vector a1
    vectorZipAux CInt
    -> CInt
    -> Ptr (Complex Float)
    -> TransRaw
         (Vector (Complex Float)) (CInt -> Ptr (Complex Float) -> IO CInt)
    CInt -> CInt -> Ptr (Complex Float) -> TVV (Complex Float)
    c_vectorZipQ

    foreign import ccall unsafe "zipQ" c_vectorZipQ :: CInt -> TVVV (Complex Float)

    -- | elementwise operation on CInt vectors
    vectorZipI :: FunCodeVV -> Vector CInt -> Vector CInt -> Vector CInt
    vectorZipI :: FunCodeVV -> Vector CInt -> Vector CInt -> Vector CInt
    vectorZipI = (CInt
     -> CInt -> Ptr CInt -> TransRaw (Vector CInt) (CInt :> IO CInt))
    -> FunCodeVV -> Vector CInt -> Vector CInt -> Vector CInt
    forall a c t a1.
    (Enum a, TransArray c, Storable t, Storable a1) =>
    (CInt -> CInt -> Ptr t -> TransRaw c (CInt -> Ptr a1 -> IO CInt))
    -> a -> Vector t -> c -> Vector a1
    vectorZipAux CInt
    -> CInt -> Ptr CInt -> TransRaw (Vector CInt) (CInt :> IO CInt)
    CInt -> CInt -> Ptr CInt -> CInt -> Ptr CInt -> CInt :> IO CInt
    c_vectorZipI

    foreign import ccall unsafe "zipI" c_vectorZipI :: CInt -> TVVV CInt

    -- | elementwise operation on CInt vectors
    vectorZipL :: FunCodeVV -> Vector Z -> Vector Z -> Vector Z
    vectorZipL :: FunCodeVV -> Vector Z -> Vector Z -> Vector Z
    vectorZipL = (CInt -> CInt -> Ptr Z -> TransRaw (Vector Z) (Z :> IO CInt))
    -> FunCodeVV -> Vector Z -> Vector Z -> Vector Z
    forall a c t a1.
    (Enum a, TransArray c, Storable t, Storable a1) =>
    (CInt -> CInt -> Ptr t -> TransRaw c (CInt -> Ptr a1 -> IO CInt))
    -> a -> Vector t -> c -> Vector a1
    vectorZipAux CInt -> CInt -> Ptr Z -> TransRaw (Vector Z) (Z :> IO CInt)
    CInt -> CInt -> Ptr Z -> CInt -> Ptr Z -> Z :> IO CInt
    c_vectorZipL

    foreign import ccall unsafe "zipL" c_vectorZipL :: CInt -> TVVV Z

    --------------------------------------------------------------------------------

    foreign import ccall unsafe "vectorScan" c_vectorScan
        :: CString -> Ptr CInt -> Ptr (Ptr Double) -> IO CInt

    vectorScan :: FilePath -> IO (Vector Double)
    vectorScan :: String -> IO (Vector Double)
    vectorScan String
    s = do
        pp <- IO (Ptr (Ptr Double))
    forall a. Storable a => IO (Ptr a)
    malloc
        pn <- malloc
        cs <- newCString s
        ok <- c_vectorScan cs pn pp
        when (not (ok == 0)) $
            error ("vectorScan: file \"" ++ s ++"\" not found")
        n <- fromIntegral <$> peek pn
        p <- peek pp
        v <- createVector n
        free pn
        free cs
        unsafeWith v $ \Ptr Double
    pv -> Ptr Double -> Ptr Double -> Int -> IO ()
    forall a. Storable a => Ptr a -> Ptr a -> Int -> IO ()
    copyArray Ptr Double
    pv Ptr Double
    p Int
    n
        free p
        free pp
        return v

    --------------------------------------------------------------------------------

    type Seed = Int

    data RandDist = Uniform  -- ^ uniform distribution in [0,1)
                  | Gaussian -- ^ normal distribution with mean zero and standard deviation one
                  deriving Int -> RandDist
    RandDist -> Int
    RandDist -> [RandDist]
    RandDist -> RandDist
    RandDist -> RandDist -> [RandDist]
    RandDist -> RandDist -> RandDist -> [RandDist]
    (RandDist -> RandDist)
    -> (RandDist -> RandDist)
    -> (Int -> RandDist)
    -> (RandDist -> Int)
    -> (RandDist -> [RandDist])
    -> (RandDist -> RandDist -> [RandDist])
    -> (RandDist -> RandDist -> [RandDist])
    -> (RandDist -> RandDist -> RandDist -> [RandDist])
    -> Enum RandDist
    forall a.
    (a -> a)
    -> (a -> a)
    -> (Int -> a)
    -> (a -> Int)
    -> (a -> [a])
    -> (a -> a -> [a])
    -> (a -> a -> [a])
    -> (a -> a -> a -> [a])
    -> Enum a
    $csucc :: RandDist -> RandDist
    succ :: RandDist -> RandDist
    $cpred :: RandDist -> RandDist
    pred :: RandDist -> RandDist
    $ctoEnum :: Int -> RandDist
    toEnum :: Int -> RandDist
    $cfromEnum :: RandDist -> Int
    fromEnum :: RandDist -> Int
    $cenumFrom :: RandDist -> [RandDist]
    enumFrom :: RandDist -> [RandDist]
    $cenumFromThen :: RandDist -> RandDist -> [RandDist]
    enumFromThen :: RandDist -> RandDist -> [RandDist]
    $cenumFromTo :: RandDist -> RandDist -> [RandDist]
    enumFromTo :: RandDist -> RandDist -> [RandDist]
    $cenumFromThenTo :: RandDist -> RandDist -> RandDist -> [RandDist]
    enumFromThenTo :: RandDist -> RandDist -> RandDist -> [RandDist]
    Enum

    -- | Obtains a vector of pseudorandom elements (use randomIO to get a random seed).
    randomVector :: Seed
                 -> RandDist -- ^ distribution
                 -> Int      -- ^ vector size
                 -> Vector Double
    randomVector :: Int -> RandDist -> Int -> Vector Double
    randomVector Int
    seed RandDist
    dist Int
    n = IO (Vector Double) -> Vector Double
    forall a. IO a -> a
    unsafePerformIO (IO (Vector Double) -> Vector Double)
    -> IO (Vector Double) -> Vector Double
    forall a b. (a -> b) -> a -> b
    $ do
        r <- Int -> IO (Vector Double)
    forall a. Storable a => Int -> IO (Vector a)
    createVector Int
    n
        (r # id) (c_random_vector (fi seed) ((fi.fromEnum) dist)) #|"randomVector"
        return r

    foreign import ccall unsafe "random_vector" c_random_vector :: CInt -> CInt -> Double :> Ok

    --------------------------------------------------------------------------------

    roundVector :: Vector Double -> Vector Double
    roundVector :: Vector Double -> Vector Double
    roundVector Vector Double
    v = IO (Vector Double) -> Vector Double
    forall a. IO a -> a
    unsafePerformIO (IO (Vector Double) -> Vector Double)
    -> IO (Vector Double) -> Vector Double
    forall a b. (a -> b) -> a -> b
    $ do
        r <- Int -> IO (Vector Double)
    forall a. Storable a => Int -> IO (Vector a)
    createVector (Vector Double -> Int
    forall t. Storable t => Vector t -> Int
    dim Vector Double
    v)
        (v #! r) c_round_vector #|"roundVector"
        return r

    foreign import ccall unsafe "round_vector" c_round_vector :: TVV Double

    --------------------------------------------------------------------------------

    -- |
    -- >>> range 5
    -- [0,1,2,3,4]
    -- it :: Vector I
    --
    range :: Int -> Vector I
    range :: Int -> Vector CInt
    range Int
    n = IO (Vector CInt) -> Vector CInt
    forall a. IO a -> a
    unsafePerformIO (IO (Vector CInt) -> Vector CInt)
    -> IO (Vector CInt) -> Vector CInt
    forall a b. (a -> b) -> a -> b
    $ do
        r <- Int -> IO (Vector CInt)
    forall a. Storable a => Int -> IO (Vector a)
    createVector Int
    n
        (r # id) c_range_vector #|"range"
        return r

    foreign import ccall unsafe "range_vector" c_range_vector :: CInt :> Ok

    float2DoubleV :: Vector Float -> Vector Double
    float2DoubleV :: Vector Float -> Vector Double
    float2DoubleV = (CInt -> Ptr Float -> CInt -> Ptr Double -> IO CInt)
    -> Vector Float -> Vector Double
    forall t a.
    (Storable t, Storable a) =>
    (CInt -> Ptr t -> CInt -> Ptr a -> IO CInt) -> Vector t -> Vector a
    tog CInt -> Ptr Float -> CInt -> Ptr Double -> IO CInt
    c_float2double

    double2FloatV :: Vector Double -> Vector Float
    double2FloatV :: Vector Double -> Vector Float
    double2FloatV = (CInt -> Ptr Double -> CInt -> Ptr Float -> IO CInt)
    -> Vector Double -> Vector Float
    forall t a.
    (Storable t, Storable a) =>
    (CInt -> Ptr t -> CInt -> Ptr a -> IO CInt) -> Vector t -> Vector a
    tog CInt -> Ptr Double -> CInt -> Ptr Float -> IO CInt
    c_double2float

    double2IntV :: Vector Double -> Vector CInt
    double2IntV :: Vector Double -> Vector CInt
    double2IntV = (CInt -> Ptr Double -> CInt :> IO CInt)
    -> Vector Double -> Vector CInt
    forall t a.
    (Storable t, Storable a) =>
    (CInt -> Ptr t -> CInt -> Ptr a -> IO CInt) -> Vector t -> Vector a
    tog CInt -> Ptr Double -> CInt :> IO CInt
    c_double2int

    int2DoubleV :: Vector CInt -> Vector Double
    int2DoubleV :: Vector CInt -> Vector Double
    int2DoubleV = (CInt -> Ptr CInt -> CInt -> Ptr Double -> IO CInt)
    -> Vector CInt -> Vector Double
    forall t a.
    (Storable t, Storable a) =>
    (CInt -> Ptr t -> CInt -> Ptr a -> IO CInt) -> Vector t -> Vector a
    tog CInt -> Ptr CInt -> CInt -> Ptr Double -> IO CInt
    c_int2double

    double2longV :: Vector Double -> Vector Z
    double2longV :: Vector Double -> Vector Z
    double2longV = (CInt -> Ptr Double -> Z :> IO CInt) -> Vector Double -> Vector Z
    forall t a.
    (Storable t, Storable a) =>
    (CInt -> Ptr t -> CInt -> Ptr a -> IO CInt) -> Vector t -> Vector a
    tog CInt -> Ptr Double -> Z :> IO CInt
    c_double2long

    long2DoubleV :: Vector Z -> Vector Double
    long2DoubleV :: Vector Z -> Vector Double
    long2DoubleV = (CInt -> Ptr Z -> CInt -> Ptr Double -> IO CInt)
    -> Vector Z -> Vector Double
    forall t a.
    (Storable t, Storable a) =>
    (CInt -> Ptr t -> CInt -> Ptr a -> IO CInt) -> Vector t -> Vector a
    tog CInt -> Ptr Z -> CInt -> Ptr Double -> IO CInt
    c_long2double

    float2IntV :: Vector Float -> Vector CInt
    float2IntV :: Vector Float -> Vector CInt
    float2IntV = (CInt -> Ptr Float -> CInt :> IO CInt)
    -> Vector Float -> Vector CInt
    forall t a.
    (Storable t, Storable a) =>
    (CInt -> Ptr t -> CInt -> Ptr a -> IO CInt) -> Vector t -> Vector a
    tog CInt -> Ptr Float -> CInt :> IO CInt
    c_float2int

    int2floatV :: Vector CInt -> Vector Float
    int2floatV :: Vector CInt -> Vector Float
    int2floatV = (CInt -> Ptr CInt -> CInt -> Ptr Float -> IO CInt)
    -> Vector CInt -> Vector Float
    forall t a.
    (Storable t, Storable a) =>
    (CInt -> Ptr t -> CInt -> Ptr a -> IO CInt) -> Vector t -> Vector a
    tog CInt -> Ptr CInt -> CInt -> Ptr Float -> IO CInt
    c_int2float

    int2longV :: Vector I -> Vector Z
    int2longV :: Vector CInt -> Vector Z
    int2longV = (CInt -> Ptr CInt -> Z :> IO CInt) -> Vector CInt -> Vector Z
    forall t a.
    (Storable t, Storable a) =>
    (CInt -> Ptr t -> CInt -> Ptr a -> IO CInt) -> Vector t -> Vector a
    tog CInt -> Ptr CInt -> Z :> IO CInt
    c_int2long

    long2intV :: Vector Z -> Vector I
    long2intV :: Vector Z -> Vector CInt
    long2intV = (CInt -> Ptr Z -> CInt :> IO CInt) -> Vector Z -> Vector CInt
    forall t a.
    (Storable t, Storable a) =>
    (CInt -> Ptr t -> CInt -> Ptr a -> IO CInt) -> Vector t -> Vector a
    tog CInt -> Ptr Z -> CInt :> IO CInt
    c_long2int

    tog :: (Storable t, Storable a)
        => (CInt -> Ptr t -> CInt -> Ptr a -> IO CInt) -> Vector t -> Vector a
    tog :: forall t a.
    (Storable t, Storable a) =>
    (CInt -> Ptr t -> CInt -> Ptr a -> IO CInt) -> Vector t -> Vector a
    tog CInt -> Ptr t -> CInt -> Ptr a -> IO CInt
    f Vector t
    v = IO (Vector a) -> Vector a
    forall a. IO a -> a
    unsafePerformIO (IO (Vector a) -> Vector a) -> IO (Vector a) -> Vector a
    forall a b. (a -> b) -> a -> b
    $ do
        r <- Int -> IO (Vector a)
    forall a. Storable a => Int -> IO (Vector a)
    createVector (Vector t -> Int
    forall t. Storable t => Vector t -> Int
    dim Vector t
    v)
        (v #! r) f #|"tog"
        return r

    foreign import ccall unsafe "float2double" c_float2double :: Float :> Double :> Ok
    foreign import ccall unsafe "double2float" c_double2float :: Double :> Float :> Ok
    foreign import ccall unsafe "int2double"   c_int2double   :: CInt :> Double :> Ok
    foreign import ccall unsafe "double2int"   c_double2int   :: Double :> CInt :> Ok
    foreign import ccall unsafe "long2double"  c_long2double   :: Z :> Double :> Ok
    foreign import ccall unsafe "double2long"  c_double2long   :: Double :> Z :> Ok
    foreign import ccall unsafe "int2float"    c_int2float    :: CInt :> Float :> Ok
    foreign import ccall unsafe "float2int"    c_float2int    :: Float :> CInt :> Ok
    foreign import ccall unsafe "int2long"    c_int2long    :: I :> Z :> Ok
    foreign import ccall unsafe "long2int"    c_long2int    :: Z :> I :> Ok

    ---------------------------------------------------------------

    stepg :: (Storable t, Storable a)
          => (CInt -> Ptr t -> CInt -> Ptr a -> IO CInt) -> Vector t -> Vector a
    stepg :: forall t a.
    (Storable t, Storable a) =>
    (CInt -> Ptr t -> CInt -> Ptr a -> IO CInt) -> Vector t -> Vector a
    stepg CInt -> Ptr t -> CInt -> Ptr a -> IO CInt
    f Vector t
    v = IO (Vector a) -> Vector a
    forall a. IO a -> a
    unsafePerformIO (IO (Vector a) -> Vector a) -> IO (Vector a) -> Vector a
    forall a b. (a -> b) -> a -> b
    $ do
        r <- Int -> IO (Vector a)
    forall a. Storable a => Int -> IO (Vector a)
    createVector (Vector t -> Int
    forall t. Storable t => Vector t -> Int
    dim Vector t
    v)
        (v #! r) f #|"step"
        return r

    stepD :: Vector Double -> Vector Double
    stepD :: Vector Double -> Vector Double
    stepD = TVV Double -> Vector Double -> Vector Double
    forall t a.
    (Storable t, Storable a) =>
    (CInt -> Ptr t -> CInt -> Ptr a -> IO CInt) -> Vector t -> Vector a
    stepg TVV Double
    c_stepD

    stepF :: Vector Float -> Vector Float
    stepF :: Vector Float -> Vector Float
    stepF = TVV Float -> Vector Float -> Vector Float
    forall t a.
    (Storable t, Storable a) =>
    (CInt -> Ptr t -> CInt -> Ptr a -> IO CInt) -> Vector t -> Vector a
    stepg TVV Float
    c_stepF

    stepI :: Vector CInt -> Vector CInt
    stepI :: Vector CInt -> Vector CInt
    stepI = (CInt -> Ptr CInt -> CInt :> IO CInt) -> Vector CInt -> Vector CInt
    forall t a.
    (Storable t, Storable a) =>
    (CInt -> Ptr t -> CInt -> Ptr a -> IO CInt) -> Vector t -> Vector a
    stepg CInt -> Ptr CInt -> CInt :> IO CInt
    c_stepI

    stepL :: Vector Z -> Vector Z
    stepL :: Vector Z -> Vector Z
    stepL = (CInt -> Ptr Z -> Z :> IO CInt) -> Vector Z -> Vector Z
    forall t a.
    (Storable t, Storable a) =>
    (CInt -> Ptr t -> CInt -> Ptr a -> IO CInt) -> Vector t -> Vector a
    stepg CInt -> Ptr Z -> Z :> IO CInt
    c_stepL

    foreign import ccall unsafe "stepF" c_stepF :: TVV Float
    foreign import ccall unsafe "stepD" c_stepD :: TVV Double
    foreign import ccall unsafe "stepI" c_stepI :: TVV CInt
    foreign import ccall unsafe "stepL" c_stepL :: TVV Z

    --------------------------------------------------------------------------------

    conjugateAux :: (Storable t, Storable a)
                 => (CInt -> Ptr t -> CInt -> Ptr a -> IO CInt) -> Vector t -> Vector a
    conjugateAux :: forall t a.
    (Storable t, Storable a) =>
    (CInt -> Ptr t -> CInt -> Ptr a -> IO CInt) -> Vector t -> Vector a
    conjugateAux CInt -> Ptr t -> CInt -> Ptr a -> IO CInt
    fun Vector t
    x = IO (Vector a) -> Vector a
    forall a. IO a -> a
    unsafePerformIO (IO (Vector a) -> Vector a) -> IO (Vector a) -> Vector a
    forall a b. (a -> b) -> a -> b
    $ do
        v <- Int -> IO (Vector a)
    forall a. Storable a => Int -> IO (Vector a)
    createVector (Vector t -> Int
    forall t. Storable t => Vector t -> Int
    dim Vector t
    x)
        (x #! v) fun #|"conjugateAux"
        return v

    conjugateQ :: Vector (Complex Float) -> Vector (Complex Float)
    conjugateQ :: Vector (Complex Float) -> Vector (Complex Float)
    conjugateQ = TVV (Complex Float)
    -> Vector (Complex Float) -> Vector (Complex Float)
    forall t a.
    (Storable t, Storable a) =>
    (CInt -> Ptr t -> CInt -> Ptr a -> IO CInt) -> Vector t -> Vector a
    conjugateAux TVV (Complex Float)
    c_conjugateQ
    foreign import ccall unsafe "conjugateQ" c_conjugateQ :: TVV (Complex Float)

    conjugateC :: Vector (Complex Double) -> Vector (Complex Double)
    conjugateC :: Vector (Complex Double) -> Vector (Complex Double)
    conjugateC = TVV (Complex Double)
    -> Vector (Complex Double) -> Vector (Complex Double)
    forall t a.
    (Storable t, Storable a) =>
    (CInt -> Ptr t -> CInt -> Ptr a -> IO CInt) -> Vector t -> Vector a
    conjugateAux TVV (Complex Double)
    c_conjugateC
    foreign import ccall unsafe "conjugateC" c_conjugateC :: TVV (Complex Double)

    --------------------------------------------------------------------------------

    cloneVector :: Storable t => Vector t -> IO (Vector t)
    cloneVector :: forall t. Storable t => Vector t -> IO (Vector t)
    cloneVector Vector t
    v = do
            let n :: Int
    n = Vector t -> Int
    forall t. Storable t => Vector t -> Int
    dim Vector t
    v
            r <- Int -> IO (Vector t)
    forall a. Storable a => Int -> IO (Vector a)
    createVector Int
    n
            let f CInt
    _ Ptr t
    s CInt
    _ Ptr t
    d =  Ptr t -> Ptr t -> Int -> IO ()
    forall a. Storable a => Ptr a -> Ptr a -> Int -> IO ()
    copyArray Ptr t
    d Ptr t
    s Int
    n IO () -> IO CInt -> IO CInt
    forall a b. IO a -> IO b -> IO b
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> CInt -> IO CInt
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return CInt
    0
            (v #! r) f #|"cloneVector"
            return r

    --------------------------------------------------------------------------------

    constantAux :: (Storable a1, Storable a)
                => (Ptr a1 -> CInt -> Ptr a -> IO CInt) -> a1 -> Int -> Vector a
    constantAux :: forall a1 a.
    (Storable a1, Storable a) =>
    (Ptr a1 -> CInt -> Ptr a -> IO CInt) -> a1 -> Int -> Vector a
    constantAux Ptr a1 -> CInt -> Ptr a -> IO CInt
    fun a1
    x Int
    n = IO (Vector a) -> Vector a
    forall a. IO a -> a
    unsafePerformIO (IO (Vector a) -> Vector a) -> IO (Vector a) -> Vector a
    forall a b. (a -> b) -> a -> b
    $ do
        v <- Int -> IO (Vector a)
    forall a. Storable a => Int -> IO (Vector a)
    createVector Int
    n
        px <- newArray [x]
        (v # id) (fun px) #|"constantAux"
        free px
        return v

    type TConst t = Ptr t -> t :> Ok

    foreign import ccall unsafe "constantF" cconstantF :: TConst Float
    foreign import ccall unsafe "constantR" cconstantR :: TConst Double
    foreign import ccall unsafe "constantQ" cconstantQ :: TConst (Complex Float)
    foreign import ccall unsafe "constantC" cconstantC :: TConst (Complex Double)
    foreign import ccall unsafe "constantI" cconstantI :: TConst CInt
    foreign import ccall unsafe "constantL" cconstantL :: TConst Z

    ----------------------------------------------------------------------