Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Tiago Peixoto
graph-tool
Commits
7c559195
Commit
7c559195
authored
Dec 01, 2014
by
Tiago Peixoto
Browse files
Add optional 'vals' parameter to Graph.new_vertex_property()/Graph.new_edge_property()
parent
98674cb9
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/graph_tool/__init__.py
View file @
7c559195
...
...
@@ -1720,34 +1720,51 @@ class Graph(object):
# Property map creation
def
new_property
(
self
,
key_type
,
value_type
):
def
new_property
(
self
,
key_type
,
value_type
,
vals
=
None
):
"""Create a new (uninitialized) vertex property map of key type
``key_type`` (``v``, ``e`` or ``g``), value type ``value_type``, and
return it.
return it. If provided, the values will be initialized by ``vals``,
which should be a sequence.
"""
if
key_type
==
"v"
or
key_type
==
"vertex"
:
return
self
.
new_vertex_property
(
value_type
)
return
self
.
new_vertex_property
(
value_type
,
vals
)
if
key_type
==
"e"
or
key_type
==
"edge"
:
return
self
.
new_edge_property
(
value_type
)
return
self
.
new_edge_property
(
value_type
,
vals
)
if
key_type
==
"g"
or
key_type
==
"graph"
:
return
self
.
new_graph_property
(
value_type
)
return
self
.
new_graph_property
(
value_type
,
vals
)
raise
ValueError
(
"unknown key type: "
+
key_type
)
def
new_vertex_property
(
self
,
value_type
):
"""Create a new (uninitialized) vertex property map of type
``value_type``, and return it."""
return
PropertyMap
(
new_vertex_property
(
_type_alias
(
value_type
),
def
new_vertex_property
(
self
,
value_type
,
vals
=
None
):
"""Create a new (uninitialized) vertex property map of type ``value_type``,
and return it. If provided, the values will be initialized by ``vals``,
which should be a sequence."""
prop
=
PropertyMap
(
new_vertex_property
(
_type_alias
(
value_type
),
self
.
__graph
.
GetVertexIndex
(),
libcore
.
any
()),
self
,
"v"
)
if
vals
is
not
None
:
try
:
prop
.
a
=
vals
except
ValueError
:
for
v
,
x
in
zip
(
self
.
vertices
(),
vals
):
prop
[
v
]
=
x
return
prop
def
new_edge_property
(
self
,
value_type
):
def
new_edge_property
(
self
,
value_type
,
vals
=
None
):
"""Create a new (uninitialized) edge property map of type
``value_type``, and return it."""
return
PropertyMap
(
new_edge_property
(
_type_alias
(
value_type
),
``value_type``, and return it. If provided, the values will be
initialized by ``vals``, which should be a sequence."""
prop
=
PropertyMap
(
new_edge_property
(
_type_alias
(
value_type
),
self
.
__graph
.
GetEdgeIndex
(),
libcore
.
any
()),
self
,
"e"
)
if
vals
is
not
None
:
try
:
prop
.
a
=
vals
except
ValueError
:
for
e
,
x
in
zip
(
self
.
edges
(),
vals
):
prop
[
e
]
=
x
return
prop
def
new_graph_property
(
self
,
value_type
,
val
=
None
):
"""Create a new graph property map of type ``value_type``, and return
...
...
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