MonoshiTonmoy/Code_Statement_Prediction_Dataset huggingface dataset:
Project Name: google-research+arxiv-latex-cleaner
Language: Python
Statement Type: Arithmetic Assignment

Source Code:
def _remove_command(text, command, keep_text=False):
  """Removes '\\command{*}' from the string 'text'.

  Regex `base_pattern` used to match balanced parentheses taken from:
  https://stackoverflow.com/questions/546433/regular-expression-to-match-balanced-parentheses/35271017#35271017
  """
  base_pattern = r'\\' + command + r'\{((?:[^{}]+|\{(?1)\})*)\}'
  # Loops in case of nested commands that need to retain text, e.g.,
  # \red{hello \red{world}}.
  while True:
    all_substitutions = []
    has_match = False
    for match in regex.finditer(base_pattern, text):
      # In case there are only spaces or nothing up to the following newline,
      # adds a percent, not to alter the newlines.
      has_match = True
      new_substring = (
          ''
          if not keep_text
          else text[match.span()[0] + len(command) + 2 : match.span()[1] - 1]
      )
      if match.span()[1] < len(text):
        next_newline = text[match.span()[1] :].find('\n')
        if next_newline != -1:
          text_until_newline = text[
              match.span()[1] : match.span()[1] + next_newline
          ]
          if (
              not text_until_newline or text_until_newline.isspace()
          ) and not keep_text:
            new_substring = '%'
      all_substitutions.append(
          (match.span()[0], match.span()[1], new_substring)
      )

    for start, end, new_substring in reversed(all_substitutions):
      text = text[:start] + new_substring + text[end:]

    if not keep_text or not has_match:
      break

  return text

_remove_command(text='A\\todo{B\nC}D\nE\n\\end{document}', command='todo', keep_text=False)

Selected Statement: base_pattern = r'\\' + command + r'\{((?:[^{}]+|\{(?1)\})*)\}'

Function Input:
text: 'A\\todo{B\nC}D\nE\n\\end{document}'
command: 'todo'
keep_text: False

Variable Values Before Statement:

Value After Statement Execution: '\\\\todo\\{((?:[^{}]+|\\{(?1)\\})*)\\}'

Variable States During Runtime (line, value):
text: 1
'A\\todo{B\nC}D\nE\n\\end{document}'
37
'AD\nE\n\\end{document}'
command: 1
'todo'
keep_text: 1
False
base_pattern: 7
'\\\\todo\\{((?:[^{}]+|\\{(?1)\\})*)\\}'
all_substitutions: 11
32
[(1, 11, '')]
has_match: 12
False
16
True
match: 13
<regex.Match object; span=(1, 11), match='\\todo{B\nC}'>
new_substring: 17
''
next_newline: 23
1
text_until_newline: 25
'D'
start: 36
1
end: 36
11
Project Name: google-research+arxiv-latex-cleaner
Language: Python
Statement Type: Arithmetic Assignment

Source Code:
def _search_reference(filename, contents, strict=False):
  """Returns a match object if filename is referenced in contents, and None otherwise.

  If not strict mode, path prefix and extension are optional.
  """
  if strict:
    # regex pattern for strict=True for path/to/img.ext:
    # \{[\s%]*path/to/img\.ext[\s%]*\}
    filename_regex = filename.replace('.', r'\.')
  else:
    filename_path = Path(filename)

    # make extension optional
    root, extension = filename_path.stem, filename_path.suffix
    basename_regex = '{}({})?'.format(
        regex.escape(root), regex.escape(extension)
    )

    # iterate through parent fragments to make path prefix optional
    path_prefix_regex = ''
    for fragment in reversed(filename_path.parents):
      if fragment.name == '.':
        continue
      fragment = regex.escape(fragment.name)
      path_prefix_regex = '({}{}{})?'.format(
          path_prefix_regex, fragment, os.sep
      )

    # Regex pattern for strict=True for path/to/img.ext:
    # \{[\s%]*(<path_prefix>)?<basename>(<ext>)?[\s%]*\}
    filename_regex = path_prefix_regex + basename_regex

  # Some files 'path/to/file' are referenced in tex as './path/to/file' thus
  # adds prefix for relative paths starting with './' or '.\' to regex search.
  filename_regex = r'(.' + os.sep + r')?' + filename_regex

  # Pads with braces and optional whitespace/comment characters.
  patn = r'\{{[\s%]*{}[\s%]*\}}'.format(filename_regex)
  # Picture references in LaTeX are allowed to be in different cases.
  return regex.search(patn, contents, regex.IGNORECASE)

