{-# LINE 1 "src/Data/Number/Flint/Groups/Bool/Mat/FFI.hsc" #-}
module Data.Number.Flint.Groups.Bool.Mat.FFI (
BoolMat (..)
, CBoolMat (..)
, newBoolMat
, withBoolMat
, withNewBoolMat
, bool_mat_get_entry
, bool_mat_set_entry
, bool_mat_init
, bool_mat_clear
, bool_mat_is_empty
, bool_mat_is_square
, bool_mat_entry
, bool_mat_set
, bool_mat_get_str
, bool_mat_print
, bool_mat_fprint
, bool_mat_equal
, bool_mat_any
, bool_mat_all
, bool_mat_is_diagonal
, bool_mat_is_lower_triangular
, bool_mat_is_transitive
, bool_mat_is_nilpotent
, bool_mat_randtest
, bool_mat_randtest_diagonal
, bool_mat_randtest_nilpotent
, bool_mat_zero
, bool_mat_one
, bool_mat_directed_path
, bool_mat_directed_cycle
, bool_mat_transpose
, bool_mat_complement
, bool_mat_add
, bool_mat_mul
, bool_mat_mul_entrywise
, bool_mat_sqr
, bool_mat_pow_ui
, bool_mat_trace
, bool_mat_nilpotency_degree
, bool_mat_transitive_closure
, bool_mat_get_strongly_connected_components
, bool_mat_all_pairs_longest_walk
) where
import System.IO.Unsafe
import Control.Monad
import Foreign.C.String
import Foreign.C.Types
import Foreign.ForeignPtr
import Foreign.Ptr ( Ptr, FunPtr, nullPtr, plusPtr )
import Foreign.Marshal.Array ( advancePtr )
import Foreign.Storable
import Foreign.Marshal ( free )
import Data.Number.Flint.Flint
import Data.Number.Flint.Fmpz
import Data.Number.Flint.Fmpz.Poly
import Data.Number.Flint.Fmpz.Mat
import Data.Number.Flint.Fmpq
import Data.Number.Flint.NMod.Types
import Data.Number.Flint.Support.D.Mat
import Data.Number.Flint.Support.Mpf.Mat
data BoolMat = BoolMat {-# UNPACK #-} !(ForeignPtr CBoolMat)
data CBoolMat = CBoolMat (Ptr CInt) CLong CLong (Ptr (Ptr CInt))
instance Storable CBoolMat where
{-# INLINE sizeOf #-}
sizeOf :: CBoolMat -> Int
sizeOf CBoolMat
_ = (Int
32)
{-# LINE 107 "src/Data/Number/Flint/Groups/Bool/Mat/FFI.hsc" #-}
{-# INLINE alignment #-}
alignment :: CBoolMat -> Int
alignment CBoolMat
_ = Int
8
{-# LINE 109 "src/Data/Number/Flint/Groups/Bool/Mat/FFI.hsc" #-}
peek ptr = CBoolMat
<$> (\hsc_ptr -> peekByteOff hsc_ptr 0) ptr
{-# LINE 111 "src/Data/Number/Flint/Groups/Bool/Mat/FFI.hsc" #-}
<*> (\hsc_ptr -> peekByteOff hsc_ptr 8) ptr
{-# LINE 112 "src/Data/Number/Flint/Groups/Bool/Mat/FFI.hsc" #-}
<*> (\hsc_ptr -> peekByteOff hsc_ptr 16) ptr
{-# LINE 113 "src/Data/Number/Flint/Groups/Bool/Mat/FFI.hsc" #-}
<*> (\hsc_ptr -> peekByteOff hsc_ptr 24) ptr
{-# LINE 114 "src/Data/Number/Flint/Groups/Bool/Mat/FFI.hsc" #-}
poke = error "CBoolMat.poke: Not defined."
newBoolMat :: CLong -> CLong -> IO BoolMat
newBoolMat CLong
rows CLong
cols = do
ForeignPtr CBoolMat
x <- forall a. Storable a => IO (ForeignPtr a)
mallocForeignPtr
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr CBoolMat
x forall a b. (a -> b) -> a -> b
$ \Ptr CBoolMat
x -> Ptr CBoolMat -> CLong -> CLong -> IO ()
bool_mat_init Ptr CBoolMat
x CLong
rows CLong
cols
forall a. FinalizerPtr a -> ForeignPtr a -> IO ()
addForeignPtrFinalizer FunPtr (Ptr CBoolMat -> IO ())
p_bool_mat_clear ForeignPtr CBoolMat
x
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ ForeignPtr CBoolMat -> BoolMat
BoolMat ForeignPtr CBoolMat
x
{-# INLINE withBoolMat #-}
withBoolMat :: BoolMat -> (Ptr CBoolMat -> IO a) -> IO (BoolMat, a)
withBoolMat (BoolMat ForeignPtr CBoolMat
x) Ptr CBoolMat -> IO a
f = do
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr CBoolMat
x forall a b. (a -> b) -> a -> b
$ \Ptr CBoolMat
px -> Ptr CBoolMat -> IO a
f Ptr CBoolMat
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 CBoolMat -> BoolMat
BoolMat ForeignPtr CBoolMat
x,)
{-# INLINE withNewBoolMat #-}
withNewBoolMat :: CLong -> CLong -> (Ptr CBoolMat -> IO a) -> IO (BoolMat, a)
withNewBoolMat CLong
rows CLong
cols Ptr CBoolMat -> IO a
f = do
BoolMat
x <- CLong -> CLong -> IO BoolMat
newBoolMat CLong
rows CLong
cols
forall {a}. BoolMat -> (Ptr CBoolMat -> IO a) -> IO (BoolMat, a)
withBoolMat BoolMat
x Ptr CBoolMat -> IO a
f
bool_mat_get_entry :: Ptr CBoolMat -> CLong -> CLong -> IO CInt
bool_mat_get_entry :: Ptr CBoolMat -> CLong -> CLong -> IO CInt
bool_mat_get_entry Ptr CBoolMat
mat CLong
i CLong
j = do
CBoolMat Ptr CInt
p CLong
r CLong
c Ptr (Ptr CInt)
_ <- forall a. Storable a => Ptr a -> IO a
peek Ptr CBoolMat
mat
CInt
result <- forall a. Storable a => Ptr a -> IO a
peek (Ptr CInt
p 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)))
forall (m :: * -> *) a. Monad m => a -> m a
return CInt
result
bool_mat_set_entry :: Ptr CBoolMat -> CLong -> CLong -> CInt -> IO ()
bool_mat_set_entry :: Ptr CBoolMat -> CLong -> CLong -> CInt -> IO ()
bool_mat_set_entry Ptr CBoolMat
mat CLong
i CLong
j CInt
x = do
CBoolMat Ptr CInt
p CLong
r CLong
c Ptr (Ptr CInt)
_ <- forall a. Storable a => Ptr a -> IO a
peek Ptr CBoolMat
mat
forall a. Storable a => Ptr a -> a -> IO ()
poke (Ptr CInt
p 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))) CInt
x
foreign import ccall "bool_mat.h bool_mat_init"
bool_mat_init :: Ptr CBoolMat -> CLong -> CLong -> IO ()
foreign import ccall "bool_mat.h bool_mat_clear"
bool_mat_clear :: Ptr CBoolMat -> IO ()
foreign import ccall "bool_mat.h &bool_mat_clear"
p_bool_mat_clear :: FunPtr (Ptr CBoolMat -> IO ())
bool_mat_is_empty :: Ptr CBoolMat -> IO CInt
bool_mat_is_empty :: Ptr CBoolMat -> IO CInt
bool_mat_is_empty Ptr CBoolMat
mat = do
CBoolMat Ptr CInt
_ CLong
r CLong
c Ptr (Ptr CInt)
_ <- forall a. Storable a => Ptr a -> IO a
peek Ptr CBoolMat
mat
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ if CLong
r forall a. Eq a => a -> a -> Bool
== CLong
0 Bool -> Bool -> Bool
|| CLong
c forall a. Eq a => a -> a -> Bool
== CLong
0 then CInt
1 else CInt
0
bool_mat_is_square :: Ptr CBoolMat -> IO CInt
bool_mat_is_square :: Ptr CBoolMat -> IO CInt
bool_mat_is_square Ptr CBoolMat
mat = do
CBoolMat Ptr CInt
_ CLong
r CLong
c Ptr (Ptr CInt)
_ <- forall a. Storable a => Ptr a -> IO a
peek Ptr CBoolMat
mat
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ if CLong
r forall a. Eq a => a -> a -> Bool
== CLong
c then CInt
1 else CInt
0
bool_mat_entry :: Ptr CBoolMat -> CLong -> CLong -> IO (Ptr CInt)
bool_mat_entry Ptr CBoolMat
mat CLong
i CLong
j = do
CBoolMat Ptr CInt
entries CLong
r CLong
c Ptr (Ptr CInt)
rows <- forall a. Storable a => Ptr a -> IO a
peek Ptr CBoolMat
mat
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Ptr CInt
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 "bool_mat.h bool_mat_set"
bool_mat_set :: Ptr CBoolMat -> Ptr CBoolMat -> IO ()
foreign import ccall "bool_mat.h bool_mat_get_str"
bool_mat_get_str :: Ptr CBoolMat -> IO CString
bool_mat_print :: Ptr CBoolMat -> IO ()
bool_mat_print :: Ptr CBoolMat -> IO ()
bool_mat_print Ptr CBoolMat
mat = do
forall a. (Ptr a -> IO CString) -> Ptr a -> IO CInt
printCStr Ptr CBoolMat -> IO CString
bool_mat_get_str Ptr CBoolMat
mat
forall (m :: * -> *) a. Monad m => a -> m a
return ()
foreign import ccall "bool_mat.h bool_mat_fprint"
bool_mat_fprint :: Ptr CFile -> Ptr CBoolMat -> IO ()
foreign import ccall "bool_mat.h bool_mat_equal"
bool_mat_equal :: Ptr CBoolMat -> Ptr CBoolMat -> IO CInt
foreign import ccall "bool_mat.h bool_mat_any"
bool_mat_any :: Ptr CBoolMat -> IO CInt
foreign import ccall "bool_mat.h bool_mat_all"
bool_mat_all :: Ptr CBoolMat -> IO CInt
foreign import ccall "bool_mat.h bool_mat_is_diagonal"
bool_mat_is_diagonal :: Ptr CBoolMat -> IO CInt
foreign import ccall "bool_mat.h bool_mat_is_lower_triangular"
bool_mat_is_lower_triangular :: Ptr CBoolMat -> IO CInt
foreign import ccall "bool_mat.h bool_mat_is_transitive"
bool_mat_is_transitive :: Ptr CBoolMat -> IO CInt
foreign import ccall "bool_mat.h bool_mat_is_nilpotent"
bool_mat_is_nilpotent :: Ptr CBoolMat -> IO CInt
foreign import ccall "bool_mat.h bool_mat_randtest"
bool_mat_randtest :: Ptr CBoolMat -> Ptr CFRandState -> IO ()
foreign import ccall "bool_mat.h bool_mat_randtest_diagonal"
bool_mat_randtest_diagonal :: Ptr CBoolMat -> Ptr CFRandState -> IO ()
foreign import ccall "bool_mat.h bool_mat_randtest_nilpotent"
bool_mat_randtest_nilpotent :: Ptr CBoolMat -> Ptr CFRandState -> IO ()
foreign import ccall "bool_mat.h bool_mat_zero"
bool_mat_zero :: Ptr CBoolMat -> IO ()
foreign import ccall "bool_mat.h bool_mat_one"
bool_mat_one :: Ptr CBoolMat -> IO ()
foreign import ccall "bool_mat.h bool_mat_directed_path"
bool_mat_directed_path :: Ptr CBoolMat -> IO ()
foreign import ccall "bool_mat.h bool_mat_directed_cycle"
bool_mat_directed_cycle :: Ptr CBoolMat -> IO ()
foreign import ccall "bool_mat.h bool_mat_transpose"
bool_mat_transpose :: Ptr CBoolMat -> Ptr CBoolMat -> IO ()
foreign import ccall "bool_mat.h bool_mat_complement"
bool_mat_complement :: Ptr CBoolMat -> Ptr CBoolMat -> IO ()
foreign import ccall "bool_mat.h bool_mat_add"
bool_mat_add :: Ptr CBoolMat -> Ptr CBoolMat -> Ptr CBoolMat -> IO ()
foreign import ccall "bool_mat.h bool_mat_mul"
bool_mat_mul :: Ptr CBoolMat -> Ptr CBoolMat -> Ptr CBoolMat -> IO ()
foreign import ccall "bool_mat.h bool_mat_mul_entrywise"
bool_mat_mul_entrywise :: Ptr CBoolMat -> Ptr CBoolMat -> Ptr CBoolMat -> IO ()
bool_mat_sqr :: Ptr CBoolMat -> Ptr CBoolMat -> IO ()
bool_mat_sqr :: Ptr CBoolMat -> Ptr CBoolMat -> IO ()
bool_mat_sqr Ptr CBoolMat
b Ptr CBoolMat
a = Ptr CBoolMat -> Ptr CBoolMat -> Ptr CBoolMat -> IO ()
bool_mat_mul Ptr CBoolMat
b Ptr CBoolMat
a Ptr CBoolMat
a
foreign import ccall "bool_mat.h bool_mat_pow_ui"
bool_mat_pow_ui :: Ptr CBoolMat -> Ptr CBoolMat -> CULong -> IO ()
foreign import ccall "bool_mat.h bool_mat_trace"
bool_mat_trace :: Ptr CBoolMat -> IO CInt
foreign import ccall "bool_mat.h bool_mat_nilpotency_degree"
bool_mat_nilpotency_degree :: Ptr CBoolMat -> IO CLong
foreign import ccall "bool_mat.h bool_mat_transitive_closure"
bool_mat_transitive_closure :: Ptr CBoolMat -> Ptr CBoolMat -> IO ()
foreign import ccall "bool_mat.h bool_mat_get_strongly_connected_components"
bool_mat_get_strongly_connected_components :: Ptr CLong -> Ptr CBoolMat -> IO CLong
foreign import ccall "bool_mat.h bool_mat_all_pairs_longest_walk"
bool_mat_all_pairs_longest_walk :: Ptr CFmpzMat -> Ptr CBoolMat -> IO CLong