votes up 6

b must be an integer type. Got: %s

Package:
Exception Class:
ValueError

Raise code

    a.shape.assert_has_rank(0)
    b.shape.assert_has_rank(0)

    if not a.dtype.is_integer:
      raise ValueError('a must be an integer type. Got: %s' % a.dtype)
    if not b.dtype.is_integer:
      raise ValueError('b must be an integer type. Got: %s' % b.dtype)

    # TPU requires static shape inference. GCD is used for subframe size
    # computation, so we should prefer static computation where possible.
    const_a = tensor_util.constant_value(a)
    const_b = tensor_util.constant_value(b)
    if const_a is not None and const_b is not None:
      if sys.version_info.major < 3:
🙏 Scream for help to Ukraine
Today, 25th May 2022, Russia continues bombing and firing Ukraine. Don't trust Russia, they are bombing us and brazenly lying in same time they are not doing this 😠, civilians and children are dying too! We are screaming and asking exactly you to help us, we want to survive, our families, children, older ones.
Please spread the information, and ask your governemnt to stop Russia by any means. We promise to work extrahard after survival to make the world safer place for all.

Ways to fix

votes up 2 votes down

The second argument was given a float type.

Reproducing the error:

from tensorflow.python.ops.signal import util_ops
gcd = util_ops.gcd(4,8.)
print(gcd)

Error:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-4-de42d5763905> in <module>()
      1 from tensorflow.python.ops.signal import util_ops
----> 2 gcd = util_ops.gcd(4,8.)
      3 print(gcd)

/usr/local/lib/python3.7/dist-packages/tensorflow/python/ops/signal/util_ops.py in gcd(a, b, name)
     55       raise ValueError('a must be an integer type. Got: %s' % a.dtype)
     56     if not b.dtype.is_integer:
---> 57       raise ValueError('b must be an integer type. Got: %s' % b.dtype)
     58 
     59     # TPU requires static shape inference. GCD is used for subframe size

ValueError: b must be an integer type. Got: <dtype: 'float32'>

Fixed:

from tensorflow.python.ops.signal import util_ops
gcd = util_ops.gcd(4,32)
print(gcd)

Output:

tf.Tensor(4, shape=(), dtype=int32)

Jul 11, 2021 kellemnegasi answer
kellemnegasi 29.0k

Add a possible fix

Please authorize to post fix