_search_reference(filename='to/img.ext', contents='{img.ext}', strict=False)

Selected Statement: filename_regex = path_prefix_regex + basename_regex

Function Input:
filename: 'to/img.ext'
contents: '{img.ext}'
strict: False

Variable Values Before Statement:
path_prefix_regex: '((/)?to/)?'
basename_regex: 'img(\\.ext)?'

Value After Statement Execution: '((/)?to/)?img(\\.ext)?'

Variable States During Runtime (line, value):
filename: 1
'to/img.ext'
contents: 1
'{img.ext}'
strict: 1
False
filename_path: 11
PosixPath('to/img.ext')
root: 14
'img'
extension: 14
'.ext'
basename_regex: 15
'img(\\.ext)?'
path_prefix_regex: 20
''
25
'(/)?'
25
'((/)?to/)?'
fragment: 21
PosixPath('.')
24
''
21
PosixPath('to')
24
'to'
filename_regex: 31
'((/)?to/)?img(\\.ext)?'
35
'(./)?((/)?to/)?img(\\.ext)?'
patn: 38
'\\{[\\s%]*(./)?((/)?to/)?img(\\.ext)?[\\s%]*\\}'
Project Name: Mikubill+sd-webui-controlnet
Language: Python
Statement Type: Arithmetic Assignment

Source Code:
def digit_version(version_str: str, length: int = 4):
    """Convert a version string into a tuple of integers.

    This method is usually used for comparing two versions. For pre-release
    versions: alpha < beta < rc.

    Args:
        version_str (str): The version string.
        length (int): The maximum number of version levels. Default: 4.

    Returns:
        tuple[int]: The version info in digits (integers).
    """
    assert 'parrots' not in version_str
    version = parse(version_str)
    assert version.release, f'failed to parse version {version_str}'
    release = list(version.release)
    release = release[:length]
    if len(release) < length:
        release = release + [0] * (length - len(release))
    if version.is_prerelease:
        mapping = {'a': -3, 'b': -2, 'rc': -1}
        val = -4
        # version.pre can be None
        if version.pre:
            if version.pre[0] not in mapping:
                warnings.warn(f'unknown prerelease version {version.pre[0]}, '
                              'version checking may go wrong')
            else:
                val = mapping[version.pre[0]]
            release.extend([val, version.pre[-1]])
        else:
            release.extend([val, 0])

    elif version.is_postrelease:
        release.extend([1, version.post])
    else:
        release.extend([0, 0])
    return tuple(release)

digit_version(version_str='2.2.2+cu121', length=4)

Selected Statement: release = release + [0] * (length - len(release))

Function Input:
version_str: '2.2.2+cu121'
length: 4

Variable Values Before Statement:
release: [2, 2, 2]

Value After Statement Execution: [2, 2, 2, 0]

Variable States During Runtime (line, value):
version_str: 1
'2.2.2+cu121'
length: 1
4
version: 15
<Version('2.2.2+cu121')>
release: 17
[2, 2, 2]
20
[2, 2, 2, 0]
38
[2, 2, 2, 0, 0, 0]
Project Name: d3rp+clima
Language: Python
Statement Type: Arithmetic Assignment

Source Code:
def SeparateFlagArgs(args: list):
  """Splits a list of args into those for Flags and those for Fire.

  If an isolated '--' arg is not present in the arg list, then all of the args
  are for Fire. If there is an isolated '--', then the args after the final '--'
  are flag args, and the rest of the args are fire args.

  Args:
    args: The list of arguments received by the Fire command.
  Returns:
    A tuple with the Fire args (a list), followed by the Flag args (a list).
  """
  if len(args) > 0 and (args[-1] == '-h' or args[-1] == '--help') and '--' not in args:
    args.pop()
    args.append('--')
    args.append('-h')

  if '--' in args:
    separator_index = len(args) - 1 - args[::-1].index('--')  # index of last --
    flag_args = args[separator_index + 1:]
    args = args[:separator_index]
    return args, flag_args

  return args, []

SeparateFlagArgs(args=['a', 'b', '--'])

Selected Statement: separator_index = len(args) - 1 - args[::-1].index('--')  # index of last --

Function Input:
args: a, b, --

Variable Values Before Statement:

Value After Statement Execution: 2

Variable States During Runtime (line, value):
args: 1
a, b, --
21
a, b
separator_index: 19
2
flag_args: 20
Project Name: d3rp+clima
Language: Python
Statement Type: Arithmetic Assignment

Source Code:
def _ParseFn(args):
    """Parses the list of `args` into (varargs, kwargs), remaining_args."""
    kwargs, remaining_kwargs, remaining_args = _ParseKeywordArgs(
        args, all_args, fn_spec.varkw)

    # Note: _ParseArgs modifies kwargs.
    parsed_args, kwargs, remaining_args, capacity = _ParseArgs(
        fn_spec.args, fn_spec.defaults, num_required_args, kwargs,
        remaining_args, metadata)

    if fn_spec.varargs or fn_spec.varkw:
      # If we're allowed *varargs or **kwargs, there's always capacity.
      capacity = True

    extra_kw = set(kwargs) - set(fn_spec.kwonlyargs)
    if fn_spec.varkw is None and extra_kw:
      raise FireError('Unexpected kwargs present:', extra_kw)

    missing_kwonly = set(required_kwonly) - set(kwargs)
    if missing_kwonly:
      raise FireError('Missing required flags:', missing_kwonly)

    # If we accept *varargs, then use all remaining arguments for *varargs.
    if fn_spec.varargs is not None:
      varargs, remaining_args = remaining_args, []
    else:
      varargs = []

    for index, value in enumerate(varargs):
      varargs[index] = _ParseValue(value, None, None, metadata)

    varargs = parsed_args + varargs
    remaining_args += remaining_kwargs

    consumed_args = args[:len(args) - len(remaining_args)]
    return (varargs, kwargs), consumed_args, remaining_args, capacity

_ParseFn(args=['x'], all_args=[], fn_spec={args=[], varargs=None, varkw='cli_args', defaults=(), kwonlyargs=[], kwonlydefaults={}, annotations={}}, metadata={'ACCEPTS_POSITIONAL_ARGS': False}, num_required_args=0, required_kwonly=set())

Selected Statement: extra_kw = set(kwargs) - set(fn_spec.kwonlyargs)

Function Input:
args: x
fn_spec: {args=[], varargs=None, varkw='cli_args', defaults=(), kwonlyargs=[], kwonlydefaults={}, annotations={}}
metadata: ACCEPTS_POSITIONAL_ARGS: no
num_required_args: 0
required_kwonly: set()

Variable Values Before Statement:

Value After Statement Execution: set()

Variable States During Runtime (line, value):
args: 1
x
all_args: 1
fn_spec: 1
{args=[], varargs=None, varkw='cli_args', defaults=(), kwonlyargs=[], kwonlydefaults={}, annotations={}}
metadata: 1
ACCEPTS_POSITIONAL_ARGS: no
num_required_args: 1
0
required_kwonly: 1
set()
kwargs: 3
remaining_kwargs: 3
remaining_args: 3
x
parsed_args: 7
capacity: 7
False
13
True
extra_kw: 15
set()
missing_kwonly: 19
set()
varargs: 27
consumed_args: 35
Project Name: paul-gauthier+aider
Language: Python
Statement Type: Arithmetic Assignment

Source Code:
def find_original_update_blocks(content, fence=DEFAULT_FENCE):
    # make sure we end with a newline, otherwise the regex will miss <<UPD on the last line
    if not content.endswith("\n"):
        content = content + "\n"

    pieces = re.split(split_re, content)

    pieces.reverse()
    processed = []

    # Keep using the same filename in cases where GPT produces an edit block
    # without a filename.
    current_filename = None
    try:
        while pieces:
            cur = pieces.pop()

            if cur in (DIVIDER, UPDATED):
                processed.append(cur)
                raise ValueError(f"Unexpected {cur}")

            if cur.strip() != HEAD:
                processed.append(cur)
                continue

            processed.append(cur)  # original_marker

            filename = strip_filename(processed[-2].splitlines()[-1], fence)
            try:
                if not filename:
                    filename = strip_filename(processed[-2].splitlines()[-2], fence)
                if not filename:
                    if current_filename:
                        filename = current_filename
                    else:
                        raise ValueError(missing_filename_err)
            except IndexError:
                if current_filename:
                    filename = current_filename
                else:
                    raise ValueError(missing_filename_err)

            current_filename = filename

            original_text = pieces.pop()
            processed.append(original_text)

            divider_marker = pieces.pop()
            processed.append(divider_marker)
            if divider_marker.strip() != DIVIDER:
                raise ValueError(f"Expected `{DIVIDER}` not {divider_marker.strip()}")

            updated_text = pieces.pop()
            processed.append(updated_text)

            updated_marker = pieces.pop()
            processed.append(updated_marker)
            if updated_marker.strip() != UPDATED:
                raise ValueError(f"Expected `{UPDATED}` not `{updated_marker.strip()}")

            yield filename, original_text, updated_text
    except ValueError as e:
        processed = "".join(processed)
        err = e.args[0]
        raise ValueError(f"{processed}\n^^^ {err}")
    except IndexError:
        processed = "".join(processed)
        raise ValueError(f"{processed}\n^^^ Incomplete SEARCH/REPLACE block.")
    except Exception:
        processed = "".join(processed)
        raise ValueError(f"{processed}\n^^^ Error parsing SEARCH/REPLACE block.")

find_original_update_blocks(content='ok', fence=('<source>', '</source>'))

Selected Statement: content = content + "\n"

Function Input:
content: 'ok'
fence: ('<source>', '</source>')

Variable Values Before Statement:
content: 'ok'

Value After Statement Execution: 'ok\n'

Variable States During Runtime (line, value):
content: 1
'ok'
4
'ok\n'
fence: 1
('<source>', '</source>')
pieces: 6
ok

16
processed: 9
23
ok

current_filename: 13
None
cur: 16
'ok\n'
Project Name: paul-gauthier+aider
Language: Python
Statement Type: Arithmetic Assignment

Source Code:
def perfect_replace(whole_lines, part_lines, replace_lines):
    part_tup = tuple(part_lines)
    part_len = len(part_lines)

    for i in range(len(whole_lines) - part_len + 1):
        whole_tup = tuple(whole_lines[i : i + part_len])
        if part_tup == whole_tup:
            res = whole_lines[:i] + replace_lines + whole_lines[i + part_len :]
            return "".join(res)

perfect_replace(whole_lines=['two\n'], part_lines=['two\n'], replace_lines=['three\n'])

Selected Statement: res = whole_lines[:i] + replace_lines + whole_lines[i + part_len :]

Function Input:
whole_lines: two

part_lines: two

replace_lines: three


Variable Values Before Statement:

Value After Statement Execution: three


Variable States During Runtime (line, value):
whole_lines: 1
two

part_lines: 1
two

replace_lines: 1
three

part_tup: 2
('two\n',)
part_len: 3
1
i: 5
0
whole_tup: 6
('two\n',)
res: 8
three
Project Name: paul-gauthier+aider
Language: Python
Statement Type: Arithmetic Assignment

