Skip to content

Commit cb4bec5

Browse files
committed
Replace withInitScope with liftToInitScope
Signed-off-by: Ryan Nett <[email protected]>
1 parent fbd5ad0 commit cb4bec5

File tree

2 files changed

+10
-25
lines changed

2 files changed

+10
-25
lines changed

tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/ExecutionEnvironment.java

+1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ default ExecutionEnvironment initEnv() {
115115
*
116116
* <p><b>Should generally only be used internally, prefer {@link
117117
* org.tensorflow.op.Ops#initScope()}.</b>
118+
* @throws IllegalArgumentException if the op or one of its inputs can't be made an init op.
118119
*/
119120
void registerInitOp(Operation op);
120121

tensorflow-core/tensorflow-core-generator/src/main/java/org/tensorflow/processor/operator/OperatorProcessor.java

+9-25
Original file line numberDiff line numberDiff line change
@@ -566,33 +566,17 @@ private static TypeSpec buildTopClass(OpsSpec spec) {
566566
.addJavadoc("Returns an API that builds init operations.\n" + initScopeComment)
567567
.build());
568568

569+
TypeVariableName T = TypeVariableName.get("T").withBounds(Names.Operand);
569570
opsBuilder.addMethod(
570-
MethodSpec.methodBuilder("withInitScope")
571-
.addTypeVariable(TypeVariableName.get("R"))
571+
MethodSpec.methodBuilder("liftToInitScope")
572+
.addTypeVariable(T)
572573
.addModifiers(Modifier.PUBLIC)
573-
.addParameter(
574-
ParameterizedTypeName.get(
575-
ClassName.get(Function.class), Names.Ops, TypeVariableName.get("R")),
576-
"block")
577-
.returns(TypeVariableName.get("R"))
578-
.addStatement("return block.apply(initScope())")
579-
.addJavadoc(
580-
"Call {@code block} with an init scope.\n"
581-
+ initScopeComment
582-
+ "\n@see #initScope()")
583-
.build());
584-
585-
opsBuilder.addMethod(
586-
MethodSpec.methodBuilder("withInitScope")
587-
.addModifiers(Modifier.PUBLIC)
588-
.addParameter(
589-
ParameterizedTypeName.get(ClassName.get(Consumer.class), Names.Ops), "block")
590-
.returns(TypeName.VOID)
591-
.addStatement("block.accept(initScope())")
592-
.addJavadoc(
593-
"Call {@code block} with an init scope.\n"
594-
+ initScopeComment
595-
+ "\n@see #initScope()")
574+
.addParameter(T, "op")
575+
.returns(T)
576+
.addStatement("scope.env().registerInitOp(op.op())")
577+
.addStatement("return op")
578+
.addJavadoc("Make {@code op} an init operation, doing the same for all of it's inputs (and control inputs).\n" + initScopeComment +
579+
"\n@throws IllegalArgumentException if the op or one of its inputs can't be made an init op.")
596580
.build());
597581

598582
opsBuilder.addMethod(

0 commit comments

Comments
 (0)