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
5b8ed8af
Commit
5b8ed8af
authored
Apr 30, 2018
by
Kai Zhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
minor
parent
0c650a74
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
12 deletions
+13
-12
IGraph.hs
src/IGraph.hs
+13
-11
Motif.chs
src/IGraph/Motif.chs
+0
-1
No files found.
src/IGraph.hs
View file @
5b8ed8af
...
@@ -189,18 +189,20 @@ fromLabeledEdges es = mkGraph labels es'
...
@@ -189,18 +189,20 @@ fromLabeledEdges es = mkGraph labels es'
labelToId
=
M
.
fromList
$
zip
labels
[
0
..
]
labelToId
=
M
.
fromList
$
zip
labels
[
0
..
]
-- | Create a graph from a stream of labeled edges.
-- | Create a graph from a stream of labeled edges.
fromLabeledEdges'
::
(
SingI
d
,
Hashable
v
,
Serialize
v
,
Eq
v
,
Serialize
e
)
fromLabeledEdges'
::
(
MonadUnliftIO
m
,
SingI
d
,
Hashable
v
,
Serialize
v
,
Eq
v
,
Serialize
e
)
=>
a
-- ^ Input, usually a file
=>
a
-- ^ Input, usually a file
->
(
a
->
ConduitT
()
((
v
,
v
),
e
)
IO
()
)
-- ^ deserialize the input into a stream of edges
->
(
a
->
ConduitT
()
((
v
,
v
),
e
)
m
()
)
-- ^ deserialize the input into a stream of edges
->
IO
(
Graph
d
v
e
)
->
m
(
Graph
d
v
e
)
fromLabeledEdges'
input
mkConduit
=
do
fromLabeledEdges'
input
mkConduit
=
do
(
labelToId
,
_
,
ne
)
<-
runConduit
$
mkConduit
input
.|
(
labelToId
,
_
,
ne
)
<-
runConduit
$
mkConduit
input
.|
foldlC
f
(
M
.
empty
,
0
::
Int
,
0
::
Int
)
foldlC
f
(
M
.
empty
,
0
::
Int
,
0
::
Int
)
allocaVectorN
(
2
*
ne
)
$
\
evec
->
allocaBSVectorN
ne
$
\
bsvec
->
do
let
action
evec
bsvec
=
do
let
getId
x
=
M
.
lookupDefault
undefined
x
labelToId
let
getId
x
=
M
.
lookupDefault
undefined
x
labelToId
runConduit
$
mkConduit
input
.|
runConduit
$
mkConduit
input
.|
mapC
(
\
((
v1
,
v2
),
e
)
->
((
getId
v1
,
getId
v2
),
e
))
.|
mapC
(
\
((
v1
,
v2
),
e
)
->
((
getId
v1
,
getId
v2
),
e
))
.|
deserializeGraph
(
fst
$
unzip
$
sortBy
(
comparing
snd
)
$
M
.
toList
labelToId
)
evec
bsvec
deserializeGraph
(
fst
$
unzip
$
sortBy
(
comparing
snd
)
$
M
.
toList
labelToId
)
evec
bsvec
withRunInIO
$
\
runInIO
->
allocaVectorN
(
2
*
ne
)
$
\
evec
->
allocaBSVectorN
ne
$
\
bsvec
->
(
runInIO
$
action
evec
bsvec
)
where
where
f
(
vs
,
nn
,
ne
)
((
v1
,
v2
),
_
)
=
f
(
vs
,
nn
,
ne
)
((
v1
,
v2
),
_
)
=
let
(
vs'
,
nn'
)
=
add
v1
$
add
v2
(
vs
,
nn
)
let
(
vs'
,
nn'
)
=
add
v1
$
add
v2
(
vs
,
nn
)
...
@@ -210,11 +212,11 @@ fromLabeledEdges' input mkConduit = do
...
@@ -210,11 +212,11 @@ fromLabeledEdges' input mkConduit = do
then
(
m
,
i
)
then
(
m
,
i
)
else
(
M
.
insert
v
i
m
,
i
+
1
)
else
(
M
.
insert
v
i
m
,
i
+
1
)
deserializeGraph
::
(
SingI
d
,
Hashable
v
,
Serialize
v
,
Eq
v
,
Serialize
e
)
deserializeGraph
::
(
MonadIO
m
,
SingI
d
,
Hashable
v
,
Serialize
v
,
Eq
v
,
Serialize
e
)
=>
[
v
]
=>
[
v
]
->
Ptr
Vector
-- ^ a vector that is sufficient to hold all edges
->
Ptr
Vector
-- ^ a vector that is sufficient to hold all edges
->
Ptr
BSVector
->
Ptr
BSVector
->
ConduitT
(
LEdge
e
)
o
IO
(
Graph
d
v
e
)
->
ConduitT
(
LEdge
e
)
o
m
(
Graph
d
v
e
)
deserializeGraph
nds
evec
bsvec
=
do
deserializeGraph
nds
evec
bsvec
=
do
let
f
i
((
fr
,
to
),
attr
)
=
liftIO
$
do
let
f
i
((
fr
,
to
),
attr
)
=
liftIO
$
do
igraphVectorSet
evec
(
i
*
2
)
$
fromIntegral
fr
igraphVectorSet
evec
(
i
*
2
)
$
fromIntegral
fr
...
@@ -222,8 +224,8 @@ deserializeGraph nds evec bsvec = do
...
@@ -222,8 +224,8 @@ deserializeGraph nds evec bsvec = do
bsvectorSet
bsvec
i
$
encode
attr
bsvectorSet
bsvec
i
$
encode
attr
return
$
i
+
1
return
$
i
+
1
_
<-
foldMC
f
0
_
<-
foldMC
f
0
gr
@
(
MGraph
g
)
<-
new
0
liftIO
$
do
liftIO
$
do
gr
@
(
MGraph
g
)
<-
new
0
addLNodes
nds
gr
addLNodes
nds
gr
withBSAttr
edgeAttr
bsvec
$
\
ptr
->
withBSAttr
edgeAttr
bsvec
$
\
ptr
->
withPtrs
[
ptr
]
(
igraphAddEdges
g
evec
.
castPtr
)
withPtrs
[
ptr
]
(
igraphAddEdges
g
evec
.
castPtr
)
...
...
src/IGraph/Motif.chs
View file @
5b8ed8af
...
@@ -9,7 +9,6 @@ import Data.Hashable (Hashable)
...
@@ -9,7 +9,6 @@ import Data.Hashable (Hashable)
import System.IO.Unsafe (unsafePerformIO)
import System.IO.Unsafe (unsafePerformIO)
import Foreign
import Foreign
import qualified Foreign.Ptr as C2HSImp
import IGraph
import IGraph
{#import IGraph.Internal #}
{#import IGraph.Internal #}
...
...
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