Commit 0ebf6b7
Convert Tensor from Java to Kotlin (#19823)
Summary:
Pull Request resolved: #19823
Convert `Tensor.java` to idiomatic Kotlin while preserving full JNI and Java interop compatibility:
- `abstract class Tensor` with `protected constructor` for subclass access
- `JvmField DoNotStrip val shape` for direct JNI field access
- `JvmStatic` on all companion factory methods (`fromBlob`, `ones`, `zeros`, `numel`, `allocate*Buffer`)
- `DoNotStrip` on JNI-called methods (`nativeNewTensor`, `dtypeJniCode`, `getRawDataBuffer`)
- Nested tensor type classes (`Tensor_uint8`, `Tensor_int8`, etc.) with `internal constructor`
- `halfBitsToFloat` moved to `Tensor_float16.Companion`, using `Float.fromBits()`
- `when` expressions replace `switch` statements and `if-else` chains
- Kotlin array initializers for `ones()`/`zeros()`
- Updated BUCK to reference `.kt` source
Differential Revision: D1065571561 parent b1446cc commit 0ebf6b7
3 files changed
Lines changed: 766 additions & 1197 deletions
File tree
- extension/android
- executorch_android/src/main/java/org/pytorch/executorch
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| |||
0 commit comments