Hi Volker
I think I understand mutability. What I was wondering was in above MWE, 
everything works for the first time I insert an inequality and then the 
second time it raises this error.( Did you mean to say I should set the 
vectors immutable somewhere inside your code? Just tried setting "ineq" 
immutable which doesnt work.)

I want to use DD iteration as a routine in a polyhedral projection 
algorithm. Now I could pull out DD iteration code from 
double_description.py (have already done so. It works fine. I like the 
caching for zero_set.), but if I am to submit the projection code as a 
ticket, it would mean duplication of code. 
Thanks

On Thursday, 19 March 2015 17:38:49 UTC-4, Volker Braun wrote:
>
> The double description implementation isn't really meant to be used 
> directly, which is also why it is not by default in the global namespace.
>
> Basically all input must be immutable to be able to use caching. To make 
> an immutable vector, use:
>
> sage: v = vector([1,2,3])
> sage: v.set_immutable()
>
> Immutable means the entries can't be changed any more:
>
> sage: v[0] = 1
> ---------------------------------------------------------------------------
> ValueError                                Traceback (most recent call last)
> <ipython-input-6-cd90ec5e6613> in <module>()
> ----> 1 v[Integer(0)] = Integer(1)
>
> /mnt/disk/home/release/Sage/src/sage/modules/vector_integer_dense.pyx in 
> sage.modules.vector_integer_dense.Vector_integer_dense.__setitem__ 
> (build/cythonized/sage/modules/vector_integer_dense.c:3829)()
>     183         """
>     184         if not self._is_mutable:
> --> 185             raise ValueError("vector is immutable; please change a 
> copy instead (use copy())")
>     186         cdef Integer z
>     187         cdef Py_ssize_t k, d, n
>
> ValueError: vector is immutable; please change a copy instead (use copy())
>
>
> On Thursday, March 19, 2015 at 8:28:47 PM UTC+1, Jayant Apte wrote:
>>
>> Hi
>> I was trying to use add_inequality( ) method 
>> of sage.geometry.polyhedron.double_description.StandardDoubleDescriptionPair 
>> when I encountered an error (see the MWE below). Upon pulling out the 
>> functions required for add_inequality( ) and running it seperately, it 
>> works fine. I wonder if this is a bug or I'm doing something wrong:
>>
>> sage: from sage.geometry.polyhedron.double_description import 
>> StandardAlgorithm
>> sage: A= matrix([(-1, -1, 0, 0), (-1, 0, 0, 0), (-1, 0, -1, 0), (-1, 0, 
>> 0, -1)])
>> sage: DD, _ = StandardAlgorithm(A).initial_pair()
>> sage: ineq=vector([-1, -1, -1, -1])
>> sage: DD = DD.add_inequality(ineq);  
>> sage: print DD
>> Double description pair (A, R) defined by
>>     [-1 -1  0  0]    
>>     [-1  0  0  0]        [ 0  0  0 -1 -1 -1]
>> A = [-1  0 -1  0],   R = [-1  0  0 -1  1  1]
>>     [-1  0  0 -1]        [ 0 -1  0  1 -1  1]
>>     [-1 -1 -1 -1]        [ 0  0 -1  1  1 -1]
>> sage: ineq=vector([-1,0,-1,-1])
>> sage: DD = DD.add_inequality(ineq);  
>>
>> ---------------------------------------------------------------------------
>> TypeError                                 Traceback (most recent call 
>> last)
>> <ipython-input-8-d81bd32d70b2> in <module>()
>> ----> 1 DD = DD.add_inequality(ineq);
>>
>> /home/jayant/Software/sagemath6_6/sage/local/lib/python2.7/site-packages/sage/geometry/polyhedron/double_description.pyc
>>  
>> in add_inequality(self, a)
>>     681         R_new = []
>>     682         for rp, rn in CartesianProduct(R_pos, R_neg):
>> --> 683             if not self.are_adjacent(rp, rn):
>>     684                 continue
>>     685             r = a.inner_product(rp) * rn - a.inner_product(rn) * 
>> rp
>>
>> /home/jayant/Software/sagemath6_6/sage/local/lib/python2.7/site-packages/sage/geometry/polyhedron/double_description.pyc
>>  
>> in are_adjacent(self, r1, r2)
>>     418         Z_r1 = self.zero_set(r1)
>>     419         Z_r2 = self.zero_set(r2)
>> --> 420         Z_12 = set(Z_r1).intersection(Z_r2)
>>     421         A_Z12 = matrix(self.problem.base_ring(), list(Z_12))
>>     422         return A_Z12.rank() == self.problem.dim() - 2
>>
>> /home/jayant/Software/sagemath6_6/sage/src/sage/modules/vector_integer_dense.pyx
>>  
>> in sage.modules.vector_integer_dense.Vector_integer_dense.__hash__ 
>> (build/cythonized/sage/modules/vector_integer_dense.c:3589)()
>>     170             True
>>     171         """
>> --> 172         return 
>> free_module_element.FreeModuleElement.__hash__(self)
>>     173 
>>     174     def __setitem__(self, i, value):
>>
>> /home/jayant/Software/sagemath6_6/sage/src/sage/modules/free_module_element.pyx
>>  
>> in sage.modules.free_module_element.FreeModuleElement.__hash__ 
>> (build/cythonized/sage/modules/free_module_element.c:7403)()
>>     963         """
>>     964         if self._is_mutable:
>> --> 965             raise TypeError("mutable vectors are unhashable")
>>     966         return hash(tuple(self))
>>     967 
>>
>> TypeError: mutable vectors are unhashable
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to