In the development workflow of DeepSeek Harness (DSH), large models often incur numerical errors when performing matrix multiplication, determinant calculation, matrix inversion, and solving linear systems. The dsh-linalg plugin offloads such computations from model inference to local exact code execution, ensuring deterministic results.

Plugin Purpose

dsh-linalg is a linear algebra toolbox for DeepSeek Harness (dsh). It is maintained by TYEclipse. It provides purely local arithmetic with zero runtime dependencies, handling matrix multiplication, determinants, matrix inverses, eigenvalue decomposition, and vector operations to ensure deterministic and correct results.

Core Features

This plugin provides the following verified features:

  • Matrix Operations: matrix multiplication, determinant, inverse, trace, transpose, reduced row echelon form (RREF), rank, integer matrix powers.
  • Linear System Solving: solve Ax = b and classify solution cases (unique solution, infinite solutions, no solution).
  • Eigenvalue Decomposition: eigenvalue decomposition for symmetric matrices, including residual measurement.
  • Vector Operations: dot product, cross product, norm, projection, angle calculation.

Installation and Enablement

Before installing, ensure that pnpm is in the system PATH.

  1. Run the following command to add the plugin:
dsh plugin --profile web add github:TYEclipse/dsh-linalg

(Replace web with your actual profile name)

Typical Usage

Matrix Computations

Calculate the determinant:

matrix_compute(matrix=[[2,1,1],[1,3,2],[1,0,0]], op="determinant")
# 返回:-1

Calculate the inverse matrix:

matrix_compute(matrix=[[4,7],[2,6]], op="inverse")
# 返回:[[0.6,-0.7],[-0.2,0.4]]

Linear System Solving

Solve the system of linear equations:

solve_linear(a=[[2,3],[1,-1]], b=[8,1])
# 返回:unique solution: [2.2, 1.2]

Vector Operations

Calculate the cross product:

vector_ops(op="cross", a=[1,2,3], b=[4,5,6])
# 返回:[-3,6,-3]

Calculate the angle between vectors (in degrees):

vector_ops(op="angle", a=[3,4], b=[4,0])
# 返回:53.1301023542

Configuration

The plugin supports the following configuration (YAML format):

- name: 'github:TYEclipse/dsh-linalg'
  config:
    maxDimension: 20   # 矩阵最大维度(行/列),范围 1-50
    roundPlaces: 10    # 输出数字保留的小数位数,范围 1-15

Numerical Behavior and Notes

  • Algorithms: Gaussian elimination with partial pivoting is used; eigenvalue decomposition uses cyclic Jacobi method; integer power calculations use binary exponentiation.
  • Precision: All output numbers retain 10 decimal places by default (configurable via roundPlaces); values with absolute value less than 5e-12 are zeroed out to avoid -0.
  • Tolerance: The pivot tolerance is 1e-12; entries below this value are treated as zero to prevent ill-conditioned matrices from producing spurious results.
  • Limitations: Default matrix dimension limit is 20×20 (configurable); exponent for integer power operations is limited to -64 through 64.

Summary

dsh-linalg provides reliable local arithmetic support for DSH, addressing instability issues in large models’ mathematical calculations.

  • GitHub: https://github.com/TYEclipse/dsh-linalg
  • Plugin Directory: https://www.skillhub.cn/plugins/TYEclipse/dsh-linalg