HazyResearch/numbskull

View on GitHub

Showing 497 of 497 total issues

Function eval_factor has a Cognitive Complexity of 224 (exceeds 5 allowed). Consider refactoring.
Open

def eval_factor(factor_id, var_samp, value, var_copy, variable, factor, fmap,
                var_value):
    """TODO."""
    ####################
    # BINARY VARIABLES #
Severity: Minor
Found in numbskull/inference.py - About 4 days 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

Similar blocks of code found in 2 locations. Consider refactoring.
Open

    elif factor[factor_id]["factorFunction"] == FUNC_DP_GEN_DEP_FIXING:
        # NB: this doesn't make sense for categoricals
        y_index = value if fmap[ftv_start]["vid"] == var_samp else \
            var_value[var_copy][fmap[ftv_start]["vid"]]
        l1_index = value if fmap[ftv_start + 1]["vid"] == var_samp else \
Severity: Major
Found in numbskull/inference.py and 1 other location - About 3 days to fix
numbskull/inference.py on lines 364..380

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 318.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

    elif factor[factor_id]["factorFunction"] == FUNC_DP_GEN_DEP_REINFORCING:
        # NB: this doesn't make sense for categoricals
        y_index = value if fmap[ftv_start]["vid"] == var_samp else \
            var_value[var_copy][fmap[ftv_start]["vid"]]
        l1_index = value if fmap[ftv_start + 1]["vid"] == var_samp else \
Severity: Major
Found in numbskull/inference.py and 1 other location - About 3 days to fix
numbskull/inference.py on lines 347..363

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 318.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Cyclomatic complexity is too high in function eval_factor. (121)
Open

@jit(nopython=True, cache=True, nogil=True)
def eval_factor(factor_id, var_samp, value, var_copy, variable, factor, fmap,
                var_value):
    """TODO."""
    ####################
Severity: Minor
Found in numbskull/inference.py by radon

Cyclomatic Complexity

Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

Construct Effect on CC Reasoning
if +1 An if statement is a single decision.
elif +1 The elif statement adds another decision.
else +0 The else statement does not cause a new decision. The decision is at the if.
for +1 There is a decision at the start of the loop.
while +1 There is a decision at the while statement.
except +1 Each except branch adds a new conditional path of execution.
finally +0 The finally block is unconditionally executed.
with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
assert +1 The assert statement internally roughly equals a conditional statement.
Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

Source: http://radon.readthedocs.org/en/latest/intro.html

File messages.py has 975 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""TODO."""

from __future__ import print_function
import numbskull
from numbskull.numbskulltypes import *
Severity: Major
Found in salt/src/messages.py - About 2 days to fix

    Identical blocks of code found in 2 locations. Consider refactoring.
    Open

                for j in range(factor[i]["arity"]):
                    vid1 = fmap[factor[i]["ftv_offset"] + j]["vid"]
                    local_vid = inverse_map(vid, vid1)
                    ex = (local_vid != -1) and (var_pt[local_vid] != 80 or var_ufo[local_vid])
                    exist += ex
    Severity: Major
    Found in salt/src/messages.py and 1 other location - About 1 day to fix
    salt/src/messages.py on lines 954..966

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 181.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Identical blocks of code found in 2 locations. Consider refactoring.
    Open

                for j in range(factor[i]["arity"]):
                    vid1 = fmap[factor[i]["ftv_offset"] + j]["vid"]
                    local_vid = inverse_map(vid, vid1)
                    ex = (local_vid != -1) and (var_pt[local_vid] != 80 or var_ufo[local_vid])
                    exist += ex
    Severity: Major
    Found in salt/src/messages.py and 1 other location - About 1 day to fix
    salt/src/messages.py on lines 1008..1020

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 181.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

        elif factor[factor_id]["factorFunction"] == FUNC_IMPLY_NATURAL_CAT:
            for l in range(ftv_start, ftv_end - 1):
                v = value if (fmap[l]["vid"] == var_samp) \
                    else var_value[var_copy][fmap[l]["vid"]]
                if v != fmap[l]["dense_equal_to"]:
    Severity: Major
    Found in numbskull/inference.py and 1 other location - About 1 day to fix
    numbskull/inference.py on lines 281..295

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 176.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

        elif factor[factor_id]["factorFunction"] == FUNC_IMPLY_MLN_CAT:
            for l in range(ftv_start, ftv_end - 1):
                v = value if (fmap[l]["vid"] == var_samp) \
                    else var_value[var_copy][fmap[l]["vid"]]
                if v != fmap[l]["dense_equal_to"]:
    Severity: Major
    Found in numbskull/inference.py and 1 other location - About 1 day to fix
    numbskull/inference.py on lines 266..280

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 176.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

    @numba.jit(nopython=True, cache=True, nogil=True)
    def compute_map_minion(vid, var_pt):
        l = 0
        for i in range(len(var_pt)):
            if var_pt[i] == 68:  # 68 = "D"
    Severity: Major
    Found in salt/src/messages.py and 1 other location - About 1 day to fix
    salt/src/messages.py on lines 1253..1267

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 141.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

    @numba.jit(nopython=True, cache=True, nogil=True)
    def compute_map_master(vid, var_pt):
        l = 0
        for i in range(len(var_pt)):
            if var_pt[i] == 66:  # 66 = "B"
    Severity: Major
    Found in salt/src/messages.py and 1 other location - About 1 day to fix
    salt/src/messages.py on lines 1270..1284

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 141.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Function find_ufo has a Cognitive Complexity of 54 (exceeds 5 allowed). Consider refactoring.
    Open

    def find_ufo(factor, factor_pt, factor_ufo, fmap, vid, variable, var_pt,
                 var_ufo, pf_ufo_var_list, pf_var_begin):
        # Count number of factors with UFO
        n_ufo_recv = 0  # Number of ufo to receive
        n_ufo_send = 0  # Number of ufo to send
    Severity: Minor
    Found in salt/src/messages.py - About 1 day 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

    Identical blocks of code found in 2 locations. Consider refactoring.
    Open

        def parse_args(self, argv):
            """TODO."""
            if argv is None:
                argv = sys.argv[1:]
            parser = argparse.ArgumentParser(
    Severity: Major
    Found in salt/src/numbskull_minion.py and 1 other location - About 1 day to fix
    salt/src/numbskull_master.py on lines 484..504

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 126.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Identical blocks of code found in 2 locations. Consider refactoring.
    Open

        def parse_args(self, argv):
            """TODO."""
            if argv is None:
                argv = sys.argv[1:]
            parser = argparse.ArgumentParser(
    Severity: Major
    Found in salt/src/numbskull_master.py and 1 other location - About 1 day to fix
    salt/src/numbskull_minion.py on lines 43..63

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 126.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Function _set_tcp_keepalive has a Cognitive Complexity of 52 (exceeds 5 allowed). Consider refactoring.
    Open

    def _set_tcp_keepalive(sock, opts):
        """Ensure that TCP keepalives are set for the socket."""
        if hasattr(socket, 'SO_KEEPALIVE'):
            if opts.get('tcp_keepalive', False):
                sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
    Severity: Minor
    Found in salt/src/numbskull_minion_server.py - About 1 day 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 compute_ufo_map has a Cognitive Complexity of 49 (exceeds 5 allowed). Consider refactoring.
    Open

    def compute_ufo_map(factor, factor_pt, factor_ufo, fmap, vid, variable, var_pt, var_ufo, ufo_send, pf_ufo_var_list, pf_var_begin):
        ufo_length = np.zeros(ufo_send.size, np.int64)
        ufo_start = np.zeros(ufo_send.size + 1, np.int64)
        ufo = np.zeros(1, dtype=UnaryFactorOpt)
        if len(ufo_send) == 0:
    Severity: Minor
    Found in salt/src/messages.py - About 7 hrs 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

    File numbskull_master.py has 466 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    
    """TODO."""
    
    
    Severity: Minor
    Found in salt/src/numbskull_master.py - About 7 hrs to fix

      File numbskull_minion_server.py has 419 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      """TODO."""
      
      # Import python libs
      from __future__ import absolute_import
      import logging
      Severity: Minor
      Found in salt/src/numbskull_minion_server.py - About 6 hrs to fix

        Function set_pf has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
        Open

        def set_pf(factor, factor_pt, factor_ufo, fmap, fid, vid, variable, var_pt, var_ufo, pf_var_begin, vid_max, ismaster, pf_ufo_var_list):
            # vid_max should just be np.iinfo(vid.dtype).max, but numba doesn't support iinfo   
        
            # Setting fake variables
            for i in range(pf_var_begin, len(vid)):
        Severity: Minor
        Found in salt/src/messages.py - About 5 hrs 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

        Cyclomatic complexity is too high in function compute_ufo_map. (27)
        Open

        @numba.jit(nopython=True, cache=True, nogil=True)
        def compute_ufo_map(factor, factor_pt, factor_ufo, fmap, vid, variable, var_pt, var_ufo, ufo_send, pf_ufo_var_list, pf_var_begin):
            ufo_length = np.zeros(ufo_send.size, np.int64)
            ufo_start = np.zeros(ufo_send.size + 1, np.int64)
            ufo = np.zeros(1, dtype=UnaryFactorOpt)
        Severity: Minor
        Found in salt/src/messages.py by radon

        Cyclomatic Complexity

        Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

        Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

        Construct Effect on CC Reasoning
        if +1 An if statement is a single decision.
        elif +1 The elif statement adds another decision.
        else +0 The else statement does not cause a new decision. The decision is at the if.
        for +1 There is a decision at the start of the loop.
        while +1 There is a decision at the while statement.
        except +1 Each except branch adds a new conditional path of execution.
        finally +0 The finally block is unconditionally executed.
        with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
        assert +1 The assert statement internally roughly equals a conditional statement.
        Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
        Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

        Source: http://radon.readthedocs.org/en/latest/intro.html

        Severity
        Category
        Status
        Source
        Language