On 8/16/13 4:40 PM, GaryMak wrote:
Hi all

I hesitate to declare a <<bug>>, since it's probably something I cannot
find in the help, but the following is very strange ....

The following code always seems to output many vectors "quad" of length
4 each of whose numerical approx "quad.n()" is a vector which only has
length 3 ...

Indeed, it is a bug. The problem is that quad is a sparse vector with zero as its last entry. You see, diagonal_matrix creates a sparse matrix, so ZZ^indy creates a sparse vector. That means that quad+ZZ^indy is a sparse vector. Then the bug bites us when the last element is zero. The .n() function for a sparse vector calls this one-liner:

vector(dict([(e[0],e[1].n(prec, digits)) for e in self._entries.iteritems()]), sparse=True)

Notice that the size isn't specified anywhere, so it is guessed from the biggest element of the dictionary. Since the last element was zero, it's not in the dictionary, so the vector is shortened.

Instead, that sparse _numerical_approx function should be:

vector(R, len(self), dict([(e[0],e[1].n(prec, digits)) for e in self._entries.iteritems()]), sparse=True)

where the ring R is somehow determined. Maybe the dictionary can be constructed first, then the ring in which the entries live can be determined, and then the vector call can be made.

Alternatively, a final zero element can be added to the dictionary, so the one-liner above becomes:

entries=dict([(e[0],e[1].n(prec, digits)) for e in self._entries.iteritems()])
if len(self)-1 not in entries:
    entries[len(self)-1]=0
vector(entries, sparse=True)

since this apparently works:

v=vector({1:32,4:2,10:0},sparse=True)


Gary: are you comfortable making a trac ticket and patch for this? It looks like the function that needs to be fixed is the very last function in SAGE_ROOT/devel/sage/sage/modules/free_module_element.pyx:

https://github.com/sagemath/sage/blob/master/src/sage/modules/free_module_element.pyx#L4503


Thanks,

Jason


--
You received this message because you are subscribed to the Google Groups 
"sage-support" 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-support.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to