SciRuby/nmatrix

View on GitHub
lib/nmatrix/shortcuts.rb

Summary

Maintainability
D
1 day
Test Coverage

File shortcuts.rb has 308 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class NMatrix

  # Methods for generating magic matrix.
  module MagicHelpers
    class << self
Severity: Minor
Found in lib/nmatrix/shortcuts.rb - About 3 hrs to fix

    Class NMatrix has 23 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class NMatrix
    
      # Methods for generating magic matrix.
      module MagicHelpers
        class << self
    Severity: Minor
    Found in lib/nmatrix/shortcuts.rb - About 2 hrs to fix

      Method block_diagonal has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

          def block_diagonal(*params)
            options = params.last.is_a?(Hash) ? params.pop : {}
      
            params.each_index do |i|
              params[i] = params[i].to_nm if params[i].is_a?(Array) # Convert Array to NMatrix
      Severity: Minor
      Found in lib/nmatrix/shortcuts.rb - 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

      Method doubly_even_magic has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

            def doubly_even_magic(nm, shape)
              mini_square_num = shape / 4
              count = 1     
              inv_count = shape * shape
              shape.times do |row|
      Severity: Minor
      Found in lib/nmatrix/shortcuts.rb - 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

      Method singly_even_magic has 35 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def singly_even_magic(nm, shape)
              half_shape = shape / 2
              complementary_pair = (shape - 2) / 4
              swap_col = NMatrix.new([shape])
              index = 0 
      Severity: Minor
      Found in lib/nmatrix/shortcuts.rb - About 1 hr to fix

        Method inv_hilbert has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            def inv_hilbert(shape, opts={})
              opts = {:dtype => :float64}.merge(opts)
              m = NMatrix.new([shape,shape],opts)
              combination = NMatrix.new([2*shape,2*shape],opts)
              #combinations refers to the combination of n things taken k at a time
        Severity: Minor
        Found in lib/nmatrix/shortcuts.rb - 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

        Method new has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def new(*args)
              stype = args[0].is_a?(Symbol) ? args.shift : :dense
              shape = args[0].is_a?(Array) ? args.shift  : [1,args.shift]
        
              if shape.size != 2 || !shape.include?(1) || shape == [1,1]
        Severity: Minor
        Found in lib/nmatrix/shortcuts.rb - About 25 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

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

            def linspace(base, limit, shape = [100])
              
              # Convert shape to array format 
              shape = [shape] if shape.is_a? Integer 
              
        Severity: Minor
        Found in lib/nmatrix/shortcuts.rb and 1 other location - About 50 mins to fix
        lib/nmatrix/shortcuts.rb on lines 644..658

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

        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 linspace(base, limit, shape = [100])
              
              # Convert shape to array format 
              shape = [shape] if shape.is_a? Integer 
              
        Severity: Minor
        Found in lib/nmatrix/shortcuts.rb and 1 other location - About 50 mins to fix
        lib/nmatrix/shortcuts.rb on lines 744..758

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

        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 logspace(base, limit, shape = [50], exponent_base: 10)
        
              #Calculate limit for [10 ^ base ... Math::PI] if limit = :pi
              limit = Math.log(Math::PI, exponent_base = 10) if limit == :pi 
              shape = [shape] if shape.is_a? Integer
        Severity: Minor
        Found in lib/nmatrix/shortcuts.rb and 1 other location - About 40 mins to fix
        lib/nmatrix/shortcuts.rb on lines 798..806

        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

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

            def logspace(base, limit, shape = [50], exponent_base: 10)
        
              #Calculate limit for [10 ^ base ... Math::PI] if limit = :pi
              limit = Math.log(Math::PI, exponent_base = 10) if limit == :pi 
              shape = [shape] if shape.is_a? Integer
        Severity: Minor
        Found in lib/nmatrix/shortcuts.rb and 1 other location - About 40 mins to fix
        lib/nmatrix/shortcuts.rb on lines 698..706

        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

        There are no issues that match your filters.

        Category
        Status