docs: public Mat asMat(INDArray array, int dataType) {
          if (array.rank() > 4 || (array.rank() > 3 && array.size(0) != 1)) {
              throw new UnsupportedOperationException("Only rank 3 (or rank 4 with size(0) == 1) arrays supported");
          }
          int rank = array.rank();
          long[] stride = array.stride();
          long offset = array.data().offset();
          Pointer pointer = array.data().pointer().position(offset);
  
          long rows = array.size(rank == 3 ? 1 : 2);
          long cols = array.size(rank == 3 ? 2 : 3);
          long channels = array.size(rank == 3 ? 0 : 1);
          boolean done = false;
  
          if (dataType < 0) {
              dataType = pointer instanceof DoublePointer ? CV_64F : CV_32F;
          }
          Mat mat = new Mat((int)Math.min(rows, Integer.MAX_VALUE), (int)Math.min(cols, Integer.MAX_VALUE),
                  CV_MAKETYPE(dataType, (int)Math.min(channels, Integer.MAX_VALUE)));
          Indexer matidx = mat.createIndexer(direct);
  
          Nd4j.getAffinityManager().ensureLocation(array, AffinityManager.Location.HOST);
  
          if (pointer instanceof FloatPointer && dataType == CV_32F) {
              FloatIndexer ptridx = FloatIndexer.create((FloatPointer)pointer, new long[] {channels, rows, cols},
                      new long[] {stride[rank == 3 ? 0 : 1], stride[rank == 3 ? 1 : 2], stride[rank == 3 ? 2 : 3]}, direct);
              FloatIndexer idx = (FloatIndexer)matidx;
              for (long k = 0; k < channels; k++) {
                  for (long i = 0; i < rows; i++) {
                      for (long j = 0; j < cols; j++) {
                          idx.put(i, j, k, ptridx.get(k, i, j));
                      }
                  }
              }
              done = true;
              ptridx.release();
          } else if (pointer instanceof DoublePointer && dataType == CV_64F) {
              DoubleIndexer ptridx = DoubleIndexer.create((DoublePointer)pointer, new long[] {channels, rows, cols},
                      new long[] {stride[rank == 3 ? 0 : 1], stride[rank == 3 ? 1 : 2], stride[rank == 3 ? 2 : 3]}, direct);
              DoubleIndexer idx = (DoubleIndexer)matidx;
              for (long k = 0; k < channels; k++) {
                  for (long i = 0; i < rows; i++) {
                      for (long j = 0; j < cols; j++) {
                          idx.put(i, j, k, ptridx.get(k, i, j));
                      }
                  }
              }
              done = true;
              ptridx.release();
          }
  
          if (!done) {
              for (long k = 0; k < channels; k++) {
                  for (long i = 0; i < rows; i++) {
                      for (long j = 0; j < cols; j++) {
                          if (rank == 3) {
                              matidx.putDouble(new long[] {i, j, k}, array.getDouble(k, i, j));
                          } else {
                              matidx.putDouble(new long[] {i, j, k}, array.getDouble(0, k, i, j));
                          }
                      }
                  }
              }
          }
  
          matidx.release();
          return mat;
      }