跳转到主要内容

计算Hermite正交形式和Smith正交形式。

项目描述

hsnf

testing Documentation Status pre-commit.ci status codecov MIT License PyPI - Python Version PyPI version PyPI - Downloads

使用转换矩阵计算Hermite正交形式和Smith正交形式。

使用方法

import numpy as np
from hsnf import column_style_hermite_normal_form, row_style_hermite_normal_form, smith_normal_form

# Integer matrix to be decomposed
M = np.array(
    [
        [-6, 111, -36, 6],
        [5, -672, 210, 74],
        [0, -255, 81, 24],
    ]
)

# Smith normal form
D, L, R = smith_normal_form(M)
"""
D = array([
[   1    0    0    0]
[   0    3    0    0]
[   0    0 2079    0]])
"""
assert np.allclose(L @ M @ R, D)
assert np.around(np.abs(np.linalg.det(L))) == 1  # unimodular
assert np.around(np.abs(np.linalg.det(R))) == 1  # unimodular

# Row-style hermite normal form
H, L = row_style_hermite_normal_form(M)
"""
H = array([
[     1      0    420  -2522]
[     0      3   1809 -10860]
[     0      0   2079 -12474]])
"""
assert np.allclose(L @ M, H)
assert np.around(np.abs(np.linalg.det(L))) == 1  # unimodular

# Column-style hermite normal form
H, R = column_style_hermite_normal_form(M)
"""
H = array([
[   3    0    0    0]
[   0    1    0    0]
[1185  474 2079    0]])
"""
assert np.allclose(np.dot(M, R), H)
assert np.around(np.abs(np.linalg.det(R))) == 1  # unimodular

安装

hsnf与Python3.8+兼容,可以通过PyPI安装

pip install hsnf

或本地安装

git clone git@github.com:lan496/hsnf.git
cd hsnf
pip install -e .[dev,docs]

参考资料

项目详情


下载文件

下载适用于您的平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源代码分发

hsnf-0.3.16.tar.gz (21.2 kB 查看哈希值)

上传时间 源代码

构建版本

hsnf-0.3.16-py3-none-any.whl (11.1 kB 查看哈希值)

上传时间 Python 3