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
1
Issues
1
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
,
U
(
..
)
,
D
(
..
)
,
Graph
(
..
)
,
empty
,
mkGraph
,
fromLabeledEdges
...
...
@@ -136,6 +137,10 @@ instance Graph D where
isDirected
=
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
)
=>
[
v
]
->
[(
Edge
,
e
)]
->
LGraph
d
v
e
mkGraph
vattr
es
=
runST
$
do
...
...
src/IGraph/Structure.hs
View file @
53c5c9d7
...
...
@@ -87,15 +87,22 @@ pagerank :: Graph d
->
Maybe
[
Double
]
-- ^ edge weights
->
Double
-- ^ damping factor, usually around 0.85
->
[
Double
]
pagerank
gr
ws
d
=
unsafePerformIO
$
alloca
$
\
p
->
do
vptr
<-
igraphVectorNew
0
vsptr
<-
igraphVsAll
ws'
<-
case
ws
of
Just
w
->
listToVector
w
_
->
liftM
VectorPtr
$
newForeignPtr_
$
castPtr
nullPtr
igraphPagerank
(
_graph
gr
)
IgraphPagerankAlgoPrpack
vptr
p
vsptr
(
isDirected
gr
)
d
ws'
nullPtr
vectorPtrToList
vptr
pagerank
gr
ws
d
|
n
==
0
=
[]
|
otherwise
=
unsafePerformIO
$
alloca
$
\
p
->
do
vptr
<-
igraphVectorNew
0
vsptr
<-
igraphVsAll
ws'
<-
case
ws
of
Just
w
->
if
length
w
/=
m
then
error
"pagerank: incorrect length of edge weight vector"
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
=>
LGraph
d
v
e
...
...
@@ -103,13 +110,21 @@ personalizedPagerank :: Graph d
->
Maybe
[
Double
]
->
Double
->
[
Double
]
personalizedPagerank
gr
reset
ws
d
=
unsafePerformIO
$
alloca
$
\
p
->
do
vptr
<-
igraphVectorNew
0
vsptr
<-
igraphVsAll
ws'
<-
case
ws
of
Just
w
->
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
personalizedPagerank
gr
reset
ws
d
|
n
==
0
=
[]
|
length
reset
/=
n
=
error
"personalizedPagerank: incorrect length of reset vector"
|
otherwise
=
unsafePerformIO
$
alloca
$
\
p
->
do
vptr
<-
igraphVectorNew
0
vsptr
<-
igraphVsAll
ws'
<-
case
ws
of
Just
w
->
if
length
w
/=
m
then
error
"pagerank: incorrect length of edge weight vector"
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