oujago/NumpyDL

View on GitHub

Showing 63 of 162 total issues

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

    def forward(self, input, mask, c0=None, h0=None):
        assert np.ndim(input) == 3, 'Only support batch training.'

        # record
        self.last_input = input
Severity: Minor
Found in npdl/layers/recurrent.py - About 55 mins 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 forward has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

    def forward(self, input, c0=None, h0=None):
        """Forward propagation.
        
        Parameters
        ----------
Severity: Minor
Found in npdl/layers/recurrent.py - About 55 mins 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 7 arguments (exceeds 4 allowed). Consider refactoring.
Open

    def __init__(self, embed_words=None, static=None,
Severity: Major
Found in npdl/layers/embedding.py - About 50 mins to fix

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

        def __init__(self, num_inputs, num_hidden, num_outputs,
    Severity: Major
    Found in docs/tutorials/mlp_bp.py - About 50 mins to fix

      Avoid deeply nested control flow statements.
      Open

                              for w in np.arange(new_w):
                                  outputs[a, b, h, w] = np.mean(input[a, b, h:h + pool_h, w:w + pool_w])
      
      Severity: Major
      Found in npdl/layers/pooling.py - About 45 mins to fix

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

            def __init__(self, nb_filter, filter_size, input_shape=None, stride=1,
        Severity: Minor
        Found in npdl/layers/convolution.py - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                                  for h in np.arange(new_img_h):
                                      for w in np.arange(new_img_w):
                                          h_shift, w_shift = h * self.stride, w * self.stride
                                          layer_grads[b, t, h_shift:h_shift + filter_h, w_shift:w_shift + filter_w] += \
                                              self.W[r, t] * delta[b, r, h, w]
          Severity: Major
          Found in npdl/layers/convolution.py - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                    for w in np.arange(new_w):
                                        patch = self.last_input[a, b, h:h + pool_h, w:w + pool_w]
                                        max_idx = np.unravel_index(patch.argmax(), patch.shape)
                                        h_shift, w_shift = h * pool_h + max_idx[0], w * pool_w + max_idx[1]
                                        layer_grads[a, b, h_shift, w_shift] = pre_grad[a, b, a, w]
            Severity: Major
            Found in npdl/layers/pooling.py - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                                      for w in np.arange(new_w):
                                          h_shift, w_shift = h * pool_h, w * pool_w
                                          layer_grads[a, b, h_shift: h_shift + pool_h, w_shift: w_shift + pool_w] = \
                                              pre_grad[a, b, h, w] / length
              
              Severity: Major
              Found in npdl/layers/pooling.py - About 45 mins to fix

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

                    def forward(self, idxs, masks):
                        ##############################
                        # Encode
                        ##############################
                
                
                Severity: Minor
                Found in applications/chatbot/model.py - About 45 mins 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

                Avoid deeply nested control flow statements.
                Open

                                        for w in np.arange(new_w):
                                            outputs[a, b, h, w] = np.max(input[a, b, h:h + pool_h, w:w + pool_w])
                
                Severity: Major
                Found in npdl/layers/pooling.py - About 45 mins to fix

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

                      def __init__(self, beta1=0.9, beta2=0.999, epsilon=1e-8, *args, **kwargs):
                  Severity: Minor
                  Found in npdl/optimizers.py - About 35 mins to fix

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

                        def __init__(self, lr=0.001, clip=-1, decay=0., lr_min=0., lr_max=np.inf):
                    Severity: Minor
                    Found in npdl/optimizers.py - About 35 mins to fix

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

                          def __init__(self, epsilon=1e-6, momentum=0.9, axis=0,
                      Severity: Minor
                      Found in npdl/layers/normalization.py - About 35 mins to fix

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

                            def __init__(self, beta1=0.9, beta2=0.999, epsilon=1e-8, *args, **kwargs):
                        Severity: Minor
                        Found in npdl/optimizers.py - About 35 mins to fix

                          Function init_weights_from_hidden_layer_neurons_to_output_layer_neurons has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                          Open

                              def init_weights_from_hidden_layer_neurons_to_output_layer_neurons(self, output_layer_weights):
                                  weight_num = 0
                                  for o in range(len(self.output_layer.neurons)):
                                      for h in range(len(self.hidden_layer.neurons)):
                                          if not output_layer_weights:
                          Severity: Minor
                          Found in docs/tutorials/mlp_bp.py - About 35 mins 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_weights_from_inputs_to_hidden_layer_neurons has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                          Open

                              def init_weights_from_inputs_to_hidden_layer_neurons(self, hidden_layer_weights):
                                  weight_num = 0
                                  for h in range(len(self.hidden_layer.neurons)):
                                      for i in range(self.num_inputs):
                                          if not hidden_layer_weights:
                          Severity: Minor
                          Found in docs/tutorials/mlp_bp.py - About 35 mins 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

                          Avoid too many return statements within this function.
                          Open

                                  return copy.deepcopy(activation)
                          Severity: Major
                          Found in npdl/activations.py - About 30 mins to fix

                            Avoid too many return statements within this function.
                            Open

                                        return LecunUniform()
                            Severity: Major
                            Found in npdl/initializations.py - About 30 mins to fix

                              Avoid too many return statements within this function.
                              Open

                                      return copy.deepcopy(optimizer)
                              Severity: Major
                              Found in npdl/optimizers.py - About 30 mins to fix
                                Severity
                                Category
                                Status
                                Source
                                Language