Files
marqdo-cli/tests/conformance/semantics/73-sparse-matrix.mq.md
T
cflmy 8bbed34bd3 test(c12): add sparse-matrix triples and multiply fixture
- Fixture 73 implements triple-list lookup, dense conversion and sparse
  multiply with Int arithmetic and exact indexing.
- Include it in the P2 pure closure lane and update golden count to 73,
  C12 evidence mapping, status/README/changelog.

Gate: fmt, clippy -D warnings, 430 tests passed.
2026-11-20 23:19:45 +08:00

1.3 KiB

查值

(三元组, 行, 列)

值 = 0

下标 = 0

  • 下标 < 长度(三元组)

    1. 三元组[下标][0] == 行 and 三元组[下标][1] == 列

      值 = 三元组[下标][2]

    2. true

      忽略 = 0

    下标 = 下标 + 1

值

三列转稠密

(三元组, 行数, 列数)

矩阵 = []

行号 = 0

  • 行号 < 行数

    行 = []

    列号 = 0

    • 列号 < 列数

      行 = list.append(行, 查值(三元组, 行号, 列号))

      列号 = 列号 + 1

    矩阵 = list.append(矩阵, 行)

    行号 = 行号 + 1

矩阵

稀疏乘法

(左, 右, 行数, 内维, 列数)

结果 = []

行号 = 0

  • 行号 < 行数

    列号 = 0

    • 列号 < 列数

      和 = 0

      内号 = 0

      • 内号 < 内维

        左值 = 查值(左, 行号, 内号)

        右值 = 查值(右, 内号, 列号)

        和 = 和 + 左值 * 右值

        内号 = 内号 + 1

      1. 和 != 0

        结果 = list.append(结果, [行号, 列号, 和])

      2. true

        忽略 = 0

      列号 = 列号 + 1

    行号 = 行号 + 1

结果

main

左 = 0, 0, 1], [0, 2, 2], [1, 1, 3

右 = 0, 0, 4], [1, 1, 5], [2, 0, 6

乘积 = 稀疏乘法(左, 右, 2, 3, 2)

[乘积, 三列转稠密(乘积, 2, 2)]