csdigit 0.1__tar.gz → 0.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. {csdigit-0.1 → csdigit-0.2}/.github/workflows/ci.yml +2 -2
  2. {csdigit-0.1 → csdigit-0.2}/.github/workflows/multi-platforms.yml +6 -4
  3. {csdigit-0.1 → csdigit-0.2}/.github/workflows/python-package.yml +2 -1
  4. {csdigit-0.1 → csdigit-0.2}/.pre-commit-config.yaml +2 -0
  5. csdigit-0.2/.vscode/settings.json +3 -0
  6. csdigit-0.2/GEMINI.md +84 -0
  7. csdigit-0.2/IFLOW.md +75 -0
  8. {csdigit-0.1 → csdigit-0.2}/LICENSE.txt +1 -1
  9. {csdigit-0.1/src/csdigit.egg-info → csdigit-0.2}/PKG-INFO +4 -2
  10. {csdigit-0.1 → csdigit-0.2}/README.md +3 -1
  11. {csdigit-0.1 → csdigit-0.2}/benches/test_bench.py +2 -2
  12. csdigit-0.2/cpp_ai/.gitignore +152 -0
  13. csdigit-0.2/cpp_ai/CMakeLists.txt +96 -0
  14. csdigit-0.2/cpp_ai/LICENSE +21 -0
  15. csdigit-0.2/cpp_ai/README.md +133 -0
  16. csdigit-0.2/cpp_ai/examples/basic_usage.cpp +62 -0
  17. csdigit-0.2/cpp_ai/examples/cli_usage.cpp +35 -0
  18. csdigit-0.2/cpp_ai/include/csdigit/csdigit.hpp +108 -0
  19. csdigit-0.2/cpp_ai/src/cli/main.cpp +121 -0
  20. csdigit-0.2/cpp_ai/src/csdigit/csd.cpp +233 -0
  21. csdigit-0.2/cpp_ai/src/csdigit/csd_multiplier.cpp +78 -0
  22. csdigit-0.2/cpp_ai/src/csdigit/lcsre.cpp +40 -0
  23. csdigit-0.2/cpp_ai/test_compile.cpp +16 -0
  24. csdigit-0.2/cpp_ai/tests/test_csdigit.cpp +94 -0
  25. csdigit-0.2/cpp_ai/xmake.lua +57 -0
  26. {csdigit-0.1 → csdigit-0.2}/docs/conf.py +1 -4
  27. csdigit-0.2/mypy.ini +21 -0
  28. csdigit-0.2/rust_ai/.gitignore +88 -0
  29. csdigit-0.2/rust_ai/Cargo.toml +28 -0
  30. csdigit-0.2/rust_ai/LICENSE +21 -0
  31. csdigit-0.2/rust_ai/README.md +133 -0
  32. csdigit-0.2/rust_ai/examples/basic_usage.rs +58 -0
  33. csdigit-0.2/rust_ai/examples/cli_usage.rs +36 -0
  34. csdigit-0.2/rust_ai/src/bin/main.rs +82 -0
  35. csdigit-0.2/rust_ai/src/lib.rs +478 -0
  36. {csdigit-0.1 → csdigit-0.2}/src/csdigit/cli.py +34 -21
  37. csdigit-0.2/src/csdigit/csd.py +409 -0
  38. csdigit-0.2/src/csdigit/csd_multiplier.py +413 -0
  39. {csdigit-0.1 → csdigit-0.2}/src/csdigit/lcsre.py +42 -27
  40. csdigit-0.2/src/csdigit/py.typed +0 -0
  41. {csdigit-0.1 → csdigit-0.2/src/csdigit.egg-info}/PKG-INFO +4 -2
  42. {csdigit-0.1 → csdigit-0.2}/src/csdigit.egg-info/SOURCES.txt +29 -0
  43. csdigit-0.2/src/pycsd/csd/__init__.py +3 -0
  44. csdigit-0.2/src/pycsd/csd/csd.py +160 -0
  45. csdigit-0.2/src/pycsd/csd_orig.py +129 -0
  46. {csdigit-0.1 → csdigit-0.2}/src/pycsd/dev/csd_numbers.py +25 -22
  47. {csdigit-0.1 → csdigit-0.2}/src/pycsd/test/decimal_tests.py +9 -8
  48. {csdigit-0.1 → csdigit-0.2}/src/pycsd/test/test_csd_decimals.py +5 -5
  49. {csdigit-0.1 → csdigit-0.2}/src/pycsd/test/test_csd_integers.py +2 -2
  50. {csdigit-0.1 → csdigit-0.2}/src/pycsd/test/test_to_and_fro_10bits.py +2 -2
  51. csdigit-0.2/tests/test_cli.py +83 -0
  52. csdigit-0.2/tests/test_csd.py +329 -0
  53. csdigit-0.2/tests/test_csd_multiplier.py +460 -0
  54. csdigit-0.2/tests/test_lcsre.py +164 -0
  55. csdigit-0.1/src/csdigit/csd.py +0 -309
  56. csdigit-0.1/src/pycsd/csd/__init__.py +0 -1
  57. csdigit-0.1/src/pycsd/csd/csd.py +0 -118
  58. csdigit-0.1/src/pycsd/csd_orig.py +0 -99
  59. csdigit-0.1/tests/test_cli.py +0 -23
  60. csdigit-0.1/tests/test_csd.py +0 -61
  61. csdigit-0.1/tests/test_lcsre.py +0 -23
  62. {csdigit-0.1 → csdigit-0.2}/.coveragerc +0 -0
  63. {csdigit-0.1 → csdigit-0.2}/.github/workflows/codecov.yml +0 -0
  64. {csdigit-0.1 → csdigit-0.2}/.github/workflows/jekyll-gh-pages.yml +0 -0
  65. {csdigit-0.1 → csdigit-0.2}/.github/workflows/python-app.yml +0 -0
  66. {csdigit-0.1 → csdigit-0.2}/.github/workflows/python-publish.yml +0 -0
  67. {csdigit-0.1 → csdigit-0.2}/.gitignore +0 -0
  68. {csdigit-0.1 → csdigit-0.2}/.isort.cfg +0 -0
  69. {csdigit-0.1 → csdigit-0.2}/.readthedocs.yml +0 -0
  70. {csdigit-0.1 → csdigit-0.2}/AUTHORS.md +0 -0
  71. {csdigit-0.1 → csdigit-0.2}/CHANGELOG.md +0 -0
  72. {csdigit-0.1 → csdigit-0.2}/CONTRIBUTING.md +0 -0
  73. {csdigit-0.1 → csdigit-0.2}/_config.yml +0 -0
  74. {csdigit-0.1 → csdigit-0.2}/docs/Makefile +0 -0
  75. {csdigit-0.1 → csdigit-0.2}/docs/_static/.gitignore +0 -0
  76. {csdigit-0.1 → csdigit-0.2}/docs/authors.md +0 -0
  77. {csdigit-0.1 → csdigit-0.2}/docs/changelog.md +0 -0
  78. {csdigit-0.1 → csdigit-0.2}/docs/contributing.md +0 -0
  79. {csdigit-0.1 → csdigit-0.2}/docs/index.md +0 -0
  80. {csdigit-0.1 → csdigit-0.2}/docs/license.md +0 -0
  81. {csdigit-0.1 → csdigit-0.2}/docs/readme.md +0 -0
  82. {csdigit-0.1 → csdigit-0.2}/docs/requirements.txt +0 -0
  83. {csdigit-0.1 → csdigit-0.2}/environment.yml +0 -0
  84. {csdigit-0.1 → csdigit-0.2}/experiments/notes.md +0 -0
  85. {csdigit-0.1 → csdigit-0.2}/experiments/random_gen.py +0 -0
  86. {csdigit-0.1 → csdigit-0.2}/pyproject.toml +0 -0
  87. {csdigit-0.1 → csdigit-0.2}/requirements/README.md +0 -0
  88. {csdigit-0.1 → csdigit-0.2}/requirements/default.txt +0 -0
  89. {csdigit-0.1 → csdigit-0.2}/requirements/doc.txt +0 -0
  90. {csdigit-0.1 → csdigit-0.2}/requirements/extras.txt +0 -0
  91. {csdigit-0.1 → csdigit-0.2}/requirements/test.txt +0 -0
  92. {csdigit-0.1 → csdigit-0.2}/requirements.txt +0 -0
  93. {csdigit-0.1 → csdigit-0.2}/setup.cfg +0 -0
  94. {csdigit-0.1 → csdigit-0.2}/setup.py +0 -0
  95. {csdigit-0.1 → csdigit-0.2}/src/csdigit/__init__.py +0 -0
  96. {csdigit-0.1 → csdigit-0.2}/src/csdigit.egg-info/dependency_links.txt +0 -0
  97. {csdigit-0.1 → csdigit-0.2}/src/csdigit.egg-info/not-zip-safe +0 -0
  98. {csdigit-0.1 → csdigit-0.2}/src/csdigit.egg-info/requires.txt +0 -0
  99. {csdigit-0.1 → csdigit-0.2}/src/csdigit.egg-info/top_level.txt +0 -0
  100. {csdigit-0.1 → csdigit-0.2}/src/pycsd/README +0 -0
  101. {csdigit-0.1 → csdigit-0.2}/src/pycsd/__init__.py +0 -0
  102. {csdigit-0.1 → csdigit-0.2}/src/pycsd/from_csd +0 -0
  103. {csdigit-0.1 → csdigit-0.2}/src/pycsd/run_tests.py +0 -0
  104. {csdigit-0.1 → csdigit-0.2}/src/pycsd/test/__init__.py +0 -0
  105. {csdigit-0.1 → csdigit-0.2}/src/pycsd/to_csd +0 -0
  106. {csdigit-0.1 → csdigit-0.2}/tests/conftest.py +0 -0
  107. {csdigit-0.1 → csdigit-0.2}/tox.ini +0 -0
