Skip to content

Commit

Permalink
Merge pull request #50 from perlinm/fix-stubs
Browse files Browse the repository at this point in the history
Fix stub file generation bug
  • Loading branch information
quantumgizmos authored Nov 29, 2024
2 parents 9bdb670 + 9ca7458 commit 95059f6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
29 changes: 14 additions & 15 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,27 @@ def generate_cython_stub_file(pyx_filepath: str, output_filepath: str) -> None:
# identify top-level import lines
pattern = re.compile(r"^(import|from)\s+.*\n", re.MULTILINE)
for match in pattern.finditer(pyx_content):
pyi_content += pyx_content[match.start():match.end()]
pyi_content += pyx_content[match.start() : match.end()]

# identify patterns to ignore
ignore_pattern = re.compile(r"__cinit__\(|__del__\(")

# identify class or function declarations
decorator = r"^\s*@.*\n"
declaration = r"^\s*(?:class|def)\s+.*(?:.|\n)\n"
docstring_double = r"\"\"\"(?:.|\n)*?\"\"\""
docstring_single = r"'''(?:.|\n)*?'''"
docstring = rf"\s*(?:{docstring_double}|{docstring_single})\s*\n"
pattern = re.compile(rf"({decorator})?({declaration})({docstring})?", re.MULTILINE)
decorator = r"^\s*@.*?\n"
declaration = r"^\s*(?:class|def)\s+.*?:\s*\n"
docstring_double = r"\"\"\".*?\"\"\""
docstring_single = r"'''.*?'''"
docstring = rf"\s*?(?:{docstring_double}|{docstring_single})\s*?\n"
pattern = re.compile(rf"({decorator})?({declaration})({docstring})?", re.DOTALL | re.MULTILINE)
for match in pattern.finditer(pyx_content):
content = pyx_content[match.start():match.end()]
content = pyx_content[match.start() : match.end()]
if not ignore_pattern.match(content, re.MULTILINE):
pyi_content += content.rstrip()
if match.group(3):
# there is a docstring!
pyi_content += "\n"
else:
# there is no docstring
pyi_content += " ...\n"
pyi_content += content.rstrip() # strip trailing whitespace

# If there is a docstring, we only need to add a newline character. Otherwise, we also
# need to add ellipses as a placeholder for the class/method "body".
suffix = "\n" if match.group(3) else " ...\n"
pyi_content += suffix

open(output_filepath, "w").write(pyi_content)

Expand Down
6 changes: 5 additions & 1 deletion src_python/ldpc/bp_decoder/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,11 @@ class BpDecoder(BpDecoderBase):
Note, it is only necessary to specify this value when the parity check matrix is square. When the
parity matrix is non-square the input vector type is inferred automatically from its length.
"""
def __init__(self, pcm: Union[np.ndarray, scipy.sparse.spmatrix], error_rate: Optional[float] = None, ...
def __init__(self, pcm: Union[np.ndarray, scipy.sparse.spmatrix], error_rate: Optional[float] = None,
error_channel: Optional[Union[np.ndarray,List[float]]] = None, max_iter: Optional[int] = 0, bp_method: Optional[str] = 'minimum_sum',
ms_scaling_factor: Optional[float] = 1.0, schedule: Optional[str] = 'parallel', omp_thread_count: Optional[int] = 1,
random_schedule_seed: Optional[int] = 0, serial_schedule_order: Optional[List[int]] = None,
input_vector_type: str = "auto", **kwargs): ...
def decode(self, input_vector: np.ndarray) -> np.ndarray:
"""
Decode the input input_vector using belief propagation decoding algorithm.
Expand Down

0 comments on commit 95059f6

Please sign in to comment.