csdigit 0.2__tar.gz → 0.4__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.
- {csdigit-0.2 → csdigit-0.4}/.github/workflows/ci.yml +1 -1
- {csdigit-0.2 → csdigit-0.4}/.github/workflows/python-app.yml +2 -2
- {csdigit-0.2 → csdigit-0.4}/.github/workflows/python-package.yml +2 -2
- {csdigit-0.2 → csdigit-0.4}/.gitignore +4 -0
- {csdigit-0.2 → csdigit-0.4}/.pre-commit-config.yaml +1 -1
- csdigit-0.4/CHANGELOG.md +19 -0
- {csdigit-0.2 → csdigit-0.4}/CONTRIBUTING.md +20 -18
- {csdigit-0.2/src/csdigit.egg-info → csdigit-0.4}/PKG-INFO +1 -2
- csdigit-0.4/benches/bench_csd.py +20 -0
- csdigit-0.4/benches/verify_output.py +36 -0
- {csdigit-0.2 → csdigit-0.4}/docs/conf.py +1 -0
- csdigit-0.4/docs/examples/plot_csd_conversion.py +20 -0
- csdigit-0.4/docs/examples/plot_csd_distribution.py +30 -0
- csdigit-0.4/docs/figures_demo.md +25 -0
- {csdigit-0.2 → csdigit-0.4}/docs/index.md +1 -0
- {csdigit-0.2 → csdigit-0.4}/mypy.ini +0 -5
- {csdigit-0.2 → csdigit-0.4}/setup.cfg +0 -3
- csdigit-0.4/src/csdigit/__init__.py +10 -0
- {csdigit-0.2 → csdigit-0.4}/src/csdigit/cli.py +12 -13
- {csdigit-0.2 → csdigit-0.4}/src/csdigit/csd.py +21 -35
- {csdigit-0.2 → csdigit-0.4}/src/csdigit/csd_multiplier.py +1 -1
- {csdigit-0.2 → csdigit-0.4}/src/csdigit/lcsre.py +8 -28
- {csdigit-0.2 → csdigit-0.4/src/csdigit.egg-info}/PKG-INFO +1 -2
- {csdigit-0.2 → csdigit-0.4}/src/csdigit.egg-info/SOURCES.txt +7 -23
- {csdigit-0.2 → csdigit-0.4}/src/csdigit.egg-info/requires.txt +0 -3
- csdigit-0.4/src/csdigit.egg-info/scm_file_list.json +79 -0
- csdigit-0.4/src/csdigit.egg-info/scm_version.json +8 -0
- {csdigit-0.2 → csdigit-0.4}/src/pycsd/csd/csd.py +2 -2
- {csdigit-0.2 → csdigit-0.4}/src/pycsd/csd_orig.py +2 -2
- {csdigit-0.2 → csdigit-0.4}/src/pycsd/dev/csd_numbers.py +4 -4
- {csdigit-0.2 → csdigit-0.4}/src/pycsd/test/decimal_tests.py +2 -2
- {csdigit-0.2 → csdigit-0.4}/src/pycsd/test/test_csd_decimals.py +2 -2
- {csdigit-0.2 → csdigit-0.4}/src/pycsd/test/test_csd_integers.py +1 -1
- {csdigit-0.2 → csdigit-0.4}/src/pycsd/test/test_to_and_fro_10bits.py +1 -1
- {csdigit-0.2 → csdigit-0.4}/tests/test_csd.py +10 -0
- {csdigit-0.2 → csdigit-0.4}/tests/test_csd_multiplier.py +242 -6
- csdigit-0.2/CHANGELOG.md +0 -7
- csdigit-0.2/IFLOW.md +0 -75
- csdigit-0.2/cpp_ai/.gitignore +0 -152
- csdigit-0.2/cpp_ai/CMakeLists.txt +0 -96
- csdigit-0.2/cpp_ai/LICENSE +0 -21
- csdigit-0.2/cpp_ai/README.md +0 -133
- csdigit-0.2/cpp_ai/examples/basic_usage.cpp +0 -62
- csdigit-0.2/cpp_ai/examples/cli_usage.cpp +0 -35
- csdigit-0.2/cpp_ai/include/csdigit/csdigit.hpp +0 -108
- csdigit-0.2/cpp_ai/src/cli/main.cpp +0 -121
- csdigit-0.2/cpp_ai/src/csdigit/csd.cpp +0 -233
- csdigit-0.2/cpp_ai/src/csdigit/csd_multiplier.cpp +0 -78
- csdigit-0.2/cpp_ai/src/csdigit/lcsre.cpp +0 -40
- csdigit-0.2/cpp_ai/test_compile.cpp +0 -16
- csdigit-0.2/cpp_ai/tests/test_csdigit.cpp +0 -94
- csdigit-0.2/cpp_ai/xmake.lua +0 -57
- csdigit-0.2/rust_ai/.gitignore +0 -88
- csdigit-0.2/rust_ai/Cargo.toml +0 -28
- csdigit-0.2/rust_ai/LICENSE +0 -21
- csdigit-0.2/rust_ai/README.md +0 -133
- csdigit-0.2/rust_ai/examples/basic_usage.rs +0 -58
- csdigit-0.2/rust_ai/examples/cli_usage.rs +0 -36
- csdigit-0.2/rust_ai/src/bin/main.rs +0 -82
- csdigit-0.2/rust_ai/src/lib.rs +0 -478
- csdigit-0.2/src/csdigit/__init__.py +0 -16
- {csdigit-0.2 → csdigit-0.4}/.coveragerc +0 -0
- {csdigit-0.2 → csdigit-0.4}/.github/workflows/codecov.yml +0 -0
- {csdigit-0.2 → csdigit-0.4}/.github/workflows/jekyll-gh-pages.yml +0 -0
- {csdigit-0.2 → csdigit-0.4}/.github/workflows/multi-platforms.yml +0 -0
- {csdigit-0.2 → csdigit-0.4}/.github/workflows/python-publish.yml +0 -0
- {csdigit-0.2 → csdigit-0.4}/.isort.cfg +0 -0
- {csdigit-0.2 → csdigit-0.4}/.readthedocs.yml +0 -0
- {csdigit-0.2 → csdigit-0.4}/.vscode/settings.json +0 -0
- {csdigit-0.2 → csdigit-0.4}/AUTHORS.md +0 -0
- {csdigit-0.2 → csdigit-0.4}/GEMINI.md +0 -0
- {csdigit-0.2 → csdigit-0.4}/LICENSE.txt +0 -0
- {csdigit-0.2 → csdigit-0.4}/README.md +0 -0
- {csdigit-0.2 → csdigit-0.4}/_config.yml +0 -0
- {csdigit-0.2 → csdigit-0.4}/benches/test_bench.py +0 -0
- {csdigit-0.2 → csdigit-0.4}/docs/Makefile +0 -0
- {csdigit-0.2 → csdigit-0.4}/docs/_static/.gitignore +0 -0
- {csdigit-0.2 → csdigit-0.4}/docs/authors.md +0 -0
- {csdigit-0.2 → csdigit-0.4}/docs/changelog.md +0 -0
- {csdigit-0.2 → csdigit-0.4}/docs/contributing.md +0 -0
- {csdigit-0.2 → csdigit-0.4}/docs/license.md +0 -0
- {csdigit-0.2 → csdigit-0.4}/docs/readme.md +0 -0
- {csdigit-0.2 → csdigit-0.4}/docs/requirements.txt +0 -0
- {csdigit-0.2 → csdigit-0.4}/environment.yml +0 -0
- {csdigit-0.2 → csdigit-0.4}/experiments/notes.md +0 -0
- {csdigit-0.2 → csdigit-0.4}/experiments/random_gen.py +0 -0
- {csdigit-0.2 → csdigit-0.4}/pyproject.toml +0 -0
- {csdigit-0.2 → csdigit-0.4}/requirements/README.md +0 -0
- {csdigit-0.2 → csdigit-0.4}/requirements/default.txt +0 -0
- {csdigit-0.2 → csdigit-0.4}/requirements/doc.txt +0 -0
- {csdigit-0.2 → csdigit-0.4}/requirements/extras.txt +0 -0
- {csdigit-0.2 → csdigit-0.4}/requirements/test.txt +0 -0
- {csdigit-0.2 → csdigit-0.4}/requirements.txt +0 -0
- {csdigit-0.2 → csdigit-0.4}/setup.py +0 -0
- {csdigit-0.2 → csdigit-0.4}/src/csdigit/py.typed +0 -0
- {csdigit-0.2 → csdigit-0.4}/src/csdigit.egg-info/dependency_links.txt +0 -0
- {csdigit-0.2 → csdigit-0.4}/src/csdigit.egg-info/not-zip-safe +0 -0
- {csdigit-0.2 → csdigit-0.4}/src/csdigit.egg-info/top_level.txt +0 -0
- {csdigit-0.2 → csdigit-0.4}/src/pycsd/README +0 -0
- {csdigit-0.2 → csdigit-0.4}/src/pycsd/__init__.py +0 -0
- {csdigit-0.2 → csdigit-0.4}/src/pycsd/csd/__init__.py +0 -0
- {csdigit-0.2 → csdigit-0.4}/src/pycsd/from_csd +0 -0
- {csdigit-0.2 → csdigit-0.4}/src/pycsd/run_tests.py +0 -0
- {csdigit-0.2 → csdigit-0.4}/src/pycsd/test/__init__.py +0 -0
- {csdigit-0.2 → csdigit-0.4}/src/pycsd/to_csd +0 -0
- {csdigit-0.2 → csdigit-0.4}/tests/conftest.py +0 -0
- {csdigit-0.2 → csdigit-0.4}/tests/test_cli.py +0 -0
- {csdigit-0.2 → csdigit-0.4}/tests/test_lcsre.py +0 -0
- {csdigit-0.2 → csdigit-0.4}/tox.ini +0 -0
|
@@ -8,7 +8,7 @@ on:
|
|
|
8
8
|
push:
|
|
9
9
|
# Avoid using all the resources/limits available by checking only
|
|
10
10
|
# relevant branches and tags. Other branches can be checked via PRs.
|
|
11
|
-
branches: [main]
|
|
11
|
+
branches: [ main, dev ]
|
|
12
12
|
tags: ["v[0-9]*", "[0-9]+.[0-9]+*"] # Match tags that resemble a version
|
|
13
13
|
pull_request: # Run in every PR
|
|
14
14
|
workflow_dispatch: # Allow manually triggering the workflow
|
csdigit-0.4/CHANGELOG.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## Version 0.4 (2026-07-16)
|
|
4
|
+
|
|
5
|
+
### Documentation
|
|
6
|
+
- **Sphinx docs with plot_directive and svgbob**: Enabled matplotlib `plot_directive` for auto-generated figures and `sphinxcontrib.svgbob` for ASCII-to-SVG diagrams. Added CSD distribution and conversion example plots under `docs/examples/`. Added svgbob diagram to `csd.py` module docstring. (#a6e57f8)
|
|
7
|
+
|
|
8
|
+
### Code Cleanup
|
|
9
|
+
- **Removed PyScaffold boilerplate**: Deleted `skeleton.py` and `test_skeleton.py` (unused Fibonacci CLI scaffold). (#27813b4)
|
|
10
|
+
- **Dropped Python < 3.9 compat**: Removed `importlib-metadata` conditional dependency and compat guard from `__init__.py` (project now targets 3.10+). (#27813b4)
|
|
11
|
+
- **Config cleanup**: Removed dead `fibonacci = skeleton:run` entry point from `setup.cfg` and unused `ignore_missing_imports` from `mypy.ini`. (#27813b4)
|
|
12
|
+
- **Removed stale files**: Deleted `IFLOW.md` and duplicate `LICENSE`. (#27813b4)
|
|
13
|
+
- **Updated `.gitignore`**: Added `.ruff_cache/` and `.benchmarks/`. (#27813b4)
|
|
14
|
+
|
|
15
|
+
### Build & CI
|
|
16
|
+
- **CI repair**: Fixed broken `entry_points` configuration and lingering `skeleton` imports breaking the CI pipeline. (#0b2459b)
|
|
17
|
+
|
|
18
|
+
### Testing & Code Quality
|
|
19
|
+
- **Benchmark & verification scripts**: Added `benches/bench_csd.py` and `benches/verify_output.py` for performance tracking and output verification. (#09da08a)
|
|
@@ -69,27 +69,29 @@ by adding missing information and correcting mistakes.
|
|
|
69
69
|
This means that the docs are kept in the same repository as the project code, and
|
|
70
70
|
that any documentation update is done in the same way was a code contribution.
|
|
71
71
|
|
|
72
|
-
```{todo}
|
|
72
|
+
```{todo}
|
|
73
|
+
Don't forget to mention which markup language you are using.
|
|
73
74
|
|
|
74
|
-
|
|
75
|
+
e.g., [reStructuredText] or [CommonMark] with [MyST] extensions.
|
|
75
76
|
```
|
|
76
77
|
|
|
77
|
-
```{todo}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
78
|
+
```{todo}
|
|
79
|
+
If your project is hosted on GitHub, you can also mention the following tip:
|
|
80
|
+
|
|
81
|
+
:::{tip}
|
|
82
|
+
Please notice that the [GitHub web interface] provides a quick way of
|
|
83
|
+
propose changes in `csdigit`'s files. While this mechanism can
|
|
84
|
+
be tricky for normal code contributions, it works perfectly fine for
|
|
85
|
+
contributing to the docs, and can be quite handy.
|
|
86
|
+
|
|
87
|
+
If you are interested in trying this method out, please navigate to
|
|
88
|
+
the `docs` folder in the source [repository], find which file you
|
|
89
|
+
would like to propose changes and click in the little pencil icon at the
|
|
90
|
+
top, to open [GitHub's code editor]. Once you finish editing the file,
|
|
91
|
+
please write a message in the form at the bottom of the page describing
|
|
92
|
+
which changes have you made and what are the motivations behind them and
|
|
93
|
+
submit your proposal.
|
|
94
|
+
:::
|
|
93
95
|
```
|
|
94
96
|
|
|
95
97
|
When working on documentation changes in your local machine, you can
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: csdigit
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4
|
|
4
4
|
Summary: Add a short description here!
|
|
5
5
|
Home-page: https://github.com/pyscaffold/pyscaffold/
|
|
6
6
|
Author: Wai-Shing Luk
|
|
@@ -12,7 +12,6 @@ Classifier: Development Status :: 4 - Beta
|
|
|
12
12
|
Classifier: Programming Language :: Python
|
|
13
13
|
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
14
14
|
License-File: LICENSE.txt
|
|
15
|
-
Requires-Dist: importlib-metadata; python_version < "3.9"
|
|
16
15
|
Provides-Extra: testing
|
|
17
16
|
Requires-Dist: setuptools; extra == "testing"
|
|
18
17
|
Requires-Dist: pytest; extra == "testing"
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import timeit
|
|
2
|
+
from csdigit.csd import to_csd, to_csd_i, to_decimal, to_decimal_using_pow, to_csdnnz
|
|
3
|
+
|
|
4
|
+
def bench(name, stmt, globals_dict=None, number=50000):
|
|
5
|
+
if globals_dict is None:
|
|
6
|
+
globals_dict = globals()
|
|
7
|
+
t = timeit.timeit(stmt, globals=globals_dict, number=number)
|
|
8
|
+
ns_per_op = t * 1e9 / number
|
|
9
|
+
print(f" {name:<30} {ns_per_op:>8.1f} ns/op ({number} iters)")
|
|
10
|
+
|
|
11
|
+
print("=== CSD Benchmarks (Python) ===")
|
|
12
|
+
bench("to_csd(28.5, 10)", "to_csd(28.5, 10)")
|
|
13
|
+
bench("to_csd_i(28)", "to_csd_i(28)")
|
|
14
|
+
bench("to_csdnnz(28.5, 4)", "to_csdnnz(28.5, 4)")
|
|
15
|
+
bench("to_decimal('+00-00.+0')", "to_decimal('+00-00.+0')")
|
|
16
|
+
bench("to_decimal_using_pow('+00-00')", "to_decimal_using_pow('+00-00')")
|
|
17
|
+
bench("to_csd(0.0, 10) [zero]", "to_csd(0.0, 10)")
|
|
18
|
+
bench("to_csd(-28.5, 10) [neg]", "to_csd(-28.5, 10)")
|
|
19
|
+
bench("to_csd(0.5, 10) [small]", "to_csd(0.5, 10)")
|
|
20
|
+
bench("to_csd(1024.75, 10) [large]", "to_csd(1024.75, 10)")
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
from csdigit.csd import to_csd, to_csd_i, to_decimal, to_decimal_using_pow, to_csdnnz, to_csdnnz_i
|
|
2
|
+
|
|
3
|
+
print("=== to_csd (float) ===")
|
|
4
|
+
for v, p in [(28.5,2), (-0.5,2), (0.0,2), (2.5,4), (0.0,0), (7.0,0), (-7.0,0), (28.5,0)]:
|
|
5
|
+
res = to_csd(v, p)
|
|
6
|
+
print(f' to_csd({v}, {p}) = "{res}"')
|
|
7
|
+
|
|
8
|
+
print()
|
|
9
|
+
print("=== to_csd_i (integer) ===")
|
|
10
|
+
for v in [28, 0, -28, 7, -7, 1, -1]:
|
|
11
|
+
res = to_csd_i(v)
|
|
12
|
+
print(f' to_csd_i({v}) = "{res}"')
|
|
13
|
+
|
|
14
|
+
print()
|
|
15
|
+
print("=== to_decimal ===")
|
|
16
|
+
for s in ["+00-00.+", "0.-", "0", "0.0", "0.+", "0.-", "0.++", "0.-+", "+00-00"]:
|
|
17
|
+
res = to_decimal(s)
|
|
18
|
+
print(f' to_decimal("{s}") = {res}')
|
|
19
|
+
|
|
20
|
+
print()
|
|
21
|
+
print("=== to_decimal_using_pow (integer CSD) ===")
|
|
22
|
+
for s in ["+00-00", "0", "-00+00"]:
|
|
23
|
+
res = to_decimal_using_pow(s)
|
|
24
|
+
print(f' to_decimal_using_pow("{s}") = {res}')
|
|
25
|
+
|
|
26
|
+
print()
|
|
27
|
+
print("=== to_csdnnz (float, limited nnz) ===")
|
|
28
|
+
for v, n in [(28.5,4), (-0.5,4), (0.0,4), (0.5,4), (0.0,0), (28.5,2), (28.5,1)]:
|
|
29
|
+
res = to_csdnnz(v, n)
|
|
30
|
+
print(f' to_csdnnz({v}, {n}) = "{res}"')
|
|
31
|
+
|
|
32
|
+
print()
|
|
33
|
+
print("=== to_csdnnz_i (integer, limited nnz) ===")
|
|
34
|
+
for v, n in [(28,4), (0,4)]:
|
|
35
|
+
res = to_csdnnz_i(v, n)
|
|
36
|
+
print(f' to_csdnnz_i({v}, {n}) = "{res}"')
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"""
|
|
2
|
+
CSD Conversion Examples
|
|
3
|
+
========================
|
|
4
|
+
|
|
5
|
+
Demonstrates CSD representation of various numbers.
|
|
6
|
+
"""
|
|
7
|
+
import matplotlib.pyplot as plt
|
|
8
|
+
|
|
9
|
+
from csdigit.csd import to_csd
|
|
10
|
+
|
|
11
|
+
test_values = [0.5, 1.0, 7.5, 15.25, 28.5, 63.125, 127.0625, 255.5]
|
|
12
|
+
|
|
13
|
+
plt.figure(figsize=(8, 5))
|
|
14
|
+
x_pos = range(len(test_values))
|
|
15
|
+
csd_strs = [to_csd(v, 4) for v in test_values]
|
|
16
|
+
plt.bar(x_pos, test_values, color="lightcoral", alpha=0.7)
|
|
17
|
+
plt.xticks(x_pos, [f"{v}\n({s})" for v, s in zip(test_values, csd_strs)], fontsize=8)
|
|
18
|
+
plt.ylabel("Decimal Value")
|
|
19
|
+
plt.title("CSD Representation of Various Numbers")
|
|
20
|
+
plt.grid(True, alpha=0.3, axis="y")
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""
|
|
2
|
+
CSD Non-zero Digit Distribution
|
|
3
|
+
================================
|
|
4
|
+
|
|
5
|
+
Shows the distribution of non-zero digits in CSD representation
|
|
6
|
+
for integers from 0 to 255.
|
|
7
|
+
"""
|
|
8
|
+
import matplotlib.pyplot as plt
|
|
9
|
+
|
|
10
|
+
from csdigit.csd import to_csd
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def count_nonzero(csd_str):
|
|
14
|
+
"""Count non-zero digits in CSD string (excluding decimal point)."""
|
|
15
|
+
return sum(1 for c in csd_str if c in "+-")
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
n_values = list(range(256))
|
|
19
|
+
nnz_counts = []
|
|
20
|
+
for n in n_values:
|
|
21
|
+
csd = to_csd(float(n), 0)
|
|
22
|
+
nnz = count_nonzero(csd.rstrip("0").rstrip("."))
|
|
23
|
+
nnz_counts.append(nnz)
|
|
24
|
+
|
|
25
|
+
plt.figure(figsize=(8, 5))
|
|
26
|
+
plt.bar(n_values, nnz_counts, width=1.0, color="steelblue", alpha=0.7)
|
|
27
|
+
plt.xlabel("Integer Value")
|
|
28
|
+
plt.ylabel("Non-zero CSD Digits")
|
|
29
|
+
plt.title("Distribution of Non-zero Digits in CSD Representation")
|
|
30
|
+
plt.grid(True, alpha=0.3, axis="y")
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Figures Demo
|
|
2
|
+
|
|
3
|
+
Auto-generated figures demonstrating csdigit functionality.
|
|
4
|
+
|
|
5
|
+
## CSD Non-zero Digit Distribution
|
|
6
|
+
|
|
7
|
+
```{plot} examples/plot_csd_distribution.py
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## CSD Conversion Examples
|
|
11
|
+
|
|
12
|
+
```{plot} examples/plot_csd_conversion.py
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### Inline Plot Example
|
|
16
|
+
|
|
17
|
+
```{plot}
|
|
18
|
+
import matplotlib.pyplot as plt
|
|
19
|
+
import numpy as np
|
|
20
|
+
|
|
21
|
+
x = np.linspace(0, 2 * np.pi, 100)
|
|
22
|
+
plt.plot(x, np.sin(x))
|
|
23
|
+
plt.title("Simple Sine Wave")
|
|
24
|
+
plt.grid(True, alpha=0.3)
|
|
25
|
+
```
|
|
@@ -5,17 +5,12 @@ warn_unused_configs = True
|
|
|
5
5
|
[mypy-setuptools.*]
|
|
6
6
|
ignore_missing_imports = True
|
|
7
7
|
|
|
8
|
-
[mypy-networkx.*]
|
|
9
8
|
ignore_missing_imports = True
|
|
10
9
|
|
|
11
|
-
[mypy-numpy.*]
|
|
12
10
|
ignore_missing_imports = True
|
|
13
11
|
|
|
14
|
-
[mypy-scipy.*]
|
|
15
12
|
ignore_missing_imports = True
|
|
16
13
|
|
|
17
|
-
[mypy-Cython.*]
|
|
18
14
|
ignore_missing_imports = True
|
|
19
15
|
|
|
20
|
-
[mypy-json.*]
|
|
21
16
|
ignore_missing_imports = True
|
|
@@ -22,7 +22,6 @@ include_package_data = True
|
|
|
22
22
|
package_dir =
|
|
23
23
|
=src
|
|
24
24
|
install_requires =
|
|
25
|
-
importlib-metadata; python_version<"3.9"
|
|
26
25
|
|
|
27
26
|
[options.packages.find]
|
|
28
27
|
where = src
|
|
@@ -37,8 +36,6 @@ testing =
|
|
|
37
36
|
pytest-benchmark
|
|
38
37
|
hypothesis
|
|
39
38
|
|
|
40
|
-
[options.entry_points]
|
|
41
|
-
|
|
42
39
|
[tool:pytest]
|
|
43
40
|
norecursedirs =
|
|
44
41
|
dist
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
2
|
+
|
|
3
|
+
try:
|
|
4
|
+
# Change here if project is renamed and does not equal the package name
|
|
5
|
+
dist_name = __name__
|
|
6
|
+
__version__ = version(dist_name)
|
|
7
|
+
except PackageNotFoundError: # pragma: no cover
|
|
8
|
+
__version__ = "unknown"
|
|
9
|
+
finally:
|
|
10
|
+
del version, PackageNotFoundError
|
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
"""
|
|
2
|
-
|
|
3
|
-
console script. To run this script uncomment the following lines in the
|
|
4
|
-
``[options.entry_points]`` section in ``setup.cfg``::
|
|
2
|
+
Command-line interface for CSD conversion.
|
|
5
3
|
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
Provides a CLI wrapper around the csdigit library, allowing conversion
|
|
5
|
+
between decimal numbers and Canonical Signed Digit (CSD) representation
|
|
6
|
+
from the terminal.
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
Supported conversions:
|
|
9
|
+
- Decimal float to CSD (--to_csd / -c)
|
|
10
|
+
- Decimal float to CSD with limited non-zero digits (--to_csdnnz / -f)
|
|
11
|
+
- CSD string to decimal (--to_decimal / -d)
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
- https://setuptools.readthedocs.io/en/latest/userguide/entry_point.html
|
|
17
|
-
- https://pip.pypa.io/en/stable/reference/pip_install
|
|
13
|
+
Usage:
|
|
14
|
+
python -m csdigit.cli --to_csd 28.5
|
|
15
|
+
python -m csdigit.cli --to_decimal "+00-00.+"
|
|
16
|
+
python -m csdigit.cli --to_csdnnz 28.5 --nnz 4
|
|
18
17
|
"""
|
|
19
18
|
|
|
20
19
|
import argparse
|
|
@@ -1,39 +1,25 @@
|
|
|
1
1
|
"""
|
|
2
|
-
Canonical Signed Digit (CSD)
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
4. to_csdnnz_i: This function is a variation of to_csd_i that allows you to specify the maximum number of non-zero digits in the result.
|
|
24
|
-
|
|
25
|
-
The code achieves its purpose through a series of mathematical operations and logical checks. For the
|
|
26
|
-
decimal to CSD conversion, it uses powers of 2 to determine which symbols (+, -, or 0) to use at each
|
|
27
|
-
position in the CSD string. It repeatedly divides the input number by 2 and checks if it's greater than,
|
|
28
|
-
less than, or close to certain thresholds to decide which symbol to use.
|
|
29
|
-
|
|
30
|
-
For the CSD to decimal conversion, it goes through each symbol in the CSD string, multiplying the running total by 2 and adding 1, subtracting 1, or doing nothing based on whether the symbol is +, -, or 0.
|
|
31
|
-
|
|
32
|
-
An important aspect of the code is how it handles the decimal point in CSD representations. It uses a separate logic for the part before the decimal point (the integral part) and the part after (the fractional part).
|
|
33
|
-
|
|
34
|
-
The code also includes error checking to ensure that only valid CSD symbols are used, and it provides detailed documentation and examples for each function to help users understand how to use them.
|
|
35
|
-
|
|
36
|
-
Overall, this code provides a comprehensive set of tools for working with CSD representations, allowing users to easily convert between decimal and CSD formats in various ways.
|
|
2
|
+
Canonical Signed Digit (CSD) conversion utilities.
|
|
3
|
+
|
|
4
|
+
Provides functions to convert between decimal numbers and Canonical Signed Digit
|
|
5
|
+
(CSD) representation — a signed-digit representation using only ``+``, ``-``,
|
|
6
|
+
and ``0`` symbols with no consecutive non-zero digits.
|
|
7
|
+
|
|
8
|
+
.. svgbob::
|
|
9
|
+
:align: center
|
|
10
|
+
|
|
11
|
+
Decimal ──► Binary ──► CSD
|
|
12
|
+
│ │
|
|
13
|
+
│ │
|
|
14
|
+
◄──────────────────────┘
|
|
15
|
+
|
|
16
|
+
Functions:
|
|
17
|
+
to_csd: Convert a decimal float to CSD string with specified precision.
|
|
18
|
+
to_csd_i: Convert an integer to CSD string.
|
|
19
|
+
to_decimal: Convert a CSD string to a decimal number.
|
|
20
|
+
to_decimal_using_pow: Convert a CSD string to decimal using pow() (deprecated).
|
|
21
|
+
to_csdnnz: Convert a decimal float to CSD with limited non-zero digits.
|
|
22
|
+
to_csdnnz_i: Convert an integer to CSD with limited non-zero digits.
|
|
37
23
|
"""
|
|
38
24
|
|
|
39
25
|
import logging
|
|
@@ -314,7 +314,7 @@ def generate_csd_multipliers(
|
|
|
314
314
|
best_occurrences: list[tuple[int, int]] = []
|
|
315
315
|
if cross:
|
|
316
316
|
|
|
317
|
-
def _scores(item):
|
|
317
|
+
def _scores(item: tuple[str, list[tuple[int, int]]]) -> int:
|
|
318
318
|
sub, occ = item
|
|
319
319
|
nnz = sub.count("+") + sub.count("-")
|
|
320
320
|
return (nnz - 1) * (len(occ) - 1)
|
|
@@ -1,35 +1,15 @@
|
|
|
1
1
|
"""
|
|
2
|
-
Longest Repeated Substring
|
|
2
|
+
Longest Repeated Non-Overlapping Substring (LCSRe) finder.
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
overlapping each other.
|
|
4
|
+
Finds the longest substring that appears at least twice in the input string
|
|
5
|
+
without overlapping occurrences. Uses dynamic programming with a space-optimized
|
|
6
|
+
2-row DP table (O(n) memory instead of O(n\\u00b2)).
|
|
8
7
|
|
|
9
|
-
|
|
8
|
+
This is used internally by the CSD multiplier generator to detect repeated
|
|
9
|
+
patterns in CSD strings, enabling hardware sharing via sub-expression wires.
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
non-overlapping substring found in the input.
|
|
14
|
-
|
|
15
|
-
To achieve its purpose, the code uses a dynamic programming approach. It creates a 2D table (called LCSRe) to keep track of the lengths of repeated substrings at different positions in the input string. The algorithm then iterates through this table, comparing characters and updating the lengths of repeated substrings it finds.
|
|
16
|
-
|
|
17
|
-
The main logic flow of the algorithm is as follows:
|
|
18
|
-
|
|
19
|
-
1. Initialize the 2D table with zeros.
|
|
20
|
-
2. Iterate through the table, comparing characters of the input string.
|
|
21
|
-
3. When matching characters are found, update the length of the repeated substring in the table.
|
|
22
|
-
4. Keep track of the maximum length of repeated substring found and its ending position.
|
|
23
|
-
5. After filling the table, extract the longest repeated substring from the input string using the recorded length and position.
|
|
24
|
-
|
|
25
|
-
An important aspect of this algorithm is that it avoids overlapping substrings. This is achieved by checking if the distance between the current positions is greater than the length of the previously found repeated substring.
|
|
26
|
-
|
|
27
|
-
The code also includes a simple example usage, where it applies the function to the string "+-00+-00+-00+-0". This demonstrates how the function can be used and what kind of output it produces.
|
|
28
|
-
|
|
29
|
-
In summary, this code provides a way to find the longest sequence of characters that repeats in a given
|
|
30
|
-
text, which can be useful in various text processing and analysis tasks. It uses a clever approach to
|
|
31
|
-
solve what could otherwise be a computationally expensive problem, making it efficient for longer input
|
|
32
|
-
strings.
|
|
11
|
+
Reference:
|
|
12
|
+
https://www.geeksforgeeks.org/longest-repeating-and-non-overlapping-substring/
|
|
33
13
|
"""
|
|
34
14
|
|
|
35
15
|
# Python 3 program to find the longest repeated
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: csdigit
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4
|
|
4
4
|
Summary: Add a short description here!
|
|
5
5
|
Home-page: https://github.com/pyscaffold/pyscaffold/
|
|
6
6
|
Author: Wai-Shing Luk
|
|
@@ -12,7 +12,6 @@ Classifier: Development Status :: 4 - Beta
|
|
|
12
12
|
Classifier: Programming Language :: Python
|
|
13
13
|
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
14
14
|
License-File: LICENSE.txt
|
|
15
|
-
Requires-Dist: importlib-metadata; python_version < "3.9"
|
|
16
15
|
Provides-Extra: testing
|
|
17
16
|
Requires-Dist: setuptools; extra == "testing"
|
|
18
17
|
Requires-Dist: pytest; extra == "testing"
|
|
@@ -7,7 +7,6 @@ AUTHORS.md
|
|
|
7
7
|
CHANGELOG.md
|
|
8
8
|
CONTRIBUTING.md
|
|
9
9
|
GEMINI.md
|
|
10
|
-
IFLOW.md
|
|
11
10
|
LICENSE.txt
|
|
12
11
|
README.md
|
|
13
12
|
_config.yml
|
|
@@ -26,31 +25,22 @@ tox.ini
|
|
|
26
25
|
.github/workflows/python-package.yml
|
|
27
26
|
.github/workflows/python-publish.yml
|
|
28
27
|
.vscode/settings.json
|
|
28
|
+
benches/bench_csd.py
|
|
29
29
|
benches/test_bench.py
|
|
30
|
-
|
|
31
|
-
cpp_ai/CMakeLists.txt
|
|
32
|
-
cpp_ai/LICENSE
|
|
33
|
-
cpp_ai/README.md
|
|
34
|
-
cpp_ai/test_compile.cpp
|
|
35
|
-
cpp_ai/xmake.lua
|
|
36
|
-
cpp_ai/examples/basic_usage.cpp
|
|
37
|
-
cpp_ai/examples/cli_usage.cpp
|
|
38
|
-
cpp_ai/include/csdigit/csdigit.hpp
|
|
39
|
-
cpp_ai/src/cli/main.cpp
|
|
40
|
-
cpp_ai/src/csdigit/csd.cpp
|
|
41
|
-
cpp_ai/src/csdigit/csd_multiplier.cpp
|
|
42
|
-
cpp_ai/src/csdigit/lcsre.cpp
|
|
43
|
-
cpp_ai/tests/test_csdigit.cpp
|
|
30
|
+
benches/verify_output.py
|
|
44
31
|
docs/Makefile
|
|
45
32
|
docs/authors.md
|
|
46
33
|
docs/changelog.md
|
|
47
34
|
docs/conf.py
|
|
48
35
|
docs/contributing.md
|
|
36
|
+
docs/figures_demo.md
|
|
49
37
|
docs/index.md
|
|
50
38
|
docs/license.md
|
|
51
39
|
docs/readme.md
|
|
52
40
|
docs/requirements.txt
|
|
53
41
|
docs/_static/.gitignore
|
|
42
|
+
docs/examples/plot_csd_conversion.py
|
|
43
|
+
docs/examples/plot_csd_distribution.py
|
|
54
44
|
experiments/notes.md
|
|
55
45
|
experiments/random_gen.py
|
|
56
46
|
requirements/README.md
|
|
@@ -58,14 +48,6 @@ requirements/default.txt
|
|
|
58
48
|
requirements/doc.txt
|
|
59
49
|
requirements/extras.txt
|
|
60
50
|
requirements/test.txt
|
|
61
|
-
rust_ai/.gitignore
|
|
62
|
-
rust_ai/Cargo.toml
|
|
63
|
-
rust_ai/LICENSE
|
|
64
|
-
rust_ai/README.md
|
|
65
|
-
rust_ai/examples/basic_usage.rs
|
|
66
|
-
rust_ai/examples/cli_usage.rs
|
|
67
|
-
rust_ai/src/lib.rs
|
|
68
|
-
rust_ai/src/bin/main.rs
|
|
69
51
|
src/csdigit/__init__.py
|
|
70
52
|
src/csdigit/cli.py
|
|
71
53
|
src/csdigit/csd.py
|
|
@@ -77,6 +59,8 @@ src/csdigit.egg-info/SOURCES.txt
|
|
|
77
59
|
src/csdigit.egg-info/dependency_links.txt
|
|
78
60
|
src/csdigit.egg-info/not-zip-safe
|
|
79
61
|
src/csdigit.egg-info/requires.txt
|
|
62
|
+
src/csdigit.egg-info/scm_file_list.json
|
|
63
|
+
src/csdigit.egg-info/scm_version.json
|
|
80
64
|
src/csdigit.egg-info/top_level.txt
|
|
81
65
|
src/pycsd/README
|
|
82
66
|
src/pycsd/__init__.py
|