Skip to content

Commit 0ebf6b7

Browse files
kirklandsignmeta-codesync[bot]
authored andcommitted
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: D106557156
1 parent b1446cc commit 0ebf6b7

3 files changed

Lines changed: 766 additions & 1197 deletions

File tree

extension/android/BUCK

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ non_fbcode_target(_kind = fb_android_library,
1414
"executorch_android/src/main/java/org/pytorch/executorch/ExecutorchRuntimeException.kt",
1515
"executorch_android/src/main/java/org/pytorch/executorch/MethodMetadata.kt",
1616
"executorch_android/src/main/java/org/pytorch/executorch/Module.java",
17-
"executorch_android/src/main/java/org/pytorch/executorch/Tensor.java",
17+
"executorch_android/src/main/java/org/pytorch/executorch/Tensor.kt",
1818
"executorch_android/src/main/java/org/pytorch/executorch/annotations/Experimental.kt",
1919
],
2020
autoglob = False,

0 commit comments

Comments
 (0)