{-# LINE 1 "./Foreign/CUDA/BLAS/Sparse/Matrix/Descriptor.chs" #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE ForeignFunctionInterface #-}
module Foreign.CUDA.BLAS.Sparse.Matrix.Descriptor (
MatrixDescriptor(..),
MatrixType(..),
IndexBase(..),
Diagonal(..),
Fill(..),
createMatDescr,
destroyMatDescr,
getDiagonal,
getFillMode,
getIndexBase,
getMatrixType,
setDiagonal,
setFillMode,
setIndexBase,
setMatrixType,
) where
import qualified Foreign.C.Types as C2HSImp
import qualified Foreign.Ptr as C2HSImp
import Foreign.CUDA.BLAS.Sparse.Error
import Foreign.CUDA.BLAS.Sparse.Internal.C2HS
import Foreign
import Foreign.C
import Control.Monad ( liftM )
{-# LINE 48 "./Foreign/CUDA/BLAS/Sparse/Matrix/Descriptor.chs" #-}
newtype MatrixDescriptor = MatrixDescriptor { useMatDescr :: ((C2HSImp.Ptr ()))}
data Diagonal = NonUnit
| Unit
deriving (Eq,Show)
instance Enum Diagonal where
succ NonUnit = Unit
succ Unit = error "Diagonal.succ: Unit has no successor"
pred Unit = NonUnit
pred NonUnit = error "Diagonal.pred: NonUnit has no predecessor"
enumFromTo from to = go from
where
end = fromEnum to
go v = case compare (fromEnum v) end of
LT -> v : go (succ v)
EQ -> [v]
GT -> []
enumFrom from = enumFromTo from Unit
fromEnum NonUnit = 0
fromEnum Unit = 1
toEnum 0 = NonUnit
toEnum 1 = Unit
toEnum unmatched = error ("Diagonal.toEnum: Cannot match " ++ show unmatched)
{-# LINE 66 "./Foreign/CUDA/BLAS/Sparse/Matrix/Descriptor.chs" #-}
data Fill = Lower
| Upper
deriving (Eq,Show)
instance Enum Fill where
succ Lower = Upper
succ Upper = error "Fill.succ: Upper has no successor"
pred Upper = Lower
pred Lower = error "Fill.pred: Lower has no predecessor"
enumFromTo from to = go from
where
end = fromEnum to
go v = case compare (fromEnum v) end of
LT -> v : go (succ v)
EQ -> [v]
GT -> []
enumFrom from = enumFromTo from Upper
fromEnum Lower = 0
fromEnum Upper = 1
toEnum 0 = Lower
toEnum 1 = Upper
toEnum unmatched = error ("Fill.toEnum: Cannot match " ++ show unmatched)
{-# LINE 74 "./Foreign/CUDA/BLAS/Sparse/Matrix/Descriptor.chs" #-}
data IndexBase = Zero
| One
deriving (Eq,Show)
instance Enum IndexBase where
succ Zero = One
succ One = error "IndexBase.succ: One has no successor"
pred One = Zero
pred Zero = error "IndexBase.pred: Zero has no predecessor"
enumFromTo from to = go from
where
end = fromEnum to
go v = case compare (fromEnum v) end of
LT -> v : go (succ v)
EQ -> [v]
GT -> []
enumFrom from = enumFromTo from One
fromEnum Zero = 0
fromEnum One = 1
toEnum 0 = Zero
toEnum 1 = One
toEnum unmatched = error ("IndexBase.toEnum: Cannot match " ++ show unmatched)
{-# LINE 82 "./Foreign/CUDA/BLAS/Sparse/Matrix/Descriptor.chs" #-}
data MatrixType = General
| Symmetric
| Hermitian
| Triangular
deriving (Eq,Show)
instance Enum MatrixType where
succ General = Symmetric
succ Symmetric = Hermitian
succ Hermitian = Triangular
succ Triangular = error "MatrixType.succ: Triangular has no successor"
pred Symmetric = General
pred Hermitian = Symmetric
pred Triangular = Hermitian
pred General = error "MatrixType.pred: General has no predecessor"
enumFromTo from to = go from
where
end = fromEnum to
go v = case compare (fromEnum v) end of
LT -> v : go (succ v)
EQ -> [v]
GT -> []
enumFrom from = enumFromTo from Triangular
fromEnum General = 0
fromEnum Symmetric = 1
fromEnum Hermitian = 2
fromEnum Triangular = 3
toEnum 0 = General
toEnum 1 = Symmetric
toEnum 2 = Hermitian
toEnum 3 = Triangular
toEnum unmatched = error ("MatrixType.toEnum: Cannot match " ++ show unmatched)
{-# LINE 90 "./Foreign/CUDA/BLAS/Sparse/Matrix/Descriptor.chs" #-}
{-# INLINEABLE createMatDescr #-}
createMatDescr :: IO ((MatrixDescriptor))
createMatDescr =
alloca $ \a1' ->
createMatDescr'_ a1' >>= \res ->
checkStatus res >>
peekMD a1'>>= \a1'' ->
return (a1'')
{-# LINE 100 "./Foreign/CUDA/BLAS/Sparse/Matrix/Descriptor.chs" #-}
where
peekMD = liftM MatrixDescriptor . peek
{-# INLINEABLE destroyMatDescr #-}
destroyMatDescr :: (MatrixDescriptor) -> IO ((()))
destroyMatDescr a1 =
let {a1' = useMatDescr a1} in
destroyMatDescr'_ a1' >>= \res ->
checkStatus res >>= \res' ->
return (res')
{-# LINE 110 "./Foreign/CUDA/BLAS/Sparse/Matrix/Descriptor.chs" #-}
{-# INLINEABLE getDiagonal #-}
getDiagonal :: (MatrixDescriptor) -> IO ((Diagonal))
getDiagonal a1 =
let {a1' = useMatDescr a1} in
getDiagonal'_ a1' >>= \res ->
let {res' = cToEnum res} in
return (res')
{-# LINE 119 "./Foreign/CUDA/BLAS/Sparse/Matrix/Descriptor.chs" #-}
{-# INLINEABLE getFillMode #-}
getFillMode :: (MatrixDescriptor) -> IO ((Fill))
getFillMode a1 =
let {a1' = useMatDescr a1} in
getFillMode'_ a1' >>= \res ->
let {res' = cToEnum res} in
return (res')
{-# LINE 127 "./Foreign/CUDA/BLAS/Sparse/Matrix/Descriptor.chs" #-}
{-# INLINEABLE getIndexBase #-}
getIndexBase :: (MatrixDescriptor) -> IO ((IndexBase))
getIndexBase a1 =
let {a1' = useMatDescr a1} in
getIndexBase'_ a1' >>= \res ->
let {res' = cToEnum res} in
return (res')
{-# LINE 135 "./Foreign/CUDA/BLAS/Sparse/Matrix/Descriptor.chs" #-}
{-# INLINEABLE getMatrixType #-}
getMatrixType :: (MatrixDescriptor) -> IO ((MatrixType))
getMatrixType a1 =
let {a1' = useMatDescr a1} in
getMatrixType'_ a1' >>= \res ->
let {res' = cToEnum res} in
return (res')
{-# LINE 143 "./Foreign/CUDA/BLAS/Sparse/Matrix/Descriptor.chs" #-}
{-# INLINEABLE setDiagonal #-}
setDiagonal :: (MatrixDescriptor) -> (Diagonal) -> IO ((()))
setDiagonal a1 a2 =
let {a1' = useMatDescr a1} in
let {a2' = cFromEnum a2} in
setDiagonal'_ a1' a2' >>= \res ->
checkStatus res >>= \res' ->
return (res')
{-# LINE 152 "./Foreign/CUDA/BLAS/Sparse/Matrix/Descriptor.chs" #-}
{-# INLINEABLE setFillMode #-}
setFillMode :: (MatrixDescriptor) -> (Fill) -> IO ((()))
setFillMode a1 a2 =
let {a1' = useMatDescr a1} in
let {a2' = cFromEnum a2} in
setFillMode'_ a1' a2' >>= \res ->
checkStatus res >>= \res' ->
return (res')
{-# LINE 160 "./Foreign/CUDA/BLAS/Sparse/Matrix/Descriptor.chs" #-}
{-# INLINEABLE setIndexBase #-}
setIndexBase :: (MatrixDescriptor) -> (IndexBase) -> IO ((()))
setIndexBase a1 a2 =
let {a1' = useMatDescr a1} in
let {a2' = cFromEnum a2} in
setIndexBase'_ a1' a2' >>= \res ->
checkStatus res >>= \res' ->
return (res')
{-# LINE 168 "./Foreign/CUDA/BLAS/Sparse/Matrix/Descriptor.chs" #-}
{-# INLINEABLE setMatrixType #-}
setMatrixType :: (MatrixDescriptor) -> (MatrixType) -> IO ((()))
setMatrixType a1 a2 =
let {a1' = useMatDescr a1} in
let {a2' = cFromEnum a2} in
setMatrixType'_ a1' a2' >>= \res ->
checkStatus res >>= \res' ->
return (res')
{-# LINE 176 "./Foreign/CUDA/BLAS/Sparse/Matrix/Descriptor.chs" #-}
foreign import ccall unsafe "Foreign/CUDA/BLAS/Sparse/Matrix/Descriptor.chs.h cusparseCreateMatDescr"
createMatDescr'_ :: ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CInt))
foreign import ccall unsafe "Foreign/CUDA/BLAS/Sparse/Matrix/Descriptor.chs.h cusparseDestroyMatDescr"
destroyMatDescr'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt))
foreign import ccall unsafe "Foreign/CUDA/BLAS/Sparse/Matrix/Descriptor.chs.h cusparseGetMatDiagType"
getDiagonal'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt))
foreign import ccall unsafe "Foreign/CUDA/BLAS/Sparse/Matrix/Descriptor.chs.h cusparseGetMatFillMode"
getFillMode'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt))
foreign import ccall unsafe "Foreign/CUDA/BLAS/Sparse/Matrix/Descriptor.chs.h cusparseGetMatIndexBase"
getIndexBase'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt))
foreign import ccall unsafe "Foreign/CUDA/BLAS/Sparse/Matrix/Descriptor.chs.h cusparseGetMatType"
getMatrixType'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt))
foreign import ccall unsafe "Foreign/CUDA/BLAS/Sparse/Matrix/Descriptor.chs.h cusparseSetMatDiagType"
setDiagonal'_ :: ((C2HSImp.Ptr ()) -> (C2HSImp.CInt -> (IO C2HSImp.CInt)))
foreign import ccall unsafe "Foreign/CUDA/BLAS/Sparse/Matrix/Descriptor.chs.h cusparseSetMatFillMode"
setFillMode'_ :: ((C2HSImp.Ptr ()) -> (C2HSImp.CInt -> (IO C2HSImp.CInt)))
foreign import ccall unsafe "Foreign/CUDA/BLAS/Sparse/Matrix/Descriptor.chs.h cusparseSetMatIndexBase"
setIndexBase'_ :: ((C2HSImp.Ptr ()) -> (C2HSImp.CInt -> (IO C2HSImp.CInt)))
foreign import ccall unsafe "Foreign/CUDA/BLAS/Sparse/Matrix/Descriptor.chs.h cusparseSetMatType"
setMatrixType'_ :: ((C2HSImp.Ptr ()) -> (C2HSImp.CInt -> (IO C2HSImp.CInt)))