Skip to content

Releases: TYEclipse/dsh-linalg

v0.3.0 — LU / QR / Cholesky factorizations + least squares

Choose a tag to compare

@TYEclipse TYEclipse released this 21 Oct 21:50

v0.3.0 — factorizations and least squares

Two new tools, both carrying the residual they actually measured.

matrix_decompose (kind: lu | qr | cholesky)

  • lu — LU with partial pivoting: P·A = L·U (unit lower L, upper U). Returns the row permutation p (row i of P·A is row p[i] of A), the swap count, the determinant sign, the determinant implied by U, and max |P·A − L·U|. Singular matrices are still factored and flagged with singular: true instead of silently returning wrong factors.
  • qr — thin QR with a positive diagonal in R, which makes the factorization unique: A = Q·R, Q has orthonormal columns, plus max |A − Q·R| and max |QᵀQ − I|. Linearly dependent columns are an error naming the column — no orthonormal completion is invented. Rows must be ≥ columns.
  • cholesky — A = L·Lᵀ for symmetric positive definite input, with max |A − L·Lᵀ| and the determinant implied by L. An asymmetric matrix is rejected with the offending entry and the asymmetry size; an indefinite one with the failing pivot.

least_squares

For tall systems (m ≥ n), returns the x minimizing ‖A·x − b‖, the minimum residual norm itself, and max |Aᵀ(A·x − b)| — zero confirms the answer really is the minimizer. Solved through the thin QR factorization rather than the normal equations (which square the condition number). Rank-deficient or underdetermined input is an error: the minimizer is not unique, so none is invented.

least_squares(a=[[1,1],[1,2],[1,3]], b=[1,2,2])
→ x1 = 0.6666666667, x2 = 0.5
  min ‖A·x − b‖ = 0.4082482905, max |Aᵀ(A·x − b)| = 0

Quality

  • 128 → 156 tests; line coverage 94.48% → 96.08% (baseline ratcheted up).
  • The oracle test/oracle/anchors.py gained a section D that re-derives every anchor independently: exact rational Gaussian elimination for LU / Cholesky / least squares (via the normal equations) and classical Gram–Schmidt for QR — a different algorithm from the implementation's modified Gram–Schmidt. Its --check asserts L·U = P·A, QᵀQ = I, L·Lᵀ = A, that the LU determinant equals the exact determinant, and that the least-squares residual is orthogonal to the columns.
  • Writing those self-checks caught one wrong expectation of mine immediately (the sign convention of the residual vector), which is exactly what the oracle is for.

中文摘要:新增 matrix_decompose(lu:P·A = L·U,奇异矩阵如实标记;qr:薄分解 A = Q·R,R 对角为正;cholesky:A = L·Lᵀ,仅对称正定)与 least_squares(超定最小二乘:解、最小残差范数、max |Aᵀ(A·x − b)|;秩亏或欠定直接报错)。每种分解都回报实测重构残差,不编造正交补、不挑一个解充数。测试 128 → 156,行覆盖 94.48% → 96.08%,随仓 oracle 增 D 区(精确有理数实现 + 经典 Gram–Schmidt,与实现算法不同)。

v0.2.0

Choose a tag to compare

@TYEclipse TYEclipse released this 02 Oct 21:52

dsh-linalg v0.2.0

Two user-visible additions on top of v0.1.3 — no breaking changes.

New tool: matrix_eigen

Eigen-decomposition of a real symmetric matrix (cyclic Jacobi method, full double precision):

  • all eigenvalues in descending order + a matching unit eigenvector per eigenvalue
  • deterministic sign convention: the leading non-zero component of each eigenvector is positive
  • maxResidual — the largest |A·v − λ·v| entry actually measured, reported so accuracy is visible instead of assumed
  • traceSum — sum of the eigenvalues, equal to the trace (self-check in every reply)
  • non-square / non-symmetric input and non-convergence are errors, never a guessed spectrum

matrix_compute gains two operations

  • rank — rank via reduced row echelon form (rectangular input allowed)
  • power — integer matrix power by binary exponentiation; exponent takes −64…64, negative exponents invert first (clean failure on singular input), 0 gives the identity

