Add basic tests for drop_dims
[linpy.git] / pypol / domains.py
index 9bb403e..be87ffb 100644 (file)
@@ -138,10 +138,11 @@ class Domain:
         return self.complement()
 
     def simplify(self):
-        # see isl_set_coalesce, isl_set_detect_equalities,
-        # isl_set_remove_redundancies
-        # which ones? in which order?
-        raise NotImplementedError
+        #does not change anything in any of the examples
+        #isl seems to do this naturally 
+        islset = self._toislset(self.polyhedra, self.symbols)
+        islset = libisl.isl_set_remove_redundancies(islset)
+        return self._fromislset(islset, self.symbols)
 
     def polyhedral_hull(self):
         # several types of hull are available
@@ -151,11 +152,21 @@ class Domain:
         islbset = libisl.isl_set_polyhedral_hull(islset)
         return Polyhedron._fromislbasicset(islbset, self.symbols)
 
-    def project(self, symbols):
-        # not sure what isl_set_project_out actually does…
-        # use isl_set_drop_constraints_involving_dims instead?
-        raise NotImplementedError
-
+    def drop_dims(self, dims):
+        # use to remove certain variables use isl_set_drop_constraints_involving_dims instead?
+        from .polyhedra import Polyhedron      
+        dims = list(dims)
+        symbols = list(self.symbols)
+        islset = self._toislset(self.polyhedra, self.symbols)
+        for dim in dims:
+            if dim in symbols:
+                first = symbols.index(dim)
+                islbset = libisl.isl_set_project_out(islset, libisl.isl_dim_set, first, 1)  
+                symbols.__delitem__(first)     
+            else:
+                islbset = libisl.isl_set_project_out(islset, libisl.isl_dim_set, 0, 0)        
+        return Polyhedron._fromislset(islbset, symbols)
+    
     def sample(self):
         from .polyhedra import Polyhedron
         islset = self._toislset(self.polyhedra, self.symbols)
@@ -329,7 +340,6 @@ class Domain:
     def tosympy(self):
         raise NotImplementedError
 
-
 def And(*domains):
     if len(domains) == 0:
         from .polyhedra import Universe