'Getting exception when code runs but no when code is being debugged on DJL

I am using DJL as a wrapper library for Numpy in Java to perform complex operations on matrices and I am having issues while trying to perform an NDArray#any() call.

I am creating a matrix from a serie of operations and then I want to test if it contains any true value.

The code snippet that causes this issue is as follows:

      NDArray orthogonallyAccessibleMaskMax = columns.get(index).eq(maxs.get(index))
          .logicalAnd(infiniteSurfaceMask.neg()).logicalAnd(
              deltaNormalsPositions.dot(loopArgumentsMatrixMax.get(index)).gt(RADIUS_TOLERANCE))
          .toType(DataType.FLOAT32, true);

      if (orthogonallyAccessibleMaskMax.any().getBoolean()) {
        infiniteSurfaceMask.add(orthogonallyAccessibleMaskMax);
      }

The exception is:

ai.djl.engine.EngineException: MXNet engine call failed: MXNetError: Unknown type enum 7
Stack trace:
  File "C:\Users\Administrator\kimbergz\b4\src\operator\numpy\../tensor/elemwise_unary_op.h", line 252


    at ai.djl.mxnet.jna.JnaUtils.checkCall(JnaUtils.java:1930)
    at ai.djl.mxnet.jna.JnaUtils.waitToRead(JnaUtils.java:473)
    at ai.djl.mxnet.engine.MxNDArray.close(MxNDArray.java:1629)
    at ai.djl.mxnet.engine.MxNDArray.sum(MxNDArray.java:996)
    at ai.djl.ndarray.NDArray.any(NDArray.java:4299)
    at com.package.calculateInfiniteSurfaceMask(DeltaThicknessStep.java:137)

Curious is that, if I debug the code and go step by step, the operation is correctly performed and I get the boolean value that I am looking for. But if I let the code run without breakpoints every operation performed on orthogonallyAccessibleMaskMax will throw this exception.



Solution 1:[1]

This is due the limited support of boolean type in MXNet. You can reproduce the same issue in Python:

from mxnet import nd
array = nd.zeros(1, dtype='bool')
nd.negative(array)

You can try to use PyTorch engine instead of MXNet engine

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Frank Liu