Opened 7 years ago

Closed 7 years ago

# Wrong comparison of sparse vectors

Reported by: Owned by: tfeulner jason, was major sage-5.7 linear algebra comparison, sparse, free module sage-5.7.beta2 Thomas Feulner Christian Nassau N/A

### Description

The comparison of sparse vectors gives wrong results at the moment:

```sage: V = FreeModule( GF(3), 2, sparse=True)
sage: a = V([0,1])
sage: b = V([1,0])
sage: cmp(a, b)
1 # should be -1, since we are using the lexicographic order
```

In particular, this leads to different results when using sparse and dense vectors at the same time:

```sage: cmp(a.dense_vector(), b)
-1
sage: cmp(a, b.dense_vector())
1
```

### comment:1 Changed 7 years ago by tfeulner

• Summary changed from Wrong comparison of sparse to Wrong comparison of sparse vectors

### comment:2 Changed 7 years ago by tfeulner

• Status changed from new to needs_review

### comment:3 Changed 7 years ago by cnassau

• Reviewers set to Christian Nassau
• Status changed from needs_review to positive_review

The patch seems to be correct (tested it against Sage 5.5) and does indeed fix a bug in the sorting order. I would have chosen a more informative doctest, for example

```sage: sorted(FreeModule(GF(3),2,sparse=True))
[(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0), (2, 1), (2, 2)]
sage: sorted(FreeModule(GF(3),2,sparse=False))
[(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0), (2, 1), (2, 2)]
```

But I think the patch is ready to go as it is, so I'm giving it a positive review.

### comment:4 Changed 7 years ago by jdemeyer

• Merged in set to sage-5.7.beta2
• Resolution set to fixed
• Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.