# HG changeset patch
# User Volker Braun <vbraun@stp.dias.ie>
# Date 1296676298 0
# Node ID 7d005b9bc6579828fe4ddb8ebcf4b3a1865c5706
# Parent  3daeb8c700d0b8e746bfc67fb9879c1c76b5d47f
Trac #10731: Bugfix for sheaf cohomology computation.

diff -r 3daeb8c700d0 -r 7d005b9bc657 sage/schemes/generic/toric_divisor.py
--- a/sage/schemes/generic/toric_divisor.py	Tue Feb 01 18:10:49 2011 +0000
+++ b/sage/schemes/generic/toric_divisor.py	Wed Feb 02 19:51:38 2011 +0000
@@ -1532,6 +1532,18 @@
             (1, 0, 0)
             sage: D._sheaf_cohomology( SimplicialComplex([1,2,3],[[1,2],[2,3],[3,1]]) )
             (0, 0, 1)
+
+        A more complicated example to test that trac #10731 is fixed::
+
+            sage: cell24 = Polyhedron(vertices=[   
+            ...    (1,0,0,0),(0,1,0,0),(0,0,1,0),(0,0,0,1),(1,-1,-1,1),(0,0,-1,1),          
+            ...    (0,-1,0,1),(-1,0,0,1),(1,0,0,-1),(0,1,0,-1),(0,0,1,-1),(-1,1,1,-1),
+            ...    (1,-1,-1,0),(0,0,-1,0),(0,-1,0,0),(-1,0,0,0),(1,-1,0,0),(1,0,-1,0),
+            ...    (0,1,1,-1),(-1,1,1,0),(-1,1,0,0),(-1,0,1,0),(0,-1,-1,1),(0,0,0,-1)])
+            sage: X = ToricVariety(FaceFan(cell24.lattice_polytope()))  # long time
+            sage: D = -X.divisor(0)       # long time
+            sage: D.cohomology(dim=True)  # long time
+            (0, 0, 0, 0, 0)
         """
         d = self.parent().scheme().dimension()
         if cplx.dimension()==-1:
@@ -1540,10 +1552,12 @@
         HH = cplx.homology(base_ring=QQ, cohomology=True)
         HH_list = [0]*(d+1)
         for h in HH.iteritems():
-            if h[0]==d:
-                assert(h[1].dimension()==0)
+            degree = h[0]+1  
+            cohomology_dim = h[1].dimension()
+            if degree>d or degree<0:
+                assert(cohomology_dim==0)
                 continue
-            HH_list[ h[0]+1 ] = h[1].dimension()
+            HH_list[ degree ] = cohomology_dim
 
         return vector(ZZ, HH_list)
       
