59
59
import org .tensorflow .op .core .BatchToSpace ;
60
60
import org .tensorflow .op .core .BatchToSpaceNd ;
61
61
import org .tensorflow .op .core .Bitcast ;
62
+ import org .tensorflow .op .core .BooleanMask ;
63
+ import org .tensorflow .op .core .BooleanMaskUpdate ;
62
64
import org .tensorflow .op .core .BroadcastDynamicShape ;
63
65
import org .tensorflow .op .core .BroadcastTo ;
64
66
import org .tensorflow .op .core .Bucketize ;
@@ -362,10 +364,10 @@ public final class Ops {
362
364
363
365
public final SignalOps signal ;
364
366
365
- public final QuantizationOps quantization ;
366
-
367
367
public final TrainOps train ;
368
368
369
+ public final QuantizationOps quantization ;
370
+
369
371
private final Scope scope ;
370
372
371
373
private Ops (Scope scope ) {
@@ -388,8 +390,8 @@ private Ops(Scope scope) {
388
390
math = new MathOps (this );
389
391
audio = new AudioOps (this );
390
392
signal = new SignalOps (this );
391
- quantization = new QuantizationOps (this );
392
393
train = new TrainOps (this );
394
+ quantization = new QuantizationOps (this );
393
395
}
394
396
395
397
/**
@@ -1005,6 +1007,61 @@ public <U extends TType> Bitcast<U> bitcast(Operand<? extends TType> input, Clas
1005
1007
return Bitcast .create (scope , input , type );
1006
1008
}
1007
1009
1010
+ /**
1011
+ * Apply boolean mask to tensor. Returns the flat array of each element corresponding to a {@code true} in the mask.
1012
+ * <p>
1013
+ * Numpy equivalent is {@code tensor[mask]}.
1014
+ * <p>
1015
+ * In general, {@code 0 < dim(mask) = K <= dim(tensor)}, and {@code mask}'s shape must match
1016
+ * the first K dimensions of {@code tensor}'s shape. We then have:
1017
+ * {@code booleanMask(tensor, mask)[i, j1,...,jd] = tensor[i1,...,iK,j1,...,jd]}
1018
+ * where {@code (i1,...,iK)} is the ith {@code true} entry of {@code mask} (row-major order).
1019
+ * <p>
1020
+ * The {@code axis} could be used with {@code mask} to indicate the axis to mask from (it's 0 by default).
1021
+ * In that case, {@code axis + dim(mask) <= dim(tensor)} and {@code mask}'s shape must match
1022
+ * the first {@code axis + dim(mask)} dimensions of {@code tensor}'s shape.
1023
+ *
1024
+ * @param scope
1025
+ * @param tensor The tensor to mask.
1026
+ * @param mask The mask to apply.
1027
+ * @param options carries optional attributes values
1028
+ * @return The masked tensor.
1029
+ */
1030
+ public <T extends TType > Operand <T > booleanMask (Operand <T > tensor , Operand <TBool > mask ,
1031
+ BooleanMask .Options ... options ) {
1032
+ return BooleanMask .create (scope , tensor , mask , options );
1033
+ }
1034
+
1035
+ /**
1036
+ * Updates a tensor at the masked values, and returns the updated tensor. Does not mutate the input tensors. {@code
1037
+ * updates} will be broadcasted by default
1038
+ * <p>
1039
+ * Numpy equivalent is `tensor[mask] = updates`.
1040
+ * <p>
1041
+ * In general, {@code 0 < dim(mask) = K <= dim(tensor)}, and {@code mask}'s shape must match the first K dimensions of
1042
+ * {@code tensor}'s shape. We then have: {@code booleanMask(tensor, mask)[i, j1,...,jd] =
1043
+ * tensor[i1,...,iK,j1,...,jd]} where {@code (i1,...,iK)} is the ith {@code true} entry of {@code mask} (row-major
1044
+ * order).
1045
+ * <p>
1046
+ * The {@code axis} could be used with {@code mask} to indicate the axis to mask from (it's 0 by default). In that
1047
+ * case, {@code axis + dim(mask) <= dim(tensor)} and {@code mask}'s shape must match the first {@code axis +
1048
+ * dim(mask)} dimensions of {@code tensor}'s shape.
1049
+ * <p>
1050
+ * The shape of {@code updates} should be {@code [n, t_1, t_2, ...]} where {@code n} is the number of true values in
1051
+ * {@code mask} and {@code t_i} is the {@code i}th dimension of {@code tensor} after {@code axis} and {@code mask}.
1052
+ * {@code updates} will be broadcasted to this shape by default, which can be disabled using {@code options}.
1053
+ *
1054
+ * @param tensor The tensor to mask.
1055
+ * @param mask The mask to apply.
1056
+ * @param updates the new values
1057
+ * @param options carries optional attributes values
1058
+ * @return The masked tensor.
1059
+ */
1060
+ public <T extends TType > Operand <T > booleanMaskUpdate (Operand <T > tensor , Operand <TBool > mask ,
1061
+ Operand <T > updates , BooleanMaskUpdate .Options ... options ) {
1062
+ return BooleanMaskUpdate .create (scope , tensor , mask , updates , options );
1063
+ }
1064
+
1008
1065
/**
1009
1066
* Return the shape of s0 op s1 with broadcast.
1010
1067
* <p>
@@ -1850,13 +1907,14 @@ public Constant<TInt32> constant(Shape shape, IntDataBuffer data) {
1850
1907
}
1851
1908
1852
1909
/**
1853
- * Creates a scalar of {@code type}, with the value of {@code number}.
1854
- * {@code number} may be truncated if it does not fit in the target type.
1910
+ * Creates a scalar of {@code type}, with the value of {@code number}. {@code number} may be truncated if it does not
1911
+ * fit in the target type.
1855
1912
*
1856
1913
* @param type the type of tensor to create. Must be concrete (i.e. not {@link org.tensorflow.types.family.TFloating})
1857
1914
* @param number the value of the tensor
1858
1915
* @return a constant of the passed type
1859
- * @throws IllegalArgumentException if the type is abstract (i.e. {@link org.tensorflow.types.family.TFloating}) or unknown.
1916
+ * @throws IllegalArgumentException if the type is abstract (i.e. {@link org.tensorflow.types.family.TFloating}) or
1917
+ * unknown.
1860
1918
*/
1861
1919
public <T extends TNumber > Constant <T > constant (Class <T > type , Number number ) {
1862
1920
return Constant .tensorOf (scope , type , number );
@@ -1908,14 +1966,14 @@ public <T extends TType> Constant<T> constantOf(T tensor) {
1908
1966
}
1909
1967
1910
1968
/**
1911
- * Creates a scalar of the same type as {@code toMatch}, with the value of {@code number}.
1912
- * {@code number} may be truncated if it does not fit in the target type.
1969
+ * Creates a scalar of the same type as {@code toMatch}, with the value of {@code number}. {@code number} may be
1970
+ * truncated if it does not fit in the target type.
1913
1971
*
1914
1972
* @param toMatch the operand providing the target type
1915
1973
* @param number the value of the tensor
1916
1974
* @return a constant with the same type as {@code toMatch}
1917
- * @see Ops#constant(Class, Number)
1918
1975
* @throws IllegalArgumentException if the type is unknown (which should be impossible).
1976
+ * @see Ops#constant(Class, Number)
1919
1977
*/
1920
1978
public <T extends TNumber > Constant <T > constantOfSameType (Operand <T > toMatch , Number number ) {
1921
1979
return Constant .tensorOfSameType (scope , toMatch , number );
0 commit comments