Opened 7 years ago

Closed 7 years ago

#13929 closed defect (fixed)

Wrong comparison of sparse vectors

Reported by: tfeulner Owned by: jason, was
Priority: major Milestone: sage-5.7
Component: linear algebra Keywords: comparison, sparse, free module
Cc: Merged in: sage-5.7.beta2
Authors: Thomas Feulner Reviewers: Christian Nassau
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

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

Attachments (1)

trac_13929-sparse_vector_comparison.patch (1.2 KB) - added by tfeulner 7 years ago.

Download all attachments as: .zip

Change History (5)

comment:1 Changed 7 years ago by tfeulner

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

Changed 7 years ago by tfeulner

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.