Skip to content

Commit

Permalink
[api] Fixes NDArrayAdapter toDevice() and toType() behavior (#1839)
Browse files Browse the repository at this point in the history
Change-Id: Iaf90c609a832f3f7bc2a863bdb44cfc7df34dbae
  • Loading branch information
frankfliu authored Jul 26, 2022
1 parent c04c9ab commit 2763699
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions api/src/main/java/ai/djl/ndarray/NDArrayAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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} */
Expand Down

0 comments on commit 2763699

Please sign in to comment.