-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcontainer.py
More file actions
60 lines (50 loc) · 1.55 KB
/
container.py
File metadata and controls
60 lines (50 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
def GraphObjectContainer_byindex(self, idx):
for e in self:
if e.index() == idx:
return e
raise IndexError("Container has no element with index %s." % idx)
def advance_iterator(self):
if not self.valid():
raise StopIteration()
val = self.__deref__()
self.__preinc__()
return val
def cpp_iterator(self):
it = self.begin()
while it != self.end():
yield it.__deref__()
it.__preinc__()
def iterable_getitem(self, key):
if isinstance(key, slice):
indices = range(*key.indices(len(self)))
elems = []
try:
next_ind = next(indices)
for i, e in enumerate(self):
if i == next_ind:
elems.append(e)
next_ind = next(indices)
except StopIteration:
pass
return elems
elif isinstance(key, int):
if key < 0:
key += len(self)
if key < 0 or key >= len(self):
raise IndexError("The index (%d) is out of range." % key)
for i, e in enumerate(self):
if i == key:
return e
else:
raise TypeError("Invalid argument type %s." % type(key))
def get_adjentry_array_keys(aea):
for e in aea.graphOf().edges:
yield e.adjSource()
yield e.adjTarget()
ArrayKeys = {
"Node": lambda na: na.graphOf().nodes,
"Edge": lambda ea: ea.graphOf().edges,
"AdjEntry": get_adjentry_array_keys,
"Cluster": lambda ca: ca.graphOf().clusters,
"Face": lambda fa: fa.embeddingOf().faces,
}