Commit 22ca7495 authored by Kai Zhang's avatar Kai Zhang

clean up

parent 3908932e
......@@ -31,7 +31,6 @@ library
IGraph
IGraph.Mutable
IGraph.Types
IGraph.Read
IGraph.Exporter.GEXF
IGraph.Algorithms
IGraph.Algorithms.Structure
......@@ -54,13 +53,12 @@ library
build-depends:
base >= 4.0 && < 5.0
, bytestring >= 0.9
, bytestring-lexing >= 0.5
, cereal
, colour
, conduit >= 1.3.0
, containers
, data-ordlist
, primitive
, containers
, hxt
, split
, singletons
......
......@@ -11,7 +11,6 @@ module IGraph.Algorithms.Generators
, rewire
) where
import Control.Monad (when, forM_)
import Data.Serialize (Serialize)
import Data.Singletons (SingI, Sing, sing, fromSing)
import System.IO.Unsafe (unsafePerformIO)
......@@ -22,7 +21,6 @@ import Foreign
import IGraph
import IGraph.Mutable (MGraph(..))
import qualified IGraph.Mutable as GM
{#import IGraph.Internal #}
{#import IGraph.Internal.Constants #}
{# import IGraph.Internal.Initialization #}
......
......@@ -16,7 +16,6 @@ import Foreign.C.Types
import IGraph
import IGraph.Internal.Initialization (igraphInit)
import IGraph.Mutable
{#import IGraph.Internal #}
#include "haskell_igraph.h"
......
......@@ -9,7 +9,6 @@ module IGraph.Algorithms.Layout
import Data.Maybe (isJust)
import Foreign (nullPtr)
import qualified Foreign.Ptr as C2HSImp
import Foreign
import IGraph
......
......@@ -11,9 +11,7 @@ module IGraph.Algorithms.Structure
) where
import Control.Monad
import Data.Either (fromRight)
import qualified Data.Map.Strict as M
import Data.Serialize (Serialize, decode)
import Data.Serialize (Serialize)
import Data.List (foldl')
import System.IO.Unsafe (unsafePerformIO)
import Data.Maybe
......@@ -23,7 +21,6 @@ import Foreign
import Foreign.C.Types
import IGraph
import IGraph.Mutable (MGraph(..))
{#import IGraph.Internal #}
{#import IGraph.Internal.Constants #}
......
module IGraph.Read
( readAdjMatrix
, fromAdjMatrix
, readAdjMatrixWeighted
) where
import qualified Data.ByteString.Char8 as B
import Data.ByteString.Lex.Fractional (readExponential, readSigned)
import Data.Maybe (fromJust)
import Data.Singletons (SingI)
import IGraph
readDouble :: B.ByteString -> Double
readDouble = fst . fromJust . readSigned readExponential
{-# INLINE readDouble #-}
readAdjMatrix :: SingI d => FilePath -> IO (Graph d B.ByteString ())
readAdjMatrix = fmap fromAdjMatrix . B.readFile
fromAdjMatrix :: SingI d => B.ByteString -> Graph d B.ByteString ()
fromAdjMatrix bs =
let (header:xs) = B.lines bs
mat = map (map readDouble . B.words) xs
es = fst $ unzip $ filter f $ zip [ (i,j) | i <- [0..nrow-1], j <- [0..nrow-1] ] $ concat mat
nrow = length mat
ncol = length $ head mat
in if nrow /= ncol
then error "fromAdjMatrix: nrow != ncol"
else mkGraph (B.words header) $ zip es $ repeat ()
where
f ((i,j),v) = i < j && v /= 0
{-# INLINE fromAdjMatrix #-}
readAdjMatrixWeighted :: SingI d => FilePath -> IO (Graph d B.ByteString Double)
readAdjMatrixWeighted fl = do
c <- B.readFile fl
let (header:xs) = B.lines c
mat = map (map readDouble . B.words) xs
(es, ws) = unzip $ filter f $ zip [ (i,j) | i <- [0..nrow-1], j <- [0..nrow-1] ] $ concat mat
nrow = length mat
ncol = length $ head mat
if nrow /= ncol
then error "nrow != ncol"
else return $ mkGraph (B.words header) $ zip es ws
where
f ((i,j),v) = i < j && v /= 0
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment