Repository navigation
Commit c17afa3
committed
Make bool(), int() and float() of an ExecuTorchResult raise TypeError
An ExecuTorchResult supports the buffer protocol but has no truth value or
number conversion of its own. So Python falls back to defaults that can give
wrong answers without an error: bool(result) is always True, and int() and
float() parse the raw bytes as text, so a uint8 result that holds 55 (the
character "7") gives 7.
Now all three raise TypeError and say how to convert the result first:
bool(result)
# TypeError: ExecuTorchResult has no truth value. Convert it first, for
# example with numpy.asarray(result) or torch.from_dlpack(result).
Tested with the standalone no-ATen build: a new test checks that all three
raise TypeError, and it fails without this change.1 parent 656de46 commit c17afa3
3 files changed
Lines changed: 33 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
106 | | - | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
107 | 109 | | |
108 | 110 | | |
109 | 111 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5447 | 5447 | | |
5448 | 5448 | | |
5449 | 5449 | | |
| 5450 | + | |
| 5451 | + | |
| 5452 | + | |
| 5453 | + | |
| 5454 | + | |
| 5455 | + | |
| 5456 | + | |
| 5457 | + | |
| 5458 | + | |
5450 | 5459 | | |
5451 | 5460 | | |
5452 | 5461 | | |
| |||
5579 | 5588 | | |
5580 | 5589 | | |
5581 | 5590 | | |
| 5591 | + | |
| 5592 | + | |
| 5593 | + | |
| 5594 | + | |
| 5595 | + | |
| 5596 | + | |
5582 | 5597 | | |
5583 | 5598 | | |
5584 | 5599 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
211 | 211 | | |
212 | 212 | | |
213 | 213 | | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
214 | 229 | | |
215 | 230 | | |
216 | 231 | | |
| |||
0 commit comments