deeplearning4j/deeplearning4j

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

Summary

Maintainability
F
1 wk
Test Coverage

DefaultDataBufferFactory has 131 methods (exceeds 20 allowed). Consider refactoring.
Open

public class DefaultDataBufferFactory implements DataBufferFactory {
    protected DataBuffer.AllocationMode allocationMode;


    @Override

    File DefaultDataBufferFactory.java has 709 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

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

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

          @Override
          public DataBuffer create(DataBuffer underlyingBuffer, long offset, long length) {
              if (underlyingBuffer.dataType() == DataType.DOUBLE) {
                  return new DoubleBuffer(underlyingBuffer, length, offset);
              } else if (underlyingBuffer.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 create has 32 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          @Override
          public DataBuffer create(@NonNull DataType dataType, long length, boolean initialize) {
              switch (dataType) {
                  case DOUBLE:
                      return new DoubleBuffer(length, initialize);

        Method create has 32 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            @Override
            public DataBuffer create(ByteBuffer underlyingBuffer, DataType dataType, long length, long offset) {
                switch (dataType) {
                    case DOUBLE:
                        return new DoubleBuffer(underlyingBuffer, dataType, length, offset);

          Method create has 30 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              @Override
              public DataBuffer create(DataBuffer underlyingBuffer, long offset, long length) {
                  if (underlyingBuffer.dataType() == DataType.DOUBLE) {
                      return new DoubleBuffer(underlyingBuffer, length, offset);
                  } else if (underlyingBuffer.dataType() == DataType.FLOAT) {

            Method create has 30 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                @Override
                public DataBuffer create(DataType dataType, long length, boolean initialize, MemoryWorkspace workspace) {
                    switch (dataType) {
                        case DOUBLE:
                            return new DoubleBuffer(length, initialize, workspace);

              Method create has 29 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  @Override
                  public DataBuffer create(Pointer pointer, DataType type, long length, @NonNull Indexer indexer) {
                      switch (type) {
                          case BOOL:
                              return new BoolBuffer(pointer, indexer, length);

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

                    public DataBuffer create(Pointer pointer, Pointer specialPointer, DataType type, long length, @NonNull Indexer indexer) {

                  Avoid too many return statements within this method.
                  Open

                              return new FloatBuffer(underlyingBuffer, length, offset);

                    Avoid too many return statements within this method.
                    Open

                                return new Int16Buffer(underlyingBuffer, length, offset);

                      Avoid too many return statements within this method.
                      Open

                                  return new BoolBuffer(underlyingBuffer, length, offset);

                        Avoid too many return statements within this method.
                        Open

                                    return new LongBuffer(underlyingBuffer, length, offset);

                          Avoid too many return statements within this method.
                          Open

                                      return new Int8Buffer(underlyingBuffer, length, offset);

                            Avoid too many return statements within this method.
                            Open

                                        return new UInt32Buffer(underlyingBuffer, length, offset);

                              Avoid too many return statements within this method.
                              Open

                                      return null;

                                Avoid too many return statements within this method.
                                Open

                                            return new UInt8Buffer(underlyingBuffer, length, offset);

                                  Avoid too many return statements within this method.
                                  Open

                                              return new IntBuffer(underlyingBuffer, length, offset);

                                    Avoid too many return statements within this method.
                                    Open

                                                return new DoubleBuffer(underlyingBuffer, length, offset);

                                      Avoid too many return statements within this method.
                                      Open

                                                  return new UInt16Buffer(underlyingBuffer, length, offset);

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

                                            @Override
                                            public DataBuffer create(ByteBuffer underlyingBuffer, DataType dataType, long length, long offset) {
                                                switch (dataType) {
                                                    case DOUBLE:
                                                        return new DoubleBuffer(underlyingBuffer, dataType, length, offset);
                                        nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/buffer/factory/CudaDataBufferFactory.java on lines 67..101

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

                                        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

                                            @Override
                                            public DataBuffer create(Pointer pointer, DataType type, long length, @NonNull Indexer indexer) {
                                                switch (type) {
                                                    case BOOL:
                                                        return new BoolBuffer(pointer, indexer, length);
                                        nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/buffer/factory/CudaDataBufferFactory.java on lines 689..721

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

                                        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

                                                switch (dataType) {
                                                    case DOUBLE:
                                                        return new DoubleBuffer(length, initialize, workspace);
                                                    case FLOAT:
                                                        return new FloatBuffer(length, initialize, workspace);
                                        nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/buffer/factory/CudaDataBufferFactory.java on lines 399..428

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

                                        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

                                            @Override
                                            public DataBuffer create(@NonNull DataType dataType, long length, boolean initialize) {
                                                switch (dataType) {
                                                    case DOUBLE:
                                                        return new DoubleBuffer(length, initialize);
                                        nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/buffer/factory/CudaDataBufferFactory.java on lines 358..392

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

                                        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 DataBuffer.AllocationMode allocationMode() {
                                                if (allocationMode == null) {
                                                    String otherAlloc = System.getProperty("alloc");
                                                    if (otherAlloc.equals("heap"))
                                        nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/buffer/factory/CudaDataBufferFactory.java on lines 53..65

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

                                        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 3 locations. Consider refactoring.
                                        Open

                                            @Override
                                            public DataBuffer create(IntPointer intPointer, long length) {
                                                intPointer.capacity(length);
                                                intPointer.limit(length);
                                                intPointer.position(0);
                                        nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cpu-backend-common/src/main/java/org/nd4j/linalg/cpu/nativecpu/buffer/DefaultDataBufferFactory.java on lines 747..753
                                        nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cpu-backend-common/src/main/java/org/nd4j/linalg/cpu/nativecpu/buffer/DefaultDataBufferFactory.java on lines 773..779

                                        Duplicated Code

                                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                        Tuning

                                        This issue has a mass of 43.

                                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                        Refactorings

                                        Further Reading

                                        Similar blocks of code found in 3 locations. Consider refactoring.
                                        Open

                                            @Override
                                            public DataBuffer create(FloatPointer floatPointer, long length) {
                                                floatPointer.capacity(length);
                                                floatPointer.limit(length);
                                                floatPointer.position(0);
                                        nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cpu-backend-common/src/main/java/org/nd4j/linalg/cpu/nativecpu/buffer/DefaultDataBufferFactory.java on lines 747..753
                                        nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cpu-backend-common/src/main/java/org/nd4j/linalg/cpu/nativecpu/buffer/DefaultDataBufferFactory.java on lines 760..766

                                        Duplicated Code

                                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                        Tuning

                                        This issue has a mass of 43.

                                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                        Refactorings

                                        Further Reading

                                        Similar blocks of code found in 3 locations. Consider refactoring.
                                        Open

                                            @Override
                                            public DataBuffer create(DoublePointer doublePointer, long length) {
                                                doublePointer.capacity(length);
                                                doublePointer.limit(length);
                                                doublePointer.position(0);
                                        nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cpu-backend-common/src/main/java/org/nd4j/linalg/cpu/nativecpu/buffer/DefaultDataBufferFactory.java on lines 760..766
                                        nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cpu-backend-common/src/main/java/org/nd4j/linalg/cpu/nativecpu/buffer/DefaultDataBufferFactory.java on lines 773..779

                                        Duplicated Code

                                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                        Tuning

                                        This issue has a mass of 43.

                                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                        Refactorings

                                        Further Reading

                                        There are no issues that match your filters.

                                        Category
                                        Status