deeplearning4j/deeplearning4j

View on GitHub
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/checkutil/NDArrayCreationUtil.java

Summary

Maintainability
F
4 days
Test Coverage

File NDArrayCreationUtil.java has 617 lines of code (exceeds 250 allowed). Consider refactoring.
Open

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

    NDArrayCreationUtil has 41 methods (exceeds 20 allowed). Consider refactoring.
    Open

    public class NDArrayCreationUtil {
        private NDArrayCreationUtil() {}
    
        /** Get an array of INDArrays (2d) all with the specified shape. Pair<INDArray,String> returned to aid
         * debugging: String contains information on how to reproduce the matrix (i.e., which function, and arguments)

      Method get6dSubArraysWithShape has 52 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public static List<Pair<INDArray, String>> get6dSubArraysWithShape(int seed, int[] shape, DataType dataType) {
              List<Pair<INDArray, String>> list = new ArrayList<>();
              String baseMsg = "get6dSubArraysWithShape(" + seed + "," + Arrays.toString(shape) + ")";
              //Create and return various sub arrays:
              Nd4j.getRandom().setSeed(seed);

        Method get5dSubArraysWithShape has 45 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public static List<Pair<INDArray, String>> get5dSubArraysWithShape(int seed, int[] shape, DataType dataType) {
                List<Pair<INDArray, String>> list = new ArrayList<>();
                String baseMsg = "get5dSubArraysWithShape(" + seed + "," + Arrays.toString(shape) + ")";
                //Create and return various sub arrays:
                Nd4j.getRandom().setSeed(seed);

          Method get4dSubArraysWithShape has 42 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public static List<Pair<INDArray, String>> get4dSubArraysWithShape(int seed, int[] shape, DataType dataType) {
                  List<Pair<INDArray, String>> list = new ArrayList<>();
                  String baseMsg = "get4dSubArraysWithShape(" + seed + "," + Arrays.toString(shape) + ")";
                  //Create and return various sub arrays:
                  Nd4j.getRandom().setSeed(seed);

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

                public static List<Pair<INDArray, String>> getTensorAlongDimensionMatricesWithShape(char ordering, long rows, long cols, long seed, DataType dataType) {
                    Nd4j.getRandom().setSeed(seed);
                    //From 3d NDArray: do various tensors. One offset 0, one offset > 0
                    //[0,1], [0,2], [1,0], [1,2], [2,0], [2,1]
                    INDArray[] out = new INDArray[12];

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

                  public static List<Pair<INDArray, String>> get3dSubArraysWithShape(long seed, long[] shape, DataType dataType) {
                      List<Pair<INDArray, String>> list = new ArrayList<>();
                      String baseMsg = "get3dSubArraysWithShape(" + seed + "," + Arrays.toString(shape) + ")";
                      //Create and return various sub arrays:
                      Nd4j.getRandom().setSeed(seed);

                Method get3dTensorAlongDimensionWithShape has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public static List<Pair<INDArray, String>> get3dTensorAlongDimensionWithShape(long seed, long[] shape, DataType dataType) {
                        List<Pair<INDArray, String>> list = new ArrayList<>();
                        String baseMsg = "get3dTensorAlongDimensionWithShape(" + seed + "," + Arrays.toString(shape) + ")";
                
                        //Create some 4d arrays and get subsets using 3d TAD on them

                  Method get4dTensorAlongDimensionWithShape has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      public static List<Pair<INDArray, String>> get4dTensorAlongDimensionWithShape(int seed, int[] shape, DataType dataType) {
                          List<Pair<INDArray, String>> list = new ArrayList<>();
                          String baseMsg = "get4dTensorAlongDimensionWithShape(" + seed + "," + Arrays.toString(shape) + ")";
                  
                          //Create some 5d arrays and get subsets using 4d TAD on them

                    Method getTestMatricesWithVaryingShapes has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        public static List<Pair<INDArray, String>> getTestMatricesWithVaryingShapes(int rank, char order, DataType dataType) {
                            List<Pair<INDArray, String>> all = new ArrayList<>();
                            if (rank == 0) {
                                //scalar
                                all.add(new Pair<>(Nd4j.scalar(dataType, Nd4j.rand(dataType, new int[]{1, 1}).getDouble(0)), "{}"));

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

                          public static List<Pair<INDArray, String>> getTensorAlongDimensionMatricesWithShape(char ordering, long rows, long cols, long seed, DataType dataType) {

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

                            public static Pair<INDArray, String> getTransposedMatrixWithShape(char ordering, int rows, int cols, int seed, DataType dataType) {

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

                              public static Pair<INDArray, String> getPermutedWithShape(char ordering, long rows, long cols, long seed, DataType dataType) {

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

                                public static Pair<INDArray, String> getReshapedWithShape(char ordering, long rows, long cols, long seed, DataType dataType) {

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

                                  public static List<Pair<INDArray, String>> getAllTestMatricesWithShape(char ordering, int rows, int cols, int seed, DataType dataType) {

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

                                    public static List<Pair<INDArray, String>> getSubMatricesWithShape(char ordering, long rows, long cols, long seed, DataType dataType) {

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

                                      public static int[][] getRandomBroadCastShape(long seed, int rank, int numShapes) {
                                          Nd4j.getRandom().setSeed(seed);
                                          INDArray coinFlip = Nd4j.getDistributions().createBinomial(1, 0.5).sample(new int[] {numShapes, rank});
                                          int[][] ret = new int[(int) coinFlip.rows()][(int) coinFlip.columns()];
                                          for (int i = 0; i < coinFlip.rows(); i++) {

                                  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

                                      public static int[] broadcastToShape(int[] inputShapeWithOnes, long seed) {
                                          Nd4j.getRandom().setSeed(seed);
                                          int[] shape = new int[inputShapeWithOnes.length];
                                          for (int i = 0; i < shape.length; i++) {
                                              if (inputShapeWithOnes[i] == 1) {
                                  nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/checkutil/NDArrayCreationUtil.java on lines 855..866

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

                                  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

                                      public static long[] broadcastToShape(long[] inputShapeWithOnes, long seed) {
                                          Nd4j.getRandom().setSeed(seed);
                                          val shape = new long[inputShapeWithOnes.length];
                                          for (int i = 0; i < shape.length; i++) {
                                              if (inputShapeWithOnes[i] == 1) {
                                  nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/checkutil/NDArrayCreationUtil.java on lines 842..853

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

                                  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

                                          int[] shape4d1 = {3, shape[0], shape[1], shape[2], shape[3], shape[4]};
                                  nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/checkutil/NDArrayCreationUtil.java on lines 658..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 40.

                                  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

                                          int[] shape4d2 = {3, shape[0], shape[1], shape[2], shape[3], shape[4]};
                                  nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/checkutil/NDArrayCreationUtil.java on lines 649..649

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

                                  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