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
02184221
Commit
02184221
authored
Jun 05, 2015
by
Kai Zhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add Layout module
parent
4ff1d01e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
89 additions
and
2 deletions
+89
-2
haskell-igraph.cabal
haskell-igraph.cabal
+3
-0
Data.chs
src/IGraph/Internal/Data.chs
+30
-2
Layout.chs
src/IGraph/Internal/Layout.chs
+24
-0
Layout.hs
src/IGraph/Layout.hs
+32
-0
No files found.
haskell-igraph.cabal
View file @
02184221
...
...
@@ -27,12 +27,14 @@ library
IGraph.Internal.Structure
IGraph.Internal.Clique
IGraph.Internal.Community
IGraph.Internal.Layout
IGraph
IGraph.Mutable
IGraph.Clique
IGraph.Structure
IGraph.Community
IGraph.Read
IGraph.Layout
-- other-modules:
-- other-extensions:
build-depends:
...
...
@@ -42,6 +44,7 @@ library
, primitive
, unordered-containers
, hashable
, split
extra-libraries: igraph
hs-source-dirs: src
...
...
src/IGraph/Internal/Data.chs
View file @
02184221
...
...
@@ -7,6 +7,8 @@ import Foreign
import Foreign.C.Types
import Foreign.C.String
import System.IO.Unsafe (unsafePerformIO)
import Data.List (transpose)
import Data.List.Split (chunksOf)
#include "cbits/haskelligraph.c"
...
...
@@ -111,6 +113,32 @@ listToStrVector xs = do
{#fun igraph_matrix_fill as ^ { `MatrixPtr', `Double' } -> `()' #}
{#fun
pure
igraph_matrix_e as ^ { `MatrixPtr', `Int', `Int' } -> `Double' #}
{#fun igraph_matrix_e as ^ { `MatrixPtr', `Int', `Int' } -> `Double' #}
{#fun pure igraph_matrix_set as ^ { `MatrixPtr', `Int', `Int', `Double' } -> `()' #}
{#fun igraph_matrix_set as ^ { `MatrixPtr', `Int', `Int', `Double' } -> `()' #}
{#fun igraph_matrix_copy_to as ^ { `MatrixPtr', id `Ptr CDouble' } -> `()' #}
{#fun igraph_matrix_nrow as ^ { `MatrixPtr' } -> `Int' #}
{#fun igraph_matrix_ncol as ^ { `MatrixPtr' } -> `Int' #}
listsToMatrixPtr :: [[Double]] -> IO MatrixPtr
listsToMatrixPtr xs = do
mptr <- igraphMatrixNew r c
forM_ (zip [0..] xs) $ \(i, row) ->
forM_ (zip [0..] row) $ \(j,v) ->
igraphMatrixSet mptr i j v
return mptr
where
r = length xs
c = maximum $ map length xs
matrixPtrToLists :: MatrixPtr -> IO [[Double]]
matrixPtrToLists mptr = do
r <- igraphMatrixNrow mptr
c <- igraphMatrixNcol mptr
xs <- allocaArray (r*c) $ \ptr -> do
igraphMatrixCopyTo mptr ptr
peekArray (r*c) ptr
return $ transpose $ chunksOf r $ map realToFrac xs
src/IGraph/Internal/Layout.chs
0 → 100644
View file @
02184221
{-# LANGUAGE ForeignFunctionInterface #-}
module IGraph.Internal.Layout where
import Foreign
import Foreign.C.Types
{#import IGraph.Internal.Graph #}
{#import IGraph.Internal.Data #}
#include "igraph/igraph.h"
{#fun igraph_layout_kamada_kawai as ^ { `IGraphPtr'
, `MatrixPtr'
, `Int'
, `Double'
, `Double'
, `Double'
, `Double'
, `Bool'
, id `Ptr VectorPtr'
, id `Ptr VectorPtr'
, id `Ptr VectorPtr'
, id `Ptr VectorPtr'
} -> `Int' #}
src/IGraph/Layout.hs
0 → 100644
View file @
02184221
module
IGraph.Layout
(
kamadaKawai
)
where
import
Foreign
(
nullPtr
)
import
Control.Applicative
((
<$>
))
import
System.IO.Unsafe
(
unsafePerformIO
)
import
IGraph
import
IGraph.Internal.Clique
import
IGraph.Internal.Layout
import
IGraph.Internal.Data
data
LayoutOpt
=
LayoutOpt
{
_seed
::
Maybe
[(
Double
,
Double
)]
,
_nIter
::
Int
}
deriving
(
Show
)
kamadaKawai
::
Graph
d
=>
LGraph
d
v
e
->
Double
->
Double
->
Double
->
Double
->
LayoutOpt
->
[(
Double
,
Double
)]
kamadaKawai
gr
sigma
initemp
coolexp
kkconst
opt
=
unsafePerformIO
$
do
mptr
<-
mat
igraphLayoutKamadaKawai
(
_graph
gr
)
mptr
(
_nIter
opt
)
sigma
initemp
coolexp
kkconst
useSeed
nullPtr
nullPtr
nullPtr
nullPtr
[
x
,
y
]
<-
matrixPtrToLists
mptr
return
$
zip
x
y
where
(
useSeed
,
mat
)
=
case
_seed
opt
of
Just
xs
->
if
length
xs
/=
nNodes
gr
then
error
"Seed error: incorrect size"
else
(
True
,
f
xs
)
_
->
(
False
,
igraphMatrixNew
0
0
)
f
xs
=
let
(
x
,
y
)
=
unzip
xs
in
listsToMatrixPtr
[
x
,
y
]
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