{"record":{"id":"84d23285126b74db","repo":"deeplearning4j/deeplearning4j","slug":"only-contiguous-supported","errorCode":null,"errorMessage":"Only contiguous supported","messagePattern":"Only contiguous supported","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/buffer/CudaUByteDataBuffer.java","lineNumber":129,"sourceCode":"\n\n    @Override\n    public void assign(long[] indices, double[] data, boolean contiguous, long inc) {\n\n        if (indices.length != data.length)\n            throw new IllegalArgumentException(\"Indices and data length must be the same\");\n        if (indices.length > length())\n            throw new IllegalArgumentException(\"More elements than space to assign. This buffer is of length \"\n                            + length() + \" where the indices are of length \" + data.length);\n\n        if (contiguous) {\n            /*long offset = indices[0];\n            Pointer p = Pointer.to(data);\n            set(offset, data.length, p, inc);\n            */\n            throw new UnsupportedOperationException();\n        } else\n            throw new UnsupportedOperationException(\"Only contiguous supported\");\n    }\n\n    @Override\n    protected DataBuffer create(long length) {\n        return new CudaUByteDataBuffer(length);\n    }\n\n\n    @Override\n    public float[] getFloatsAt(long offset, long inc, int length) {\n        return super.getFloatsAt(offset, inc, length);\n    }\n\n    @Override\n    public double[] getDoublesAt(long offset, long inc, int length) {\n        return ArrayUtil.toDoubles(getFloatsAt(offset, inc, length));\n    }\n","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/deeplearning4j/deeplearning4j/blob/4c22ac5fe4a8350d05d224e7f4499429f7f69c93/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/buffer/CudaUByteDataBuffer.java#L111-L147","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Avoid this assign overload on CUDA buffers; use Nd4j's INDArray put(...) APIs implemented via the executioner instead.","Copy into a CPU (heap) buffer, perform the indexed assignment there, then copy back to the device.","Write values into a contiguous temporary buffer and use Nd4j create/slice operations to place them at the target indices."],"exampleFix":"// before\nbuf.assign(indices, values, false, 1); // throws\n// after\nINDArray a = Nd4j.create(buf);\na.put(Nd4j.create(indices), Nd4j.create(values));","handlingStrategy":"try-catch","validationCode":"if (!contiguous) throw new UnsupportedOperationException(\"CudaUByteDataBuffer.assign only supports contiguous writes; use INDArray.put instead\");","typeGuard":null,"tryCatchPattern":"try {\n    buf.assign(indices, values, contiguous, inc);\n} catch (UnsupportedOperationException e) {\n    INDArray a = Nd4j.create(buf);\n    a.put(Nd4j.create(indices), Nd4j.create(values));\n}","preventionTips":["Avoid raw buffer assign on CUDA backends; prefer INDArray-level APIs.","Treat per-dtype buffer assign overloads as unimplemented on GPU backends.","Route scattered writes through the executioner (put/putScalar).","Test CPU-to-CUDA ported code paths for backend feature gaps."],"tags":["nd4j","cuda","unsupported","buffer"],"backgroundTag":"unsupported-operation","analyzedSha":"4c22ac5fe4a8350d05d224e7f4499429f7f69c93","analyzedAt":"2026-09-07T05:27:04.714Z","contentChangedAt":"2026-09-07T05:27:04.714Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}