{-# LINE 1 "src/Data/Number/Flint/Support/Mpf/Mat/FFI.hsc" #-}
module Data.Number.Flint.Support.Mpf.Mat.FFI (
MpfMat (..)
, CMpfMat (..)
, newMpfMat
, withMpfMat
, withNewMpfMat
, mpf_mat_init
, mpf_mat_clear
, mpf_mat_set
, mpf_mat_swap
, mpf_mat_swap_entrywise
, mpf_mat_entry
, mpf_mat_zero
, mpf_mat_one
, mpf_mat_randtest
, mpf_mat_print
, mpf_mat_equal
, mpf_mat_approx_equal
, mpf_mat_is_zero
, mpf_mat_is_empty
, mpf_mat_is_square
, mpf_mat_mul
, mpf_mat_gso
, mpf_mat_qr
) where
import Foreign.C.Types
import Foreign.Ptr
import Foreign.ForeignPtr
import Foreign.Storable
import Foreign.Marshal.Array
import Data.Number.Flint.Flint
data MpfMat = MpfMat {-# UNPACK #-} !(ForeignPtr CMpfMat)
data CMpfMat = CMpfMat (Ptr CMpf) CLong CLong (Ptr (Ptr CMpf))
instance Storable CMpfMat where
{-# INLINE sizeOf #-}
sizeOf :: CMpfMat -> Int
sizeOf CMpfMat
_ = (Int
40)
{-# LINE 62 "src/Data/Number/Flint/Support/Mpf/Mat/FFI.hsc" #-}
{-# INLINE alignment #-}
alignment :: CMpfMat -> Int
alignment CMpfMat
_ = Int
8
{-# LINE 64 "src/Data/Number/Flint/Support/Mpf/Mat/FFI.hsc" #-}
peek ptr = CMpfMat
<$> (\hsc_ptr -> peekByteOff hsc_ptr 0) ptr
{-# LINE 66 "src/Data/Number/Flint/Support/Mpf/Mat/FFI.hsc" #-}
<*> (\hsc_ptr -> peekByteOff hsc_ptr 8) ptr
{-# LINE 67 "src/Data/Number/Flint/Support/Mpf/Mat/FFI.hsc" #-}
<*> (\hsc_ptr -> peekByteOff hsc_ptr 16) ptr
{-# LINE 68 "src/Data/Number/Flint/Support/Mpf/Mat/FFI.hsc" #-}
<*> (\hsc_ptr -> peekByteOff hsc_ptr 32) ptr
{-# LINE 69 "src/Data/Number/Flint/Support/Mpf/Mat/FFI.hsc" #-}
poke = error "CMpfMat.poke: Not defined."
newMpfMat :: CLong -> CLong -> CFBitCnt -> IO MpfMat
newMpfMat CLong
rows CLong
cols CFBitCnt
prec = do
ForeignPtr CMpfMat
x <- forall a. Storable a => IO (ForeignPtr a)
mallocForeignPtr
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr CMpfMat
x forall a b. (a -> b) -> a -> b
$ \Ptr CMpfMat
x -> Ptr CMpfMat -> CLong -> CLong -> CFBitCnt -> IO ()
mpf_mat_init Ptr CMpfMat
x CLong
rows CLong
cols CFBitCnt
prec
forall a. FinalizerPtr a -> ForeignPtr a -> IO ()
addForeignPtrFinalizer FunPtr (Ptr CMpfMat -> IO ())
p_mpf_mat_clear ForeignPtr CMpfMat
x
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ ForeignPtr CMpfMat -> MpfMat
MpfMat ForeignPtr CMpfMat
x
{-# INLINE withMpfMat #-}
withMpfMat :: MpfMat -> (Ptr CMpfMat -> IO a) -> IO (MpfMat, a)
withMpfMat (MpfMat ForeignPtr CMpfMat
x) Ptr CMpfMat -> IO a
f = do
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr CMpfMat
x forall a b. (a -> b) -> a -> b
$ \Ptr CMpfMat
px -> Ptr CMpfMat -> IO a
f Ptr CMpfMat
px forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ForeignPtr CMpfMat -> MpfMat
MpfMat ForeignPtr CMpfMat
x,)
withNewMpfMat :: CLong
-> CLong -> CFBitCnt -> (Ptr CMpfMat -> IO a) -> IO (MpfMat, a)
withNewMpfMat CLong
rows CLong
cols CFBitCnt
prec Ptr CMpfMat -> IO a
f = do
MpfMat
x <- CLong -> CLong -> CFBitCnt -> IO MpfMat
newMpfMat CLong
rows CLong
cols CFBitCnt
prec
forall {a}. MpfMat -> (Ptr CMpfMat -> IO a) -> IO (MpfMat, a)
withMpfMat MpfMat
x Ptr CMpfMat -> IO a
f
foreign import ccall "mpf_mat.h mpf_mat_init"
mpf_mat_init :: Ptr CMpfMat -> CLong -> CLong -> CFBitCnt -> IO ()
foreign import ccall "mpf_mat.h mpf_mat_clear"
mpf_mat_clear :: Ptr CMpfMat -> IO ()
foreign import ccall "mpf_mat.h &mpf_mat_clear"
p_mpf_mat_clear :: FunPtr (Ptr CMpfMat -> IO ())
foreign import ccall "mpf_mat.h mpf_mat_set"
mpf_mat_set :: Ptr CMpfMat -> Ptr CMpfMat -> IO ()
foreign import ccall "mpf_mat.h mpf_mat_swap"
mpf_mat_swap :: Ptr CMpfMat -> Ptr CMpfMat -> IO ()
foreign import ccall "mpf_mat.h mpf_mat_swap_entrywise"
mpf_mat_swap_entrywise :: Ptr CMpfMat -> Ptr CMpfMat -> IO ()
mpf_mat_entry :: Ptr CMpfMat -> CLong -> CLong -> IO (Ptr CMpf)
mpf_mat_entry :: Ptr CMpfMat -> CLong -> CLong -> IO (Ptr CMpf)
mpf_mat_entry Ptr CMpfMat
mat CLong
i CLong
j = do
CMpfMat Ptr CMpf
entries CLong
r CLong
c Ptr (Ptr CMpf)
rows <- forall a. Storable a => Ptr a -> IO a
peek Ptr CMpfMat
mat
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Ptr CMpf
entries forall a. Storable a => Ptr a -> Int -> Ptr a
`advancePtr` (forall a b. (Integral a, Num b) => a -> b
fromIntegral (CLong
iforall a. Num a => a -> a -> a
*CLong
c forall a. Num a => a -> a -> a
+ CLong
j))
foreign import ccall "mpf_mat.h mpf_mat_zero"
mpf_mat_zero :: Ptr CMpfMat -> IO ()
foreign import ccall "mpf_mat.h mpf_mat_one"
mpf_mat_one :: Ptr CMpfMat -> IO ()
foreign import ccall "mpf_mat.h mpf_mat_randtest"
mpf_mat_randtest :: Ptr CMpfMat -> Ptr CFRandState -> CFBitCnt -> IO ()
foreign import ccall "mpf_mat.h mpf_mat_print"
mpf_mat_print :: Ptr CMpfMat -> IO ()
foreign import ccall "mpf_mat.h mpf_mat_equal"
mpf_mat_equal :: Ptr CMpfMat -> Ptr CMpfMat -> IO CInt
foreign import ccall "mpf_mat.h mpf_mat_approx_equal"
mpf_mat_approx_equal :: Ptr CMpfMat -> Ptr CMpfMat -> CFBitCnt -> IO CInt
foreign import ccall "mpf_mat.h mpf_mat_is_zero"
mpf_mat_is_zero :: Ptr CMpfMat -> IO CInt
foreign import ccall "mpf_mat.h mpf_mat_is_empty"
mpf_mat_is_empty :: Ptr CMpfMat -> IO CInt
foreign import ccall "mpf_mat.h mpf_mat_is_square"
mpf_mat_is_square :: Ptr CMpfMat -> IO CInt
foreign import ccall "mpf_mat.h mpf_mat_mul"
mpf_mat_mul :: Ptr CMpfMat -> Ptr CMpfMat -> Ptr CMpfMat -> IO ()
foreign import ccall "mpf_mat.h mpf_mat_gso"
mpf_mat_gso :: Ptr CMpfMat -> Ptr CMpfMat -> IO ()
foreign import ccall "mpf_mat.h mpf_mat_qr"
mpf_mat_qr :: Ptr CMpfMat -> Ptr CMpfMat -> Ptr CMpfMat -> IO ()