Skip to content

Commit 50ee05e

Browse files
authored
Convert Experimental, DType, MethodMetadata from Java to Kotlin
Differential Revision: D106394605 Pull Request resolved: #19775
1 parent fb3f6eb commit 50ee05e

7 files changed

Lines changed: 31 additions & 117 deletions

File tree

extension/android/BUCK

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,19 @@ non_fbcode_target(_kind = fb_android_library,
88
warnings_as_errors = False,
99
required_for_source_only_abi = True,
1010
srcs = [
11-
"executorch_android/src/main/java/org/pytorch/executorch/DType.java",
11+
"executorch_android/src/main/java/org/pytorch/executorch/DType.kt",
1212
"executorch_android/src/main/java/org/pytorch/executorch/EValue.java",
1313
"executorch_android/src/main/java/org/pytorch/executorch/ExecuTorchRuntime.java",
1414
"executorch_android/src/main/java/org/pytorch/executorch/ExecutorchRuntimeException.java",
15-
"executorch_android/src/main/java/org/pytorch/executorch/MethodMetadata.java",
15+
"executorch_android/src/main/java/org/pytorch/executorch/MethodMetadata.kt",
1616
"executorch_android/src/main/java/org/pytorch/executorch/Module.java",
1717
"executorch_android/src/main/java/org/pytorch/executorch/Tensor.java",
18-
"executorch_android/src/main/java/org/pytorch/executorch/annotations/Experimental.java",
18+
"executorch_android/src/main/java/org/pytorch/executorch/annotations/Experimental.kt",
1919
],
2020
autoglob = False,
21-
language = "JAVA",
21+
language = "KOTLIN",
22+
pure_kotlin = False,
23+
extra_kotlinc_arguments = ["-Xjvm-default=all"],
2224
deps = [
2325
"//fbandroid/java/com/facebook/jni:jni",
2426
"//fbandroid/libraries/soloader/java/com/facebook/soloader/nativeloader:nativeloader",

extension/android/executorch_android/src/main/java/org/pytorch/executorch/DType.java renamed to extension/android/executorch_android/src/main/java/org/pytorch/executorch/DType.kt

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9-
package org.pytorch.executorch;
9+
package org.pytorch.executorch
1010

11-
import org.pytorch.executorch.annotations.Experimental;
11+
import org.pytorch.executorch.annotations.Experimental
1212

1313
/**
1414
* Codes representing tensor data types.
1515
*
16-
* <p>Warning: These APIs are experimental and subject to change without notice
16+
* Warning: These APIs are experimental and subject to change without notice
1717
*/
1818
@Experimental
19-
public enum DType {
19+
enum class DType(@JvmField val jniCode: Int) {
2020
// NOTE: "jniCode" must be kept in sync with scalar_type.h.
2121
// NOTE: Never serialize "jniCode", because it can change between releases.
2222

@@ -68,18 +68,10 @@ public enum DType {
6868
BITS16(22),
6969
;
7070

71-
final int jniCode;
72-
73-
DType(int jniCode) {
74-
this.jniCode = jniCode;
75-
}
76-
77-
public static DType fromJniCode(int jniCode) {
78-
for (DType dtype : values()) {
79-
if (dtype.jniCode == jniCode) {
80-
return dtype;
81-
}
82-
}
83-
throw new IllegalArgumentException("No DType found for jniCode " + jniCode);
71+
companion object {
72+
@JvmStatic
73+
fun fromJniCode(jniCode: Int): DType =
74+
entries.find { it.jniCode == jniCode }
75+
?: throw IllegalArgumentException("No DType found for jniCode $jniCode")
8476
}
8577
}

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

Lines changed: 0 additions & 34 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
package org.pytorch.executorch
10+
11+
/** Immutable metadata for a method in a Module. */
12+
class MethodMetadata internal constructor(val name: String, val backends: Array<String>)

extension/android/executorch_android/src/main/java/org/pytorch/executorch/annotations/Experimental.java renamed to extension/android/executorch_android/src/main/java/org/pytorch/executorch/annotations/Experimental.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9-
package org.pytorch.executorch.annotations;
9+
package org.pytorch.executorch.annotations
1010

1111
/**
1212
* This annotation indicates that an API is experimental and may change or be removed at any time.
1313
* It does not provide any guarantees for API stability or backward-compatibility.
1414
*
15-
* <p>This status is not permanent, and APIs marked with this annotation will need to be either made
15+
* This status is not permanent, and APIs marked with this annotation will need to be either made
1616
* more robust or removed in the future.
1717
*/
18-
public @interface Experimental {}
18+
@Retention(AnnotationRetention.BINARY)
19+
annotation class Experimental

extension/android/executorch_android/src/main/java/org/pytorch/executorch/annotations/package-info.java

Lines changed: 0 additions & 2 deletions
This file was deleted.

extension/android/executorch_android/src/main/java/org/pytorch/executorch/package-info.java

Lines changed: 0 additions & 57 deletions
This file was deleted.

0 commit comments

Comments
 (0)