Skip to content

Commit f1c0e01

Browse files
committed
[Android] Add unknown Tensor type instead of crash
1 parent 98c2c53 commit f1c0e01

File tree

1 file changed

+22
-1
lines changed
  • extension/android/executorch_android/src/main/java/org/pytorch/executorch

1 file changed

+22
-1
lines changed

extension/android/executorch_android/src/main/java/org/pytorch/executorch/Tensor.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,27 @@ public String toString() {
630630
}
631631
}
632632

633+
static class Tensor_unknown extends Tensor {
634+
private final ByteBuffer data;
635+
private final DType myDtype;
636+
637+
private Tensor_raw_data_16b(ByteBuffer data, long[] shape, DType dtype) {
638+
super(shape);
639+
this.data = data;
640+
this.myDtype = dtype;
641+
}
642+
643+
@Override
644+
public DType dtype() {
645+
return myDtype;
646+
}
647+
648+
@Override
649+
public String toString() {
650+
return String.format("Tensor(%s, dtype=%d)", Arrays.toString(shape), this.myDtype);
651+
}
652+
}
653+
633654
// region checks
634655
private static void checkArgument(boolean expression, String errorMessage, Object... args) {
635656
if (!expression) {
@@ -675,7 +696,7 @@ private static Tensor nativeNewTensor(
675696
} else if (DType.INT8.jniCode == dtype) {
676697
tensor = new Tensor_int8(data, shape);
677698
} else {
678-
throw new IllegalArgumentException("Unknown Tensor dtype");
699+
tensor = new Tensor_unknown(data, shape, dtype);
679700
}
680701
tensor.mHybridData = hybridData;
681702
return tensor;

0 commit comments

Comments
 (0)