Repository navigation
Description
Please make sure that this is a bug. As per our GitHub Policy, we only address code/doc bugs, performance issues, feature requests and build/installation issues on GitHub. tag:bug_template
Describe the current behavior
In talking with @karllessard, we saw
java/tensorflow-core/tensorflow-core-api/src/gen/annotations/org/tensorflow/op/NnOps.java
Lines 3109 to 3131 in e9c854f
| /** | |
| * Finds values and indices of the {@code k} largest elements for the last dimension. | |
| * If the input is a vector (rank-1), finds the {@code k} largest entries in the vector | |
| * and outputs their values and indices as vectors. Thus {@code values[j]} is the | |
| * {@code j}-th largest entry in {@code input}, and its index is {@code indices[j]}. | |
| * <p>For matrices (resp. higher rank input), computes the top {@code k} entries in each | |
| * row (resp. vector along the last dimension). Thus, | |
| * <pre> | |
| * values.shape = indices.shape = input.shape[:-1] + [k] | |
| * </pre> | |
| * <p>If two elements are equal, the lower-index element appears first. | |
| * | |
| * @param input 1-D or higher with last dimension at least {@code k}. | |
| * @param k 0-D. Number of top elements to look for along the last dimension (along each | |
| * row for matrices). | |
| * @param options carries optional attribute values | |
| * @param <T> data type for {@code TopKV2} output and operands | |
| * @return a new instance of TopK, with default output types | |
| */ | |
| public <T extends TNumber> TopK<T, TInt32> topK(Operand<T> input, Operand<? extends TNumber> k, | |
| TopK.Options[] options) { | |
| return TopK.create(scope, input, k, options); | |
| } |
TopK.Options[] options
Describe the expected behavior
It should accept variadic argument TopK.Options... options just like its variant
java/tensorflow-core/tensorflow-core-api/src/gen/annotations/org/tensorflow/op/NnOps.java
Lines 3154 to 3157 in e9c854f
| public <T extends TNumber, V extends TNumber> TopK<T, V> topK(Operand<T> input, | |
| Operand<? extends TNumber> k, Class<V> indexType, TopK.Options... options) { | |
| return TopK.create(scope, input, k, indexType, options); | |
| } |
Code to reproduce the issue
Calling tf.nn.topK(input, k) would be a method not found
Other info / logs
Method topK(org.tensorflow.op.core.Placeholder,org.tensorflow.op.core.Constant) cannot be found on type org.tensorflow.op.NnOps
Activity
sshekhar-04 commentedon Jan 20, 2026
Hi @karllessard and @Craigacp,
I've analyzed this issue. I see that the generated NnOps.java is currently missing the variadic syntax for one specific topK overload, causing the method not found error when optional arguments are omitted.
Since NnOps.java is an auto-generated file, I assume a manual fix there would be overwritten. Should I look into modifying the "OpGenerator" logic within the "tensorflow-core-generator" module to ensure this overload correctly uses variadic arguments?