106
106
import org .tensorflow .op .core .IdentityN ;
107
107
import org .tensorflow .op .core .If ;
108
108
import org .tensorflow .op .core .ImmutableConst ;
109
- import org .tensorflow .op .core .Init ;
110
109
import org .tensorflow .op .core .InitializeTable ;
111
110
import org .tensorflow .op .core .InitializeTableFromTextFile ;
112
111
import org .tensorflow .op .core .InplaceAdd ;
295
294
import org .tensorflow .op .core .VariableShape ;
296
295
import org .tensorflow .op .core .Where ;
297
296
import org .tensorflow .op .core .While ;
297
+ import org .tensorflow .op .core .XlaConvV2 ;
298
+ import org .tensorflow .op .core .XlaDotV2 ;
299
+ import org .tensorflow .op .core .XlaSetDynamicDimensionSize ;
300
+ import org .tensorflow .op .core .XlaSpmdFullToShardShape ;
301
+ import org .tensorflow .op .core .XlaSpmdShardToFullShape ;
302
+ import org .tensorflow .op .core .XlaVariadicSort ;
298
303
import org .tensorflow .op .core .Zeros ;
299
304
import org .tensorflow .op .core .ZerosLike ;
300
305
import org .tensorflow .types .TBool ;
@@ -366,20 +371,20 @@ public final class Ops {
366
371
367
372
public final SparseOps sparse ;
368
373
369
- public final TpuOps tpu ;
370
-
371
374
public final BitwiseOps bitwise ;
372
375
376
+ public final TpuOps tpu ;
377
+
373
378
public final MathOps math ;
374
379
375
380
public final AudioOps audio ;
376
381
377
382
public final SignalOps signal ;
378
383
379
- public final QuantizationOps quantization ;
380
-
381
384
public final TrainOps train ;
382
385
386
+ public final QuantizationOps quantization ;
387
+
383
388
private final Scope scope ;
384
389
385
390
private Ops (Scope scope ) {
@@ -397,13 +402,13 @@ private Ops(Scope scope) {
397
402
random = new RandomOps (this );
398
403
strings = new StringsOps (this );
399
404
sparse = new SparseOps (this );
400
- tpu = new TpuOps (this );
401
405
bitwise = new BitwiseOps (this );
406
+ tpu = new TpuOps (this );
402
407
math = new MathOps (this );
403
408
audio = new AudioOps (this );
404
409
signal = new SignalOps (this );
405
- quantization = new QuantizationOps (this );
406
410
train = new TrainOps (this );
411
+ quantization = new QuantizationOps (this );
407
412
}
408
413
409
414
/**
@@ -1952,14 +1957,15 @@ public Constant<TFloat32> constant(Shape shape, FloatDataBuffer data) {
1952
1957
}
1953
1958
1954
1959
/**
1955
- * Creates a scalar of {@code type}, with the value of {@code number}. {@code number} may be truncated if it does not
1956
- * fit in the target type.
1960
+ * Creates a scalar of {@code type}, with the value of {@code number}. {@code number} may be
1961
+ * truncated if it does not fit in the target type.
1957
1962
*
1958
- * @param type the type of tensor to create. Must be concrete (i.e. not {@link org.tensorflow.types.family.TFloating})
1963
+ * @param type the type of tensor to create. Must be concrete (i.e. not {@link
1964
+ * org.tensorflow.types.family.TFloating})
1959
1965
* @param number the value of the tensor
1960
1966
* @return a constant of the passed type
1961
- * @throws IllegalArgumentException if the type is abstract (i.e. {@link org.tensorflow.types.family.TFloating}) or
1962
- * unknown.
1967
+ * @throws IllegalArgumentException if the type is abstract (i.e. {@link
1968
+ * org.tensorflow.types.family.TFloating}) or unknown.
1963
1969
*/
1964
1970
public <T extends TNumber > Constant <T > constant (Class <T > type , Number number ) {
1965
1971
return Constant .tensorOf (scope , type , number );
@@ -1994,11 +2000,12 @@ public <T extends TType> Constant<T> constant(Class<T> type, Shape shape, ByteDa
1994
2000
}
1995
2001
1996
2002
/**
1997
- * Create a constant by making an immutable copy of {@code tensor}. {@code tensor} may be closed afterwards without
1998
- * issue.
2003
+ * Create a constant by making an immutable copy of {@code tensor}. {@code tensor} may be closed
2004
+ * afterwards without issue.
1999
2005
*
2000
2006
* <p>Note: this endpoint cannot be simply called {@code constant} since it will conflict with
2001
- * other endpoints accepting an NdArray in parameter {e.g. {@link #tensorOf(Scope, FloatNdArray)}}.
2007
+ * other endpoints accepting an NdArray in parameter {e.g. {@link #tensorOf(Scope,
2008
+ * FloatNdArray)}}.
2002
2009
*
2003
2010
* @param tensor a Tensor holding the constant value
2004
2011
* @return a constant of the same data type as `tensor`
@@ -2008,8 +2015,8 @@ public <T extends TType> Constant<T> constantOf(T tensor) {
2008
2015
}
2009
2016
2010
2017
/**
2011
- * Creates a scalar of the same type as {@code toMatch}, with the value of {@code number}. {@code number} may be
2012
- * truncated if it does not fit in the target type.
2018
+ * Creates a scalar of the same type as {@code toMatch}, with the value of {@code number}. {@code
2019
+ * number} may be truncated if it does not fit in the target type.
2013
2020
*
2014
2021
* @param toMatch the operand providing the target type
2015
2022
* @param number the value of the tensor
@@ -2993,80 +3000,6 @@ public <T extends TType> ImmutableConst<T> immutableConst(Class<T> dtype, Shape
2993
3000
return ImmutableConst .create (scope , dtype , shape , memoryRegionName );
2994
3001
}
2995
3002
2996
- /**
2997
- * Factory method to create an operation executing all initializers of a graph.
2998
- *
2999
- * <p>All initializers added to a graph via
3000
- * {@link org.tensorflow.op.core.Init#add(Scope, Op) tf.initAdd} are grouped together as a single
3001
- * unit of computation in the graph. This operation must then be added to any graph using one or
3002
- * more {@link Variable variables} and executed once before running the graph so the variable
3003
- * states are initialized properly.</p>
3004
- *
3005
- * <p>When the graph is built by the same process that is running the session, the initializers
3006
- * can be invoked by executing this single endpoint. For example:</p>
3007
- * <pre>{@code
3008
- * try (Graph g = new Graph()) {
3009
- * Variable<TInt32> x = tf.variable(tf.constant(10)); // initAdd is called implicitly
3010
- * Variable<TInt32> y = tf.variable(tf.constant(20)); // idem
3011
- * Add<TInt32> z = tf.math.add(x, y);
3012
- *
3013
- * try (Session s = new Session(g)) {
3014
- * s.run(tf.init()); // initialize all variables
3015
- *
3016
- * try (TInt32 t = (TInt32)s.runner().fetch(z).run().get(0)) {
3017
- * assertEquals(30, t.data().getInt());
3018
- * }
3019
- * }
3020
- * }
3021
- * }</pre>
3022
- *
3023
- * <p>When the graph is built by a separate process, the initializers can be invoked by running
3024
- * the init op by its name, which defaults to {@link org.tensorflow.op.core.Init#DEFAULT_NAME}.
3025
- * For example:</p>
3026
- * <pre>{@code
3027
- * // Building the model
3028
- * try (Graph g = new Graph()) {
3029
- * Variable<TInt32> x = tf.variable(tf.constant(10)); // initAdd is called implicitly
3030
- * Variable<TInt32> y = tf.variable(tf.constant(20)); // idem
3031
- * Add<TInt32> z = tf.withName("z").math.add(x, y);
3032
- *
3033
- * tf.init(); // add variables initializers to the graph, as Init.DEFAULT_NAME
3034
- * // ...exporting graph as a saved model...
3035
- * }
3036
- *
3037
- * ...
3038
- *
3039
- * // Running the model
3040
- * try (SavedModelBundle model = SavedModelBundle.load("/path/to/model", "train")) {
3041
- * model.session().run(Init.DEFAULT_NAME);
3042
- *
3043
- * try (TInt32 t = (TInt32)s.runner().fetch("z").run().get(0)) {
3044
- * assertEquals(30, t.data().getInt());
3045
- * }
3046
- * }
3047
- * }</pre>
3048
- *
3049
- * @return an op grouping all initializers added to the graph
3050
- * @throws IllegalArgumentException if the execution environment in scope is not a graph
3051
- */
3052
- public Init init () {
3053
- return Init .create (scope );
3054
- }
3055
-
3056
- /**
3057
- * Register an op as an initializer of the graph.
3058
- *
3059
- * <p>Registered initializers are then grouped as a single unit of computation by adding
3060
- * and executing an {@link org.tensorflow.op.core.Init#create(Scope) init} operation from a graph
3061
- * session. This is a no-op if executed in an eager session.
3062
- *
3063
- * @param initializer
3064
- * @see org.tensorflow.op.core.Init#create(Scope) init
3065
- */
3066
- public void initAdd (Op initializer ) {
3067
- Init .add (scope , initializer );
3068
- }
3069
-
3070
3003
/**
3071
3004
* Table initializer that takes two tensors for keys and values respectively.
3072
3005
*
@@ -7948,9 +7881,9 @@ public VarIsInitializedOp varIsInitializedOp(Operand<? extends TType> resource)
7948
7881
7949
7882
/**
7950
7883
* Factory method to create a new Variable with it's initializer.
7951
- * <p>
7952
- * Only supported on Graph sessions as the {@link org.tensorflow.op.core.Assign} op
7953
- * does not work in an EagerSession.
7884
+ *
7885
+ * <p> Only supported on Graph sessions as the {@link org.tensorflow.op.core.Assign} op does not
7886
+ * work in an EagerSession.
7954
7887
*
7955
7888
* @param init The op to use to initialise this variable.
7956
7889
* @param options carries optional attributes values
@@ -8143,6 +8076,26 @@ public Ops withSubScope(String childScopeName) {
8143
8076
return new Ops (scope .withSubScope (childScopeName ));
8144
8077
}
8145
8078
8079
+ /**
8080
+ * Returns an API that builds init operations.
8081
+ * <p>Init operations will be initialized at session creation, will have their inputs (and control inputs) made init ops as well, and are never used as control dependencies.
8082
+ * Additionally, this scope drops all of its control dependencies. If an input can not be made an init op (i.e. a Placeholder), will error on op creation.
8083
+ */
8084
+ public Ops initScope () {
8085
+ return new Ops (scope .initScope ());
8086
+ }
8087
+
8088
+ /**
8089
+ * Make {@code op} an init operation, doing the same for all of it's inputs (and control inputs).
8090
+ * <p>Init operations will be initialized at session creation, will have their inputs (and control inputs) made init ops as well, and are never used as control dependencies.
8091
+ * Additionally, this scope drops all of its control dependencies. If an input can not be made an init op (i.e. a Placeholder), will error on op creation.
8092
+ * @throws IllegalArgumentException if the op or one of its inputs can't be made an init op.
8093
+ */
8094
+ public <T extends Operand > T liftToInitScope (T op ) {
8095
+ scope .env ().registerInitOp (op .op ());
8096
+ return op ;
8097
+ }
8098
+
8146
8099
/**
8147
8100
* Returns an API that uses the provided name for an op.
8148
8101
*
0 commit comments