{-# LINE 1 "src/Data/Number/Flint/Groups/Dirichlet/FFI.hsc" #-}
module Data.Number.Flint.Groups.Dirichlet.FFI (
DirichletGroup (..)
, CDirichletGroup (..)
, newDirichletGroup
, withDirichletGroup
, withNewDirichletGroup
, dirichlet_group_init
, dirichlet_subgroup_init
, dirichlet_group_clear
, dirichlet_group_size
, dirichlet_group_num_primitive
, dirichlet_group_dlog_precompute
, dirichlet_group_dlog_clear
, DirichletChar (..)
, CDirichletChar (..)
, newDirichletChar
, withDirichletChar
, withNewDirichletChar
, dirichlet_char_init
, dirichlet_char_clear
, dirichlet_char_print
, dirichlet_char_log
, dirichlet_char_exp
, _dirichlet_char_exp
, dirichlet_char_one
, dirichlet_char_first_primitive
, dirichlet_char_set
, dirichlet_char_next
, dirichlet_char_next_primitive
, dirichlet_index_char
, dirichlet_char_index
, dirichlet_char_eq
, dirichlet_char_eq_deep
, dirichlet_char_is_principal
, dirichlet_conductor_ui
, dirichlet_conductor_char
, dirichlet_parity_ui
, dirichlet_parity_char
, dirichlet_order_ui
, dirichlet_order_char
, dirichlet_char_is_real
, dirichlet_char_is_primitive
, dirichlet_pairing
, dirichlet_pairing_char
, dirichlet_chi
, dirichlet_chi_vec
, dirichlet_chi_vec_order
, dirichlet_char_mul
, dirichlet_char_pow
, dirichlet_char_lift
, dirichlet_char_lower
) where
import Foreign.C.Types
import Foreign.C.String
import Foreign.Ptr
import Foreign.ForeignPtr
import Foreign.Storable
import Data.Number.Flint.Flint
data DirichletGroup =
DirichletGroup {-# UNPACK #-} !(ForeignPtr CDirichletGroup)
data CDirichletGroup = CFlint DirichletGroup
newDirichletGroup :: a -> IO DirichletGroup
newDirichletGroup a
n = do
ForeignPtr CDirichletGroup
x <- forall a. Storable a => IO (ForeignPtr a)
mallocForeignPtr
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr CDirichletGroup
x forall a b. (a -> b) -> a -> b
$ \Ptr CDirichletGroup
x -> do
Ptr CDirichletGroup -> CULong -> IO CInt
dirichlet_group_init Ptr CDirichletGroup
x (forall a b. (Integral a, Num b) => a -> b
fromIntegral a
n)
forall a. FinalizerPtr a -> ForeignPtr a -> IO ()
addForeignPtrFinalizer FunPtr (Ptr CDirichletGroup -> IO ())
p_dirichlet_group_clear ForeignPtr CDirichletGroup
x
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ ForeignPtr CDirichletGroup -> DirichletGroup
DirichletGroup ForeignPtr CDirichletGroup
x
{-# INLINE withDirichletGroup #-}
withDirichletGroup :: DirichletGroup
-> (Ptr CDirichletGroup -> IO a) -> IO (DirichletGroup, a)
withDirichletGroup (DirichletGroup ForeignPtr CDirichletGroup
p) Ptr CDirichletGroup -> IO a
f = do
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr CDirichletGroup
p forall a b. (a -> b) -> a -> b
$ \Ptr CDirichletGroup
fp -> (ForeignPtr CDirichletGroup -> DirichletGroup
DirichletGroup ForeignPtr CDirichletGroup
p,) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ptr CDirichletGroup -> IO a
f Ptr CDirichletGroup
fp
{-# INLINE withNewDirichletGroup #-}
withNewDirichletGroup :: a -> (Ptr CDirichletGroup -> IO a) -> IO (DirichletGroup, a)
withNewDirichletGroup a
n Ptr CDirichletGroup -> IO a
f = do
DirichletGroup
x <- forall {a}. Integral a => a -> IO DirichletGroup
newDirichletGroup a
n
forall {a}.
DirichletGroup
-> (Ptr CDirichletGroup -> IO a) -> IO (DirichletGroup, a)
withDirichletGroup DirichletGroup
x Ptr CDirichletGroup -> IO a
f
instance Storable CDirichletGroup where
{-# INLINE sizeOf #-}
sizeOf :: CDirichletGroup -> Int
sizeOf CDirichletGroup
_ = (Int
104)
{-# LINE 105 "src/Data/Number/Flint/Groups/Dirichlet/FFI.hsc" #-}
{-# INLINE alignment #-}
alignment :: CDirichletGroup -> Int
alignment CDirichletGroup
_ = Int
8
{-# LINE 107 "src/Data/Number/Flint/Groups/Dirichlet/FFI.hsc" #-}
peek = undefined
poke :: Ptr CDirichletGroup -> CDirichletGroup -> IO ()
poke = forall a. HasCallStack => a
undefined
foreign import ccall "dirichlet.h dirichlet_group_init"
dirichlet_group_init :: Ptr CDirichletGroup -> CULong -> IO CInt
foreign import ccall "dirichlet.h dirichlet_subgroup_init"
dirichlet_subgroup_init :: Ptr CDirichletGroup -> Ptr CDirichletGroup -> CULong -> IO ()
foreign import ccall "dirichlet.h dirichlet_group_clear"
dirichlet_group_clear :: Ptr CDirichletGroup -> IO ()
foreign import ccall "dirichlet.h &dirichlet_group_clear"
p_dirichlet_group_clear :: FunPtr (Ptr CDirichletGroup -> IO ())
foreign import ccall "dirichlet.h dirichlet_group_size"
dirichlet_group_size :: Ptr CDirichletGroup -> IO CULong
foreign import ccall "dirichlet.h dirichlet_group_num_primitive"
dirichlet_group_num_primitive :: Ptr CDirichletGroup -> IO CULong
foreign import ccall "dirichlet.h dirichlet_group_dlog_precompute"
dirichlet_group_dlog_precompute :: Ptr CDirichletGroup -> CULong -> IO ()
foreign import ccall "dirichlet.h dirichlet_group_dlog_clear"
dirichlet_group_dlog_clear :: Ptr CDirichletGroup -> CULong -> IO ()
data DirichletChar = DirichletChar {-# UNPACK #-} !(ForeignPtr CDirichletChar)
data CDirichletChar = CDirichletChar CULong (Ptr CULong)
newDirichletChar :: DirichletGroup -> IO DirichletChar
newDirichletChar DirichletGroup
group = do
ForeignPtr CDirichletChar
x <- forall a. Storable a => IO (ForeignPtr a)
mallocForeignPtr
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr CDirichletChar
x forall a b. (a -> b) -> a -> b
$ \Ptr CDirichletChar
x -> do
forall {a}.
DirichletGroup
-> (Ptr CDirichletGroup -> IO a) -> IO (DirichletGroup, a)
withDirichletGroup DirichletGroup
group forall a b. (a -> b) -> a -> b
$ \Ptr CDirichletGroup
group -> do
Ptr CDirichletChar -> Ptr CDirichletGroup -> IO ()
dirichlet_char_init Ptr CDirichletChar
x Ptr CDirichletGroup
group
forall a. FinalizerPtr a -> ForeignPtr a -> IO ()
addForeignPtrFinalizer FunPtr (Ptr CDirichletChar -> IO ())
p_dirichlet_char_clear ForeignPtr CDirichletChar
x
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ ForeignPtr CDirichletChar -> DirichletChar
DirichletChar ForeignPtr CDirichletChar
x
{-# INLINE withDirichletChar #-}
withDirichletChar :: DirichletChar
-> (Ptr CDirichletChar -> IO a) -> IO (DirichletChar, a)
withDirichletChar (DirichletChar ForeignPtr CDirichletChar
p) Ptr CDirichletChar -> IO a
f = do
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr CDirichletChar
p forall a b. (a -> b) -> a -> b
$ \Ptr CDirichletChar
fp -> (ForeignPtr CDirichletChar -> DirichletChar
DirichletChar ForeignPtr CDirichletChar
p,) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ptr CDirichletChar -> IO a
f Ptr CDirichletChar
fp
{-# INLINE withNewDirichletChar #-}
withNewDirichletChar :: DirichletGroup
-> (Ptr CDirichletChar -> IO a) -> IO (DirichletChar, a)
withNewDirichletChar DirichletGroup
group Ptr CDirichletChar -> IO a
f = do
DirichletChar
x <- DirichletGroup -> IO DirichletChar
newDirichletChar DirichletGroup
group
forall {a}.
DirichletChar
-> (Ptr CDirichletChar -> IO a) -> IO (DirichletChar, a)
withDirichletChar DirichletChar
x Ptr CDirichletChar -> IO a
f
instance Storable CDirichletChar where
{-# INLINE sizeOf #-}
sizeOf :: CDirichletChar -> Int
sizeOf CDirichletChar
_ = (Int
16)
{-# LINE 211 "src/Data/Number/Flint/Groups/Dirichlet/FFI.hsc" #-}
{-# INLINE alignment #-}
alignment :: CDirichletChar -> Int
alignment CDirichletChar
_ = Int
8
{-# LINE 213 "src/Data/Number/Flint/Groups/Dirichlet/FFI.hsc" #-}
peek ptr = CDirichletChar
<$> (\hsc_ptr -> peekByteOff hsc_ptr 0) ptr
{-# LINE 215 "src/Data/Number/Flint/Groups/Dirichlet/FFI.hsc" #-}
<*> (\hsc_ptr -> peekByteOff hsc_ptr 8) ptr
{-# LINE 216 "src/Data/Number/Flint/Groups/Dirichlet/FFI.hsc" #-}
poke ptr (CDirichletChar n log) = do
(\hsc_ptr -> pokeByteOff hsc_ptr 0) ptr n
{-# LINE 218 "src/Data/Number/Flint/Groups/Dirichlet/FFI.hsc" #-}
(\hsc_ptr -> pokeByteOff hsc_ptr 8) ptr log
{-# LINE 219 "src/Data/Number/Flint/Groups/Dirichlet/FFI.hsc" #-}
foreign import ccall "dirichlet.h dirichlet_char_init"
dirichlet_char_init :: Ptr CDirichletChar -> Ptr CDirichletGroup -> IO ()
foreign import ccall "dirichlet.h dirichlet_char_clear"
dirichlet_char_clear :: Ptr CDirichletChar -> IO ()
foreign import ccall "dirichlet.h &dirichlet_char_clear"
p_dirichlet_char_clear :: FunPtr (Ptr CDirichletChar -> IO ())
dirichlet_char_print :: Ptr CDirichletGroup -> Ptr CDirichletChar -> IO ()
dirichlet_char_print :: Ptr CDirichletGroup -> Ptr CDirichletChar -> IO ()
dirichlet_char_print Ptr CDirichletGroup
g Ptr CDirichletChar
c = do
forall a. (Ptr a -> IO CString) -> Ptr a -> IO CInt
printCStr (Ptr CDirichletGroup -> Ptr CDirichletChar -> IO CString
dirichlet_char_get_str Ptr CDirichletGroup
g) Ptr CDirichletChar
c
forall (m :: * -> *) a. Monad m => a -> m a
return ()
foreign import ccall "dirichlet.h dirichlet_char_get_str"
dirichlet_char_get_str :: Ptr CDirichletGroup
-> Ptr CDirichletChar -> IO CString
foreign import ccall "dirichlet.h dirichlet_char_log"
dirichlet_char_log :: Ptr CDirichletChar -> Ptr CDirichletGroup -> CULong -> IO ()
foreign import ccall "dirichlet.h dirichlet_char_exp"
dirichlet_char_exp :: Ptr CDirichletGroup -> Ptr CDirichletChar -> IO CULong
foreign import ccall "dirichlet.h _dirichlet_char_exp"
_dirichlet_char_exp :: Ptr CDirichletChar -> Ptr CDirichletGroup -> IO CULong
foreign import ccall "dirichlet.h dirichlet_char_one"
dirichlet_char_one :: Ptr CDirichletChar -> Ptr CDirichletGroup -> IO ()
foreign import ccall "dirichlet.h dirichlet_char_first_primitive"
dirichlet_char_first_primitive :: Ptr CDirichletChar -> Ptr CDirichletGroup -> IO ()
foreign import ccall "dirichlet.h dirichlet_char_set"
dirichlet_char_set :: Ptr CDirichletChar -> Ptr CDirichletGroup -> Ptr CDirichletChar -> IO ()
foreign import ccall "dirichlet.h dirichlet_char_next"
dirichlet_char_next :: Ptr CDirichletChar -> Ptr CDirichletGroup -> IO CInt
foreign import ccall "dirichlet.h dirichlet_char_next_primitive"
dirichlet_char_next_primitive :: Ptr CDirichletChar -> Ptr CDirichletGroup -> IO CInt
foreign import ccall "dirichlet.h dirichlet_index_char"
dirichlet_index_char :: Ptr CDirichletGroup -> Ptr CDirichletChar -> IO CULong
foreign import ccall "dirichlet.h dirichlet_char_index"
dirichlet_char_index :: Ptr CDirichletChar -> Ptr CDirichletGroup -> CULong -> IO ()
foreign import ccall "dirichlet.h dirichlet_char_eq"
dirichlet_char_eq :: Ptr CDirichletChar -> Ptr CDirichletChar -> IO CInt
foreign import ccall "dirichlet.h dirichlet_char_eq_deep"
dirichlet_char_eq_deep :: Ptr CDirichletGroup -> Ptr CDirichletChar -> Ptr CDirichletChar -> IO CInt
foreign import ccall "dirichlet.h dirichlet_char_is_principal"
dirichlet_char_is_principal :: Ptr CDirichletGroup -> Ptr CDirichletChar -> IO CInt
foreign import ccall "dirichlet.h dirichlet_conductor_ui"
dirichlet_conductor_ui :: Ptr CDirichletGroup -> CULong -> IO CULong
foreign import ccall "dirichlet.h dirichlet_conductor_char"
dirichlet_conductor_char :: Ptr CDirichletGroup -> Ptr CDirichletChar -> IO CULong
foreign import ccall "dirichlet.h dirichlet_parity_ui"
dirichlet_parity_ui :: Ptr CDirichletGroup -> CULong -> IO CInt
foreign import ccall "dirichlet.h dirichlet_parity_char"
dirichlet_parity_char :: Ptr CDirichletGroup -> Ptr CDirichletChar -> IO CInt
foreign import ccall "dirichlet.h dirichlet_order_ui"
dirichlet_order_ui :: Ptr CDirichletGroup -> CULong -> IO CULong
foreign import ccall "dirichlet.h dirichlet_order_char"
dirichlet_order_char :: Ptr CDirichletGroup -> Ptr CDirichletChar -> IO CULong
foreign import ccall "dirichlet.h dirichlet_char_is_real"
dirichlet_char_is_real :: Ptr CDirichletGroup -> Ptr CDirichletChar -> IO CInt
foreign import ccall "dirichlet.h dirichlet_char_is_primitive"
dirichlet_char_is_primitive :: Ptr CDirichletGroup -> Ptr CDirichletChar -> IO CInt
foreign import ccall "dirichlet.h dirichlet_pairing"
dirichlet_pairing :: Ptr CDirichletGroup -> CULong -> CULong -> IO CULong
foreign import ccall "dirichlet.h dirichlet_pairing_char"
dirichlet_pairing_char :: Ptr CDirichletGroup -> Ptr CDirichletChar -> Ptr CDirichletChar -> IO CULong
foreign import ccall "dirichlet.h dirichlet_chi"
dirichlet_chi :: Ptr CDirichletGroup -> Ptr CDirichletChar -> CULong -> IO CULong
foreign import ccall "dirichlet.h dirichlet_chi_vec"
dirichlet_chi_vec :: Ptr CULong -> Ptr CDirichletGroup -> Ptr CDirichletChar -> CLong -> IO ()
foreign import ccall "dirichlet.h dirichlet_chi_vec_order"
dirichlet_chi_vec_order :: Ptr CULong -> Ptr CDirichletGroup -> Ptr CDirichletChar -> CULong -> CLong -> IO ()
foreign import ccall "dirichlet.h dirichlet_char_mul"
dirichlet_char_mul :: Ptr CDirichletChar -> Ptr CDirichletGroup -> Ptr CDirichletChar -> Ptr CDirichletChar -> IO ()
foreign import ccall "dirichlet.h dirichlet_char_pow"
dirichlet_char_pow :: Ptr CDirichletChar -> Ptr CDirichletGroup -> Ptr CDirichletChar -> CULong -> IO ()
foreign import ccall "dirichlet.h dirichlet_char_lift"
dirichlet_char_lift :: Ptr CDirichletChar -> Ptr CDirichletGroup -> Ptr CDirichletChar -> Ptr CDirichletGroup -> IO ()
foreign import ccall "dirichlet.h dirichlet_char_lower"
dirichlet_char_lower :: Ptr CDirichletChar -> Ptr CDirichletGroup -> Ptr CDirichletChar -> Ptr CDirichletGroup -> IO ()