diff --git a/api/src/main/java/ai/djl/ndarray/NDArrayAdapter.java b/api/src/main/java/ai/djl/ndarray/NDArrayAdapter.java index 541e93d7590..23b788cb39f 100644 --- a/api/src/main/java/ai/djl/ndarray/NDArrayAdapter.java +++ b/api/src/main/java/ai/djl/ndarray/NDArrayAdapter.java @@ -133,19 +133,26 @@ public Shape getShape() { /** {@inheritDoc} */ @Override public NDArray toDevice(Device device, boolean copy) { - if (device.equals(getDevice()) && !copy) { + if (device.equals(getDevice())) { + if (copy) { + return duplicate(); + } return this; } - return duplicate(); + throw new UnsupportedOperationException(UNSUPPORTED_MSG); } /** {@inheritDoc} */ @Override public NDArray toType(DataType dataType, boolean copy) { - if (dataType.equals(getDataType()) && !copy) { + if (dataType.equals(getDataType())) { + if (copy) { + return duplicate(); + } return this; } - return duplicate(); + // TODO: each engine should override this method + throw new UnsupportedOperationException(UNSUPPORTED_MSG); } /** {@inheritDoc} */