Fix a bug in tf.metrics.mean_tensor for case that the weights are very small.
We have renamed metrics_test.MeanTensorTest.testWeighted1d as metrics_test.MeanTensorTest.testBinaryWeighted1d, since the weights on the instances are zeros and ones.
We have added a new metrics_test.MeanTensorTest.testWeighted1d that has small weights. It was failing for the previous implementation, but passes now.
Now the code for mean_tensor() and mean() now use the same _safe_div method. Previously, mean_tensor() used a different means to ensure that we don't divide by zero. This set the denominator to max(1., sum(weights)), which was inaccurate when sum(weights) is non-zero, but less than one.
PiperOrigin-RevId:
186503714