WenjieDu/PyPOTS

View on GitHub
pypots/nn/modules/reformer/lsh_attention.py

Summary

Maintainability
D
2 days
Test Coverage

File lsh_attention.py has 510 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""
Locality-Sensitive Hashing (LSH) Attention from https://github.com/lucidrains/reformer-pytorch
"""

# Created by Wenjie Du <wenjay.du@gmail.com>
Severity: Major
Found in pypots/nn/modules/reformer/lsh_attention.py - About 1 day to fix

    Function __init__ has 19 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def __init__(
    Severity: Major
    Found in pypots/nn/modules/reformer/lsh_attention.py - About 2 hrs to fix

      Function forward has 52 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def forward(
              self,
              qk,
              v,
              query_len=None,
      Severity: Major
      Found in pypots/nn/modules/reformer/lsh_attention.py - About 2 hrs to fix

        Function forward has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

            def forward(
                self,
                qk,
                v,
                query_len=None,
        Severity: Minor
        Found in pypots/nn/modules/reformer/lsh_attention.py - About 1 hr to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function cache_method_decorator has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

        def cache_method_decorator(cache_attr, cache_namespace, reexecute=False):
            def inner_fn(fn):
                @wraps(fn)
                def wrapper(
                    self, *args, key_namespace=None, fetch=False, set_cache=True, **kwargs
        Severity: Minor
        Found in pypots/nn/modules/reformer/lsh_attention.py - About 1 hr to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function __init__ has 10 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def __init__(
        Severity: Major
        Found in pypots/nn/modules/reformer/lsh_attention.py - About 1 hr to fix

          Function forward has 7 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def forward(
          Severity: Major
          Found in pypots/nn/modules/reformer/lsh_attention.py - About 50 mins to fix

            Function forward has 7 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                def forward(
            Severity: Major
            Found in pypots/nn/modules/reformer/lsh_attention.py - About 50 mins to fix

              Function wrapper has 6 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                      def wrapper(
              Severity: Minor
              Found in pypots/nn/modules/reformer/lsh_attention.py - About 45 mins to fix

                Function forward has 6 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                    def forward(
                Severity: Minor
                Found in pypots/nn/modules/reformer/lsh_attention.py - About 45 mins to fix

                  There are no issues that match your filters.

                  Category
                  Status