deeplearning4j/deeplearning4j

View on GitHub
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ops/BaseOp.java

Summary

Maintainability
F
4 days
Test Coverage

Method computeVariables has a Cognitive Complexity of 47 (exceeds 5 allowed). Consider refactoring.
Open

    public void computeVariables(SDVariable[] newVars) {
        if(sameDiff.isEagerMode()) {
            SDVariable[] args = args();
            if(args.length == 1) {
                x = args[0].getArr();

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 BaseOp.java has 357 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/*
 *  ******************************************************************************
 *  *
 *  *
 *  * This program and the accompanying materials are made available under the

    Method extraArgsDataBuff has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
    Open

        @Override
        public DataBuffer extraArgsDataBuff(DataType dtype) {
            if (extraArgz != null)
                return extraArgz;
    
    

    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

    BaseOp has 27 methods (exceeds 20 allowed). Consider refactoring.
    Open

    @Data
    public abstract class BaseOp extends DifferentialFunction implements Op {
    
        protected INDArray x, y, z;
    
    

      Method equals has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

          @Override
          public boolean equals(Object o) {
              if (this == o) return true;
              if (o == null || getClass() != o.getClass()) return false;
      
      

      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 computeVariables has 52 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public void computeVariables(SDVariable[] newVars) {
              if(sameDiff.isEagerMode()) {
                  SDVariable[] args = args();
                  if(args.length == 1) {
                      x = args[0].getArr();

        Method getOpType has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

            public static Type getOpType(Op op) {
                Type type = null;
        
                if (op instanceof CustomOp) {
                    return Type.CUSTOM;

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

            @Override
            public SDVariable[] outputVariables(String baseName) {
                if(zVertexId == null)  {
                    val outputNames = sameDiff.getOutputsForOp(this);
                    //no need to dynamically create if already exists

        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 extraArgsDataBuff has 30 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            @Override
            public DataBuffer extraArgsDataBuff(DataType dtype) {
                if (extraArgz != null)
                    return extraArgz;
        
        

          Method outputVariables has 28 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              @Override
              public SDVariable[] outputVariables(String baseName) {
                  if(zVertexId == null)  {
                      val outputNames = sameDiff.getOutputsForOp(this);
                      //no need to dynamically create if already exists

            Method extraArgsBuff has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                @Override
                public Buffer extraArgsBuff() {
                    if (extraArgs != null) {
                        DataBuffer retBuff;
                        if (x.data().dataType() == DataType.FLOAT) {

            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 getOpType has 26 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public static Type getOpType(Op op) {
                    Type type = null;
            
                    if (op instanceof CustomOp) {
                        return Type.CUSTOM;

              Method toCustomOp has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                  @Override
                  public CustomOp toCustomOp() {
                      DynamicCustomOp.DynamicCustomOpsBuilder customOpBuilder = DynamicCustomOp.builder(opName());
                      customOpBuilder.callInplace(x() == z());
              
              

              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

              Consider simplifying this complex logical expression.
              Open

                              else if((opType() == Type.REDUCE_FLOAT || opType() == Type.REDUCE_LONG || opType() == Type.REDUCE_BOOL  || opType() == Type.REDUCE_BOOL || opType() == Type.REDUCE_SAME) && args.length > 1) {
                                  this.dimensionz = args[1].getArr();
                                  this.dimensions = args[1].getArr().toLongVector();
                              }

                Avoid too many return statements within this method.
                Open

                        return new SDVariable[]{sameDiff.getVariable(zVertexId)};

                  Avoid too many return statements within this method.
                  Open

                          if (z != null ? !z.equals(baseOp.z) : baseOp.z != null) return false;

                    Avoid too many return statements within this method.
                    Open

                            if (!Arrays.equals(extraArgs, baseOp.extraArgs)) return false;

                      Avoid too many return statements within this method.
                      Open

                              return extraArgz != null ? extraArgz.equals(baseOp.extraArgz) : baseOp.extraArgz == null;

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

                            protected void defineDimensions(long... dimensions) {
                                if (dimensions != null && dimensions.length > 0) {
                                    if(x != null) {
                                        dimensions = Shape.normalizeAxis(x.rank(), dimensions);
                                    }

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

                            public Number getFinalResult() {
                                if (this.z == null)
                                    throw new ND4JIllegalStateException("Op.Z is null. Op wasn't executed yet?");
                        
                                if (z.isEmpty())

                        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

                                    } else {
                                        retBuff = Nd4j.createBuffer(new double[extraArgs.length]);
                                        for (int i = 0; i < extraArgs.length; i++) {
                                            Number val = (Number) extraArgs[i];
                                            retBuff.put(i, val.doubleValue());
                        nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ops/BaseOp.java on lines 182..189

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

                        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

                                    if (x.data().dataType() == DataType.FLOAT) {
                                        retBuff = Nd4j.createBuffer(new float[extraArgs.length]);
                                        for (int i = 0; i < extraArgs.length; i++) {
                                            Number val = (Number) extraArgs[i];
                                            retBuff.put(i, val.floatValue());
                        nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ops/BaseOp.java on lines 189..196

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

                        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