Quality

  • every numeric expectation in the tests is produced by the independent oracle test/oracle/anchors.py (exact fractions arithmetic for det/inverse/rref/rank/power, closed-form spectra — 2 − 2·cos(kπ/5), 1 ± 2√2, and an integer matrix with the exact spectrum 8, 4, 0, −8 — cross-checked against an independent pure-Python Jacobi implementation). python3 test/oracle/anchors.py --check self-verifies.
  • tests 97 → 128, coverage 92.91% → 94.48% (baseline ratcheted up)

安装(两者等价):dsh plugin --profile <profile> add github:TYEclipse/dsh-linalg


dsh-linalg v0.2.0(中文)

在 v0.1.3 基础上新增两项用户可见能力,无破坏性变更。

新工具 matrix_eigen:实对称矩阵特征分解(循环 Jacobi 旋转,全双精度)——特征值降序 + 每个特征值对应的单位特征向量;符号约定为首个非零分量为正;回复里带 maxResidual(实测的 max|A·v − λ·v|,精度可见而非假设)与 traceSum(特征值之和 = 迹,自检)。非方阵 / 非对称 / 不收敛一律报错,不给猜测的谱。

matrix_compute 新增两个操作:rank(行最简形求秩,允许长方形输入)、power(二进制快速幂,exponent 取 −64…64,负指数先求逆、奇异矩阵明确报错,0 得单位阵)。

质量:测试里的每一个数值断言都由独立 oracle test/oracle/anchors.py 产出(det/inverse/rref/rank/power 走 fractions 精确算术;特征值走闭式解 2 − 2·cos(kπ/5)、1 ± 2√2,以及一个谱恰为 8, 4, 0, −8 的整数矩阵,并与独立的纯 Python Jacobi 实现交叉核对)。测试 97 → 128 条,覆盖率 92.91% → 94.48%(基线棘轮上调)。

v0.1.0

Choose a tag to compare

@TYEclipse TYEclipse released this 07 Sep 21:57

dsh-linalg v0.1.0 — Linear algebra toolbox for DeepSeek Harness

First release: four pure-math tools with zero runtime dependencies.

✨ New

  • matrix_multiply — matrix product A·B with exact dimension checking
  • matrix_compute — transpose / determinant / inverse / trace / reduced row echelon form (rref)
  • solve_linear — solve Ax = b, classified as unique / infinitely many (particular solution + nullspace basis + free-variable count) / no solution (inconsistent system)
  • vector_ops — dot / cross (3D) / norm / projection / angle (degrees)

🔧 Implementation

  • Gaussian elimination with partial pivoting; pivot tolerance 1e-12
  • All output numbers rounded to 10 decimal places (configurable), near-zero values snapped to exactly 0
  • Singular inverses and inconsistent systems fail cleanly with explicit messages — never fabricate results
  • 84 tests, anchored by an independent exact-arithmetic (fractions) oracle

📦 Install

dsh plugin --profile web add github:TYEclipse/dsh-linalg

dsh-linalg v0.1.0 — DeepSeek Harness 线性代数工具箱

首发版本:四个纯数学工具,零运行时依赖。

✨ 新增

  • matrix_multiply — 矩阵乘法(严格维度校验)
  • matrix_compute — 转置 / 行列式 / 逆矩阵 / 迹 / 行最简形(rref)
  • solve_linear — 解线性方程组 Ax=b,分类为唯一解 / 无穷多解(特解+零空间基+自由变量个数)/ 无解(矛盾方程组)
  • vector_ops — 点积 / 叉积(3D)/ 模长 / 投影 / 夹角(度)

🔧 实现

  • 部分主元高斯消元,主元容差 1e-12
  • 所有输出统一舍入到 10 位小数(可配),接近零的值精确归零
  • 奇异矩阵与矛盾方程组明确报错,绝不编造结果
  • 84 个测试,锚点由独立精确算术(fractions)oracle 生成

📦 安装

dsh plugin --profile web add github:TYEclipse/dsh-linalg