deeplearning4j/deeplearning4j

View on GitHub
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/samediff/SDVariable.java

Summary

Maintainability
F
1 wk
Test Coverage

SDVariable has 157 methods (exceeds 20 allowed). Consider refactoring.
Open

@Data
@NoArgsConstructor
@Slf4j
public class SDVariable implements Serializable {

    File SDVariable.java has 874 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

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

      Method get has a Cognitive Complexity of 71 (exceeds 5 allowed). Consider refactoring.
      Open

          public SDVariable get(SDIndex... indices) {
              int ndims = indices.length;
              boolean variableIndices = false;
              //copy because we can mutate this internally
              SDIndex[] inputIndices = Arrays.copyOf(indices,indices.length);

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

          public void addControlDependency(SDVariable controlDependency){
              Variable vThis = sameDiff.getVariables().get(getVarName());
              Variable vCD = sameDiff.getVariables().get(controlDependency.name());
      
              //If possible: add control dependency on ops

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

          public SDVariable get(SDIndex... indices) {
              int ndims = indices.length;
              boolean variableIndices = false;
              //copy because we can mutate this internally
              SDIndex[] inputIndices = Arrays.copyOf(indices,indices.length);

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

            public void addControlDependency(SDVariable controlDependency){
                Variable vThis = sameDiff.getVariables().get(getVarName());
                Variable vCD = sameDiff.getVariables().get(controlDependency.name());
        
                //If possible: add control dependency on ops

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

              public SDVariable put(SDVariable indices,SDVariable toPut,SDVariable putIndices) {
                  //start at 1 because we start with the initial output (basically the item at the first element in the indices)
                  SDVariable currIteration = sameDiff.var(Nd4j.zeros(1).castTo(DataType.INT32));
                  //this condition is normally used when you want to toss in an extra condition to terminate early
                  SDVariable cond = sameDiff.constant(true);

            Method get has 34 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public SDVariable get(SDVariable indices) {
                    SDVariable initialSize = sameDiff.zerosLike(shape()).castTo(DataType.INT64);
                    //pull from the first slice as the starting point and concatenate each result together
                    SDVariable startResult = sameDiff.slice(this, initialSize.castTo(DataType.INT64), sliceEnd(this,
                            sameDiff.onesLike(shape()).castTo(DataType.INT64)));

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

                  @Override
                  public boolean equals(Object o){
                      if(o == this) return true;
                      if(!(o instanceof SDVariable))
                          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 getArr has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                  public INDArray getArr(boolean enforceExistence) {
                      if(sameDiff.arrayAlreadyExistsForVarName(getVarName()))
                          return sameDiff.getArrForVarName(getVarName());
                      if(variableType == VariableType.ARRAY && enforceExistence) {
                          throw new UnsupportedOperationException("Cannot get array for ARRAY type SDVariable - use SDVariable.exec or SameDiff.output instead");

              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 method.
              Open

                      return true;

                Avoid too many return statements within this method.
                Open

                            return false;

                  Avoid too many return statements within this method.
                  Open

                              return a1.equals(a2);

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

                        public long[] getShape() {
                            if (variableType == VariableType.PLACEHOLDER  || shape != null) {
                                return shape;
                            } else if(variableType == VariableType.VARIABLE || variableType == VariableType.CONSTANT) {
                                if(getArr() != null)

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

                        public DataType dataType() {
                            if(this.dataType == null) {
                                //Try to infer datatype instead of returning null
                                if(variableType != VariableType.ARRAY && getArr() != null) {
                                    this.dataType = getArr().dataType();

                    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

                                    if (index.getIntervalEnd() == null && indexType != SDIndex.IndexType.INTERVAL_INPUT) {
                                        end_mask_arr[i] = 1;
                                    } else if(indexType == SDIndex.IndexType.INTERVAL_INPUT) {
                                        if(endVar == null) {
                                            endVar = index.getIntervalInputEnd();
                    nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/samediff/SDVariable.java on lines 1644..1654

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

                    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 (index.getIntervalBegin() == null && indexType != SDIndex.IndexType.INTERVAL_INPUT) {
                                        begin_mask_arr[i] = 1;
                                    } else if(indexType == SDIndex.IndexType.INTERVAL_INPUT) {
                                        if(beginVar == null) {
                                            beginVar = index.getIntervalInputBegin();
                    nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/samediff/SDVariable.java on lines 1655..1665

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

                    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

                        public SDVariable clone(SameDiff sd) {
                            SDVariable v = new SDVariable();
                            v.varName = varName;
                            v.variableType = variableType;
                            v.shape = shape == null ? null : shape.clone();
                    nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/samediff/SDVariable.java on lines 2040..2048

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

                    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

                        public SDVariable clone(String name,SameDiff sd) {
                            SDVariable v = new SDVariable();
                            v.varName = name;
                            v.variableType = variableType;
                            v.shape = shape == null ? null : shape.clone();
                    nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/samediff/SDVariable.java on lines 2050..2058

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

                    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