deeplearning4j/deeplearning4j · error · UnsupportedOperationException

Only contiguous supported

Error message

Only contiguous supported

What it means

CudaUByteDataBuffer.assign(long[], double[], boolean, long) only implements a contiguous (inc-based) assignment path; the actual contiguous branch body is commented out and both branches end in UnsupportedOperationException. When contiguous is false (non-contiguous/scattered assignment), it throws UnsupportedOperationException('Only contiguous supported'), meaning this CUDA backend method simply does not support indexed scattered writes of double data into a ubyte buffer.

Solutions

  1. Avoid this assign overload on CUDA buffers; use Nd4j's INDArray put(...) APIs implemented via the executioner instead.
  2. Copy into a CPU (heap) buffer, perform the indexed assignment there, then copy back to the device.
  3. Write values into a contiguous temporary buffer and use Nd4j create/slice operations to place them at the target indices.

Example fix

// before
buf.assign(indices, values, false, 1); // throws
// after
INDArray a = Nd4j.create(buf);
a.put(Nd4j.create(indices), Nd4j.create(values));
Defensive patterns

Strategy: try-catch

Validate before calling

if (!contiguous) throw new UnsupportedOperationException("CudaUByteDataBuffer.assign only supports contiguous writes; use INDArray.put instead");

Try / catch

try {
    buf.assign(indices, values, contiguous, inc);
} catch (UnsupportedOperationException e) {
    INDArray a = Nd4j.create(buf);
    a.put(Nd4j.create(indices), Nd4j.create(values));
}

Prevention

When it happens

Trigger: Calling assign(long[] indices, double[] data, false, inc) on a CudaUByteDataBuffer; note that the contiguous=true path also throws a bare UnsupportedOperationException because its body is commented out, so effectively any call to this overload on this buffer type fails.

Common situations: Porting CPU code that used indexed scatter writes to the CUDA backend; using put/assign APIs that internally route to this overload with contiguous=false; assuming all BaseDataBuffer subclasses implement assign identically.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of deeplearning4j/deeplearning4j@4c22ac5fe4 (2026-09-07). Data as JSON: /api/errors/84d23285126b74db. Report an issue: GitHub.

Appendix: source

Thrown at nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/buffer/CudaUByteDataBuffer.java:129


    @Override
    public void assign(long[] indices, double[] data, boolean contiguous, long inc) {

        if (indices.length != data.length)
            throw new IllegalArgumentException("Indices and data length must be the same");
        if (indices.length > length())
            throw new IllegalArgumentException("More elements than space to assign. This buffer is of length "
                            + length() + " where the indices are of length " + data.length);

        if (contiguous) {
            /*long offset = indices[0];
            Pointer p = Pointer.to(data);
            set(offset, data.length, p, inc);
            */
            throw new UnsupportedOperationException();
        } else
            throw new UnsupportedOperationException("Only contiguous supported");
    }

    @Override
    protected DataBuffer create(long length) {
        return new CudaUByteDataBuffer(length);
    }


    @Override
    public float[] getFloatsAt(long offset, long inc, int length) {
        return super.getFloatsAt(offset, inc, length);
    }

    @Override
    public double[] getDoublesAt(long offset, long inc, int length) {
        return ArrayUtil.toDoubles(getFloatsAt(offset, inc, length));
    }

View on GitHub (pinned to 4c22ac5fe4)