Source Code:
def replace_part_with_missing_leading_whitespace(whole_lines, part_lines, replace_lines):
    # GPT often messes up leading whitespace.
    # It usually does it uniformly across the ORIG and UPD blocks.
    # Either omitting all leading whitespace, or including only some of it.

    # Outdent everything in part_lines and replace_lines by the max fixed amount possible
    leading = [len(p) - len(p.lstrip()) for p in part_lines if p.strip()] + [
        len(p) - len(p.lstrip()) for p in replace_lines if p.strip()
    ]

    if leading and min(leading):
        num_leading = min(leading)
        part_lines = [p[num_leading:] if p.strip() else p for p in part_lines]
        replace_lines = [p[num_leading:] if p.strip() else p for p in replace_lines]

    # can we find an exact match not including the leading whitespace
    num_part_lines = len(part_lines)

    for i in range(len(whole_lines) - num_part_lines + 1):
        add_leading = match_but_for_leading_whitespace(
            whole_lines[i : i + num_part_lines], part_lines
        )

        if add_leading is None:
            continue

        replace_lines = [add_leading + rline if rline.strip() else rline for rline in replace_lines]
        whole_lines = whole_lines[:i] + replace_lines + whole_lines[i + num_part_lines :]
        return "".join(whole_lines)

    return None

replace_part_with_missing_leading_whitespace(whole_lines=['    line1\n', '    line2\n', '    line3\n'], part_lines=[' line1\n', ' line2\n'], replace_lines=[' new_line1\n', '     new_line2\n'])