@@ -60,8 +60,8 @@ jobs:
60
60
  strategy:
61
61
  matrix:
62
62
  python:
63
- - "3.9" # oldest Python supported by PSF
64
- - "3.11" # newest Python that is stable
63
+ - "3.10" # oldest Python supported by PSF
64
+ - "3.12" # newest Python that is stable
65
65
  platform:
66
66
  - ubuntu-latest
67
67
  - macos-latest
@@ -8,10 +8,10 @@ jobs:
8
8
  strategy:
9
9
  matrix:
10
10
  os: ["ubuntu-latest", "windows-latest"]
11
- version: ["3.9", "3.11"]
11
+ version: ["3.10", "3.12"]
12
12
  steps:
13
- - uses: actions/checkout@v2
14
- - uses: conda-incubator/setup-miniconda@v2
13
+ - uses: actions/checkout@v3
14
+ - uses: conda-incubator/setup-miniconda@v3
15
15
  with:
16
16
  activate-environment: test
17
17
  environment-file: environment.yml
@@ -31,5 +31,7 @@ jobs:
31
31
  shell: bash -l {0}
32
32
  run: |
33
33
  conda install pytest
34
- python setup.py develop
34
+ conda install pip
35
+ conda install setuptools wheel setuptools_scm
36
+ pip install -e .
35
37
  pytest
