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
53c5c9d7
Commit
53c5c9d7
authored
Sep 06, 2017
by
Kai Zhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perform input sanity check in pagerank
parent
edc195d9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
19 deletions
+39
-19
IGraph.hs
src/IGraph.hs
+5
-0
Structure.hs
src/IGraph/Structure.hs
+34
-19
No files found.
src/IGraph.hs
View file @
53c5c9d7
...
@@ -5,6 +5,7 @@ module IGraph
...
@@ -5,6 +5,7 @@ module IGraph
,
U
(
..
)
,
U
(
..
)
,
D
(
..
)
,
D
(
..
)
,
Graph
(
..
)
,
Graph
(
..
)
,
empty
,
mkGraph
,
mkGraph
,
fromLabeledEdges
,
fromLabeledEdges
...
@@ -136,6 +137,10 @@ instance Graph D where
...
@@ -136,6 +137,10 @@ instance Graph D where
isDirected
=
const
True
isDirected
=
const
True
isD
=
const
True
isD
=
const
True
empty
::
(
Graph
d
,
Hashable
v
,
Read
v
,
Eq
v
,
Show
v
,
Show
e
)
=>
LGraph
d
v
e
empty
=
runST
$
new
0
>>=
unsafeFreeze
mkGraph
::
(
Graph
d
,
Hashable
v
,
Read
v
,
Eq
v
,
Show
v
,
Show
e
)
mkGraph
::
(
Graph
d
,
Hashable
v
,
Read
v
,
Eq
v
,
Show
v
,
Show
e
)
=>
[
v
]
->
[(
Edge
,
e
)]
->
LGraph
d
v
e
=>
[
v
]
->
[(
Edge
,
e
)]
->
LGraph
d
v
e
mkGraph
vattr
es
=
runST
$
do
mkGraph
vattr
es
=
runST
$
do
...
...
src/IGraph/Structure.hs
View file @
53c5c9d7
...
@@ -87,15 +87,22 @@ pagerank :: Graph d
...
@@ -87,15 +87,22 @@ pagerank :: Graph d
->
Maybe
[
Double
]
-- ^ edge weights
->
Maybe
[
Double
]
-- ^ edge weights
->
Double
-- ^ damping factor, usually around 0.85
->
Double
-- ^ damping factor, usually around 0.85
->
[
Double
]
->
[
Double
]
pagerank
gr
ws
d
=
unsafePerformIO
$
alloca
$
\
p
->
do
pagerank
gr
ws
d
vptr
<-
igraphVectorNew
0
|
n
==
0
=
[]
vsptr
<-
igraphVsAll
|
otherwise
=
unsafePerformIO
$
alloca
$
\
p
->
do
ws'
<-
case
ws
of
vptr
<-
igraphVectorNew
0
Just
w
->
listToVector
w
vsptr
<-
igraphVsAll
_
->
liftM
VectorPtr
$
newForeignPtr_
$
castPtr
nullPtr
ws'
<-
case
ws
of
igraphPagerank
(
_graph
gr
)
IgraphPagerankAlgoPrpack
vptr
p
vsptr
Just
w
->
if
length
w
/=
m
(
isDirected
gr
)
d
ws'
nullPtr
then
error
"pagerank: incorrect length of edge weight vector"
vectorPtrToList
vptr
else
listToVector
w
_
->
liftM
VectorPtr
$
newForeignPtr_
$
castPtr
nullPtr
igraphPagerank
(
_graph
gr
)
IgraphPagerankAlgoPrpack
vptr
p
vsptr
(
isDirected
gr
)
d
ws'
nullPtr
vectorPtrToList
vptr
where
n
=
nNodes
gr
m
=
nEdges
gr
personalizedPagerank
::
Graph
d
personalizedPagerank
::
Graph
d
=>
LGraph
d
v
e
=>
LGraph
d
v
e
...
@@ -103,13 +110,21 @@ personalizedPagerank :: Graph d
...
@@ -103,13 +110,21 @@ personalizedPagerank :: Graph d
->
Maybe
[
Double
]
->
Maybe
[
Double
]
->
Double
->
Double
->
[
Double
]
->
[
Double
]
personalizedPagerank
gr
reset
ws
d
=
unsafePerformIO
$
alloca
$
\
p
->
do
personalizedPagerank
gr
reset
ws
d
vptr
<-
igraphVectorNew
0
|
n
==
0
=
[]
vsptr
<-
igraphVsAll
|
length
reset
/=
n
=
error
"personalizedPagerank: incorrect length of reset vector"
ws'
<-
case
ws
of
|
otherwise
=
unsafePerformIO
$
alloca
$
\
p
->
do
Just
w
->
listToVector
w
vptr
<-
igraphVectorNew
0
_
->
liftM
VectorPtr
$
newForeignPtr_
$
castPtr
nullPtr
vsptr
<-
igraphVsAll
reset'
<-
listToVector
reset
ws'
<-
case
ws
of
igraphPersonalizedPagerank
(
_graph
gr
)
IgraphPagerankAlgoPrpack
vptr
p
vsptr
Just
w
->
if
length
w
/=
m
(
isDirected
gr
)
d
reset'
ws'
nullPtr
then
error
"pagerank: incorrect length of edge weight vector"
vectorPtrToList
vptr
else
listToVector
w
_
->
liftM
VectorPtr
$
newForeignPtr_
$
castPtr
nullPtr
reset'
<-
listToVector
reset
igraphPersonalizedPagerank
(
_graph
gr
)
IgraphPagerankAlgoPrpack
vptr
p
vsptr
(
isDirected
gr
)
d
reset'
ws'
nullPtr
vectorPtrToList
vptr
where
n
=
nNodes
gr
m
=
nEdges
gr
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