Opened 12 years ago

Closed 12 years ago

#5198 closed defect (fixed)

[with patch, positive review] apply_map skips zeroes in sparse vectors and matrices

Reported by: cwitty Owned by: was
Priority: blocker Milestone: sage-3.3
Component: linear algebra Keywords:
Cc: Merged in:
Authors: Reviewers:
Report Upstream: Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description

Consider:

sage: vector(ZZ, range(3)).apply_map(lambda x: x+1)
(1, 2, 3)
sage: vector(ZZ, range(3), sparse=True).apply_map(lambda x: x+1)
(0, 2, 3)

and

sage: matrix(ZZ, range(3)).apply_map(lambda x: x+1)
[1 2 3]
sage: matrix(ZZ, range(3), sparse=True).apply_map(lambda x: x+1)
[0 2 3]

Attachments (1)

trac5198_apply_map_sparse.patch (11.7 KB) - added by cwitty 12 years ago.

Download all attachments as: .zip

Change History (4)

Changed 12 years ago by cwitty

comment:1 Changed 12 years ago by cwitty

  • Summary changed from apply_map skips zeroes in sparse vectors and matrices to [with patch, needs review] apply_map skips zeroes in sparse vectors and matrices

The attached patch fixes the problem, and adds a sparse=True/False? argument to apply_map that may be useful if you know that the result will have a different sparsity than the input.

I also fixed a bug along the way: apply_map didn't preserve subdivisions for sparse matrices. Sorry, reviewer, whoever you are.

comment:2 Changed 12 years ago by robertwb

  • Summary changed from [with patch, needs review] apply_map skips zeroes in sparse vectors and matrices to [with patch, positive review] apply_map skips zeroes in sparse vectors and matrices

Ouch...that is a pretty bad bug.

The patch fixes the above issues and works well for me (including the subdivisions fix).

comment:3 Changed 12 years ago by mabshoff

  • Resolution set to fixed
  • Status changed from new to closed

Merged in Sage 3.3.alpha6.

Cheers,

Michael

Note: See TracTickets for help on using tickets.