@@ -15,7 +15,7 @@ jobs:
15
15
  strategy:
16
16
  fail-fast: false
17
17
  matrix:
18
- python-version: ["3.9", "3.11"]
18
+ python-version: ["3.10", "3.12"]
19
19
 
20
20
  steps:
21
21
  - uses: actions/checkout@v2
@@ -26,6 +26,7 @@ jobs:
26
26
  - name: Install dependencies
27
27
  run: |
28
28
  python -m pip install --upgrade pip
29
+ python -m pip install setuptools wheel setuptools_scm
29
30
  python -m pip install flake8 pytest
30
31
  if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
31
32
  python setup.py develop
@@ -14,8 +14,10 @@ repos:
14
14
  - id: debug-statements
15
15
  - id: end-of-file-fixer
16
16
  - id: requirements-txt-fixer
17
+ exclude: "requirements[.]txt$"
17
18
  - id: mixed-line-ending
18
19
  args: ["--fix=auto"] # replace 'auto' with 'lf' to enforce Linux/Mac line endings or 'crlf' for Windows
20
+ exclude: "requirements[.]txt$"
19
21
 
20
22
  ## If you want to automatically "modernize" your Python code:
21
23
  # - repo: https://github.com/asottile/pyupgrade
@@ -0,0 +1,3 @@
1
+ {
2
+ "cmake.ignoreCMakeListsMissing": true
3
+ }
csdigit-0.2/GEMINI.md ADDED
@@ -0,0 +1,84 @@
1
+ # GEMINI.md
2
+
3
+ ## Project Overview
4
+
5
+ This project, `csdigit`, is a Python library for Canonical Signed Digit (CSD) conversion. CSD is a number representation system that uses only three symbols: `+`, `-`, and `0`. It is used in digital signal processing and other areas of computer science for efficient arithmetic operations.
6
+
7
+ The library provides functions to convert numbers between decimal format and CSD format. It supports both integers and floating-point numbers.
8
+
9
+ The main functions are:
10
+ * `to_csd`: Converts a decimal number to a CSD string.
11
+ * `to_csd_i`: Converts an integer to a CSD string.
12
+ * `to_decimal`: Converts a CSD string to a decimal number.
13
+ * `to_csdnnz`: Converts a decimal number to a CSD string with a specified maximum number of non-zero digits.
14
+ * `to_csdnnz_i`: Converts an integer to a CSD string with a specified maximum number of non-zero digits.
15
+
16
+ The project is structured as a standard Python package using `setuptools` and `PyScaffold`.
17
+
18
+ ## Building and Running
19
+
20
+ ### Dependencies
21
+
22
+ The project's dependencies are managed in `requirements/` folder.
23
+
24
+ * **Runtime dependencies:** `decorator`
25
+ * **Testing dependencies:** `codecov`, `coverage`, `hypothesis`, `pytest`, `pytest-benchmark`, `pytest-cov`
26
+
27
+ ### Testing
28
+
29
+ The project uses `tox` for managing test environments and `pytest` for running tests.
30
+
31
+ To run the tests, execute the following command:
32
+
33
+ ```bash
34
+ tox
35
+ ```
36
+
37
+ This will run the tests in an isolated environment.
38
+
39
+ ### Linting and Formatting
40
+
41
+ The project uses `pre-commit` with `isort`, `black`, and `flake8` to enforce code style and quality.
42
+
43
+ To run the linters and formatters, execute the following command:
44
+
45
+ ```bash
46
+ pre-commit run --all-files
47
+ ```
48
+
49
+ ### Building the Package
50
+
51
+ The project uses `tox` to manage the build process.
52
+
53
+ To build the source distribution and wheel, run:
54
+
55
+ ```bash
56
+ tox -e build
57
+ ```
58
+
59
+ The distributable files will be located in the `dist/` directory.
60
+
61
+ To clean the build artifacts, run:
62
+
63
+ ```bash
64
+ tox -e clean
65
+ ```
66
+
67
+ ### Documentation
68
+
69
+ The project's documentation is built using `Sphinx`.
70
+
71
+ To build the documentation, run:
72
+
73
+ ```bash
74
+ tox -e docs
75
+ ```
76
+
77
+ The generated documentation will be in `docs/_build/html/`.
78
+
79
+ ## Development Conventions
80
+
81
+ * **Code Style:** The project follows the `black` code style and uses `isort` to sort imports. `flake8` is used for linting.
82
+ * **Testing:** The project uses `pytest` for testing. Tests are located in the `tests/` directory.
83
+ * **Commits:** The project uses `pre-commit` to run checks before each commit.
84
+ * **Versioning:** The project uses `setuptools_scm` for automatic versioning based on Git tags.
csdigit-0.2/IFLOW.md ADDED
@@ -0,0 +1,75 @@
1
+ # CSDigit iFlow Context
2
+
3
+ ## 项目概述
4
+
5
+ CSDigit 是一个 Python 库,用于在十进制数和规范符号数字 (Canonical Signed Digit, CSD) 表示之间进行转换。CSD 是一种特殊的符号数字表示法,其中每个数字被限制为 -1、0 或 1,且不允许连续的非零数字。这种表示法在数字信号处理应用中特别有用,例如滤波器设计,因为它能通过使用简单的加法器和减法器来实现高效算术运算。
6
+
7
+ ## 主要功能
8
+
9
+ - `to_csd`: 将十进制数转换为 CSD 字符串
10
+ - `to_csd_i`: 将整数转换为 CSD 字符串
11
+ - `to_decimal`: 将 CSD 字符串转换为十进制数
12
+ - `to_csdnnz`: 具有最大非零位数限制的 CSD 转换
13
+ - `to_csdnnz_i`: 整数版本的 CSD 转换,带非零位数限制
14
+ - `longest_repeated_substring`: 查找 CSD 字符串中的最长重复子串
15
+ - `generate_csd_multiplier`: 生成 CSD 乘法器的 Verilog 代码
16
+
17
+ ## 项目结构
18
+
19
+ - `src/csdigit/`: 源代码目录
20
+ - `csd.py`: 核心 CSD 转换函数
21
+ - `cli.py`: 命令行接口
22
+ - `csd_multiplier.py`: CSD 乘法器 Verilog 代码生成
23
+ - `lcsre.py`: 最长重复子串查找算法
24
+ - `tests/`: 测试代码
25
+ - `docs/`: 文档
26
+ - `requirements/`: 依赖配置
27
+
28
+ ## 构建和运行
29
+
30
+ ### 安装依赖
31
+ ```bash
32
+ pip install -r requirements.txt
33
+ ```
34
+
35
+ ### 开发安装
36
+ ```bash
37
+ pip install -e .
38
+ ```
39
+
40
+ ### 运行测试
41
+ ```bash
42
+ pytest tests/
43
+ ```
44
+
45
+ ### 使用命令行工具
46
+ ```bash
47
+ # 转换十进制到 CSD
48
+ python -m csdigit.cli -c 28.5 -p 2
49
+
50
+ # 转换 CSD 到十进制
51
+ python -m csdigit.cli -d "+00-00.+"
52
+
53
+ # 使用非零位数限制
54
+ python -m csdigit.cli -f 28.5 -z 4
55
+ ```
56
+
57
+ ## 开发约定
58
+
59
+ - 遵循 Python PEP 8 代码风格
60
+ - 使用 pytest 进行测试
61
+ - 使用 doctest 进行函数示例测试
62
+ - 使用 type hints 提供类型信息
63
+ - 遵循语义化版本控制
64
+
65
+ ## 测试
66
+
67
+ 项目包含全面的单元测试,使用 pytest 和 hypothesis 进行属性测试。主要测试包括:
68
+ - CSD 转换的正确性
69
+ - 反向转换验证 (decimal -> CSD -> decimal)
70
+ - 特殊情况处理 (零值、负数)
71
+ - 边界条件测试
72
+
73
+ ## 许可证
74
+
75
+ MIT 许可证
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2023 Wai-Shing Luk
3
+ Copyright (c) 2025 Wai-Shing Luk
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: csdigit
3
- Version: 0.1
3
+ Version: 0.2
4
4
  Summary: Add a short description here!
