Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
haskell-igraph
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
haskell-igraph
Commits
e3f55c20
Commit
e3f55c20
authored
Apr 24, 2018
by
Kai Zhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clean up
parent
a0a57b4e
Changes
16
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
138 additions
and
173 deletions
+138
-173
ChangeLog.md
ChangeLog.md
+6
-0
haskell-igraph.cabal
haskell-igraph.cabal
+1
-0
IGraph.hs
src/IGraph.hs
+46
-67
Clique.chs
src/IGraph/Clique.chs
+0
-3
Community.chs
src/IGraph/Community.chs
+5
-7
GEXF.hs
src/IGraph/Exporter/GEXF.hs
+0
-2
Generators.chs
src/IGraph/Generators.chs
+0
-1
Internal.chs
src/IGraph/Internal.chs
+0
-2
Constants.chs
src/IGraph/Internal/Constants.chs
+0
-2
Types.chs
src/IGraph/Internal/Types.chs
+2
-13
Isomorphism.chs
src/IGraph/Isomorphism.chs
+13
-6
Layout.chs
src/IGraph/Layout.chs
+25
-28
Motif.chs
src/IGraph/Motif.chs
+2
-6
Mutable.hs
src/IGraph/Mutable.hs
+2
-4
Structure.chs
src/IGraph/Structure.chs
+34
-30
Types.hs
src/IGraph/Types.hs
+2
-2
No files found.
ChangeLog.md
View file @
e3f55c20
Revision history for haskell-igraph
Revision history for haskell-igraph
===================================
===================================
v0.4.* --
-------------------
*
Fix memory leaks.
v0.4.0 -- 2018-04-20
v0.4.0 -- 2018-04-20
-------------------
-------------------
...
...
haskell-igraph.cabal
View file @
e3f55c20
...
@@ -69,6 +69,7 @@ library
...
@@ -69,6 +69,7 @@ library
extra-libraries: igraph
extra-libraries: igraph
hs-source-dirs: src
hs-source-dirs: src
default-language: Haskell2010
default-language: Haskell2010
ghc-options: -Wall
build-tools: c2hs >=0.25.0
build-tools: c2hs >=0.25.0
c-sources:
c-sources:
cbits/haskell_igraph.c
cbits/haskell_igraph.c
...
...
src/IGraph.hs
View file @
e3f55c20
...
@@ -3,8 +3,8 @@
...
@@ -3,8 +3,8 @@
module
IGraph
module
IGraph
(
Graph
(
..
)
(
Graph
(
..
)
,
LGraph
(
..
)
,
LGraph
(
..
)
,
U
(
..
)
,
U
,
D
(
..
)
,
D
,
decodeC
,
decodeC
,
empty
,
empty
,
mkGraph
,
mkGraph
...
@@ -20,19 +20,16 @@ module IGraph
...
@@ -20,19 +20,16 @@ module IGraph
,
pre
,
pre
,
suc
,
suc
,
mapNodes
,
mapEdges
,
filterNodes
,
filterEdges
,
nmap
,
nmap
,
emap
,
emap
,
nfilter
,
efilter
)
where
)
where
import
Conduit
import
Conduit
import
Control.Arrow
((
***
))
import
Control.Arrow
((
&&&
))
import
Control.Monad
(
forM
,
forM_
,
liftM
,
replicateM
,
import
Control.Monad
(
forM
,
forM_
,
liftM
,
replicateM
)
unless
)
import
Control.Monad.Primitive
import
Control.Monad.Primitive
import
Control.Monad.ST
(
runST
)
import
Control.Monad.ST
(
runST
)
import
qualified
Data.ByteString
as
B
import
qualified
Data.ByteString
as
B
...
@@ -42,10 +39,9 @@ import Data.Hashable (Hashable)
...
@@ -42,10 +39,9 @@ import Data.Hashable (Hashable)
import
qualified
Data.HashMap.Strict
as
M
import
qualified
Data.HashMap.Strict
as
M
import
qualified
Data.HashSet
as
S
import
qualified
Data.HashSet
as
S
import
Data.List
(
sortBy
)
import
Data.List
(
sortBy
)
import
Data.Maybe
import
Data.Ord
(
comparing
)
import
Data.Ord
(
comparing
)
import
Data.Serialize
import
Data.Serialize
import
Foreign
(
castPtr
,
with
)
import
Foreign
(
castPtr
)
import
System.IO.Unsafe
(
unsafePerformIO
)
import
System.IO.Unsafe
(
unsafePerformIO
)
import
IGraph.Internal
import
IGraph.Internal
...
@@ -68,6 +64,10 @@ class MGraph d => Graph d where
...
@@ -68,6 +64,10 @@ class MGraph d => Graph d where
nodes
gr
=
[
0
..
nNodes
gr
-
1
]
nodes
gr
=
[
0
..
nNodes
gr
-
1
]
{-# INLINE nodes #-}
{-# INLINE nodes #-}
labNodes
::
Serialize
v
=>
LGraph
d
v
e
->
[
LNode
v
]
labNodes
gr
=
map
(
\
i
->
(
i
,
nodeLab
gr
i
))
$
nodes
gr
{-# INLINE labNodes #-}
-- | Return the number of edges in a graph.
-- | Return the number of edges in a graph.
nEdges
::
LGraph
d
v
e
->
Int
nEdges
::
LGraph
d
v
e
->
Int
nEdges
(
LGraph
g
_
)
=
unsafePerformIO
$
igraphEcount
g
nEdges
(
LGraph
g
_
)
=
unsafePerformIO
$
igraphEcount
g
...
@@ -75,11 +75,13 @@ class MGraph d => Graph d where
...
@@ -75,11 +75,13 @@ class MGraph d => Graph d where
-- | Return all edges.
-- | Return all edges.
edges
::
LGraph
d
v
e
->
[
Edge
]
edges
::
LGraph
d
v
e
->
[
Edge
]
edges
gr
@
(
LGraph
g
_
)
=
unsafePerformIO
$
mapM
(
igraphEdge
g
)
[
0
..
n
-
1
]
edges
gr
=
map
(
getEdgeByEid
gr
)
[
0
..
nEdges
gr
-
1
]
where
n
=
nEdges
gr
{-# INLINE edges #-}
{-# INLINE edges #-}
labEdges
::
Serialize
e
=>
LGraph
d
v
e
->
[
LEdge
e
]
labEdges
gr
=
map
(
getEdgeByEid
gr
&&&
getEdgeLabByEid
gr
)
[
0
..
nEdges
gr
-
1
]
{-# INLINE labEdges #-}
-- | Whether a edge exists in the graph.
-- | Whether a edge exists in the graph.
hasEdge
::
LGraph
d
v
e
->
Edge
->
Bool
hasEdge
::
LGraph
d
v
e
->
Edge
->
Bool
hasEdge
(
LGraph
g
_
)
(
fr
,
to
)
=
unsafePerformIO
$
do
hasEdge
(
LGraph
g
_
)
(
fr
,
to
)
=
unsafePerformIO
$
do
...
@@ -109,15 +111,15 @@ class MGraph d => Graph d where
...
@@ -109,15 +111,15 @@ class MGraph d => Graph d where
-- | Find the edge by edge ID.
-- | Find the edge by edge ID.
getEdgeByEid
::
LGraph
d
v
e
->
Int
->
Edge
getEdgeByEid
::
LGraph
d
v
e
->
Int
->
Edge
getEdgeByEid
gr
@
(
LGraph
g
_
)
i
=
unsafePerformIO
$
igraphEdge
g
i
getEdgeByEid
(
LGraph
g
_
)
i
=
unsafePerformIO
$
igraphEdge
g
i
{-# INLINE getEdgeByEid #-}
{-# INLINE getEdgeByEid #-}
-- | Find the edge label by edge ID.
-- | Find the edge label by edge ID.
e
dgeLabByEid
::
Serialize
e
=>
LGraph
d
v
e
->
Int
->
e
getE
dgeLabByEid
::
Serialize
e
=>
LGraph
d
v
e
->
Int
->
e
e
dgeLabByEid
(
LGraph
g
_
)
i
=
unsafePerformIO
$
getE
dgeLabByEid
(
LGraph
g
_
)
i
=
unsafePerformIO
$
igraphHaskellAttributeEAS
g
edgeAttr
i
>>=
bsToByteString
>>=
igraphHaskellAttributeEAS
g
edgeAttr
i
>>=
bsToByteString
>>=
return
.
fromRight
(
error
"decode failed"
)
.
decode
return
.
fromRight
(
error
"decode failed"
)
.
decode
{-# INLINE
e
dgeLabByEid #-}
{-# INLINE
getE
dgeLabByEid #-}
instance
Graph
U
where
instance
Graph
U
where
isDirected
=
const
False
isDirected
=
const
False
...
@@ -139,7 +141,7 @@ instance (Graph d, Serialize v, Serialize e, Hashable v, Eq v)
...
@@ -139,7 +141,7 @@ instance (Graph d, Serialize v, Serialize e, Hashable v, Eq v)
put
$
nNodes
gr
put
$
nNodes
gr
go
(
nodeLab
gr
)
(
nNodes
gr
)
0
go
(
nodeLab
gr
)
(
nNodes
gr
)
0
put
$
nEdges
gr
put
$
nEdges
gr
go
(
\
i
->
(
getEdgeByEid
gr
i
,
e
dgeLabByEid
gr
i
))
(
nEdges
gr
)
0
go
(
\
i
->
(
getEdgeByEid
gr
i
,
getE
dgeLabByEid
gr
i
))
(
nEdges
gr
)
0
where
where
go
f
n
i
|
i
>=
n
=
return
()
go
f
n
i
|
i
>=
n
=
return
()
|
otherwise
=
put
(
f
i
)
>>
go
f
n
(
i
+
1
)
|
otherwise
=
put
(
f
i
)
>>
go
f
n
(
i
+
1
)
...
@@ -176,8 +178,6 @@ mkGraph vattr es = runST $ do
...
@@ -176,8 +178,6 @@ mkGraph vattr es = runST $ do
addLNodes
vattr
g
addLNodes
vattr
g
addLEdges
es
g
addLEdges
es
g
unsafeFreeze
g
unsafeFreeze
g
where
n
=
length
vattr
-- | Create a graph from labeled edges.
-- | Create a graph from labeled edges.
fromLabeledEdges
::
(
Graph
d
,
Hashable
v
,
Serialize
v
,
Eq
v
,
Serialize
e
)
fromLabeledEdges
::
(
Graph
d
,
Hashable
v
,
Serialize
v
,
Eq
v
,
Serialize
e
)
...
@@ -223,7 +223,7 @@ deserializeGraph nds ne = do
...
@@ -223,7 +223,7 @@ deserializeGraph nds ne = do
igraphVectorSet
evec
(
i
*
2
+
1
)
$
fromIntegral
to
igraphVectorSet
evec
(
i
*
2
+
1
)
$
fromIntegral
to
bsvectorSet
bsvec
i
$
encode
attr
bsvectorSet
bsvec
i
$
encode
attr
return
$
i
+
1
return
$
i
+
1
foldMC
f
0
_
<-
foldMC
f
0
gr
@
(
MLGraph
g
)
<-
new
0
gr
@
(
MLGraph
g
)
<-
new
0
addLNodes
nds
gr
addLNodes
nds
gr
unsafePrimToPrim
$
withAttr
edgeAttr
bsvec
$
\
ptr
->
do
unsafePrimToPrim
$
withAttr
edgeAttr
bsvec
$
\
ptr
->
do
...
@@ -280,61 +280,40 @@ pre gr i = unsafePerformIO $ do
...
@@ -280,61 +280,40 @@ pre gr i = unsafePerformIO $ do
vit
<-
igraphVitNew
(
_graph
gr
)
vs
vit
<-
igraphVitNew
(
_graph
gr
)
vs
vitToList
vit
vitToList
vit
-- | Keep nodes that satisfy the constraint
filterNodes
::
(
Hashable
v
,
Eq
v
,
Serialize
v
,
Graph
d
)
=>
(
LGraph
d
v
e
->
Node
->
Bool
)
->
LGraph
d
v
e
->
LGraph
d
v
e
filterNodes
f
gr
=
runST
$
do
let
deleted
=
filter
(
not
.
f
gr
)
$
nodes
gr
gr'
<-
thaw
gr
delNodes
deleted
gr'
unsafeFreeze
gr'
-- | Apply a function to change nodes' labels.
-- | Apply a function to change nodes' labels.
mapNodes
::
(
Graph
d
,
Serialize
v1
,
Serialize
v2
,
Hashable
v2
,
Eq
v2
)
nmap
::
(
Graph
d
,
Serialize
v1
,
Serialize
v2
,
Hashable
v2
,
Eq
v2
)
=>
(
Node
->
v1
->
v2
)
->
LGraph
d
v1
e
->
LGraph
d
v2
e
=>
(
LNode
v1
->
v2
)
->
LGraph
d
v1
e
->
LGraph
d
v2
e
mapNodes
f
gr
=
runST
$
do
nmap
f
gr
=
runST
$
do
(
MLGraph
gptr
)
<-
thaw
gr
(
MLGraph
gptr
)
<-
thaw
gr
let
gr'
=
MLGraph
gptr
let
gr'
=
MLGraph
gptr
forM_
(
nodes
gr
)
$
\
x
->
setNodeAttr
x
(
f
x
$
nodeLab
gr
x
)
gr'
forM_
(
nodes
gr
)
$
\
x
->
setNodeAttr
x
(
f
(
x
,
nodeLab
gr
x
)
)
gr'
unsafeFreeze
gr'
unsafeFreeze
gr'
-- | Apply a function to change edges' labels.
-- | Apply a function to change edges' labels.
mapEdges
::
(
Graph
d
,
Serialize
e1
,
Serialize
e2
,
Hashable
v
,
Eq
v
,
Serialize
v
)
emap
::
(
Graph
d
,
Serialize
e1
,
Serialize
e2
,
Hashable
v
,
Eq
v
,
Serialize
v
)
=>
(
Edge
->
e1
->
e2
)
->
LGraph
d
v
e1
->
LGraph
d
v
e2
=>
(
LEdge
e1
->
e2
)
->
LGraph
d
v
e1
->
LGraph
d
v
e2
mapEdges
f
gr
=
runST
$
do
emap
f
gr
=
runST
$
do
(
MLGraph
gptr
)
<-
thaw
gr
(
MLGraph
gptr
)
<-
thaw
gr
let
gr'
=
MLGraph
gptr
let
gr'
=
MLGraph
gptr
forM_
[
0
..
nEdges
gr
-
1
]
$
\
x
->
do
forM_
[
0
..
nEdges
gr
-
1
]
$
\
i
->
do
e
<-
unsafePrimToPrim
$
igraphEdge
(
_graph
gr
)
x
let
lab
=
f
(
getEdgeByEid
gr
i
,
getEdgeLabByEid
gr
i
)
setEdgeAttr
x
(
f
e
$
edgeLabByEid
gr
x
)
gr'
setEdgeAttr
i
lab
gr'
unsafeFreeze
gr'
unsafeFreeze
gr'
-- | Keep nodes that satisfy the constraint.
-- | Keep nodes that satisfy the constraint.
filterEdges
::
(
Hashable
v
,
Eq
v
,
Serialize
v
,
Graph
d
)
nfilter
::
(
Hashable
v
,
Eq
v
,
Serialize
v
,
Graph
d
)
=>
(
LGraph
d
v
e
->
Edge
->
Bool
)
->
LGraph
d
v
e
->
LGraph
d
v
e
=>
(
LNode
v
->
Bool
)
->
LGraph
d
v
e
->
LGraph
d
v
e
filterEdges
f
gr
=
runST
$
do
nfilter
f
gr
=
runST
$
do
let
deleted
=
f
ilter
(
not
.
f
gr
)
$
edg
es
gr
let
deleted
=
f
st
$
unzip
$
filter
(
not
.
f
)
$
labNod
es
gr
gr'
<-
thaw
gr
gr'
<-
thaw
gr
del
Edg
es
deleted
gr'
del
Nod
es
deleted
gr'
unsafeFreeze
gr'
unsafeFreeze
gr'
-- | Map a function over the node labels in a graph.
-- | Keep edges that satisfy the constraint.
nmap
::
(
Graph
d
,
Serialize
v
,
Hashable
u
,
Serialize
u
,
Eq
u
)
efilter
::
(
Hashable
v
,
Eq
v
,
Serialize
v
,
Serialize
e
,
Graph
d
)
=>
((
Node
,
v
)
->
u
)
->
LGraph
d
v
e
->
LGraph
d
u
e
=>
(
LEdge
e
->
Bool
)
->
LGraph
d
v
e
->
LGraph
d
v
e
nmap
fn
gr
=
unsafePerformIO
$
do
efilter
f
gr
=
runST
$
do
(
MLGraph
g
)
<-
thaw
gr
let
deleted
=
fst
$
unzip
$
filter
(
not
.
f
)
$
labEdges
gr
forM_
(
nodes
gr
)
$
\
i
->
do
gr'
<-
thaw
gr
let
label
=
fn
(
i
,
nodeLab
gr
i
)
delEdges
deleted
gr'
asBS
(
encode
label
)
(
igraphHaskellAttributeVASSet
g
vertexAttr
i
)
unsafeFreeze
gr'
unsafeFreeze
(
MLGraph
g
)
-- | Map a function over the edge labels in a graph.
emap
::
(
Graph
d
,
Serialize
v
,
Hashable
v
,
Eq
v
,
Serialize
e1
,
Serialize
e2
)
=>
((
Edge
,
e1
)
->
e2
)
->
LGraph
d
v
e1
->
LGraph
d
v
e2
emap
fn
gr
=
unsafePerformIO
$
do
(
MLGraph
g
)
<-
thaw
gr
forM_
(
edges
gr
)
$
\
(
fr
,
to
)
->
do
i
<-
igraphGetEid
g
fr
to
True
True
let
label
=
fn
((
fr
,
to
),
edgeLabByEid
gr
i
)
asBS
(
encode
label
)
(
igraphHaskellAttributeEASSet
g
edgeAttr
i
)
unsafeFreeze
(
MLGraph
g
)
src/IGraph/Clique.chs
View file @
e3f55c20
...
@@ -7,10 +7,7 @@ module IGraph.Clique
...
@@ -7,10 +7,7 @@ module IGraph.Clique
import Control.Applicative ((<$>))
import Control.Applicative ((<$>))
import System.IO.Unsafe (unsafePerformIO)
import System.IO.Unsafe (unsafePerformIO)
import qualified Foreign.Marshal.Utils as C2HSImp
import qualified Foreign.Ptr as C2HSImp
import qualified Foreign.Ptr as C2HSImp
import Foreign
import Foreign.C.Types
import IGraph
import IGraph
{#import IGraph.Internal #}
{#import IGraph.Internal #}
...
...
src/IGraph/Community.chs
View file @
e3f55c20
...
@@ -5,12 +5,10 @@ module IGraph.Community
...
@@ -5,12 +5,10 @@ module IGraph.Community
, findCommunity
, findCommunity
) where
) where
import Control.Applicative ((<$>))
import Control.Monad
import Data.Default.Class
import Data.Default.Class
import Data.Function (on)
import Data.Function (on)
import Data.List
import Data.List
(sortBy, groupBy)
import Data.Ord
import Data.Ord
(comparing)
import System.IO.Unsafe (unsafePerformIO)
import System.IO.Unsafe (unsafePerformIO)
import Foreign
import Foreign
...
@@ -53,9 +51,9 @@ findCommunity gr opt = unsafePerformIO $ do
...
@@ -53,9 +51,9 @@ findCommunity gr opt = unsafePerformIO $ do
result <- igraphVectorNew 0
result <- igraphVectorNew 0
ws <- case _weights opt of
ws <- case _weights opt of
Just w -> fromList w
Just w -> fromList w
_ ->
liftM
Vector $ newForeignPtr_ $ castPtr nullPtr
_ ->
fmap
Vector $ newForeignPtr_ $ castPtr nullPtr
case _method opt of
_ <-
case _method opt of
LeadingEigenvector -> do
LeadingEigenvector -> do
ap <- igraphArpackNew
ap <- igraphArpackNew
igraphCommunityLeadingEigenvector (_graph gr) ws nullPtr result
igraphCommunityLeadingEigenvector (_graph gr) ws nullPtr result
...
@@ -69,7 +67,7 @@ findCommunity gr opt = unsafePerformIO $ do
...
@@ -69,7 +67,7 @@ findCommunity gr opt = unsafePerformIO $ do
IgraphSpincommUpdateConfig (_gamma opt)
IgraphSpincommUpdateConfig (_gamma opt)
IgraphSpincommImpOrig 1.0
IgraphSpincommImpOrig 1.0
liftM
( map (fst . unzip) . groupBy ((==) `on` snd)
fmap
( map (fst . unzip) . groupBy ((==) `on` snd)
. sortBy (comparing snd) . zip [0..] ) $ toList result
. sortBy (comparing snd) . zip [0..] ) $ toList result
{#fun igraph_community_spinglass as ^
{#fun igraph_community_spinglass as ^
...
...
src/IGraph/Exporter/GEXF.hs
View file @
e3f55c20
...
@@ -15,11 +15,9 @@ import Data.Colour.SRGB (channelBlue, channelGreen,
...
@@ -15,11 +15,9 @@ import Data.Colour.SRGB (channelBlue, channelGreen,
channelRed
,
toSRGB24
)
channelRed
,
toSRGB24
)
import
Data.Hashable
import
Data.Hashable
import
Data.Serialize
import
Data.Serialize
import
Data.Tree.NTree.TypeDefs
import
GHC.Generics
import
GHC.Generics
import
IGraph
import
IGraph
import
Text.XML.HXT.Core
import
Text.XML.HXT.Core
import
Text.XML.HXT.DOM.TypeDefs
instance
Serialize
(
AlphaColour
Double
)
where
instance
Serialize
(
AlphaColour
Double
)
where
get
=
do
get
=
do
...
...
src/IGraph/Generators.chs
View file @
e3f55c20
...
@@ -11,7 +11,6 @@ import Control.Monad (when)
...
@@ -11,7 +11,6 @@ import Control.Monad (when)
import Data.Hashable (Hashable)
import Data.Hashable (Hashable)
import Data.Serialize (Serialize)
import Data.Serialize (Serialize)
import qualified Foreign.Marshal.Utils as C2HSImp
import qualified Foreign.Ptr as C2HSImp
import qualified Foreign.Ptr as C2HSImp
import IGraph
import IGraph
...
...
src/IGraph/Internal.chs
View file @
e3f55c20
...
@@ -92,10 +92,8 @@ import Control.Monad
...
@@ -92,10 +92,8 @@ import Control.Monad
import qualified Data.ByteString.Char8 as B
import qualified Data.ByteString.Char8 as B
import Data.ByteString (packCStringLen)
import Data.ByteString (packCStringLen)
import Data.ByteString.Unsafe (unsafeUseAsCStringLen)
import Data.ByteString.Unsafe (unsafeUseAsCStringLen)
import System.IO.Unsafe (unsafePerformIO)
import Data.List (transpose)
import Data.List (transpose)
import Data.List.Split (chunksOf)
import Data.List.Split (chunksOf)
import Data.Serialize (Serialize, decode, encode)
import Foreign
import Foreign
import Foreign.C.Types
import Foreign.C.Types
...
...
src/IGraph/Internal/Constants.chs
View file @
e3f55c20
{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE ForeignFunctionInterface #-}
module IGraph.Internal.Constants where
module IGraph.Internal.Constants where
import Foreign
#include "igraph/igraph.h"
#include "igraph/igraph.h"
{#enum igraph_neimode_t as Neimode {underscoreToCase}
{#enum igraph_neimode_t as Neimode {underscoreToCase}
...
...
src/IGraph/Internal/Types.chs
View file @
e3f55c20
...
@@ -20,6 +20,7 @@ module IGraph.Internal.Types
...
@@ -20,6 +20,7 @@ module IGraph.Internal.Types
-- * Bytestring
-- * Bytestring
, BSLen(..)
, BSLen(..)
, withBSLen
-- * Bytestring vector
-- * Bytestring vector
, BSVector(..)
, BSVector(..)
...
@@ -65,6 +66,7 @@ module IGraph.Internal.Types
...
@@ -65,6 +66,7 @@ module IGraph.Internal.Types
-- * Igraph attribute record
-- * Igraph attribute record
, AttributeRecord(..)
, AttributeRecord(..)
, withAttributeRecord
-- * Igraph arpack options type
-- * Igraph arpack options type
, ArpackOpt(..)
, ArpackOpt(..)
...
@@ -72,20 +74,7 @@ module IGraph.Internal.Types
...
@@ -72,20 +74,7 @@ module IGraph.Internal.Types
, igraphArpackNew
, igraphArpackNew
) where
) where
import Control.Monad
import qualified Data.ByteString.Char8 as B
import Data.ByteString (packCStringLen)
import Data.ByteString.Unsafe (unsafeUseAsCStringLen)
import System.IO.Unsafe (unsafePerformIO)
import Data.List (transpose)
import Data.List.Split (chunksOf)
import Data.Serialize (Serialize, decode, encode)
import Foreign
import Foreign
import Foreign.C.Types
import Foreign.C.String
{#import IGraph.Internal.Constants #}
#include "haskell_attributes.h"
#include "haskell_attributes.h"
#include "haskell_igraph.h"
#include "haskell_igraph.h"
...
...
src/IGraph/Isomorphism.chs
View file @
e3f55c20
...
@@ -32,11 +32,18 @@ getSubisomorphisms g1 g2 = unsafePerformIO $ do
...
@@ -32,11 +32,18 @@ getSubisomorphisms g1 g2 = unsafePerformIO $ do
gptr1 = _graph g1
gptr1 = _graph g1
gptr2 = _graph g2
gptr2 = _graph g2
{-# INLINE getSubisomorphisms #-}
{-# INLINE getSubisomorphisms #-}
{#fun igraph_get_subisomorphisms_vf2 as ^ { `IGraph', `IGraph',
{#fun igraph_get_subisomorphisms_vf2 as ^
id `Ptr ()', id `Ptr ()', id `Ptr ()', id `Ptr ()', `VectorPtr',
{ `IGraph'
id `FunPtr (Ptr IGraph -> Ptr IGraph -> CInt -> CInt -> Ptr () -> IO CInt)',
, `IGraph'
id `FunPtr (Ptr IGraph -> Ptr IGraph -> CInt -> CInt -> Ptr () -> IO CInt)',
, id `Ptr ()'
id `Ptr ()'} -> `Int' #}
, id `Ptr ()'
, id `Ptr ()'
, id `Ptr ()'
, `VectorPtr'
, id `FunPtr (Ptr IGraph -> Ptr IGraph -> CInt -> CInt -> Ptr () -> IO CInt)'
, id `FunPtr (Ptr IGraph -> Ptr IGraph -> CInt -> CInt -> Ptr () -> IO CInt)'
, id `Ptr ()'
} -> `CInt' void- #}
-- | Determine whether two graphs are isomorphic.
-- | Determine whether two graphs are isomorphic.
isomorphic :: Graph d
isomorphic :: Graph d
...
@@ -47,7 +54,7 @@ isomorphic g1 g2 = unsafePerformIO $ alloca $ \ptr -> do
...
@@ -47,7 +54,7 @@ isomorphic g1 g2 = unsafePerformIO $ alloca $ \ptr -> do
_ <- igraphIsomorphic (_graph g1) (_graph g2) ptr
_ <- igraphIsomorphic (_graph g1) (_graph g2) ptr
x <- peek ptr
x <- peek ptr
return (x /= 0)
return (x /= 0)
{#fun igraph_isomorphic as ^ { `IGraph', `IGraph', id `Ptr CInt' } -> `
Int'
#}
{#fun igraph_isomorphic as ^ { `IGraph', `IGraph', id `Ptr CInt' } -> `
CInt' void-
#}
-- | Creates a graph from the given isomorphism class.
-- | Creates a graph from the given isomorphism class.
-- This function is implemented only for graphs with three or four vertices.
-- This function is implemented only for graphs with three or four vertices.
...
...
src/IGraph/Layout.chs
View file @
e3f55c20
...
@@ -6,16 +6,11 @@ module IGraph.Layout
...
@@ -6,16 +6,11 @@ module IGraph.Layout
, defaultLGL
, defaultLGL
) where
) where
import Control.Applicative ((<$>))
import Data.Default.Class
import Data.Maybe (isJust)
import Data.Maybe (isJust)
import Foreign (nullPtr)
import Foreign (nullPtr)
import System.IO.Unsafe (unsafePerformIO)
import qualified Foreign.Marshal.Utils as C2HSImp
import qualified Foreign.Ptr as C2HSImp
import qualified Foreign.Ptr as C2HSImp
import Foreign
import Foreign
import Foreign.C.Types
import IGraph
import IGraph
{#import IGraph.Internal #}
{#import IGraph.Internal #}
...
@@ -91,27 +86,29 @@ getLayout gr method = do
...
@@ -91,27 +86,29 @@ getLayout gr method = do
n = nNodes gr
n = nNodes gr
gptr = _graph gr
gptr = _graph gr
{#fun igraph_layout_kamada_kawai as ^ { `IGraph'
{#fun igraph_layout_kamada_kawai as ^
, `Matrix'
{ `IGraph'
, `Int'
, `Matrix'
, `Double'
, `Int'
, `Double'
, `Double'
, `Double'
, `Double'
, `Double'
, `Double'
, `Bool'
, `Double'
, id `Ptr Vector'
, `Bool'
, id `Ptr Vector'
, id `Ptr Vector'
, id `Ptr Vector'
, id `Ptr Vector'
, id `Ptr Vector'
, id `Ptr Vector'
} -> `Int' #}
, id `Ptr Vector'
} -> `CInt' void- #}
{# fun igraph_layout_lgl as ^ { `IGraph'
{# fun igraph_layout_lgl as ^
, `Matrix'
{ `IGraph'
, `Int'
, `Matrix'
, `Double'
, `Int'
, `Double'
, `Double'
, `Double'
, `Double'
, `Double'
, `Double'
, `Double'
, `Double'
, `Int'
, `Double'
} -> `Int' #}
, `Int'
} -> `CInt' void- #}
src/IGraph/Motif.chs
View file @
e3f55c20
...
@@ -7,14 +7,10 @@ module IGraph.Motif
...
@@ -7,14 +7,10 @@ module IGraph.Motif
import Data.Hashable (Hashable)
import Data.Hashable (Hashable)
import System.IO.Unsafe (unsafePerformIO)
import System.IO.Unsafe (unsafePerformIO)
import qualified Foreign.Marshal.Utils as C2HSImp
import qualified Foreign.Ptr as C2HSImp
import qualified Foreign.Ptr as C2HSImp
import Foreign
import Foreign.C.Types
import IGraph
import IGraph
{#import IGraph.Internal #}
{#import IGraph.Internal #}
{#import IGraph.Internal.Constants #}
#include "haskell_igraph.h"
#include "haskell_igraph.h"
...
@@ -68,7 +64,7 @@ triadCensus gr = unsafePerformIO $ do
...
@@ -68,7 +64,7 @@ triadCensus gr = unsafePerformIO $ do
-- motifsRandesu
-- motifsRandesu
{#fun igraph_triad_census as ^ { `IGraph'
{#fun igraph_triad_census as ^ { `IGraph'
, `Vector' } -> `
Int'
#}
, `Vector' } -> `
CInt' void-
#}
{#fun igraph_motifs_randesu as ^ { `IGraph', `Vector', `Int'
{#fun igraph_motifs_randesu as ^ { `IGraph', `Vector', `Int'
, `Vector' } -> `
Int'
#}
, `Vector' } -> `
CInt' void-
#}
src/IGraph/Mutable.hs
View file @
e3f55c20
...
@@ -10,10 +10,8 @@ module IGraph.Mutable
...
@@ -10,10 +10,8 @@ module IGraph.Mutable
import
Control.Monad
(
when
,
forM
)
import
Control.Monad
(
when
,
forM
)
import
Control.Monad.Primitive
import
Control.Monad.Primitive
import
qualified
Data.ByteString.Char8
as
B
import
Data.Serialize
(
Serialize
,
encode
)
import
Data.Serialize
(
Serialize
,
encode
)
import
Foreign
import
Foreign
import
Foreign.C.String
(
CString
,
withCString
)
import
IGraph.Internal
import
IGraph.Internal
import
IGraph.Internal.Initialization
import
IGraph.Internal.Initialization
...
@@ -55,7 +53,7 @@ class MGraph d where
...
@@ -55,7 +53,7 @@ class MGraph d where
delNodes
ns
(
MLGraph
g
)
=
unsafePrimToPrim
$
do
delNodes
ns
(
MLGraph
g
)
=
unsafePrimToPrim
$
do
vptr
<-
fromList
$
map
fromIntegral
ns
vptr
<-
fromList
$
map
fromIntegral
ns
vsptr
<-
igraphVsVector
vptr
vsptr
<-
igraphVsVector
vptr
igraphDeleteVertices
g
vsptr
_
<-
igraphDeleteVertices
g
vsptr
return
()
return
()
-- | Add edges to the graph.
-- | Add edges to the graph.
...
@@ -87,7 +85,7 @@ instance MGraph U where
...
@@ -87,7 +85,7 @@ instance MGraph U where
eids
<-
forM
es
$
\
(
fr
,
to
)
->
igraphGetEid
g
fr
to
False
True
eids
<-
forM
es
$
\
(
fr
,
to
)
->
igraphGetEid
g
fr
to
False
True
vptr
<-
fromList
$
map
fromIntegral
eids
vptr
<-
fromList
$
map
fromIntegral
eids
esptr
<-
igraphEsVector
vptr
esptr
<-
igraphEsVector
vptr
igraphDeleteEdges
g
esptr
_
<-
igraphDeleteEdges
g
esptr
return
()
return
()
instance
MGraph
D
where
instance
MGraph
D
where
...
...
src/IGraph/Structure.chs
View file @
e3f55c20
...
@@ -13,8 +13,6 @@ import Data.Either (fromRight)
...
@@ -13,8 +13,6 @@ import Data.Either (fromRight)
import Data.Hashable (Hashable)
import Data.Hashable (Hashable)
import qualified Data.HashMap.Strict as M
import qualified Data.HashMap.Strict as M
import Data.Serialize (Serialize, decode)
import Data.Serialize (Serialize, decode)
import Foreign
import Foreign.C.Types
import System.IO.Unsafe (unsafePerformIO)
import System.IO.Unsafe (unsafePerformIO)
import Foreign
import Foreign
...
@@ -132,24 +130,26 @@ personalizedPagerank gr reset ws d
...
@@ -132,24 +130,26 @@ personalizedPagerank gr reset ws d
n = nNodes gr
n = nNodes gr
m = nEdges gr
m = nEdges gr
{#fun igraph_induced_subgraph as ^ { `IGraph'
{#fun igraph_induced_subgraph as ^
, +160
{ `IGraph'
, %`IGraphVs'
, allocaIGraph- `IGraph' addIGraphFinalizer*
, `SubgraphImplementation' } -> `IGraph' #}
, %`IGraphVs'
, `SubgraphImplementation'
} -> `CInt' void- #}
{#fun igraph_closeness as ^ { `IGraph'
{#fun igraph_closeness as ^ { `IGraph'
, `Vector'
, `Vector'
, %`IGraphVs'
, %`IGraphVs'
, `Neimode'
, `Neimode'
, `Vector'
, `Vector'
, `Bool' } -> `
Int'
#}
, `Bool' } -> `
CInt' void-
#}
{#fun igraph_betweenness as ^ { `IGraph'
{#fun igraph_betweenness as ^ { `IGraph'
, `Vector'
, `Vector'
, %`IGraphVs'
, %`IGraphVs'
, `Bool'
, `Bool'
, `Vector'
, `Vector'
, `Bool' } -> `
Int'
#}
, `Bool' } -> `
CInt' void-
#}
{#fun igraph_eigenvector_centrality as ^ { `IGraph'
{#fun igraph_eigenvector_centrality as ^ { `IGraph'
, `Vector'
, `Vector'
...
@@ -157,25 +157,29 @@ personalizedPagerank gr reset ws d
...
@@ -157,25 +157,29 @@ personalizedPagerank gr reset ws d
, `Bool'
, `Bool'
, `Bool'
, `Bool'
, `Vector'
, `Vector'
, `ArpackOpt' } -> `Int' #}
, `ArpackOpt' } -> `CInt' void- #}
{#fun igraph_pagerank as ^ { `IGraph'
{#fun igraph_pagerank as ^
, `PagerankAlgo'
{ `IGraph'
, `Vector'
, `PagerankAlgo'
, id `Ptr CDouble'
, `Vector'
, %`IGraphVs'
, id `Ptr CDouble'
, `Bool'
, %`IGraphVs'
, `Double'
, `Bool'
, `Vector'
, `Double'
, id `Ptr ()' } -> `Int' #}
, `Vector'
, id `Ptr ()'
{#fun igraph_personalized_pagerank as ^ { `IGraph'
} -> `CInt' void- #}
, `PagerankAlgo'
, `Vector'
{#fun igraph_personalized_pagerank as ^
, id `Ptr CDouble'
{ `IGraph'
, %`IGraphVs'
, `PagerankAlgo'
, `Bool'
, `Vector'
, `Double'
, id `Ptr CDouble'
, `Vector'
, %`IGraphVs'
, `Vector'
, `Bool'
, id `Ptr ()' } -> `Int' #}
, `Double'
, `Vector'
, `Vector'
, id `Ptr ()'
} -> `CInt' void- #}
src/IGraph/Types.hs
View file @
e3f55c20
module
IGraph.Types
where
module
IGraph.Types
where
import
qualified
Data.HashMap.Strict
as
M
type
Node
=
Int
type
Node
=
Int
type
LNode
a
=
(
Node
,
a
)
type
Edge
=
(
Node
,
Node
)
type
Edge
=
(
Node
,
Node
)
type
LEdge
a
=
(
Edge
,
a
)
type
LEdge
a
=
(
Edge
,
a
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment