Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
graph-tool
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
43
Issues
43
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tiago Peixoto
graph-tool
Commits
92d0c0b5
Commit
92d0c0b5
authored
Jun 05, 2015
by
Tiago Peixoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix memory usage issue in graph_blockmodel.cc
parent
0fdb192b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
25 deletions
+32
-25
src/graph/community/graph_blockmodel.hh
src/graph/community/graph_blockmodel.hh
+27
-21
src/graph_tool/community/blockmodel.py
src/graph_tool/community/blockmodel.py
+5
-4
No files found.
src/graph/community/graph_blockmodel.hh
View file @
92d0c0b5
...
...
@@ -94,7 +94,12 @@ inline double safelog(Type x)
__attribute__
((
always_inline
))
inline
double
safelog
(
size_t
x
)
{
assert
(
x
<
__safelog_cache
.
size
());
if
(
x
>=
__safelog_cache
.
size
())
{
if
(
x
==
0
)
return
0
;
return
log
(
x
);
}
return
__safelog_cache
[
x
];
}
...
...
@@ -102,8 +107,7 @@ __attribute__((always_inline))
inline
double
xlogx
(
size_t
x
)
{
if
(
x
>=
__xlogx_cache
.
size
())
cout
<<
x
<<
" "
<<
__xlogx_cache
.
size
()
<<
endl
;
assert
(
x
<
__xlogx_cache
.
size
());
return
x
*
safelog
(
x
);
return
__xlogx_cache
[
x
];
}
...
...
@@ -1654,7 +1658,8 @@ struct egroups_manage
template
<
class
Eprop
,
class
Vprop
,
class
VEprop
,
class
Graph
,
class
VertexIndex
>
static
void
build
(
Vprop
b
,
boost
::
any
&
oegroups
,
VEprop
esrcpos
,
VEprop
etgtpos
,
Eprop
eweight
,
Graph
&
g
,
VertexIndex
vertex_index
,
size_t
B
,
bool
weighted
,
bool
empty
)
VertexIndex
vertex_index
,
size_t
B
,
bool
weighted
,
bool
empty
)
{
if
(
weighted
)
{
...
...
@@ -1666,8 +1671,7 @@ struct egroups_manage
if
(
empty
)
return
;
build_dispatch
(
b
,
egroups_checked
.
get_unchecked
(
B
),
esrcpos
,
etgtpos
,
eweight
,
g
,
vertex_index
,
B
,
mpl
::
true_
());
esrcpos
,
etgtpos
,
eweight
,
g
,
vertex_index
,
B
);
}
else
{
...
...
@@ -1679,27 +1683,29 @@ struct egroups_manage
if
(
empty
)
return
;
build_dispatch
(
b
,
egroups_checked
.
get_unchecked
(
B
),
esrcpos
,
etgtpos
,
eweight
,
g
,
vertex_index
,
B
,
mpl
::
true_
());
esrcpos
,
etgtpos
,
eweight
,
g
,
vertex_index
,
B
);
}
}
template
<
class
Eprop
,
class
Vprop
,
class
VEprop
,
class
Graph
,
class
VertexIndex
,
class
Egroups
>
template
<
class
Eprop
,
class
Vprop
,
class
VEprop
,
class
Graph
,
class
VertexIndex
,
class
Egroups
>
static
void
build_dispatch
(
Vprop
b
,
Egroups
egroups
,
VEprop
esrcpos
,
VEprop
etgtpos
,
Eprop
eweight
,
Graph
&
g
,
VertexIndex
,
size_t
,
mpl
::
true_
)
VertexIndex
,
size_t
)
{
for
(
auto
e
:
edges_range
(
g
))
{
size_t
r
=
b
[
get_source
(
e
,
g
)];
assert
(
r
<
B
);
auto
&
r_elist
=
egroups
[
r
];
esrcpos
[
e
]
=
insert_edge
(
std
::
make_tuple
(
e
,
true
),
r_elist
,
eweight
[
e
]);
esrcpos
[
e
]
=
insert_edge
(
std
::
make_tuple
(
e
,
true
),
r_elist
,
eweight
[
e
]);
size_t
s
=
b
[
get_target
(
e
,
g
)];
assert
(
s
<
B
);
auto
&
s_elist
=
egroups
[
s
];
etgtpos
[
e
]
=
insert_edge
(
std
::
make_tuple
(
e
,
false
),
s_elist
,
eweight
[
e
]);
etgtpos
[
e
]
=
insert_edge
(
std
::
make_tuple
(
e
,
false
),
s_elist
,
eweight
[
e
]);
}
}
...
...
@@ -1720,31 +1726,31 @@ struct egroups_manage
template
<
class
Edge
,
class
Epos
>
static
void
remove_edge
(
size_t
pos
,
Epos
&
esrcpos
,
Epos
&
etgtpos
,
DynamicSample
r
<
Edge
>&
elist
)
vecto
r
<
Edge
>&
elist
)
{
typedef
typename
property_traits
<
Epos
>::
value_type
val_t
;
if
(
get
<
1
>
(
elist
.
back
()))
esrcpos
[
get
<
0
>
(
elist
.
back
())]
=
pos
;
else
etgtpos
[
get
<
0
>
(
elist
.
back
())]
=
pos
;
if
(
get
<
1
>
(
elist
[
pos
]))
esrcpos
[
get
<
0
>
(
elist
[
pos
])]
=
numeric_limits
<
val_t
>::
max
();
else
etgtpos
[
get
<
0
>
(
elist
[
pos
])]
=
numeric_limits
<
val_t
>::
max
();
elist
.
remove
(
pos
);
elist
[
pos
]
=
elist
.
back
();
elist
.
pop_back
();
}
template
<
class
Edge
,
class
Epos
>
static
void
remove_edge
(
size_t
pos
,
Epos
&
esrcpos
,
Epos
&
etgtpos
,
vecto
r
<
Edge
>&
elist
)
DynamicSample
r
<
Edge
>&
elist
)
{
typedef
typename
property_traits
<
Epos
>::
value_type
val_t
;
if
(
get
<
1
>
(
elist
.
back
()))
esrcpos
[
get
<
0
>
(
elist
.
back
())]
=
pos
;
else
etgtpos
[
get
<
0
>
(
elist
.
back
())]
=
pos
;
if
(
get
<
1
>
(
elist
[
pos
]))
esrcpos
[
get
<
0
>
(
elist
[
pos
])]
=
numeric_limits
<
val_t
>::
max
();
else
etgtpos
[
get
<
0
>
(
elist
[
pos
])]
=
numeric_limits
<
val_t
>::
max
();
elist
[
pos
]
=
elist
.
back
();
elist
.
pop_back
();
elist
.
remove
(
pos
);
}
template
<
class
Vertex
,
class
Graph
,
class
EVprop
,
class
Eprop
,
class
VEprop
>
...
...
src/graph_tool/community/blockmodel.py
View file @
92d0c0b5
...
...
@@ -97,7 +97,6 @@ class BlockState(object):
def
__init__
(
self
,
g
,
eweight
=
None
,
vweight
=
None
,
b
=
None
,
B
=
None
,
clabel
=
None
,
deg_corr
=
True
,
max_BE
=
1000
,
**
kwargs
):
BlockState
.
_state_ref_count
+=
1
# initialize weights to unity, if necessary
...
...
@@ -205,9 +204,11 @@ class BlockState(object):
self
.
edges_dl
=
False
# computation cache
libcommunity
.
init_safelog
(
int
(
5
*
max
(
self
.
E
,
self
.
N
)))
libcommunity
.
init_xlogx
(
int
(
5
*
max
(
self
.
E
,
self
.
N
)))
libcommunity
.
init_lgamma
(
int
(
3
*
max
(
self
.
E
,
self
.
N
)))
E
=
g
.
num_edges
()
N
=
g
.
num_vertices
()
libcommunity
.
init_safelog
(
int
(
5
*
max
(
E
,
N
)))
libcommunity
.
init_xlogx
(
int
(
5
*
max
(
E
,
N
)))
libcommunity
.
init_lgamma
(
int
(
3
*
max
(
E
,
N
)))
def
__del__
(
self
):
try
:
...
...
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