5
5
  Home-page: https://github.com/pyscaffold/pyscaffold/
6
6
  Author: Wai-Shing Luk
@@ -54,7 +54,9 @@ The library contains a number of functions, each with a specific role.
54
54
 
55
55
  3. The functions to_decimal_using_pow and to_decimal perform the inverse of the to_csd function. They accept a CSD string as input and return a decimal number.
56
56
 
57
- 4. The to_csdnnz function is a variant of the to_csd function that allows the user to specify the maximum number of non-zero digits in the result.
57
+ 4. The to_csdnnz function is a variant of the to_csd function that allows the user to specify the maximum number of non-zero digits in the result.
58
+
59
+ 5. The to_csdnnz_i function is a variant of the to_csd_i function that allows the user to specify the maximum number of non-zero digits in the result.
58
60
 
59
61
  The library fulfills its intended function through a sequence of mathematical operations and logical tests. In order to effect a conversion from decimal to CSD, the system employs the use of powers of 2 in order to ascertain which of the three symbols (+, -, or 0) is to be used at each position within the CSD string. The algorithm then performs repeated divisions of the input number by two and compares the result to specific thresholds to determine the appropriate symbol to use.
60
62
 
@@ -31,7 +31,9 @@ The library contains a number of functions, each with a specific role.
31
31
 
