updateDensity slightly more efficient
This commit is contained in:
parent
3cdb1d6d60
commit
cad98f10cb
@ -2,6 +2,7 @@
|
|||||||
{-# LANGUAGE OverlappingInstances #-}
|
{-# LANGUAGE OverlappingInstances #-}
|
||||||
{-# LANGUAGE TypeOperators #-}
|
{-# LANGUAGE TypeOperators #-}
|
||||||
{-# LANGUAGE TypeSynonymInstances #-}
|
{-# LANGUAGE TypeSynonymInstances #-}
|
||||||
|
{-# LANGUAGE BangPatterns #-}
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
--
|
--
|
||||||
-- Module : DCB
|
-- Module : DCB
|
||||||
@ -175,6 +176,7 @@ constraint attr div req (ind, (fulfill, constr), _) newNode =
|
|||||||
updateConstr f sh@(Z:.i:.c) =
|
updateConstr f sh@(Z:.i:.c) =
|
||||||
let
|
let
|
||||||
! slice = A.slice attr (A.Any :. i)
|
! slice = A.slice attr (A.Any :. i)
|
||||||
|
-- TODO: why not compare current bounds with attribute values of new node?
|
||||||
! mins = A.traverse slice id (\g sh'@(Z :. j)-> if V.any (==j) totalInd then (g sh') else posInf)
|
! mins = A.traverse slice id (\g sh'@(Z :. j)-> if V.any (==j) totalInd then (g sh') else posInf)
|
||||||
! maxs = A.traverse slice id (\g sh'@(Z :. j)-> if V.any (==j) totalInd then (g sh') else negInf)
|
! maxs = A.traverse slice id (\g sh'@(Z :. j)-> if V.any (==j) totalInd then (g sh') else negInf)
|
||||||
|
|
||||||
@ -201,7 +203,11 @@ updateDensity :: Adj -- ^ global adjacency matrix of all nodes
|
|||||||
-> Density -- ^ new density of expanded graph
|
-> Density -- ^ new density of expanded graph
|
||||||
updateDensity adj nodes newNode dens =
|
updateDensity adj nodes newNode dens =
|
||||||
let
|
let
|
||||||
neighbourSlice = A.traverse
|
|
||||||
|
|
||||||
|
neighbourSlice = A.map (\n -> fromIntegral $adj!(A.ix2 newNode n)) nodes
|
||||||
|
{-- awefull asymptotic efficiency
|
||||||
|
A.traverse
|
||||||
(A.slice (A.map fromIntegral adj) (A.Any :. newNode)) -- Array
|
(A.slice (A.map fromIntegral adj) (A.Any :. newNode)) -- Array
|
||||||
id -- same Size
|
id -- same Size
|
||||||
(\f sh@(_ :. i) ->
|
(\f sh@(_ :. i) ->
|
||||||
@ -209,6 +215,7 @@ updateDensity adj nodes newNode dens =
|
|||||||
(f sh) --return connection
|
(f sh) --return connection
|
||||||
else
|
else
|
||||||
0) --never connect to nodes not extisting
|
0) --never connect to nodes not extisting
|
||||||
|
--}
|
||||||
neighbours = A.foldAllS (+) (0::Int) ({- trace (show $ A.computeUnboxedS neighbourSlice)-} neighbourSlice)
|
neighbours = A.foldAllS (+) (0::Int) ({- trace (show $ A.computeUnboxedS neighbourSlice)-} neighbourSlice)
|
||||||
|
|
||||||
{- A.traverse adj (reduceDim) (\f (Z :. i) ->
|
{- A.traverse adj (reduceDim) (\f (Z :. i) ->
|
||||||
|
Loading…
Reference in New Issue
Block a user