code: def testFloat(self):
      float_inputs_ = [
          0,
          1,
          -1,
          0.5,
          0.25,
          0.125,
          float("INF"),
          float("NAN"),
          float("-INF"),
      ]
  
      for dtype in (
          dtypes.half,
          dtypes.bfloat16,
          dtypes.float32,
          dtypes.float64,
      ):
          inputs = ops.convert_to_tensor(float_inputs_, dtype=dtype)
          s = lambda strs: [
              x.decode("ascii") for x in self.evaluate(strs)
          ]
          result = string_ops.as_string(inputs, shortest=True)
          self.assertAllEqual(
              s(result), ["%g" % x for x in float_inputs_]
          )
  
          result = string_ops.as_string(inputs, scientific=True)
          self.assertAllEqual(
              s(result), ["%e" % x for x in float_inputs_]
          )
  
          result = string_ops.as_string(inputs)
          self.assertAllEqual(
              s(result), ["%f" % x for x in float_inputs_]
          )
  
          result = string_ops.as_string(inputs, width=3)
          self.assertAllEqual(
              s(result), ["%3f" % x for x in float_inputs_]
          )
  
          result = string_ops.as_string(inputs, width=3, fill="0")
          self.assertAllEqual(
              s(result), ["%03f" % x for x in float_inputs_]
          )
  
          result = string_ops.as_string(
              inputs, width=3, fill="0", shortest=True
          )
          self.assertAllEqual(
              s(result), ["%03g" % x for x in float_inputs_]
          )
  
          result = string_ops.as_string(inputs, precision=10, width=3)
          self.assertAllEqual(
              s(result), ["%03.10f" % x for x in float_inputs_]
          )
  
          result = string_ops.as_string(
              inputs, precision=10, width=3, fill="0", shortest=True
          )
          self.assertAllEqual(
              s(result), ["%03.10g" % x for x in float_inputs_]
          )
  
      with self.assertRaisesOpError("Cannot select both"):
          self.evaluate(
              string_ops.as_string(
                  inputs, scientific=True, shortest=True
              )
          )
  
      with self.assertRaisesOpError("Fill string must be one or fewer"):
          self.evaluate(string_ops.as_string(inputs, fill="ab"))
  
file_path: tensorflow-upstream/tensorflow/python/kernel_tests/strings_ops/as_string_op_test.py
imports: import numpy
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import ops
  from tensorflow.python.ops import string_ops
  from tensorflow.python.platform import test
label_desc: Use image node_id 1 for calling the AsStringOpTest obj's underlying member method code with example usage: obj.testFloat() without return types