{-# 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 # :: 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
applyRaw c
a b -> IO r
b
{-# INLINE (#) #-}

(#!) :: (TransArray c, TransArray c1) => c1 -> c -> TransRaw c1 (TransRaw c (IO r)) -> IO r
c1
a #! :: 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 :: 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
enumFromThenTo :: FunCodeV -> FunCodeV -> FunCodeV -> [FunCodeV]
$cenumFromThenTo :: FunCodeV -> FunCodeV -> FunCodeV -> [FunCodeV]
enumFromTo :: FunCodeV -> FunCodeV -> [FunCodeV]
$cenumFromTo :: FunCodeV -> FunCodeV -> [FunCodeV]
enumFromThen :: FunCodeV -> FunCodeV -> [FunCodeV]
$cenumFromThen :: FunCodeV -> FunCodeV -> [FunCodeV]
enumFrom :: FunCodeV -> [FunCodeV]
$cenumFrom :: FunCodeV -> [FunCodeV]
fromEnum :: FunCodeV -> Int
$cfromEnum :: FunCodeV -> Int
toEnum :: Int -> FunCodeV
$ctoEnum :: Int -> FunCodeV
pred :: FunCodeV -> FunCodeV
$cpred :: FunCodeV -> FunCodeV
succ :: FunCodeV -> FunCodeV
$csucc :: 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
enumFromThenTo :: FunCodeSV -> FunCodeSV -> FunCodeSV -> [FunCodeSV]
$cenumFromThenTo :: FunCodeSV -> FunCodeSV -> FunCodeSV -> [FunCodeSV]
enumFromTo :: FunCodeSV -> FunCodeSV -> [FunCodeSV]
$cenumFromTo :: FunCodeSV -> FunCodeSV -> [FunCodeSV]
enumFromThen :: FunCodeSV -> FunCodeSV -> [FunCodeSV]
$cenumFromThen :: FunCodeSV -> FunCodeSV -> [FunCodeSV]
enumFrom :: FunCodeSV -> [FunCodeSV]
$cenumFrom :: FunCodeSV -> [FunCodeSV]
fromEnum :: FunCodeSV -> Int
$cfromEnum :: FunCodeSV -> Int
toEnum :: Int -> FunCodeSV
$ctoEnum :: Int -> FunCodeSV
pred :: FunCodeSV -> FunCodeSV
$cpred :: FunCodeSV -> FunCodeSV
succ :: FunCodeSV -> FunCodeSV
$csucc :: 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
enumFromThenTo :: FunCodeVV -> FunCodeVV -> FunCodeVV -> [FunCodeVV]
$cenumFromThenTo :: FunCodeVV -> FunCodeVV -> FunCodeVV -> [FunCodeVV]
enumFromTo :: FunCodeVV -> FunCodeVV -> [FunCodeVV]
$cenumFromTo :: FunCodeVV -> FunCodeVV -> [FunCodeVV]
enumFromThen :: FunCodeVV -> FunCodeVV -> [FunCodeVV]
$cenumFromThen :: FunCodeVV -> FunCodeVV -> [FunCodeVV]
enumFrom :: FunCodeVV -> [FunCodeVV]
$cenumFrom :: FunCodeVV -> [FunCodeVV]
fromEnum :: FunCodeVV -> Int
$cfromEnum :: FunCodeVV -> Int
toEnum :: Int -> FunCodeVV
$ctoEnum :: Int -> FunCodeVV
pred :: FunCodeVV -> FunCodeVV
$cpred :: FunCodeVV -> FunCodeVV
succ :: FunCodeVV -> FunCodeVV
$csucc :: 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
enumFromThenTo :: FunCodeS -> FunCodeS -> FunCodeS -> [FunCodeS]
$cenumFromThenTo :: FunCodeS -> FunCodeS -> FunCodeS -> [FunCodeS]
enumFromTo :: FunCodeS -> FunCodeS -> [FunCodeS]
$cenumFromTo :: FunCodeS -> FunCodeS -> [FunCodeS]
enumFromThen :: FunCodeS -> FunCodeS -> [FunCodeS]
$cenumFromThen :: FunCodeS -> FunCodeS -> [FunCodeS]
enumFrom :: FunCodeS -> [FunCodeS]
$cenumFrom :: FunCodeS -> [FunCodeS]
fromEnum :: FunCodeS -> Int
$cfromEnum :: FunCodeS -> Int
toEnum :: Int -> FunCodeS
$ctoEnum :: Int -> FunCodeS
pred :: FunCodeS -> FunCodeS
$cpred :: FunCodeS -> FunCodeS
succ :: FunCodeS -> FunCodeS
$csucc :: 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 :: 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 -> TVV 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 :: 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 -> TVV Z
c_sumL Z
m)

sumg :: (TransArray c, Storable a) => TransRaw c (CInt -> Ptr a -> IO CInt) -> c -> a
sumg :: 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
    Vector a
r <- Int -> IO (Vector a)
forall a. Storable a => Int -> IO (Vector a)
createVector Int
1
    (c
x c
-> Vector a
-> TransRaw c (TransRaw (Vector a) (IO CInt))
-> IO CInt
forall c c1 r.
(TransArray c, TransArray c1) =>
c1 -> c -> TransRaw c1 (TransRaw c (IO r)) -> IO r
#! Vector a
r) TransRaw c (TransRaw (Vector a) (IO CInt))
TransRaw c (CInt -> Ptr a -> IO CInt)
f IO CInt -> String -> IO ()
#| String
"sum"
    a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> IO a) -> a -> IO a
forall a b. (a -> b) -> a -> b
$ Vector a
r Vector a -> Int -> a
forall t. Storable t => Vector t -> Int -> t
@> Int
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 = TVV CInt -> Vector CInt -> CInt
forall c a.
(TransArray c, Storable a) =>
TransRaw c (CInt -> Ptr a -> IO CInt) -> c -> a
prodg (TVV CInt -> Vector CInt -> CInt)
-> (CInt -> TVV CInt) -> CInt -> Vector CInt -> CInt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CInt -> TVV CInt
c_prodI

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

prodg :: (TransArray c, Storable a)
      => TransRaw c (CInt -> Ptr a -> IO CInt) -> c -> a
prodg :: 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
    Vector a
r <- Int -> IO (Vector a)
forall a. Storable a => Int -> IO (Vector a)
createVector Int
1
    (c
x c
-> Vector a
-> TransRaw c (TransRaw (Vector a) (IO CInt))
-> IO CInt
forall c c1 r.
(TransArray c, TransArray c1) =>
c1 -> c -> TransRaw c1 (TransRaw c (IO r)) -> IO r
#! Vector a
r) TransRaw c (TransRaw (Vector a) (IO CInt))
TransRaw c (CInt -> Ptr a -> IO CInt)
f IO CInt -> String -> IO ()
#| String
"prod"
    a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> IO a) -> a -> IO a
