{-# LINE 1 "src/Data/Number/Flint/Support/Mpfr/Mat/FFI.hsc" #-}
module Data.Number.Flint.Support.Mpfr.Mat.FFI (
MpfrMat (..)
, CMpfrMat (..)
, newMpfrMat
, withMpfrMat
, withNewMpfrMat
, mpfr_mat_init
, mpfr_mat_clear
, mpfr_mat_swap
, mpfr_mat_swap_entrywise
, mpfr_mat_entry
, mpfr_mat_set
, mpfr_mat_zero
, mpfr_mat_equal
, mpfr_mat_randtest
, mpfr_mat_mul_classical
) where
import Foreign.C.Types
import Foreign.Ptr
import Foreign.ForeignPtr
import Foreign.Marshal.Array
import Foreign.Storable
import Data.Number.Flint.Flint
data MpfrMat = MpfrMat {-# UNPACK #-} !(ForeignPtr CMpfrMat)
data CMpfrMat = CMpfrMat (Ptr CMpfr) CLong CLong (Ptr (Ptr CMpfr))
instance Storable CMpfrMat where
{-# INLINE sizeOf #-}
sizeOf :: CMpfrMat -> Int
sizeOf CMpfrMat
_ = (Int
40)
{-# LINE 52 "src/Data/Number/Flint/Support/Mpfr/Mat/FFI.hsc" #-}
{-# INLINE alignment #-}
alignment :: CMpfrMat -> Int
alignment CMpfrMat
_ = Int
8
{-# LINE 54 "src/Data/Number/Flint/Support/Mpfr/Mat/FFI.hsc" #-}
peek ptr = CMpfrMat
<$> (\hsc_ptr -> peekByteOff hsc_ptr 0) ptr
{-# LINE 56 "src/Data/Number/Flint/Support/Mpfr/Mat/FFI.hsc" #-}
<*> (\hsc_ptr -> peekByteOff hsc_ptr 8) ptr
{-# LINE 57 "src/Data/Number/Flint/Support/Mpfr/Mat/FFI.hsc" #-}
<*> (\hsc_ptr -> peekByteOff hsc_ptr 16) ptr
{-# LINE 58 "src/Data/Number/Flint/Support/Mpfr/Mat/FFI.hsc" #-}
<*> (\hsc_ptr -> peekByteOff hsc_ptr 32) ptr
{-# LINE 59 "src/Data/Number/Flint/Support/Mpfr/Mat/FFI.hsc" #-}
poke = error "CMpfrMat.poke: Not defined."
newMpfrMat :: CLong -> CLong -> CMpfrPrec -> IO MpfrMat
newMpfrMat CLong
rows CLong
cols CMpfrPrec
prec = do
ForeignPtr CMpfrMat
x <- forall a. Storable a => IO (ForeignPtr a)
mallocForeignPtr
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr CMpfrMat
x forall a b. (a -> b) -> a -> b
$ \Ptr CMpfrMat
x -> Ptr CMpfrMat -> CLong -> CLong -> CMpfrPrec -> IO ()
mpfr_mat_init Ptr CMpfrMat
x CLong
rows CLong
cols CMpfrPrec
prec
forall a. FinalizerPtr a -> ForeignPtr a -> IO ()
addForeignPtrFinalizer FunPtr (Ptr CMpfrMat -> IO ())
p_mpfr_mat_clear ForeignPtr CMpfrMat
x
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ ForeignPtr CMpfrMat -> MpfrMat
MpfrMat ForeignPtr CMpfrMat
x
{-# INLINE withMpfrMat #-}
withMpfrMat :: MpfrMat -> (Ptr CMpfrMat -> IO a) -> IO (MpfrMat, a)
withMpfrMat (MpfrMat ForeignPtr CMpfrMat
x) Ptr CMpfrMat -> IO a
f = do
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr CMpfrMat
x forall a b. (a -> b) -> a -> b
$ \Ptr CMpfrMat
px -> Ptr CMpfrMat -> IO a
f Ptr CMpfrMat
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 CMpfrMat -> MpfrMat
MpfrMat ForeignPtr CMpfrMat
x,)
withNewMpfrMat :: CLong
-> CLong -> CMpfrPrec -> (Ptr CMpfrMat -> IO a) -> IO (MpfrMat, a)
withNewMpfrMat CLong
rows CLong
cols CMpfrPrec
prec Ptr CMpfrMat -> IO a
f = do
MpfrMat
x <- CLong -> CLong -> CMpfrPrec -> IO MpfrMat
newMpfrMat CLong
rows CLong
cols CMpfrPrec
prec
forall {a}. MpfrMat -> (Ptr CMpfrMat -> IO a) -> IO (MpfrMat, a)
withMpfrMat MpfrMat
x Ptr CMpfrMat -> IO a
f
foreign import ccall "mpfr_mat.h mpfr_mat_init"
mpfr_mat_init :: Ptr CMpfrMat -> CLong -> CLong -> CMpfrPrec -> IO ()
foreign import ccall "mpfr_mat.h mpfr_mat_clear"
mpfr_mat_clear :: Ptr CMpfrMat -> IO ()
foreign import ccall "mpfr_mat.h &mpfr_mat_clear"
p_mpfr_mat_clear :: FunPtr (Ptr CMpfrMat -> IO ())
mpfr_mat_entry :: Ptr CMpfrMat -> CLong -> CLong -> IO (Ptr CMpfr)
mpfr_mat_entry Ptr CMpfrMat
mat CLong
i CLong
j = do
CMpfrMat Ptr CMpfr
entries CLong
r CLong
c Ptr (Ptr CMpfr)
rows <- forall a. Storable a => Ptr a -> IO a
peek Ptr CMpfrMat
mat
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Ptr CMpfr
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 "mpfr_mat.h mpfr_mat_swap"
mpfr_mat_swap :: Ptr CMpfrMat -> Ptr CMpfrMat -> IO ()
foreign import ccall "mpfr_mat.h mpfr_mat_swap_entrywise_"
mpfr_mat_swap_entrywise :: Ptr CMpfrMat -> Ptr CMpfrMat -> IO ()
foreign import ccall "mpfr_mat.h mpfr_mat_set"
mpfr_mat_set :: Ptr CMpfrMat -> Ptr CMpfrMat -> IO ()
foreign import ccall "mpfr_mat.h mpfr_mat_zero"
mpfr_mat_zero :: Ptr CMpfrMat -> IO ()
foreign import ccall "mpfr_mat.h mpfr_mat_equal"
mpfr_mat_equal :: Ptr CMpfrMat -> Ptr CMpfrMat -> IO CInt
foreign import ccall "mpfr_mat.h mpfr_mat_randtest"
mpfr_mat_randtest :: Ptr CMpfrMat -> Ptr CFRandState -> IO ()
foreign import ccall "mpfr_mat.h mpfr_mat_mul_classical"
mpfr_mat_mul_classical :: Ptr CMpfrMat -> Ptr CMpfrMat -> Ptr CMpfrMat -> CMpfrRnd -> IO ()