csdigit 0.2__tar.gz → 0.3__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 (100) hide show
  1. {csdigit-0.2 → csdigit-0.3}/.github/workflows/ci.yml +1 -1
  2. {csdigit-0.2 → csdigit-0.3}/.github/workflows/python-app.yml +2 -2
  3. {csdigit-0.2 → csdigit-0.3}/.github/workflows/python-package.yml +2 -2
  4. {csdigit-0.2 → csdigit-0.3}/.pre-commit-config.yaml +1 -1
  5. {csdigit-0.2 → csdigit-0.3}/CONTRIBUTING.md +20 -18
  6. {csdigit-0.2/src/csdigit.egg-info → csdigit-0.3}/PKG-INFO +1 -1
  7. {csdigit-0.2 → csdigit-0.3}/src/csdigit/cli.py +12 -13
  8. {csdigit-0.2 → csdigit-0.3}/src/csdigit/csd.py +13 -35
  9. {csdigit-0.2 → csdigit-0.3}/src/csdigit/csd_multiplier.py +1 -1
  10. {csdigit-0.2 → csdigit-0.3}/src/csdigit/lcsre.py +8 -28
  11. {csdigit-0.2 → csdigit-0.3/src/csdigit.egg-info}/PKG-INFO +1 -1
  12. {csdigit-0.2 → csdigit-0.3}/src/csdigit.egg-info/SOURCES.txt +0 -22
  13. {csdigit-0.2 → csdigit-0.3}/src/pycsd/csd/csd.py +2 -2
  14. {csdigit-0.2 → csdigit-0.3}/src/pycsd/csd_orig.py +2 -2
  15. {csdigit-0.2 → csdigit-0.3}/src/pycsd/dev/csd_numbers.py +4 -4
  16. {csdigit-0.2 → csdigit-0.3}/src/pycsd/test/decimal_tests.py +2 -2
  17. {csdigit-0.2 → csdigit-0.3}/src/pycsd/test/test_csd_decimals.py +2 -2
  18. {csdigit-0.2 → csdigit-0.3}/src/pycsd/test/test_csd_integers.py +1 -1
  19. {csdigit-0.2 → csdigit-0.3}/src/pycsd/test/test_to_and_fro_10bits.py +1 -1
  20. {csdigit-0.2 → csdigit-0.3}/tests/test_csd.py +10 -0
  21. {csdigit-0.2 → csdigit-0.3}/tests/test_csd_multiplier.py +242 -6
  22. csdigit-0.2/cpp_ai/.gitignore +0 -152
  23. csdigit-0.2/cpp_ai/CMakeLists.txt +0 -96
  24. csdigit-0.2/cpp_ai/LICENSE +0 -21
  25. csdigit-0.2/cpp_ai/README.md +0 -133
  26. csdigit-0.2/cpp_ai/examples/basic_usage.cpp +0 -62
  27. csdigit-0.2/cpp_ai/examples/cli_usage.cpp +0 -35
  28. csdigit-0.2/cpp_ai/include/csdigit/csdigit.hpp +0 -108
  29. csdigit-0.2/cpp_ai/src/cli/main.cpp +0 -121
  30. csdigit-0.2/cpp_ai/src/csdigit/csd.cpp +0 -233
  31. csdigit-0.2/cpp_ai/src/csdigit/csd_multiplier.cpp +0 -78
  32. csdigit-0.2/cpp_ai/src/csdigit/lcsre.cpp +0 -40
  33. csdigit-0.2/cpp_ai/test_compile.cpp +0 -16
  34. csdigit-0.2/cpp_ai/tests/test_csdigit.cpp +0 -94
  35. csdigit-0.2/cpp_ai/xmake.lua +0 -57
  36. csdigit-0.2/rust_ai/.gitignore +0 -88
  37. csdigit-0.2/rust_ai/Cargo.toml +0 -28
  38. csdigit-0.2/rust_ai/LICENSE +0 -21
  39. csdigit-0.2/rust_ai/README.md +0 -133
  40. csdigit-0.2/rust_ai/examples/basic_usage.rs +0 -58
  41. csdigit-0.2/rust_ai/examples/cli_usage.rs +0 -36
  42. csdigit-0.2/rust_ai/src/bin/main.rs +0 -82
  43. csdigit-0.2/rust_ai/src/lib.rs +0 -478
  44. {csdigit-0.2 → csdigit-0.3}/.coveragerc +0 -0
  45. {csdigit-0.2 → csdigit-0.3}/.github/workflows/codecov.yml +0 -0
  46. {csdigit-0.2 → csdigit-0.3}/.github/workflows/jekyll-gh-pages.yml +0 -0
  47. {csdigit-0.2 → csdigit-0.3}/.github/workflows/multi-platforms.yml +0 -0
  48. {csdigit-0.2 → csdigit-0.3}/.github/workflows/python-publish.yml +0 -0
  49. {csdigit-0.2 → csdigit-0.3}/.gitignore +0 -0
  50. {csdigit-0.2 → csdigit-0.3}/.isort.cfg +0 -0
  51. {csdigit-0.2 → csdigit-0.3}/.readthedocs.yml +0 -0
  52. {csdigit-0.2 → csdigit-0.3}/.vscode/settings.json +0 -0
  53. {csdigit-0.2 → csdigit-0.3}/AUTHORS.md +0 -0
  54. {csdigit-0.2 → csdigit-0.3}/CHANGELOG.md +0 -0
  55. {csdigit-0.2 → csdigit-0.3}/GEMINI.md +0 -0
  56. {csdigit-0.2 → csdigit-0.3}/IFLOW.md +0 -0
  57. {csdigit-0.2 → csdigit-0.3}/LICENSE.txt +0 -0
  58. {csdigit-0.2 → csdigit-0.3}/README.md +0 -0
  59. {csdigit-0.2 → csdigit-0.3}/_config.yml +0 -0
  60. {csdigit-0.2 → csdigit-0.3}/benches/test_bench.py +0 -0
  61. {csdigit-0.2 → csdigit-0.3}/docs/Makefile +0 -0
  62. {csdigit-0.2 → csdigit-0.3}/docs/_static/.gitignore +0 -0
  63. {csdigit-0.2 → csdigit-0.3}/docs/authors.md +0 -0
  64. {csdigit-0.2 → csdigit-0.3}/docs/changelog.md +0 -0
  65. {csdigit-0.2 → csdigit-0.3}/docs/conf.py +0 -0
  66. {csdigit-0.2 → csdigit-0.3}/docs/contributing.md +0 -0
  67. {csdigit-0.2 → csdigit-0.3}/docs/index.md +0 -0
  68. {csdigit-0.2 → csdigit-0.3}/docs/license.md +0 -0
  69. {csdigit-0.2 → csdigit-0.3}/docs/readme.md +0 -0
  70. {csdigit-0.2 → csdigit-0.3}/docs/requirements.txt +0 -0
  71. {csdigit-0.2 → csdigit-0.3}/environment.yml +0 -0
  72. {csdigit-0.2 → csdigit-0.3}/experiments/notes.md +0 -0
  73. {csdigit-0.2 → csdigit-0.3}/experiments/random_gen.py +0 -0
  74. {csdigit-0.2 → csdigit-0.3}/mypy.ini +0 -0
  75. {csdigit-0.2 → csdigit-0.3}/pyproject.toml +0 -0
  76. {csdigit-0.2 → csdigit-0.3}/requirements/README.md +0 -0
  77. {csdigit-0.2 → csdigit-0.3}/requirements/default.txt +0 -0
  78. {csdigit-0.2 → csdigit-0.3}/requirements/doc.txt +0 -0
  79. {csdigit-0.2 → csdigit-0.3}/requirements/extras.txt +0 -0
  80. {csdigit-0.2 → csdigit-0.3}/requirements/test.txt +0 -0
  81. {csdigit-0.2 → csdigit-0.3}/requirements.txt +0 -0
  82. {csdigit-0.2 → csdigit-0.3}/setup.cfg +0 -0
  83. {csdigit-0.2 → csdigit-0.3}/setup.py +0 -0
  84. {csdigit-0.2 → csdigit-0.3}/src/csdigit/__init__.py +0 -0
  85. {csdigit-0.2 → csdigit-0.3}/src/csdigit/py.typed +0 -0
  86. {csdigit-0.2 → csdigit-0.3}/src/csdigit.egg-info/dependency_links.txt +0 -0
  87. {csdigit-0.2 → csdigit-0.3}/src/csdigit.egg-info/not-zip-safe +0 -0
  88. {csdigit-0.2 → csdigit-0.3}/src/csdigit.egg-info/requires.txt +0 -0
  89. {csdigit-0.2 → csdigit-0.3}/src/csdigit.egg-info/top_level.txt +0 -0
  90. {csdigit-0.2 → csdigit-0.3}/src/pycsd/README +0 -0
  91. {csdigit-0.2 → csdigit-0.3}/src/pycsd/__init__.py +0 -0
  92. {csdigit-0.2 → csdigit-0.3}/src/pycsd/csd/__init__.py +0 -0
  93. {csdigit-0.2 → csdigit-0.3}/src/pycsd/from_csd +0 -0
  94. {csdigit-0.2 → csdigit-0.3}/src/pycsd/run_tests.py +0 -0
  95. {csdigit-0.2 → csdigit-0.3}/src/pycsd/test/__init__.py +0 -0
  96. {csdigit-0.2 → csdigit-0.3}/src/pycsd/to_csd +0 -0
  97. {csdigit-0.2 → csdigit-0.3}/tests/conftest.py +0 -0
  98. {csdigit-0.2 → csdigit-0.3}/tests/test_cli.py +0 -0
  99. {csdigit-0.2 → csdigit-0.3}/tests/test_lcsre.py +0 -0
  100. {csdigit-0.2 → csdigit-0.3}/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
@@ -5,9 +5,9 @@ name: Generate code coverage
5
5
 
6
6
  on:
7
7
  push:
8
- branches: [main]
8
+ branches: [ main, dev ]
9
9
  pull_request:
10
- branches: [main]
10
+ branches: [ main, dev ]
11
11
 
12
12
  jobs:
13
13
  build:
@@ -5,9 +5,9 @@ name: Python package
5
5
 
6
6
  on:
7
7
  push:
8
- branches: [main]
8
+ branches: [ main, dev ]
9
9
  pull_request:
10
- branches: [main]
10
+ branches: [ main, dev ]
11
11
 
12
12
  jobs:
13
13
  build:
@@ -1,4 +1,4 @@
1
- exclude: "^docs/conf.py"
1
+ exclude: "^docs/conf.py|src/pycsd/"
2
2
 
3
3
  repos:
4
4
  - repo: https://github.com/pre-commit/pre-commit-hooks
@@ -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} Don't forget to mention which markup language you are using.
72
+ ```{todo}
73
+ Don't forget to mention which markup language you are using.
73
74
 
74
- e.g., [reStructuredText] or [CommonMark] with [MyST] extensions.
75
+ e.g., [reStructuredText] or [CommonMark] with [MyST] extensions.
75
76
  ```
76
77
 
77
- ```{todo} If your project is hosted on GitHub, you can also mention the following tip:
78
-
79
- :::{tip}
80
- Please notice that the [GitHub web interface] provides a quick way of
81
- propose changes in `csdigit`'s files. While this mechanism can
82
- be tricky for normal code contributions, it works perfectly fine for
83
- contributing to the docs, and can be quite handy.
84
-
85
- If you are interested in trying this method out, please navigate to
86
- the `docs` folder in the source [repository], find which file you
87
- would like to propose changes and click in the little pencil icon at the
88
- top, to open [GitHub's code editor]. Once you finish editing the file,
89
- please write a message in the form at the bottom of the page describing
90
- which changes have you made and what are the motivations behind them and
91
- submit your proposal.
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.2
3
+ Version: 0.3
4
4
  Summary: Add a short description here!
5
5
  Home-page: https://github.com/pyscaffold/pyscaffold/
6
6
  Author: Wai-Shing Luk
@@ -1,20 +1,19 @@
1
1
  """
2
- This is a to_csd file that can serve as a starting point for a Python
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
- console_scripts =
7
- to_csd = csdigit.to_csd:run
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
- Then run ``pip install .`` (or ``pip install -e .`` for editable mode)
10
- which will install the command ``to_csd`` inside your current environment.
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
- Besides console scripts, the header (i.e. until ``_logger``...) of this file can
13
- also be used as template for Python modules.
14
-
15
- References:
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,17 @@
1
1
  """
2
- Canonical Signed Digit (CSD) Conversion
3
-
4
- This code is all about converting numbers between decimal format and a special representation called
5
- Canonical Signed Digit (CSD). CSD is a way of writing numbers using only three symbols: 0, +, and -.
6
- It's particularly useful in certain areas of computer science and digital signal processing.
7
-
8
- The main purpose of this code is to provide functions that can convert decimal numbers to CSD format and
9
- vice versa. It takes in regular decimal numbers (like 28.5 or -0.5) and converts them to CSD strings
10
- (like "+00-00.+" or "0.-"), and it can also do the reverse, taking CSD strings and converting them back
11
- to decimal numbers.
12
-
13
- The code contains several functions, each with a specific role:
14
-
15
- 1. to_csd: This function takes a decimal number and the number of decimal places desired, and outputs a CSD string. For example, it can convert 28.5 to "+00-00.+0" (with 2 decimal places).
16
-
17
- 2. to_csd_i: Similar to to_csd, but it works specifically with integers. It converts whole numbers to CSD format without a decimal point.
18
-
19
- 3. to_decimal_using_pow and to_decimal: These functions do the opposite of to_csd. They take a CSD string and convert it back to a decimal number.
20
-
21
- 4. to_csdnnz: This function is a variation of to_csd that allows you to specify the maximum number of non-zero digits in the result.
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
+ Functions:
9
+ to_csd: Convert a decimal float to CSD string with specified precision.
10
+ to_csd_i: Convert an integer to CSD string.
11
+ to_decimal: Convert a CSD string to a decimal number.
12
+ to_decimal_using_pow: Convert a CSD string to decimal using pow() (deprecated).
13
+ to_csdnnz: Convert a decimal float to CSD with limited non-zero digits.
14
+ to_csdnnz_i: Convert an integer to CSD with limited non-zero digits.
37
15
  """
38
16
 
39
17
  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 Finder
2
+ Longest Repeated Non-Overlapping Substring (LCSRe) finder.
3
3
 
4
- This code defines a function called longest_repeated_substring that finds the longest repeated
5
- non-overlapping substring within a given string. The purpose of this code is to identify and return the
6
- longest sequence of characters that appears more than once in the input string, without the repetitions
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
- The function takes a single input: a string called cs, which represents the text in which we want to
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
- find the repeated substring. The output of the function is another string, which is the longest repeated
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.2
3
+ Version: 0.3
4
4
  Summary: Add a short description here!
5
5
  Home-page: https://github.com/pyscaffold/pyscaffold/
6
6
  Author: Wai-Shing Luk
@@ -27,20 +27,6 @@ tox.ini
27
27
  .github/workflows/python-publish.yml
28
28
  .vscode/settings.json
29
29
  benches/test_bench.py
30
- cpp_ai/.gitignore
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
44
30
  docs/Makefile
45
31
  docs/authors.md
46
32
  docs/changelog.md
@@ -58,14 +44,6 @@ requirements/default.txt
58
44
  requirements/doc.txt
59
45
  requirements/extras.txt
60
46
  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
47
  src/csdigit/__init__.py
70
48
  src/csdigit/cli.py
71
49
  src/csdigit/csd.py
@@ -18,7 +18,7 @@ License: GPL2
18
18
  from math import ceil, fabs, log, pow
19
19
 
20
20
 
21
- def to_csd(number, places=0, debug=False):
21
+ def to_csd(number: float, places: int = 0, debug: bool = False) -> str:
22
22
  """Convert a decimal number to Canonical Signed Digit (CSD) format.
23
23
 
24
24
  The CSD representation uses only three symbols: '+' (represents +1),
@@ -99,7 +99,7 @@ def to_csd(number, places=0, debug=False):
99
99
  return csd_str
100
100
 
101
101
 
102
- def to_decimal(csd_str, debug=False):
102
+ def to_decimal(csd_str: str, debug: bool = False) -> float:
103
103
  """Convert a Canonical Signed Digit (CSD) string to a decimal number.
104
104
 
105
105
  Parses the CSD string and computes its decimal value by evaluating
@@ -18,7 +18,7 @@ License: GPL2
18
18
  from math import ceil, fabs, log, pow
19
19
 
20
20
 
21
- def to_csd(number, places=0):
21
+ def to_csd(number: float, places: int = 0) -> str:
22
22
  """Convert a decimal number to Canonical Signed Digit (CSD) format.
23
23
 
24
24
  The CSD representation uses only three symbols: '+' (represents +1),
@@ -87,7 +87,7 @@ def to_csd(number, places=0):
87
87
  return csd_str
88
88
 
89
89
 
90
- def to_decimal(csd_str):
90
+ def to_decimal(csd_str: str) -> float:
91
91
  """Convert a Canonical Signed Digit (CSD) string to a decimal number.
92
92
 
93
93
  Parses the CSD string and computes its decimal value by evaluating
@@ -16,7 +16,7 @@ indent_ = 2
16
16
  csd_dict = {}
17
17
 
18
18
 
19
- def is_proper_csd(csd_num):
19
+ def is_proper_csd(csd_num: list[str]) -> bool:
20
20
  """Check we've a valid CSD number
21
21
  Returns false if the array contains consequitive non-zero terms.
22
22
  """
@@ -28,7 +28,7 @@ def is_proper_csd(csd_num):
28
28
  return True
29
29
 
30
30
 
31
- def cycle_bits(index):
31
+ def cycle_bits(index: int) -> None:
32
32
  global indent_
33
33
 
34
34
  indent_ += 2
@@ -47,7 +47,7 @@ def cycle_bits(index):
47
47
  indent_ -= 2
48
48
 
49
49
 
50
- def wiki_table():
50
+ def wiki_table() -> str:
51
51
  """A table of CSD numbers for the wiki."""
52
52
 
53
53
  ordered_keys = csd_dict.keys()
@@ -73,7 +73,7 @@ def wiki_table():
73
73
  return wiki_str
74
74
 
75
75
 
76
- def show_csd():
76
+ def show_csd() -> None:
77
77
  """ """
78
78
 
79
79
  ordered_keys = csd_dict.keys()
@@ -16,7 +16,7 @@ good_values_dict = {32.5: "+0000.+"}
16
16
 
17
17
 
18
18
  class test__integer_conversion(unittest.TestCase):
19
- def testToCSD(self):
19
+ def testToCSD(self) -> None:
20
20
  """Check that integers are converted to CSD properly."""
21
21
 
22
22
  for key in good_values_dict.keys():
@@ -24,7 +24,7 @@ class test__integer_conversion(unittest.TestCase):
24
24
  self.assert_(csd_str == good_values_dict[key])
25
25
 
26
26
 
27
- def suite():
27
+ def suite() -> unittest.TestSuite:
28
28
  suite = unittest.TestSuite()
29
29
  suite.addTest(unittest.makeSuite(IntegerConversion))
30
30
  return suite
@@ -18,7 +18,7 @@ good_values_dict = {
18
18
 
19
19
 
20
20
  class tests__decimals(unittest.TestCase):
21
- def tmp(self):
21
+ def tmp(self) -> None:
22
22
  pass
23
23
 
24
24
  def test__01_to_decimal(self) -> None:
@@ -56,7 +56,7 @@ class tests__decimals(unittest.TestCase):
56
56
  self.assertEquals(csd.to_csd(-0.25, 4), "0.0-00")
57
57
 
58
58
 
59
- def suite():
59
+ def suite() -> unittest.TestSuite:
60
60
  suite = unittest.TestSuite()
61
61
  suite.addTest(unittest.makeSuite(tests__decimals))
62
62
  return suite
@@ -28,7 +28,7 @@ class tests__integers(unittest.TestCase):
28
28
  self.assertEquals(csd_str, good_values_dict[key])
29
29
 
30
30
 
31
- def suite():
31
+ def suite() -> unittest.TestSuite:
32
32
  suite = unittest.TestSuite()
33
33
  suite.addTest(unittest.makeSuite(tests__integers))
34
34
  return suite
@@ -1399,7 +1399,7 @@ class tests__to_and_fro_10bits(unittest.TestCase):
1399
1399
  self.assertEquals(csd_str, good_values_dict[key])
1400
1400
 
1401
1401
 
1402
- def suite():
1402
+ def suite() -> unittest.TestSuite:
1403
1403
  suite = unittest.TestSuite()
1404
1404
  suite.addTest(unittest.makeSuite(tests__to_and_fro_10bits))
1405
1405
  return suite
@@ -242,6 +242,16 @@ def test_csd_addition_property(numbers: list[int]) -> None:
242
242
  assert csd_sum == original_sum
243
243
 
244
244
 
245
+ def test_to_decimal_no_dot_with_invalid_chars(
246
+ caplog: pytest.LogCaptureFixture,
247
+ ) -> None:
248
+ """Test to_decimal with invalid chars when no decimal point (covers line 244)."""
249
+ caplog.set_level(logging.INFO)
250
+ result = to_decimal("+X0-")
251
+ assert result == 7
252
+ assert "Encounter unknown character" in caplog.text
253
+
254
+
245
255
  @given(integers(min_value=-100, max_value=100), integers(min_value=1, max_value=10))
246
256
  def test_csd_power_of_two_property(number: int, power: int) -> None:
247
257
  """Test CSD representation of powers of two."""