32
32
  3. The functions to_decimal_using_pow and to_decimal perform the inverse of the to_csd function. They accept a CSD string as input and return a decimal number.
33
33
 
34
- 4. The to_csdnnz function is a variant of the to_csd function that allows the user to specify the maximum number of non-zero digits in the result.
34
+ 4. The to_csdnnz function is a variant of the to_csd function that allows the user to specify the maximum number of non-zero digits in the result.
35
+
36
+ 5. The to_csdnnz_i function is a variant of the to_csd_i function that allows the user to specify the maximum number of non-zero digits in the result.
35
37
 
36
38
  The library fulfills its intended function through a sequence of mathematical operations and logical tests. In order to effect a conversion from decimal to CSD, the system employs the use of powers of 2 in order to ascertain which of the three symbols (+, -, or 0) is to be used at each position within the CSD string. The algorithm then performs repeated divisions of the input number by two and compares the result to specific thresholds to determine the appropriate symbol to use.
37
39
 
@@ -14,9 +14,9 @@ def run_csd_orig():
14
14
  assert a == b
15
15
 
16
16
 
17
- def test_csd(benchmark):
17
+ def test_csd(benchmark) -> None:
18
18
  benchmark(run_csd)
19
19
 
20
20
 
21
- def test_csd_orig(benchmark):
21
+ def test_csd_orig(benchmark) -> None:
22
22
  benchmark(run_csd_orig)
