giuse/machine_learning_workbench

View on GitHub
lib/machine_learning_workbench/compressor/vector_quantization.rb

Summary

Maintainability
C
7 hrs
Test Coverage

Method encode has 94 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def encode vec, type: encoding_type
      case type
      when :most_similar
        simils = similarities vec
        code = simils.max_index
Severity: Major
Found in lib/machine_learning_workbench/compressor/vector_quantization.rb - About 3 hrs to fix

    Method encode has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

        def encode vec, type: encoding_type
          case type
          when :most_similar
            simils = similarities vec
            code = simils.max_index
    Severity: Minor
    Found in lib/machine_learning_workbench/compressor/vector_quantization.rb - About 2 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

    Method initialize has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        def initialize ncentrs:, dims:, vrange:, lrate:, simil_type: nil, encoding_type: nil, init_centr_vrange: nil, rseed: Random.new_seed
    
          @rng = Random.new rseed # TODO: RNG CURRENTLY NOT USED!!
    
          @dims = Array(dims)
    Severity: Minor
    Found in lib/machine_learning_workbench/compressor/vector_quantization.rb - 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

    unexpected token error (Using Ruby 2.1 parser; configure using TargetRubyVersion parameter, under AllCops)
    Open

          raise ArgumentError, "Pass a `lrate` between 0 and 1" unless lrate&.between?(0,1)

    unexpected token error (Using Ruby 2.1 parser; configure using TargetRubyVersion parameter, under AllCops)
    Open

            @encoder = nil if @encoder&.shape&.first != centrs.shape.first

    else without rescue is useless (Using Ruby 2.1 parser; configure using TargetRubyVersion parameter, under AllCops)
    Open

          else raise ArgumentError, "Unrecognized encode #{type}"

    unexpected token kEND (Using Ruby 2.1 parser; configure using TargetRubyVersion parameter, under AllCops)
    Open

    end

    unexpected token kWHEN (Using Ruby 2.1 parser; configure using TargetRubyVersion parameter, under AllCops)
    Open

          when :sparse_coding

    &' interpreted as argument prefix (Using Ruby 2.1 parser; configure usingTargetRubyVersionparameter, underAllCops`)
    Open

              vrange.map &method(:Float)

    &' interpreted as argument prefix (Using Ruby 2.1 parser; configure usingTargetRubyVersionparameter, underAllCops`)
    Open

              [vrange.first, vrange.last].map &method(:Float)

    unexpected token kWHEN (Using Ruby 2.1 parser; configure using TargetRubyVersion parameter, under AllCops)
    Open

           when :sparse_coding_v2

    &' interpreted as argument prefix (Using Ruby 2.1 parser; configure usingTargetRubyVersionparameter, underAllCops`)
    Open

              simils_abs = simils.map &:abs

    There are no issues that match your filters.

    Category
    Status