forall a b. (a -> b) -> a -> b
$ Vector a
r Vector a -> Int -> a
forall t. Storable t => Vector t -> Int -> t
@> Int
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 :: (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
    Vector a1
r <- Int -> IO (Vector a1)
forall a. Storable a => Int -> IO (Vector a)
createVector Int
1
    (c
v c
-> Vector a1
-> TransRaw c (TransRaw (Vector a1) (IO CInt))
-> IO CInt
forall c c1 r.
(TransArray c, TransArray c1) =>
c1 -> c -> TransRaw c1 (TransRaw c (IO r)) -> IO r
#! Vector a1
r) (CInt -> TransRaw c (CInt -> Ptr a1 -> IO CInt)
fun (a -> CInt
forall a. Enum a => a -> CInt
fromei a
code)) IO CInt -> String -> IO ()
#|String
"toScalarAux"
    a1 -> IO a1
forall (m :: * -> *) a. Monad m => a -> m a
return (Vector a1
r Vector a1 -> Int -> a1
forall t. Storable t => Vector t -> Int -> t
@> Int
0)


vectorMapAux :: (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)
-> 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
    Vector a1
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)
    (Vector t
v Vector t
-> Vector a1
-> TransRaw (Vector t) (TransRaw (Vector a1) (IO CInt))
-> IO CInt
forall c c1 r.
(TransArray c, TransArray c1) =>
c1 -> c -> TransRaw c1 (TransRaw c (IO r)) -> IO r
#! Vector a1
r) (CInt -> CInt -> Ptr t -> CInt -> Ptr a1 -> IO CInt
fun (a -> CInt
forall a. Enum a => a -> CInt
fromei a
code)) IO CInt -> String -> IO ()
#|String
"vectorMapAux"
    Vector a1 -> IO (Vector a1)
forall (m :: * -> *) a. Monad m => a -> m a
return Vector a1
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 :: (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
    Vector a1
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)
    Ptr a2
pval <- [a2] -> IO (Ptr a2)
forall a. Storable a => [a] -> IO (Ptr a)
newArray [a2
val]
    (Vector t
v Vector t
-> Vector a1
-> TransRaw (Vector t) (TransRaw (Vector a1) (IO CInt))
-> IO CInt
forall c c1 r.
(TransArray c, TransArray c1) =>
c1 -> c -> TransRaw c1 (TransRaw c (IO r)) -> IO r
#! Vector a1
r) (CInt -> Ptr a2 -> CInt -> Ptr t -> CInt -> Ptr a1 -> IO CInt
fun (a -> CInt
forall a. Enum a => a -> CInt
fromei a
code) Ptr a2
pval) IO CInt -> String -> IO ()
#|String
"vectorMapValAux"
    Ptr a2 -> IO ()
forall a. Ptr a -> IO ()
free Ptr a2
pval
    Vector a1 -> IO (Vector a1)
forall (m :: * -> *) a. Monad m => a -> m a
return Vector a1
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 :: (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
    Vector a1
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)
    (Vector t
u Vector t
-> (TransRaw c (CInt -> Ptr a1 -> IO CInt) -> IO CInt)
-> TransRaw (Vector t) (TransRaw c (CInt -> Ptr a1 -> IO CInt))
-> IO CInt
forall c b r.
TransArray c =>
c -> (b -> IO r) -> TransRaw c b -> IO r
# c
v c
-> Vector a1
-> TransRaw c (TransRaw (Vector a1) (IO CInt))
-> IO CInt
forall c c1 r.
(TransArray c, TransArray c1) =>
c1 -> c -> TransRaw c1 (TransRaw c (IO r)) -> IO r
#! Vector a1
r) (CInt -> CInt -> Ptr t -> TransRaw c (CInt -> Ptr a1 -> IO CInt)
fun (a -> CInt
forall a. Enum a => a -> CInt
fromei a
code)) IO CInt -> String -> IO ()
#|String
"vectorZipAux"
    Vector a1 -> IO (Vector a1)
forall (m :: * -> *) a. Monad m => a -> m a
return Vector a1
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 -> Ptr 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 -> Ptr CInt -> IO CInt)
CInt -> TVV 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) (CInt -> Ptr 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) (CInt -> Ptr Z -> IO CInt)
CInt -> TVV Z
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 -> TVV 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 -> TVV 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 -> TVV Z) -> 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 -> TVV Z
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 -> TVV 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 -> TVV 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 -> TVV Z) -> 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 -> TVV Z
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 -> Ptr 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 -> Ptr CInt -> IO CInt)
CInt -> CInt -> Ptr CInt -> TVV 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) (CInt -> Ptr 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) (CInt -> Ptr Z -> IO CInt)
CInt -> CInt -> Ptr Z -> TVV Z
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
    Ptr (Ptr Double)
pp <- IO (Ptr (Ptr Double))
forall a. Storable a => IO (Ptr a)
malloc
    Ptr CInt
pn <- IO (Ptr CInt)
forall a. Storable a => IO (Ptr a)
malloc
    CString
cs <- String -> IO CString
newCString String
s
    CInt
ok <- CString -> Ptr CInt -> Ptr (Ptr Double) -> IO CInt
c_vectorScan CString
cs Ptr CInt
pn Ptr (Ptr Double)
pp
    Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Bool -> Bool
not (CInt
ok CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
== CInt
0)) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$
        String -> IO ()
forall a. HasCallStack => String -> a
error (String
"vectorScan: file \"" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
s String -> String -> String
forall a. [a] -> [a] -> [a]
++String
"\" not found")
    Int
n <- CInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (CInt -> Int) -> IO CInt -> IO Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ptr CInt -> IO CInt
forall a. Storable a => Ptr a -> IO a
peek Ptr CInt
pn
    Ptr Double
p <- Ptr (Ptr Double) -> IO (Ptr Double)
forall a. Storable a => Ptr a -> IO a
peek Ptr (Ptr Double)
pp
    Vector Double
v <- Int -> IO (Vector Double)
forall a. Storable a => Int -> IO (Vector a)
createVector Int
n
    Ptr CInt -> IO ()
forall a. Ptr a -> IO ()
free Ptr CInt
pn
    CString -> IO ()
forall a. Ptr a -> IO ()
free CString
cs
    Vector Double -> (Ptr Double -> IO ()) -> IO ()