@@ -0,0 +1,152 @@
1
+ # Build directories
2
+ build/
3
+ xmake-build/
4
+ out/
5
+ bin/
6
+ lib/
7
+ *.exe
8
+ *.out
9
+
10
+ # CMake
11
+ CMakeCache.txt
12
+ CMakeFiles/
13
+ cmake_install.cmake
14
+ Makefile
15
+ *.cmake
16
+ *.cmake.*
17
+ CMakeUserPresets.json
18
+
19
+ # xmake
20
+ .xmake/
21
+ .vscode/
22
+ .idea/
23
+
24
+ # Compiled object files
25
+ *.o
26
+ *.obj
27
+ *.ko
28
+ *.so
29
+ *.dylib
30
+ *.dll
31
+
32
+ # Precompiled Headers
33
+ *.gch
34
+ *.pch
35
+
36
+ # Compiled Dynamic libraries
37
+ *.so
38
+ *.dylib
39
+ *.dll
40
+
41
+ # Fortran module files
42
+ *.mod
43
+ *.smod
44
+
45
+ # Compiled Static libraries
46
+ *.lai
47
+ *.la
48
+ *.a
49
+ *.lib
50
+
51
+ # Executables
52
+ *.exe
53
+ *.out
54
+ *.app
55
+
56
+ # IDE files
57
+ .vscode/
58
+ .idea/
59
+ *.swp
60
+ *.swo
61
+ *~
62
+
63
+ # OS generated files
64
+ .DS_Store
65
+ .DS_Store?
66
+ ._*
67
+ .Spotlight-V100
68
+ .Trashes
69
+ ehthumbs.db
70
+ Thumbs.db
71
+
72
+ # Test coverage
73
+ *.gcda
74
+ *.gcno
75
+ *.gcov
76
+
77
+ # Profiling data
78
+ *.profraw
79
+ *.profdata
80
+
81
+ # Doxygen
82
+ docs/html/
83
+ docs/latex/
84
+
85
+ # Package managers
86
+ conanfile.txt
87
+ conaninfo.txt
88
+ conanbuildinfo.cmake
89
+ conan.lock
90
+
91
+ # Python cache
92
+ __pycache__/
93
+ *.pyc
94
+ *.pyo
95
+ *.pyd
96
+
97
+ # Temporary files
98
+ *.tmp
99
+ *.temp
100
+
101
+ # Log files
102
+ *.log
103
+ *.tlog
104
+
105
+ # Backup files
106
+ *.bak
107
+ *.backup
108
+
109
+ # VS Code
110
+ .vscode/
111
+ !.vscode/settings.json
112
+ !.vscode/tasks.json
113
+ !.vscode/launch.json
114
+ !.vscode/extensions.json
115
+
116
+ # CLion
117
+ .idea/
118
+ *.iws
119
+
120
+ # Visual Studio
121
+ *.vcxproj
122
+ *.vcxproj.filters
123
+ *.vcxproj.user
124
+ *.sln
125
+ *.suo
126
+ *.opensdf
127
+ *.sdf
128
+ *.db
129
+
130
+ # Xcode
131
+ *.xcodeproj
132
+ *.xcworkspace
133
+ xcuserdata/
134
+
135
+ # Eclipse
136
+ .project
137
+ .classpath
138
+ .settings/
139
+
140
+ # NetBeans
141
+ nbproject/
142
+
143
+ # CodeBlocks
144
+ *.cbp
145
+ *.workspace
146
+
147
+ # Dev-C++
148
+ *.dev
149
+
150
+ # Qt Creator
151
+ *.pro.user
152
+ *.pro.user.*
@@ -0,0 +1,96 @@
1
+ cmake_minimum_required(VERSION 3.12)
2
+ project(csdigit VERSION 0.1.0 LANGUAGES CXX)
3
+
4
+ set(CMAKE_CXX_STANDARD 17)
5
+ set(CMAKE_CXX_STANDARD_REQUIRED ON)
6
+ set(CMAKE_CXX_EXTENSIONS OFF)
7
+
8
+ option(BUILD_SHARED_LIBS "Build shared library" OFF)
9
+ option(BUILD_TESTS "Build tests" ON)
10
+ option(BUILD_EXAMPLES "Build examples" ON)
11
+
12
+ # Add doctest if tests are enabled
13
+ if(BUILD_TESTS)
14
+ include(FetchContent)
15
+ FetchContent_Declare(
16
+ doctest
17
+ GIT_REPOSITORY https://github.com/doctest/doctest.git
18
+ GIT_TAG v2.4.11
19
+ )
20
+ FetchContent_MakeAvailable(doctest)
21
+ endif()
22
+
23
+ # Library target
24
+ add_library(csdigit)
25
+ target_sources(csdigit
26
+ PRIVATE
27
+ src/csdigit/csd.cpp
28
+ src/csdigit/csd_multiplier.cpp
29
+ src/csdigit/lcsre.cpp
30
+ )
31
+
32
+ target_include_directories(csdigit
33
+ PUBLIC
34
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
35
+ $<INSTALL_INTERFACE:include>
36
+ )
37
+
38
+ # CLI executable
39
+ add_executable(csdigit_cli src/cli/main.cpp)
40
+ target_link_libraries(csdigit_cli csdigit)
41
+
42
+ # Tests
43
+ if(BUILD_TESTS)
44
+ add_executable(csdigit_tests tests/test_csdigit.cpp)
45
+ target_link_libraries(csdigit_tests csdigit doctest)
46
+
47
+ # Add test cases
48
+ add_test(NAME csdigit_tests COMMAND csdigit_tests)
49
+ endif()
50
+
51
+ # Examples
52
+ if(BUILD_EXAMPLES)
53
+ add_executable(example_basic examples/basic_usage.cpp)
54
+ target_link_libraries(example_basic csdigit)
55
+
56
+ add_executable(example_cli examples/cli_usage.cpp)
57
+ target_link_libraries(example_cli csdigit)
58
+ endif()
59
+
60
+ # Installation
61
+ install(TARGETS csdigit
62
+ EXPORT csdigitTargets
63
+ LIBRARY DESTINATION lib
64
+ ARCHIVE DESTINATION lib
65
+ RUNTIME DESTINATION bin
66
+ INCLUDES DESTINATION include
67
+ )
68
+
69
+ install(DIRECTORY include/csdigit DESTINATION include)
70
+
71
+ # Export targets
72
+ install(EXPORT csdigitTargets
73
+ FILE csdigitTargets.cmake
74
+ NAMESPACE csdigit::
75
+ DESTINATION lib/cmake/csdigit
76
+ )
77
+
78
+ # Package configuration
79
+ include(CMakePackageConfigHelpers)
80
+ configure_package_config_file(
81
+ ${CMAKE_CURRENT_SOURCE_DIR}/cmake/csdigitConfig.cmake.in
82
+ ${CMAKE_CURRENT_BINARY_DIR}/csdigitConfig.cmake
83
+ INSTALL_DESTINATION lib/cmake/csdigit
84
+ )
85
+
86
+ write_basic_package_version_file(
87
+ ${CMAKE_CURRENT_BINARY_DIR}/csdigitConfigVersion.cmake
88
+ VERSION ${PROJECT_VERSION}
89
+ COMPATIBILITY SameMajorVersion
90
+ )
91
+
92
+ install(FILES
93
+ ${CMAKE_CURRENT_BINARY_DIR}/csdigitConfig.cmake
94
+ ${CMAKE_CURRENT_BINARY_DIR}/csdigitConfigVersion.cmake
95
+ DESTINATION lib/cmake/csdigit
96
+ )
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Wai-Shing Luk
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,133 @@
1
+ # CSDigit - Canonical Signed Digit Conversion in C++17
2
+
3
+ A C++17 implementation of the CSDigit library for converting between decimal numbers and Canonical Signed Digit (CSD) representation.
4
+
5
+ ## Overview
6
+
7
+ CSD is a special signed-digit representation where each digit is limited to -1, 0, or 1, and consecutive non-zero digits are not allowed. This representation is particularly useful in digital signal processing applications such as filter design, as it enables efficient arithmetic operations using simple adders and subtractors.
8
+
9
+ ## Features
10
+
11
+ - Convert decimal numbers to CSD representation
12
+ - Convert CSD strings back to decimal numbers
13
+ - Support for both floating-point and integer conversions
14
+ - Non-zero digit limit for CSD conversions
15
+ - Longest repeated substring finding algorithm
16
+ - Verilog code generation for CSD multipliers
17
+ - Command-line interface
18
+ - Comprehensive doctest test suite
19
+ - CMake and xmake build system support
20
+
21
+ ## Build Systems
22
+
23
+ ### CMake
24
+ ```bash
25
+ mkdir build && cd build
26
+ cmake ..
27
+ cmake --build .
28
+ ```
29
+
30
+ ### xmake
31
+ ```bash
32
+ xmake
33
+ xmake build
34
+ ```
35
+
36
+ ## Usage
37
+
38
+ ### As a Library
39
+
40
+ ```cpp
41
+ #include "csdigit/csdigit.hpp"
42
+ #include <iostream>
43
+
44
+ int main() {
45
+ // Convert decimal to CSD
46
+ std::string csd = csdigit::to_csd(28.5, 2);
47
+ std::cout << csd << std::endl; // Output: "+00-00.+0"
48
+
49
+ // Convert CSD to decimal
50
+ double decimal = csdigit::to_decimal("+00-00.+");
51
+ std::cout << decimal << std::endl; // Output: 28.5
52
+
53
+ // Convert integer to CSD
54
+ std::string csd_int = csdigit::to_csd_i(28);
55
+ std::cout << csd_int << std::endl; // Output: "+00-00"
56
+
57
+ return 0;
58
+ }
59
+ ```
60
+
61
+ ### Command Line Interface
62
+
63
+ ```bash
64
+ # Convert decimal to CSD
65
+ ./csdigit_cli to-csd 28.5 --places 2
66
+
67
+ # Convert decimal to CSD with non-zero limit
68
+ ./csdigit_cli to-csdnnz 28.5 --nnz 4
69
+
70
+ # Convert CSD to decimal
71
+ ./csdigit_cli to-decimal "+00-00.+"
72
+
73
+ # Show help
74
+ ./csdigit_cli --help
75
+ ```
76
+
77
+ ## API Reference
78
+
79
+ ### Core Functions
80
+
81
+ - `std::string to_csd(double decimal_value, int places)`
82
+ - `std::string to_csd_i(int32_t decimal_value)`
83
+ - `double to_decimal(const std::string& csd)`
84
+ - `std::string to_csdnnz(double decimal_value, int nnz)`
85
+ - `std::string to_csdnnz_i(int32_t decimal_value, int nnz)`
86
+ - `std::string longest_repeated_substring(const std::string& cs)`
87
+ - `std::string generate_csd_multiplier(const std::string& csd, size_t n, size_t m)`
88
+
89
+ ## Testing
90
+
91
+ Run the test suite:
92
+
93
+ ```bash
94
+ # With CMake
95
+ cd build && ctest
96
+
97
+ # With xmake
98
+ xmake run csdigit_tests
99
+ ```
100
+
101
+ ## Examples
102
+
103
+ See the `examples/` directory for more usage examples.
104
+
105
+ ## Building
106
+
107
+ ### CMake
108
+ ```bash
109
+ mkdir build
110
+ cd build
111
+ cmake -DCMAKE_BUILD_TYPE=Release ..
112
+ cmake --build . --config Release
113
+ ```
114
+
115
+ ### xmake
116
+ ```bash
117
+ xmake config --mode=release
118
+ xmake build
119
+ ```
120
+
121
+ ## Dependencies
122
+
123
+ - C++17 compiler
124
+ - doctest (for testing, automatically fetched by CMake)
125
+
126
+ ## License
127
+
128
+ MIT License - see LICENSE file for details.
129
+
130
+ ## Acknowledgments
131
+
132
+ Original Python implementation by Harnesser (https://sourceforge.net/projects/pycsd/)
133
+ C++ port by Wai-Shing Luk (luk036@gmail.com)