Skip to content

Audit code for use of list comprehensions where generators would be faster #450

@rileyjmurray

Description

@rileyjmurray

While reviewing PR #445 I noticed that pyGSTi often uses patterns like tuple([ ... ]), or all([ ... ]), or sum([ ... ]), where [...] is a list comprehension. For most (all?) of these situations it should be sufficient to just drop the brackets. The resulting code would use Python's more efficient generator abstraction rather than list comprehensions.

A quick sort of the pyGSTi codebase shows ...

  • 210 hits for all([
  • 70 hits for any([
  • 161 hits for sum([
  • 38 results for prod([
  • 89 results for tuple([
  • 32 results for set([
  • 76 results for dict([

^ Those counts are slight overestimates since they don't restrict to .py files and they don't consider if an offending line is commented-out.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions