Showing 29 of 29 total issues

File pygco.py has 512 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import ctypes as ct  # noqa: F401
import sys

import numpy as np

Severity: Major
Found in src/gco/pygco.py - About 1 day to fix

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

        def init_label_at_site(self, site, label):
            """Initialize label assignment at a specified site."""
            if not (0 <= site < self.nb_sites) or not (0 <= label < self.nb_labels):
                raise IndexOutOfBoundError()
            _cgco.gcoInitLabelAtSite(self.handle, np.intc(site), np.intc(label))
    Severity: Major
    Found in src/gco/pygco.py and 1 other location - About 4 hrs to fix
    src/gco/pygco.py on lines 239..243

    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 78.

    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

        def alpha_beta_swap(self, l1, l2):
            """Do a single alpha-beta swap for specified pair of labels."""
            if not (0 <= l1 < self.nb_labels) or not (0 <= l2 < self.nb_labels):
                raise IndexOutOfBoundError()
            _cgco.gcoAlphaBetaSwap(self.handle, np.intc(l1), np.intc(l2))
    Severity: Major
    Found in src/gco/pygco.py and 1 other location - About 4 hrs to fix
    src/gco/pygco.py on lines 275..279

    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 78.

    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

    GCO has 27 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class GCO(object):
        def __init__(self):
            pass
    
        def create_general_graph(self, num_sites, num_labels, energy_is_float=False):
    Severity: Minor
    Found in src/gco/pygco.py - About 3 hrs to fix

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

          def swap(self, niters=-1):
              """Do alpha-beta swaps for the specified number of iterations.
              Return total energy after the swap moves.
              If niters is set to -1, the algorithm will run until convergence."""
              _cgco.gcoSwap(self.handle, np.intc(niters), self.energy_temp_array)
      Severity: Major
      Found in src/gco/pygco.py and 1 other location - About 2 hrs to fix
      src/gco/pygco.py on lines 217..222

      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 50.

      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

          def expansion(self, niters=-1):
              """Do alpha-expansion for specified number of iterations.
              Return total energy after the expansion moves.
              If niters is set to -1, the algorithm will run until convergence."""
              _cgco.gcoExpansion(self.handle, np.intc(niters), self.energy_temp_array)
      Severity: Major
      Found in src/gco/pygco.py and 1 other location - About 2 hrs to fix
      src/gco/pygco.py on lines 232..237

      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 50.

      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 3 locations. Consider refactoring.
      Open

          def _convert_pairwise_array(self, e):
              if self.energy_is_float:
                  return (e * _PAIRWISE_FLOAT_PRECISION).astype(np.intc)
              else:
                  return e.astype(np.intc)
      Severity: Major
      Found in src/gco/pygco.py and 2 other locations - About 1 hr to fix
      src/gco/pygco.py on lines 77..81
      src/gco/pygco.py on lines 101..105

      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 42.

      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 3 locations. Consider refactoring.
      Open

          def _convert_smooth_cost_array(self, e):
              if self.energy_is_float:
                  return (e * _SMOOTH_COST_PRECISION).astype(np.intc)
              else:
                  return e.astype(np.intc)
      Severity: Major
      Found in src/gco/pygco.py and 2 other locations - About 1 hr to fix
      src/gco/pygco.py on lines 77..81
      src/gco/pygco.py on lines 89..93

      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 42.

      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 3 locations. Consider refactoring.
      Open

          def _convert_unary_array(self, e):
              if self.energy_is_float:
                  return (e * _UNARY_FLOAT_PRECISION).astype(np.intc)
              else:
                  return e.astype(np.intc)
      Severity: Major
      Found in src/gco/pygco.py and 2 other locations - About 1 hr to fix
      src/gco/pygco.py on lines 89..93
      src/gco/pygco.py on lines 101..105

      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 42.

      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 cut_general_graph has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

      def cut_general_graph(
          edges,
          edge_weights,
          unary_cost,
          pairwise_cost=None,
      Severity: Minor
      Found in src/gco/pygco.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

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

          def compute_smooth_energy(self):
              """Compute the smooth energy of current label assignments."""
              _cgco.gcoComputeSmoothEnergy(self.handle, self.energy_temp_array)
              return self._convert_energy_back(self.energy_temp_array[0])
      Severity: Major
      Found in src/gco/pygco.py and 2 other locations - About 1 hr to fix
      src/gco/pygco.py on lines 245..248
      src/gco/pygco.py on lines 250..253

      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 40.

      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 3 locations. Consider refactoring.
      Open

          def compute_energy(self):
              """Compute energy of current label assignments."""
              _cgco.gcoComputeEnergy(self.handle, self.energy_temp_array)
              return self._convert_energy_back(self.energy_temp_array[0])
      Severity: Major
      Found in src/gco/pygco.py and 2 other locations - About 1 hr to fix
      src/gco/pygco.py on lines 250..253
      src/gco/pygco.py on lines 255..258

      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 40.

      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 3 locations. Consider refactoring.
      Open

          def compute_data_energy(self):
              """Compute the data energy of current label assignments."""
              _cgco.gcoComputeDataEnergy(self.handle, self.energy_temp_array)
              return self._convert_energy_back(self.energy_temp_array[0])
      Severity: Major
      Found in src/gco/pygco.py and 2 other locations - About 1 hr to fix
      src/gco/pygco.py on lines 245..248
      src/gco/pygco.py on lines 255..258

      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 40.

      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 3 locations. Consider refactoring.
      Open

          def _convert_smooth_cost_term(self, e):
              if self.energy_is_float:
                  return np.intc(e * _SMOOTH_COST_PRECISION)
              else:
                  return np.intc(e)
      Severity: Major
      Found in src/gco/pygco.py and 2 other locations - About 1 hr to fix
      src/gco/pygco.py on lines 83..87
      src/gco/pygco.py on lines 95..99

      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 38.

      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 3 locations. Consider refactoring.
      Open

          def _convert_unary_term(self, e):
              if self.energy_is_float:
                  return np.intc(e * _UNARY_FLOAT_PRECISION)
              else:
                  return np.intc(e)
      Severity: Major
      Found in src/gco/pygco.py and 2 other locations - About 1 hr to fix
      src/gco/pygco.py on lines 95..99
      src/gco/pygco.py on lines 107..111

      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 38.

      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 cut_general_graph has 8 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      def cut_general_graph(
      Severity: Major
      Found in src/gco/pygco.py - About 1 hr to fix

        Function cut_grid_graph has 8 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        def cut_grid_graph(
        Severity: Major
        Found in src/gco/pygco.py - About 1 hr to fix

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

              def _convert_pairwise_term(self, e):
                  if self.energy_is_float:
                      return np.intc(e * _PAIRWISE_FLOAT_PRECISION)
                  else:
                      return np.intc(e)
          Severity: Major
          Found in src/gco/pygco.py and 2 other locations - About 1 hr to fix
          src/gco/pygco.py on lines 83..87
          src/gco/pygco.py on lines 107..111

          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 38.

          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 4 locations. Consider refactoring.
          Open

                  assert len(dr_edges_from) == len(dr_edges_w), "different sizes of edges %i and weights %i" % (
                      len(dr_edges_from),
                      len(dr_edges_w),
          Severity: Major
          Found in src/gco/pygco.py and 3 other locations - About 50 mins to fix
          src/gco/pygco.py on lines 501..503
          src/gco/pygco.py on lines 506..508
          src/gco/pygco.py on lines 523..525

          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 36.

          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 4 locations. Consider refactoring.
          Open

              assert len(h_edges_from) == len(h_edges_w), "different sizes of edges %i and weights %i" % (
                  len(h_edges_from),
                  len(h_edges_w),
          Severity: Major
          Found in src/gco/pygco.py and 3 other locations - About 50 mins to fix
          src/gco/pygco.py on lines 501..503
          src/gco/pygco.py on lines 518..520
          src/gco/pygco.py on lines 523..525

          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 36.

          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

          Severity
          Category
          Status
          Source
          Language