Skip to content

Commit 0575b64

Browse files
Prevent division by 0 in LSH projection.
PiperOrigin-RevId: 387225857 Change-Id: Iaeb572a763618c64f503e0026f6dd9fd769bf50c
1 parent 13aec9e commit 0575b64

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

Diff for: tensorflow/lite/kernels/lsh_projection.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ limitations under the License.
2828
//
2929
// Input:
3030
// Tensor[0]: Hash functions. Dim.size == 2, DataType: Float.
31-
// Tensor[0].Dim[0]: Num of hash functions.
31+
// Tensor[0].Dim[0]: Num of hash functions. Must be at least 1.
3232
// Tensor[0].Dim[1]: Num of projected output bits generated by
3333
// each hash function.
3434
// In sparse case, Tensor[0].Dim[1] + ceil( log2(Tensor[0].Dim[0] )) <= 32.
@@ -82,6 +82,7 @@ TfLiteStatus Resize(TfLiteContext* context, TfLiteNode* node) {
8282
const TfLiteTensor* input;
8383
TF_LITE_ENSURE_OK(context, GetInputSafe(context, node, 1, &input));
8484
TF_LITE_ENSURE(context, NumDimensions(input) >= 1);
85+
TF_LITE_ENSURE(context, SizeOfDimension(input, 0) >= 1);
8586

8687
if (NumInputs(node) == 3) {
8788
const TfLiteTensor* weight;

0 commit comments

Comments
 (0)