LMMP 4.3.0
Lamina High-Precision Arithmetic Library
载入中...
搜索中...
未找到
mat22_mul.h
浏览该文件的文档.
1/**
2 * Copyright (C) 2026 HJimmyK (Jericho Knox)
3 *
4 * This file is part of LMMP.
5 *
6 * LMMP is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation; either version 3 of
9 * the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library. If not, see
18 * <https://www.gnu.org/licenses/>.
19 *
20 * SPDX-License-Identifier: LGPL-3.0-or-later
21 */
22
23#ifndef __LMMP_IMPL_MAT22_MUL_H__
24#define __LMMP_IMPL_MAT22_MUL_H__
25
26#include "lmmp/lmmpn.h"
27
28/*
29 2x2 非负矩阵(hgcd 变换矩阵的通用载体)。
30
31 约定:显式存储每个元素的真实长度 n[i][j](归一化,顶 limb 非零;
32 n[i][j]==0 表示该元素值为零),不做零填充——各元素缓冲 [0, n[i][j])
33 之外的内容无效,一切访问以长度为准。输入矩阵的长度由调用方保证已
34 归一化(本模块按此契约直接使用,仅以调试断言核查顶 limb)。
35
36 约定:mx(A) 即 A 矩阵中,最大的n[i][j],也即四个指针中,最长的元素的
37 limb 长度,mx(A,B) 指 A和B矩阵中,最大的n[i][j]
38
39 本布局与 lmmp_hgcd_matrix_t(numth.h)公共前缀同构(m[2][2] +
40 n[2][2],后者多一个 alloc 字段),hgcd 侧可经指针强转无缝复用,
41 无转换开销。
42*/
43
44typedef struct {
45 mp_ptr p[2][2]; /* 元素指针 */
46 mp_size_t n[2][2]; /* 元素真实长度(归一化;0 表示零元素) */
48
49/**
50 * @brief 计算 D <- A*B(2x2 非负矩阵乘法)
51 * @param dst 结果矩阵,各个元素结果写入 dst->p 中的数组,对应实际长度被写入到 dst->n 中
52 * @param a 左矩阵(元素长度为 a->n[i][j],可与 dst 别名,即支持 D <- D*B)
53 * @param b 右矩阵(元素长度为 b->n[i][j],不可与 dst 别名)
54 * @param tp 临时空间(8*(mx(a)+mx(b))+16 个limb)
55 * @warning dst!=NULL, a!=NULL, b!=NULL, tp!=NULL, sep(dst,b), eqsep(dst,a),
56 * dst 各元素缓冲容量至少为 mx(a)+mx(b)+4
57 */
58void lmmp_mat22_mul_(lmmp_mat22_t* dst, const lmmp_mat22_t* a, const lmmp_mat22_t* b, mp_ptr tp);
59
60/**
61 * @brief 计算 D <- A*A(2x2 非负矩阵平方)
62 * @param dst 结果矩阵,各个元素结果写入 dst->p 中的数组,对应实际长度被写入到 dst->n 中
63 * @param a 源矩阵(元素长度为 a->n[i][j],可与 dst 别名)
64 * @param tp 临时空间(15*mx(a)+14 个limb)
65 * @warning dst!=NULL, a!=NULL, tp!=NULL, eqsep(dst,a),
66 * dst 元素缓冲容量 >= 2*mx(a)+4
67 */
69
70#if defined(LMMP_INTERNAL_BUILD) || defined(LMMP_INTERNAL_USE)
71LMMP_API void lmmp_internal_numth_mat22_sqr_basecase(lmmp_mat22_t* dst, const lmmp_mat22_t* a, mp_ptr tp);
72LMMP_API void lmmp_internal_numth_mat22_sqr_strassen(lmmp_mat22_t* dst, const lmmp_mat22_t* a, mp_ptr tp);
73#endif
74
75#endif // __LMMP_IMPL_MAT22_MUL_H__
mp_limb_t * mp_ptr
定义 lmmp.h:96
#define LMMP_API
Copyright (C) 2026 HJimmyK (Jericho Knox)
定义 lmmp.h:77
uint64_t mp_size_t
定义 lmmp.h:93
void lmmp_mat22_sqr_(lmmp_mat22_t *dst, const lmmp_mat22_t *a, mp_ptr tp)
计算 D <- A*A(2x2 非负矩阵平方)
void lmmp_mat22_mul_(lmmp_mat22_t *dst, const lmmp_mat22_t *a, const lmmp_mat22_t *b, mp_ptr tp)
计算 D <- A*B(2x2 非负矩阵乘法)
mp_ptr p[2][2]
mp_size_t n[2][2]
Copyright (C) 2026 HJimmyK (Jericho Knox)
#define tp