Added Python closure function (for computing a k-skeleton of a closure of a list of simplices) dev
authorDmitriy Morozov <dmitriy@mrzv.org>
Tue, 07 Sep 2010 13:54:53 -0700
branchdev
changeset 228 12e2daa0e03a
parent 227 c1e2626cde8f
child 229 ed3905be234f
Added Python closure function (for computing a k-skeleton of a closure of a list of simplices)
bindings/python/dionysus/__init__.py
--- a/bindings/python/dionysus/__init__.py	Thu Sep 02 09:13:42 2010 -0700
+++ b/bindings/python/dionysus/__init__.py	Tue Sep 07 13:54:53 2010 -0700
@@ -36,3 +36,16 @@
         yield point.data
 
 Point.__iter__ = point_iterator
+
+def closure(simplices, k):
+    """Compute the k-skeleton of the closure of the list of simplices."""
+
+    res = set()
+
+    from    itertools   import combinations
+    for s in simplices:
+        for kk in xrange(1, k+2):
+            for face in combinations(s.vertices, kk):
+                res.add(Simplex(face))
+
+    return list(res)