Skip to content

Widen integer entries before abs in sparse opnorm - #1180

Merged
ViralBShah merged 1 commit into
mainfrom
vs/opnorm-typemin
Nov 18, 2026
Merged

ViralBShah merged 1 commit into
mainfrom
vs/opnorm-typemin

Conversation

@ViralBShah

Copy link
Copy Markdown
Member

Fixes #1177.

opnorm(A, 1) and opnorm(A, Inf) lose typemin entries of a signed integer sparse matrix.

Before

julia> A = sparse(Int8[1 -128; 1 0]);

julia> opnorm(A, 1), opnorm(A, Inf)
(2.0, 1.0)

julia> opnorm(sparse([typemin(Int) 0 -2; 0 0 0; -2 0 0]), 1)
2.0

After

julia> opnorm(A, 1), opnorm(A, Inf)
(128.0, 129.0)

julia> opnorm(sparse([typemin(Int) 0 -2; 0 0 0; -2 0 0]), 1)
9.223372036854776e18

The column and row sums accumulate in floating point but added abs of each stored entry evaluated in the element type, and abs(typemin(Int8)) == -128. They now add norm of the entry, as the dense opnorm1 and opnormInf do, which converts to floating point before taking the absolute value; float and complex element types give the same values and result type as before. The m == 1 and n == 1 branches and the p = 2 estimate already go through norm of the stored values and were correct, and cond takes its matrix norm from this function.

Written by Claude Code.

🤖 Generated with Claude Code

`opnorm(A, 1)` and `opnorm(A, Inf)` added `abs` of each stored entry in the
element type, where `abs(typemin(Int8)) == -128`. Take `norm` of the entry,
as the dense `opnorm1` and `opnormInf` do, which converts to floating point
first.

Fixes #1177.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.97%. Comparing base (a5441c0) to head (6614615).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1180   +/-   ##
=======================================
  Coverage   98.97%   98.97%           
=======================================
  Files          16       16           
  Lines       10751    10751           
=======================================
  Hits        10641    10641           
  Misses        110      110           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ViralBShah
ViralBShah merged commit 7d47bf1 into main Nov 18, 2026
12 checks passed
@ViralBShah
ViralBShah deleted the vs/opnorm-typemin branch November 18, 2026 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

opnorm(A, 1) / opnorm(A, Inf) on integer sparse matrices take abs before widening, so typemin entries are lost

1 participant