summaryrefslogtreecommitdiff
path: root/packages/sparse/src/Numeric/LinearAlgebra/Sparse.hs
blob: b2ca7f0cefc147a7089e11c026740f90019ee840 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE RecordWildCards #-}



module Numeric.LinearAlgebra.Sparse (
    dss
) where

import Foreign.C.Types(CInt(..))
import Numeric.LinearAlgebra.Devel
import System.IO.Unsafe(unsafePerformIO)
import Foreign(Ptr)
import Numeric.LinearAlgebra.HMatrix
import Text.Printf
import Control.Monad(when)

(???) :: Bool -> String -> IO ()
infixl 0 ???
c ??? msg = when c (error msg)

type IV t = CInt -> Ptr CInt   -> t
type  V t = CInt -> Ptr Double -> t
type SMxV = V (IV (IV (V (V (IO CInt)))))

dss :: CSR -> Vector Double -> Vector Double
dss CSR{..} b = unsafePerformIO $ do
    size b /= csrNRows ??? printf "dss: incorrect sizes: (%d,%d) x %d" csrNRows csrNCols (size b)
    r <- createVector csrNCols
    c_dss `apply` csrVals `apply` csrCols `apply` csrRows `apply` b `apply` r #|"dss"
    return r

foreign import ccall unsafe "dss"
  c_dss :: SMxV