Skip to content

This closes #2413, give det the determinant of a single element - #2420

Merged
xuri merged 3 commits into
qax-os:masterfrom
PhilflowIO:2413-minverse-shared-rows
Oct 7, 2026
Merged

xuri merged 3 commits into
qax-os:masterfrom
PhilflowIO:2413-minverse-shared-rows

Conversation

@PhilflowIO

Copy link
Copy Markdown
Contributor

PR Details

Description

Adds the 1x1 case to det: the determinant of a single element is that element. Replaces the expectation "MINVERSE(A1:B2)": "-0", which pinned the wrong result, and adds TestCalcMINVERSE plus two direct det assertions.

Related Issue

Closes #2413

Motivation and Context

The cofactors of a 2x2 matrix are 1x1 determinants. Without a 1x1 case they fell into the Laplace expansion, which takes the minor of a 1x1 matrix, gets an empty matrix and sums over nothing, so every cofactor was 0 and MINVERSE of a 2x2 matrix was all zeros. MDETERM was not affected because det has its own 2x2 branch and never descends, which is why the existing tests did not catch it.

How Has This Been Tested

TestCalcMINVERSE checks every element of the inverse of a 2x2 and a 3x3 matrix, not only the top left one, and the determinant of both. TestCalcDet calls det directly for a 1x1 and a 2x2 matrix.

go test ./... passes on go1.26.8 linux/amd64. gofmt -s -l . is empty.

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

The cofactors of a 2x2 matrix are 1x1 determinants. Without a 1x1 case they fell into the Laplace expansion, which takes the minor of a 1x1 matrix, gets an empty matrix and sums over nothing, so every cofactor was 0 and MINVERSE of a 2x2 matrix was all zeros. MDETERM was not affected because `det` has its own 2x2 branch and never descends, which is why the existing tests did not catch it.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: PhilflowIO <tech@philflow.io>
@xuri xuri added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Sep 21, 2026

@xuri xuri left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your pull request. I've left a comment.

Comment thread calc_test.go Outdated
@xuri xuri added this to v2.11.1 Oct 7, 2026

@xuri xuri left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Thanks for your contribution. I've made some changes based on your code branch.

@codecov

codecov Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.72%. Comparing base (1bfaf07) to head (a1c9164).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2420   +/-   ##
=======================================
  Coverage   99.72%   99.72%           
=======================================
  Files          32       32           
  Lines       32513    32524   +11     
=======================================
+ Hits        32423    32434   +11     
  Misses         88       88           
  Partials        2        2           
Flag Coverage Δ
unittests 99.72% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.

@xuri
xuri merged commit efb5918 into qax-os:master Oct 7, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

Status: Bugfix

Development

Successfully merging this pull request may close these issues.

MINVERSE of a 2x2 matrix returns a matrix of zeros

2 participants