forall a b. Storable a => Vector a -> (Ptr a -> IO b) -> IO b
unsafeWith Vector Double
v ((Ptr Double -> IO ()) -> IO ()) -> (Ptr Double -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \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
    Ptr Double -> IO ()
forall a. Ptr a -> IO ()
free Ptr Double
p
    Ptr (Ptr Double) -> IO ()
forall a. Ptr a -> IO ()
free Ptr (Ptr Double)
pp
    Vector Double -> IO (Vector Double)
forall (m :: * -> *) a. Monad m => a -> m a
return Vector Double
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
enumFromThenTo :: RandDist -> RandDist -> RandDist -> [RandDist]
$cenumFromThenTo :: RandDist -> RandDist -> RandDist -> [RandDist]
enumFromTo :: RandDist -> RandDist -> [RandDist]
$cenumFromTo :: RandDist -> RandDist -> [RandDist]
enumFromThen :: RandDist -> RandDist -> [RandDist]
$cenumFromThen :: RandDist -> RandDist -> [RandDist]
enumFrom :: RandDist -> [RandDist]
$cenumFrom :: RandDist -> [RandDist]
fromEnum :: RandDist -> Int
$cfromEnum :: RandDist -> Int
toEnum :: Int -> RandDist
$ctoEnum :: Int -> RandDist
pred :: RandDist -> RandDist
$cpred :: RandDist -> RandDist
succ :: RandDist -> RandDist
$csucc :: 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
    Vector Double
r <- Int -> IO (Vector Double)
forall a. Storable a => Int -> IO (Vector a)
createVector Int
n
    (Vector Double
r Vector Double
-> (IO CInt -> IO CInt)
-> TransRaw (Vector Double) (IO CInt)
-> IO CInt
forall c b r.
TransArray c =>
c -> (b -> IO r) -> TransRaw c b -> IO r
# IO CInt -> IO CInt
forall a. a -> a
id) (CInt -> CInt -> CInt -> Ptr Double -> IO CInt
c_random_vector (Int -> CInt
fi Int
seed) ((Int -> CInt
fi(Int -> CInt) -> (RandDist -> Int) -> RandDist -> CInt
forall b c a. (b -> c) -> (a -> b) -> a -> c
.RandDist -> Int
forall a. Enum a => a -> Int
fromEnum) RandDist
dist)) IO CInt -> String -> IO ()
#|String
"randomVector"
    Vector Double -> IO (Vector Double)
forall (m :: * -> *) a. Monad m => a -> m a
return Vector Double
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
    Vector Double
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)
    (Vector Double
v Vector Double
-> Vector Double
-> TransRaw (Vector Double) (TransRaw (Vector Double) (IO CInt))
-> IO CInt
forall c c1 r.
(TransArray c, TransArray c1) =>
c1 -> c -> TransRaw c1 (TransRaw c (IO r)) -> IO r
#! Vector Double
r) TransRaw (Vector Double) (TransRaw (Vector Double) (IO CInt))
TVV Double
c_round_vector IO CInt -> String -> IO ()
#|String
"roundVector"
    Vector Double -> IO (Vector Double)
forall (m :: * -> *) a. Monad m => a -> m a
return Vector Double
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
    Vector CInt
r <- Int -> IO (Vector CInt)
forall a. Storable a => Int -> IO (Vector a)
createVector Int
n
    (Vector CInt
r Vector CInt
-> (IO CInt -> IO CInt)
-> TransRaw (Vector CInt) (IO CInt)
-> IO CInt
forall c b r.
TransArray c =>
c -> (b -> IO r) -> TransRaw c b -> IO r
# IO CInt -> IO CInt
forall a. a -> a
id) TransRaw (Vector CInt) (IO CInt)
CInt -> Ptr CInt -> IO CInt
c_range_vector IO CInt -> String -> IO ()
#|String
"range"
    Vector CInt -> IO (Vector CInt)
forall (m :: * -> *) a. Monad m => a -> m a
return Vector CInt
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 -> Ptr 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 -> Ptr 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 -> CInt -> Ptr 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 -> CInt -> Ptr 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 -> Ptr 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 -> Ptr 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 -> CInt -> Ptr 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 -> CInt -> Ptr Z -> IO CInt
c_int2long

long2intV :: Vector Z -> Vector I
long2intV :: Vector Z -> Vector CInt
long2intV = (CInt -> Ptr Z -> CInt -> Ptr 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 -> Ptr CInt -> IO CInt
c_long2int


tog :: (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) -> 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
    Vector a
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)
    (Vector t
v Vector t
-> Vector a
-> TransRaw (Vector t) (TransRaw (Vector a) (IO CInt))
-> IO CInt
forall c c1 r.
(TransArray c, TransArray c1) =>
c1 -> c -> TransRaw c1 (TransRaw c (IO r)) -> IO r
#! Vector a
r) TransRaw (Vector t) (TransRaw (Vector a) (IO CInt))
CInt -> Ptr t -> CInt -> Ptr a -> IO CInt
f IO CInt -> String -> IO ()
#|String
"tog"
    Vector a -> IO (Vector a)