Selected Statement: leading = [len(p) - len(p.lstrip()) for p in part_lines if p.strip()] + [

Function Input:
whole_lines:     line1

    line2

    line3

part_lines:  line1

 line2

replace_lines:  new_line1

     new_line2


Variable Values Before Statement:

Value After Statement Execution: [1, 1, 1, 5]

Variable States During Runtime (line, value):
whole_lines: 1
    line1

    line2

    line3

28
    new_line1

        new_line2

    line3

part_lines: 1
 line1

 line2

13
line1

line2

replace_lines: 1
 new_line1

     new_line2

14
new_line1

    new_line2

27
    new_line1

        new_line2

leading: 7
[1, 1, 1, 5]
num_leading: 12
1
num_part_lines: 17
2
i: 19
0
add_leading: 20
'    '
Project Name: paul-gauthier+aider
Language: Python
Statement Type: Arithmetic Assignment

Source Code:
def check_gitignore(git_root, io, ask=True):
    if not git_root:
        return

    try:
        repo = git.Repo(git_root)
        if repo.ignored(".aider"):
            return
    except git.exc.InvalidGitRepositoryError:
        pass

    pat = ".aider*"

    gitignore_file = Path(git_root) / ".gitignore"
    if gitignore_file.exists():
        content = io.read_text(gitignore_file)
        if content is None:
            return
        if pat in content.splitlines():
            return
    else:
        content = ""

    if ask and not io.confirm_ask(f"Add {pat} to .gitignore (recommended)?"):
        return

    if content and not content.endswith("\n"):
        content += "\n"
    content += pat + "\n"
    io.write_text(gitignore_file, content)

    io.tool_output(f"Added {pat} to .gitignore")

check_gitignore(git_root=PosixPath('/tmp/tmpcr1f5en7'), io={user_input_color=None, tool_output_color=None, tool_error_color=None, input=None, output=None, pretty=False, yes=True, input_history_file=None, chat_history_file=None, encoding='utf-8', dry_run=False, console=<console width=105 None>}, ask=True)

Selected Statement: gitignore_file = Path(git_root) / ".gitignore"

Function Input:
git_root: PosixPath('/tmp/tmpcr1f5en7')
io: {user_input_color=None, tool_output_color=None, tool_error_color=None, input=None, output=None, pretty=False, yes=True, input_history_file=None, chat_history_file=None, encoding='utf-8', dry_run=False, console=<console width=105 None>}
ask: True

Variable Values Before Statement:

Value After Statement Execution: PosixPath('/tmp/tmpcr1f5en7/.gitignore')

Variable States During Runtime (line, value):
git_root: 1
PosixPath('/tmp/tmpcr1f5en7')
io: 1
{user_input_color=None, tool_output_color=None, tool_error_color=None, input=None, output=None, pretty=False, yes=True, input_history_file=None, chat_history_file=None, encoding='utf-8', dry_run=False, console=<console width=105 None>}
24
{user_input_color=None, tool_output_color=None, tool_error_color=None, input=None, output=None, pretty=False, yes=True, input_history_file=None, chat_history_file=None, encoding='utf-8', dry_run=False, console=<console width=105 None>, num_user_asks=1}
ask: 1
True
repo: 6
<git.repo.base.Repo '/tmp/tmpcr1f5en7/.git'>
pat: 12
'.aider*'
gitignore_file: 14
PosixPath('/tmp/tmpcr1f5en7/.gitignore')
content: 22
''
29
'.aider*\n'
Project Name: GeoStat-Framework+welltestpy
Language: Python
Statement Type: Arithmetic Assignment

Source Code:
def _tranmat(a, b):
    """
    Get the coefficents for the affine-linear function f(x)=Ax+s.

    Which fullfills that A is a rotation-matrix,
    f(a) = [0,0] and f(b) = [|b-a|,0].
    """
    A = np.zeros((2, 2))
    A[0, 0] = b[0] - a[0]
    A[1, 1] = b[0] - a[0]
    A[1, 0] = -(b[1] - a[1])
    A[0, 1] = +(b[1] - a[1])
    A /= _dist(a, b)
    s = -np.dot(A, a)
    return A, s

_tranmat(a=array([0., 0.]), b=array([3., 0.]))

Selected Statement: A[0, 0] = b[0] - a[0]

Function Input:
a: array([0., 0.])
b: array([3., 0.])

Variable Values Before Statement:

Value After Statement Execution: array([[3., 0.],       [0., 0.]])

Variable States During Runtime (line, value):
a: 1
array([0., 0.])
b: 1
array([3., 0.])
A: 8
array([[0., 0.],       [0., 0.]])
9
array([[3., 0.],       [0., 0.]])
10
array([[3., 0.],       [0., 3.]])
11
array([[ 3.,  0.],       [-0.,  3.]])
13
array([[ 1.,  0.],       [-0.,  1.]])
s: 14
array([-0., -0.])
Project Name: GeoStat-Framework+welltestpy
Language: Python
Statement Type: Arithmetic Assignment

Source Code:
def _yvalue(b, a, c):
    """
    Get the two possible y-values for the upper point of a triangle.

    where c is the length of the down side starting in the origin and
    lying on the x-axes, a is the distance of the unknown point to the origen
    and b is the distance of the unknown point to the righter given point
    """
    # ckeck flatness to eliminate numerical errors when the triangle is flat
    if a + b <= c or a + c <= b or b + c <= a:
        return 0.0, -0.0

    res = 2 * ((a * b) ** 2 + (a * c) ** 2 + (b * c) ** 2)
    res -= a ** 4 + b ** 4 + c ** 4
    # in case of numerical errors set res to 0 (hope you check validty before)
    res = max(res, 0.0)
    res = np.sqrt(res)
    res /= 2 * c
    return res, -res

_yvalue(b=4.0, a=2.0, c=3.0)

Selected Statement: res = 2 * ((a * b) ** 2 + (a * c) ** 2 + (b * c) ** 2)

Function Input:
b: 4.0
a: 2.0
c: 3.0

Variable Values Before Statement:

Value After Statement Execution: 488.0

Variable States During Runtime (line, value):
b: 1
4.0
a: 1
2.0
c: 1
3.0
res: 13
488.0
14
135.0
17
11.61895003862225
18
1.9364916731037083
Project Name: OxfordHED+sunbear
Language: Python
Statement Type: Arithmetic Assignment

Source Code:
def get_idx(ndim, axis=None, axis_idx=None):
    s = [midx] * ndim
    if axis is not None:
        if hasattr(axis, "__iter__"):
            for ax, axidx in zip(axis, axis_idx):
                s[ax] = axidx
        else:
            s[axis] = axis_idx
    return tuple(s)

get_idx(ndim=1, axis=0, axis_idx=slice(None, -2, None))

Selected Statement: s = [midx] * ndim

Function Input:
ndim: 1
axis: 0
axis_idx: slice(None, -2, None)

Variable Values Before Statement:
ndim: 1

Value After Statement Execution: [slice(1, -1, None)]

Variable States During Runtime (line, value):
ndim: 1
1
axis: 1
0
axis_idx: 1
slice(None, -2, None)
s: 2
[slice(1, -1, None)]
8
[slice(None, -2, None)]