Skip to content

Commit d877519

Browse files
committed
[Android] Remove runtime internal evalue list types
List types are used in runtime only. Exported model inputs and outputs won't use them. Therefore, we remove them from Java public API.
1 parent 6ac19cc commit d877519

File tree

2 files changed

+2
-216
lines changed

2 files changed

+2
-216
lines changed

extension/android/src/main/java/org/pytorch/executorch/EValue.java

Lines changed: 2 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -44,26 +44,13 @@ public class EValue {
4444
private static final int TYPE_CODE_INT = 4;
4545
private static final int TYPE_CODE_BOOL = 5;
4646

47-
private static final int TYPE_CODE_LIST_BOOL = 6;
48-
private static final int TYPE_CODE_LIST_DOUBLE = 7;
49-
private static final int TYPE_CODE_LIST_INT = 8;
50-
private static final int TYPE_CODE_LIST_TENSOR = 9;
51-
private static final int TYPE_CODE_LIST_SCALAR = 10;
52-
private static final int TYPE_CODE_LIST_OPTIONAL_TENSOR = 11;
53-
5447
private String[] TYPE_NAMES = {
5548
"None",
5649
"Tensor",
5750
"String",
5851
"Double",
5952
"Int",
6053
"Bool",
61-
"ListBool",
62-
"ListDouble",
63-
"ListInt",
64-
"ListTensor",
65-
"ListScalar",
66-
"ListOptionalTensor",
6754
};
6855

6956
@DoNotStrip private final int mTypeCode;
@@ -104,31 +91,6 @@ public boolean isString() {
10491
return TYPE_CODE_STRING == this.mTypeCode;
10592
}
10693

107-
@DoNotStrip
108-
public boolean isBoolList() {
109-
return TYPE_CODE_LIST_BOOL == this.mTypeCode;
110-
}
111-
112-
@DoNotStrip
113-
public boolean isIntList() {
114-
return TYPE_CODE_LIST_INT == this.mTypeCode;
115-
}
116-
117-
@DoNotStrip
118-
public boolean isDoubleList() {
119-
return TYPE_CODE_LIST_DOUBLE == this.mTypeCode;
120-
}
121-
122-
@DoNotStrip
123-
public boolean isTensorList() {
124-
return TYPE_CODE_LIST_TENSOR == this.mTypeCode;
125-
}
126-
127-
@DoNotStrip
128-
public boolean isOptionalTensorList() {
129-
return TYPE_CODE_LIST_OPTIONAL_TENSOR == this.mTypeCode;
130-
}
131-
13294
/** Creates a new {@code EValue} of type {@code Optional} that contains no value. */
13395
@DoNotStrip
13496
public static EValue optionalNone() {
@@ -175,46 +137,6 @@ public static EValue from(String value) {
175137
return iv;
176138
}
177139

178-
/** Creates a new {@code EValue} of type {@code List[bool]}. */
179-
@DoNotStrip
180-
public static EValue listFrom(boolean... list) {
181-
final EValue iv = new EValue(TYPE_CODE_LIST_BOOL);
182-
iv.mData = list;
183-
return iv;
184-
}
185-
186-
/** Creates a new {@code EValue} of type {@code List[int]}. */
187-
@DoNotStrip
188-
public static EValue listFrom(long... list) {
189-
final EValue iv = new EValue(TYPE_CODE_LIST_INT);
190-
iv.mData = list;
191-
return iv;
192-
}
193-
194-
/** Creates a new {@code EValue} of type {@code List[double]}. */
195-
@DoNotStrip
196-
public static EValue listFrom(double... list) {
197-
final EValue iv = new EValue(TYPE_CODE_LIST_DOUBLE);
198-
iv.mData = list;
199-
return iv;
200-
}
201-
202-
/** Creates a new {@code EValue} of type {@code List[Tensor]}. */
203-
@DoNotStrip
204-
public static EValue listFrom(Tensor... list) {
205-
final EValue iv = new EValue(TYPE_CODE_LIST_TENSOR);
206-
iv.mData = list;
207-
return iv;
208-
}
209-
210-
/** Creates a new {@code EValue} of type {@code List[Optional[Tensor]]}. */
211-
@DoNotStrip
212-
public static EValue listFrom(Optional<Tensor>... list) {
213-
final EValue iv = new EValue(TYPE_CODE_LIST_OPTIONAL_TENSOR);
214-
iv.mData = list;
215-
return iv;
216-
}
217-
218140
@DoNotStrip
219141
public Tensor toTensor() {
220142
preconditionType(TYPE_CODE_TENSOR, mTypeCode);
@@ -245,36 +167,6 @@ public String toStr() {
245167
return (String) mData;
246168
}
247169

248-
@DoNotStrip
249-
public boolean[] toBoolList() {
250-
preconditionType(TYPE_CODE_LIST_BOOL, mTypeCode);
251-
return (boolean[]) mData;
252-
}
253-
254-
@DoNotStrip
255-
public long[] toIntList() {
256-
preconditionType(TYPE_CODE_LIST_INT, mTypeCode);
257-
return (long[]) mData;
258-
}
259-
260-
@DoNotStrip
261-
public double[] toDoubleList() {
262-
preconditionType(TYPE_CODE_LIST_DOUBLE, mTypeCode);
263-
return (double[]) mData;
264-
}
265-
266-
@DoNotStrip
267-
public Tensor[] toTensorList() {
268-
preconditionType(TYPE_CODE_LIST_TENSOR, mTypeCode);
269-
return (Tensor[]) mData;
270-
}
271-
272-
@DoNotStrip
273-
public Optional<Tensor>[] toOptionalTensorList() {
274-
preconditionType(TYPE_CODE_LIST_OPTIONAL_TENSOR, mTypeCode);
275-
return (Optional<Tensor>[]) mData;
276-
}
277-
278170
private void preconditionType(int typeCodeExpected, int typeCode) {
279171
if (typeCode != typeCodeExpected) {
280172
throw new IllegalStateException(
@@ -294,8 +186,7 @@ private String getTypeName(int typeCode) {
294186
* Serializes an {@code EValue} into a byte array.
295187
*
296188
* @return The serialized byte array.
297-
* @apiNote This method is experimental and subject to change without notice. This does NOT
298-
* supoprt list type.
189+
* @apiNote This method is experimental and subject to change without notice.
299190
*/
300191
public byte[] toByteArray() {
301192
if (isNone()) {
@@ -331,8 +222,7 @@ public byte[] toByteArray() {
331222
*
332223
* @param bytes The byte array to deserialize from.
333224
* @return The deserialized {@code EValue}.
334-
* @apiNote This method is experimental and subject to change without notice. This does NOT list
335-
* type.
225+
* @apiNote This method is experimental and subject to change without notice.
336226
*/
337227
public static EValue fromByteArray(byte[] bytes) {
338228
ByteBuffer buffer = ByteBuffer.wrap(bytes);

extension/android_test/src/test/java/org/pytorch/executorch/EValueTest.java

Lines changed: 0 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -66,70 +66,6 @@ public void testStringValue() {
6666
assertEquals(evalue.toStr(), "a");
6767
}
6868

69-
@Test
70-
public void testBoolListValue() {
71-
boolean[] value = {true, false, true};
72-
EValue evalue = EValue.listFrom(value);
73-
assertTrue(evalue.isBoolList());
74-
assertTrue(Arrays.equals(value, evalue.toBoolList()));
75-
}
76-
77-
@Test
78-
public void testIntListValue() {
79-
long[] value = {Long.MIN_VALUE, 0, Long.MAX_VALUE};
80-
EValue evalue = EValue.listFrom(value);
81-
assertTrue(evalue.isIntList());
82-
assertTrue(Arrays.equals(value, evalue.toIntList()));
83-
}
84-
85-
@Test
86-
public void testDoubleListValue() {
87-
double[] value = {Double.MIN_VALUE, 0.1d, 0.01d, 0.001d, Double.MAX_VALUE};
88-
EValue evalue = EValue.listFrom(value);
89-
assertTrue(evalue.isDoubleList());
90-
assertTrue(Arrays.equals(value, evalue.toDoubleList()));
91-
}
92-
93-
@Test
94-
public void testTensorListValue() {
95-
long[][] data = {{1, 2, 3}, {1, 2, 3, 4, 5, 6}};
96-
long[][] shape = {{1, 3}, {2, 3}};
97-
Tensor[] tensors = {Tensor.fromBlob(data[0], shape[0]), Tensor.fromBlob(data[1], shape[1])};
98-
99-
EValue evalue = EValue.listFrom(tensors);
100-
assertTrue(evalue.isTensorList());
101-
102-
assertTrue(Arrays.equals(evalue.toTensorList()[0].shape, shape[0]));
103-
assertTrue(Arrays.equals(evalue.toTensorList()[0].getDataAsLongArray(), data[0]));
104-
105-
assertTrue(Arrays.equals(evalue.toTensorList()[1].shape, shape[1]));
106-
assertTrue(Arrays.equals(evalue.toTensorList()[1].getDataAsLongArray(), data[1]));
107-
}
108-
109-
@Test
110-
@SuppressWarnings("unchecked")
111-
public void testOptionalTensorListValue() {
112-
long[][] data = {{1, 2, 3}, {1, 2, 3, 4, 5, 6}};
113-
long[][] shape = {{1, 3}, {2, 3}};
114-
115-
EValue evalue =
116-
EValue.listFrom(
117-
Optional.<Tensor>empty(),
118-
Optional.of(Tensor.fromBlob(data[0], shape[0])),
119-
Optional.of(Tensor.fromBlob(data[1], shape[1])));
120-
assertTrue(evalue.isOptionalTensorList());
121-
122-
assertTrue(!evalue.toOptionalTensorList()[0].isPresent());
123-
124-
assertTrue(evalue.toOptionalTensorList()[1].isPresent());
125-
assertTrue(Arrays.equals(evalue.toOptionalTensorList()[1].get().shape, shape[0]));
126-
assertTrue(Arrays.equals(evalue.toOptionalTensorList()[1].get().getDataAsLongArray(), data[0]));
127-
128-
assertTrue(evalue.toOptionalTensorList()[2].isPresent());
129-
assertTrue(Arrays.equals(evalue.toOptionalTensorList()[2].get().shape, shape[1]));
130-
assertTrue(Arrays.equals(evalue.toOptionalTensorList()[2].get().getDataAsLongArray(), data[1]));
131-
}
132-
13369
@Test
13470
public void testAllIllegalCast() {
13571
EValue evalue = EValue.optionalNone();
@@ -174,46 +110,6 @@ public void testAllIllegalCast() {
174110
fail("Should have thrown an exception");
175111
} catch (IllegalStateException e) {
176112
}
177-
178-
// try bool list
179-
assertFalse(evalue.isBoolList());
180-
try {
181-
evalue.toBoolList();
182-
fail("Should have thrown an exception");
183-
} catch (IllegalStateException e) {
184-
}
185-
186-
// try int list
187-
assertFalse(evalue.isIntList());
188-
try {
189-
evalue.toIntList();
190-
fail("Should have thrown an exception");
191-
} catch (IllegalStateException e) {
192-
}
193-
194-
// try double list
195-
assertFalse(evalue.isDoubleList());
196-
try {
197-
evalue.toBool();
198-
fail("Should have thrown an exception");
199-
} catch (IllegalStateException e) {
200-
}
201-
202-
// try Tensor list
203-
assertFalse(evalue.isTensorList());
204-
try {
205-
evalue.toTensorList();
206-
fail("Should have thrown an exception");
207-
} catch (IllegalStateException e) {
208-
}
209-
210-
// try optional Tensor list
211-
assertFalse(evalue.isOptionalTensorList());
212-
try {
213-
evalue.toOptionalTensorList();
214-
fail("Should have thrown an exception");
215-
} catch (IllegalStateException e) {
216-
}
217113
}
218114

219115
@Test

0 commit comments

Comments
 (0)