forall (m :: * -> *) a. Monad m => a -> m a
return Vector a
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 :: (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
    Vector a
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)
    (Vector t
v Vector t
-> Vector a
-> TransRaw (Vector t) (TransRaw (Vector a) (IO CInt))
-> IO CInt
forall c c1 r.
(TransArray c, TransArray c1) =>
c1 -> c -> TransRaw c1 (TransRaw c (IO r)) -> IO r
#! Vector a
r) TransRaw (Vector t) (TransRaw (Vector a) (IO CInt))
CInt -> Ptr t -> CInt -> Ptr a -> IO CInt
f IO CInt -> String -> IO ()
#|String
"step"
    Vector a -> IO (Vector a)
forall (m :: * -> *) a. Monad m => a -> m a
return Vector a
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 = TVV 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 TVV CInt
c_stepI

stepL :: Vector Z -> Vector Z
stepL :: Vector Z -> Vector Z
stepL = TVV Z -> Vector Z -> Vector Z
forall t a.
(Storable t, Storable a) =>
(CInt -> Ptr t -> CInt -> Ptr a -> IO CInt) -> Vector t -> Vector a
stepg TVV Z
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 :: (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
    Vector a
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)
    (Vector t
x Vector t
-> Vector a
-> TransRaw (Vector t) (TransRaw (Vector a) (IO CInt))
-> IO CInt
forall c c1 r.
(TransArray c, TransArray c1) =>
c1 -> c -> TransRaw c1 (TransRaw c (IO r)) -> IO r
#! Vector a
v) TransRaw (Vector t) (TransRaw (Vector a) (IO CInt))
CInt -> Ptr t -> CInt -> Ptr a -> IO CInt
fun IO CInt -> String -> IO ()
#|String
"conjugateAux"
    Vector a -> IO (Vector a)
forall (m :: * -> *) a. Monad m => a -> m a
return Vector a
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 :: 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
        Vector t
r <- Int -> IO (Vector t)
forall a. Storable a => Int -> IO (Vector a)
createVector Int
n
        let f :: CInt -> Ptr t -> CInt -> Ptr t -> IO CInt
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 (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> CInt -> IO CInt
forall (m :: * -> *) a. Monad m => a -> m a
return CInt
0
        (Vector t
v Vector t
-> Vector t
-> TransRaw (Vector t) (TransRaw (Vector t) (IO CInt))
-> IO CInt
forall c c1 r.
(TransArray c, TransArray c1) =>
c1 -> c -> TransRaw c1 (TransRaw c (IO r)) -> IO r
#! Vector t
r) TransRaw (Vector t) (TransRaw (Vector t) (IO CInt))
CInt -> Ptr t -> CInt -> Ptr t -> IO CInt
f IO CInt -> String -> IO ()
#|String
"cloneVector"
        Vector t -> IO (Vector t)
forall (m :: * -> *) a. Monad m => a -> m a
return Vector t
r

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

constantAux :: (Storable a1, Storable a)
            => (Ptr a1 -> CInt -> Ptr a -> IO CInt) -> a1 -> Int -> Vector a
constantAux :: (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
    Vector a
v <- Int -> IO (Vector a)
forall a. Storable a => Int -> IO (Vector a)
createVector Int
n
    Ptr a1
px <- [a1] -> IO (Ptr a1)
forall a. Storable a => [a] -> IO (Ptr a)
newArray [a1
x]
    (Vector a
v Vector a
-> (IO CInt -> IO CInt) -> TransRaw (Vector a) (IO CInt) -> IO CInt
forall c b r.
TransArray c =>
c -> (b -> IO r) -> TransRaw c b -> IO r
# IO CInt -> IO CInt
forall a. a -> a
id) (Ptr a1 -> CInt -> Ptr a -> IO CInt
fun Ptr a1
px) IO CInt -> String -> IO ()
#|String
"constantAux"
    Ptr a1 -> IO ()
forall a. Ptr a -> IO ()
free Ptr a1
px
    Vector a -> IO (Vector a)
forall (m :: * -> *) a. Monad m => a -> m a
return Vector a
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

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