deeplearning4j/deeplearning4j

View on GitHub
nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cpu-backend-common/src/main/java/org/nd4j/linalg/cpu/nativecpu/CpuNDArrayFactory.java

Summary

Maintainability
F
1 wk
Test Coverage

CpuNDArrayFactory has 97 methods (exceeds 20 allowed). Consider refactoring.
Open

@Slf4j
public class CpuNDArrayFactory extends BaseNativeNDArrayFactory {

    protected ThreadLocal<PointerPointer> extrazA = new ThreadLocal<>();
    protected ThreadLocal<PointerPointer> extrazB = new ThreadLocal<>();

    File CpuNDArrayFactory.java has 722 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

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

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

          @Override
          public void shuffle(List<INDArray> arrays, Random rnd, List<long[]> dimensions) {
              if (dimensions == null || dimensions.size() == 0)
                  throw new RuntimeException("Dimension can't be null or 0-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 shuffle has 53 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          @Override
          public void shuffle(List<INDArray> arrays, Random rnd, List<long[]> dimensions) {
              if (dimensions == null || dimensions.size() == 0)
                  throw new RuntimeException("Dimension can't be null or 0-length");
      

        Method pullRows has 41 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public INDArray pullRows(INDArray source, INDArray destination, int sourceDimension, long[] indexes) {
                if (indexes == null || indexes.length < 1)
                    throw new IllegalStateException("Indexes can't be null or zero-length");
        
                long[] shape = null;

          Method average has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
          Open

              @Override
              public INDArray average(INDArray target, INDArray[] arrays) {
                  if (arrays == null || arrays.length == 0)
                      throw new RuntimeException("Input arrays are missing");
          

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

              public INDArray pullRows(INDArray source, INDArray destination, int sourceDimension, long[] indexes) {
                  if (indexes == null || indexes.length < 1)
                      throw new IllegalStateException("Indexes can't be null or zero-length");
          
                  long[] shape = 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 createBlas has 32 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              @Override
              public void createBlas() {
                  // we'll check hardware support first
                  if (!nativeOps.isMinimalRequirementsMet()) {
                      // this means cpu binary was built for some arch support, we don't have on this box

            Method average has 31 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                @Override
                public INDArray average(INDArray target, INDArray[] arrays) {
                    if (arrays == null || arrays.length == 0)
                        throw new RuntimeException("Input arrays are missing");
            

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

                  public INDArray accumulate(INDArray target, INDArray... arrays) {
              
                      if (arrays == null || arrays.length == 0)
                          throw new RuntimeException("Input arrays are missing");
              

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

                  @Override
                  public DataBuffer convertDataEx(DataTypeEx typeSrc, DataBuffer source, DataTypeEx typeDst) {
                      int elementSize = 0;
                      if (typeDst.ordinal() <= 2)
                          elementSize = 1;

                Method create has 6 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                    public INDArray create(double[] data, long[] shape, long[] stride, char order, DataType dataType, MemoryWorkspace workspace) {

                  Method create has 6 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                      public INDArray create(DataBuffer data, long[] shape, long[] stride, long offset, char ordering, DataType dataType) {

                    Method create has 6 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                        public INDArray create(DataType dataType, long[] shape, long[] paddings, long[] paddingOffsets, char ordering,
                                MemoryWorkspace workspace) { 

                      Method create has 6 arguments (exceeds 4 allowed). Consider refactoring.
                      Open

                          public INDArray create(int[] data, long[] shape, long[] stride, char order, DataType dataType, MemoryWorkspace workspace) {

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

                            @Override
                            public DataBuffer convertDataEx(DataTypeEx typeSrc, DataBuffer source, DataTypeEx typeDst) {
                                int elementSize = 0;
                                if (typeDst.ordinal() <= 2)
                                    elementSize = 1;

                        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 create has 6 arguments (exceeds 4 allowed). Consider refactoring.
                        Open

                            public INDArray create(float[] data, long[] shape, long[] stride, char order, DataType dataType, MemoryWorkspace workspace) {

                          Method create has 6 arguments (exceeds 4 allowed). Consider refactoring.
                          Open

                              public INDArray create(byte[] data, long[] shape, long[] stride, char order, DataType dataType, MemoryWorkspace workspace) {

                            Method create has 6 arguments (exceeds 4 allowed). Consider refactoring.
                            Open

                                public INDArray create(DataBuffer data, long[] shape, long[] stride, long offset, long ews, char ordering) {

                              Method create has 6 arguments (exceeds 4 allowed). Consider refactoring.
                              Open

                                  public INDArray create(float[] data, long rows, long columns, int[] stride, long offset, char ordering) {

                                Method create has 6 arguments (exceeds 4 allowed). Consider refactoring.
                                Open

                                    public INDArray create(short[] data, long[] shape, long[] stride, char order, DataType dataType, MemoryWorkspace workspace) {

                                  Method create has 6 arguments (exceeds 4 allowed). Consider refactoring.
                                  Open

                                      public INDArray create(long[] data, long[] shape, long[] stride, char order, DataType dataType, MemoryWorkspace workspace) {

                                    Method create has 6 arguments (exceeds 4 allowed). Consider refactoring.
                                    Open

                                        public INDArray create(boolean[] data, long[] shape, long[] stride, char order, DataType dataType, MemoryWorkspace workspace) {

                                      Method create has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                      Open

                                          public INDArray create(double[] data, int[] shape, int[] stride, long offset, char ordering) {

                                        Method create has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                        Open

                                            public INDArray create(boolean[] data, long[] shape, long[] stride, DataType dataType, MemoryWorkspace workspace) {

                                          Method create has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                          Open

                                              public INDArray create(byte[] data, long[] shape, long[] stride, DataType dataType, MemoryWorkspace workspace) {

                                            Method create has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                            Open

                                                public INDArray create(float[] data, long[] shape, long[] stride, char order, long offset) {

                                              Method create has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                              Open

                                                  public INDArray create(double[] data, long[] shape, long[] stride, long offset, char ordering) {

                                                Method create has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                                Open

                                                    public INDArray create(short[] data, long[] shape, long[] stride, DataType dataType, MemoryWorkspace workspace) {

                                                  Method create has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                                  Open

                                                      public INDArray create(DataBuffer data, long rows, long columns, int[] stride, long offset) {

                                                    Method create has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                                    Open

                                                        public INDArray create(DataBuffer data, long[] shape, long[] stride, long offset, char ordering) {

                                                      Method create has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                                      Open

                                                          public INDArray create(DataBuffer data, int[] newShape, int[] newStride, long offset, char ordering) {

                                                        Method create has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                                        Open

                                                            public INDArray create(float[] data, long[] shape, long[] stride, char order, DataType dataType) {

                                                          Method create has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                                          Open

                                                              public INDArray create(float[] data, long[] shape, long[] stride, long offset, char ordering) {

                                                            Method create has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                                            Open

                                                                public INDArray create(double[] data, long[] shape, long[] stride, DataType dataType, MemoryWorkspace workspace) {

                                                              Method create has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                                              Open

                                                                  public INDArray create(long[] data, long[] shape, long[] stride, DataType dataType, MemoryWorkspace workspace) {

                                                                Method convertDataEx has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                                                Open

                                                                    public void convertDataEx(DataTypeEx typeSrc, Pointer source, DataTypeEx typeDst, Pointer target,
                                                                                              long length) {

                                                                  Method create has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                                                  Open

                                                                      public INDArray create(int[] data, long[] shape, long[] stride, DataType dataType, MemoryWorkspace workspace) {

                                                                    Method create has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                                                    Open

                                                                        public INDArray create(float[] data, int[] shape, int[] stride, long offset, char ordering) {

                                                                      Method create has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                                                      Open

                                                                          public INDArray create(DataType dataType, long[] shape, long[] strides,  char ordering, MemoryWorkspace workspace ) {

                                                                        Method create has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                                                        Open

                                                                            public INDArray create(float[] data, long[] shape, long[] stride, DataType dataType, MemoryWorkspace workspace) {

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

                                                                                  if (typeDst.ordinal() <= 2)
                                                                                      elementSize = 1;
                                                                                  else if (typeDst.ordinal() <= 5)
                                                                                      elementSize = 2;
                                                                                  else if (typeDst.ordinal() == 6)
                                                                          nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/JCublasNDArrayFactory.java on lines 1223..1232

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

                                                                          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

                                                                              @Override
                                                                              public INDArray empty(DataType type) {
                                                                                  long extras  = ArrayOptionsHelper.setOptionBit(0L, ArrayType.EMPTY);
                                                                                  extras = ArrayOptionsHelper.setOptionBit(extras, type);
                                                                                  val shape = Nd4j.getShapeInfoProvider().createShapeInformation(new long[0], new long[0],1,'c', extras);
                                                                          nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/JCublasNDArrayFactory.java on lines 1381..1387

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

                                                                          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

                                                                                  if(ret == null){
                                                                                      ret = Nd4j.createUninitialized(source.dataType(), shape, order);
                                                                                  } else {
                                                                                      if(!Arrays.equals(shape, destination.shape())){
                                                                                          throw new IllegalStateException("Cannot pull rows into destination array: expected destination array of" +
                                                                          nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/JCublasNDArrayFactory.java on lines 485..492

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

                                                                          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

                                                                              @Override
                                                                              public INDArray average(INDArray[] arrays) {
                                                                                  if (arrays == null || arrays.length == 0)
                                                                                      throw new RuntimeException("Input arrays are missing");
                                                                          
                                                                          nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/JCublasNDArrayFactory.java on lines 783..792

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

                                                                          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

                                                                                  if (CompressionUtils.goingToCompress(typeSrc, typeDst)) {
                                                                                      // all types below 6 are compression modes
                                                                                      BytePointer pointer = new BytePointer(source.length() * elementSize);
                                                                                      CompressionDescriptor descriptor = new CompressionDescriptor(source, typeDst.name());
                                                                                      descriptor.setCompressionType(CompressionType.LOSSY);
                                                                          nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/JCublasNDArrayFactory.java on lines 1242..1249

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

                                                                          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

                                                                                  for (int i = 0; i < dimensions.length; i++) {
                                                                                      tadLength *= tensor.size(dimensions[i]);
                                                                                      shape[i] = tensor.size(dimensions[i]);
                                                                                  }
                                                                          nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/JCublasNDArrayFactory.java on lines 1276..1279

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

                                                                          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

                                                                                  if (zero.rank() > 1)
                                                                                      for (int i = 0; i < dimensions.get(0).length; i++) {
                                                                                          tadLength *= zero.size(dimensions.get(0)[i]);
                                                                                      }
                                                                          nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/JCublasNDArrayFactory.java on lines 853..856

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

                                                                          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