deeplearning4j/deeplearning4j

View on GitHub
python4j/python4j-core/src/main/java/org/nd4j/python4j/PythonTypes.java

Summary

Maintainability
F
3 days
Test Coverage

Method adapt has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring.
Open

        @Override
        public List adapt(Object javaObject) {
            if (javaObject instanceof List) {
                return (List) javaObject;
            } else if (javaObject.getClass().isArray()) {

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

File PythonTypes.java has 372 lines of code (exceeds 250 allowed). Consider refactoring.
Open

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

    PythonTypes has 33 methods (exceeds 20 allowed). Consider refactoring.
    Open

    public class PythonTypes {
    
    
        private static List<PythonType> getPrimitiveTypes() {
            return Arrays.asList(STR, INT, FLOAT, BOOL, BYTES,new NoneType());

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

              @Override
              public List adapt(Object javaObject) {
                  if (javaObject instanceof List) {
                      return (List) javaObject;
                  } else if (javaObject.getClass().isArray()) {

        Method toPython has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

                @Override
                public PythonObject toPython(Map javaObject) {
                    PythonGIL.assertThreadSafe();
                    PyObject pyDict = PyDict_New();
                    for (Object k : javaObject.keySet()) {

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

                @Override
                public PythonObject toPython(Map javaObject) {
                    PythonGIL.assertThreadSafe();
                    PyObject pyDict = PyDict_New();
                    for (Object k : javaObject.keySet()) {

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

                  @Override
                  public Map toJava(PythonObject pythonObject) {
                      PythonGIL.assertThreadSafe();
                      HashMap ret = new HashMap();
                      PyObject dictType = new PyObject(PyDict_Type());

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

                public static <T> PythonType<T> getPythonTypeForPythonObject(PythonObject pythonObject) {
                    PyObject pyType = PyObject_Type(pythonObject.getNativePythonObject());
                    try {
                        String pyTypeStr = PythonTypes.STR.toJava(new PythonObject(pyType, false));
            
            
            Severity: Minor
            Found in python4j/python4j-core/src/main/java/org/nd4j/python4j/PythonTypes.java - About 45 mins to fix

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

                    @Override
                    public PythonObject toPython(List javaObject) {
                        PythonGIL.assertThreadSafe();
                        PyObject pyList = PyList_New(javaObject.size());
                        for (int i = 0; i < javaObject.size(); i++) {
            Severity: Minor
            Found in python4j/python4j-core/src/main/java/org/nd4j/python4j/PythonTypes.java - About 35 mins to fix

            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 ret;
            Severity: Major
            Found in python4j/python4j-core/src/main/java/org/nd4j/python4j/PythonTypes.java - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                                  return new ArrayList<>(Arrays.asList(arr));
              Severity: Major
              Found in python4j/python4j-core/src/main/java/org/nd4j/python4j/PythonTypes.java - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                                return (List) javaObject;
                Severity: Major
                Found in python4j/python4j-core/src/main/java/org/nd4j/python4j/PythonTypes.java - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                                      return ret;
                  Severity: Major
                  Found in python4j/python4j-core/src/main/java/org/nd4j/python4j/PythonTypes.java - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                                        return ret;
                    Severity: Major
                    Found in python4j/python4j-core/src/main/java/org/nd4j/python4j/PythonTypes.java - About 30 mins to fix

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

                          public static final PythonType<Double> FLOAT = new PythonType<Double>("float", Double.class) {
                      
                              @Override
                              public Double adapt(Object javaObject) {
                                  if (javaObject instanceof Number) {
                      python4j/python4j-core/src/main/java/org/nd4j/python4j/PythonTypes.java on lines 139..167

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

                      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 final PythonType<Long> INT = new PythonType<Long>("int", Long.class) {
                              @Override
                              public Long adapt(Object javaObject) {
                                  if (javaObject instanceof Number) {
                                      return ((Number) javaObject).longValue();
                      python4j/python4j-core/src/main/java/org/nd4j/python4j/PythonTypes.java on lines 169..198

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

                      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 (k instanceof PythonObject) {
                                          pyKey = (PythonObject) k;
                                      } else if (k instanceof PyObject) {
                                          pyKey = new PythonObject((PyObject) k);
                                      } else {
                      python4j/python4j-core/src/main/java/org/nd4j/python4j/PythonTypes.java on lines 390..396

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

                      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 (v instanceof PythonObject) {
                                          pyVal = (PythonObject) v;
                                      } else if (v instanceof PyObject) {
                                          pyVal = new PythonObject((PyObject) v);
                                      } else {
                      python4j/python4j-core/src/main/java/org/nd4j/python4j/PythonTypes.java on lines 381..387

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

                      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

                                      for (int i = 0; i < ret.length; i++) {
                                          ret[i] = (byte)pythonObject.get(i).toInt();
                                      }
                      nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/imports/graphmapper/tf/TFGraphMapper.java on lines 764..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 42.

                      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