Thursday, January 22, 2026
HomeLanguagesPython – tensorflow.DeviceSpec.__eq__()

Python – tensorflow.DeviceSpec.__eq__()

TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning  neural networks.

__eq__() is used to check the equality of two DeviceSpec objects.

Syntax: tensorflow.DeviceSpec.__eq__( other )

Parameters:

  • other: It is a DeviceSpec object.

Returns: It returns True if DeviceSpec object specifications are same otherwise it returns False.

Example 1:

Python3




# Importing the library
import tensorflow as tf
  
# Initializing Device Specification
device_spec = tf.DeviceSpec(job ="gfg2", replica = 5, task = 2, device_type ="GPU", device_index = 1)
device_spec2 = tf.DeviceSpec(job ="gfg2", replica = 5, task = 2, device_type ="GPU", device_index = 1)
  
# Printing the DeviceSpec object
print('Device Spec: ', device_spec.to_string())
print('Device Spec2: ', device_spec2.to_string())
  
# Finding the result
res = device_spec.__eq__(device_spec2)
  
# Printing the result
print('Res: ', res)


Output:


Device Spec:  /job:gfg2/replica:5/task:2/device:GPU:1
Device Spec2:  /job:gfg2/replica:5/task:2/device:GPU:1
Res:  True

Example 2:

Python3




# Importing the library
import tensorflow as tf
  
# Initializing Device Specification
device_spec = tf.DeviceSpec(job ="gfg2", replica = 5, task = 2, device_type ="GPU", device_index = 1)
device_spec2 = tf.DeviceSpec(job ="gfg2", replica = 5, task = 2, device_type ="CPU", device_index = 2)
  
# Printing the DeviceSpec object
print('Device Spec: ', device_spec.to_string())
print('Device Spec2: ', device_spec2.to_string())
  
# Finding the result
res = device_spec.__eq__(device_spec2)
  
# Printing the result
print('Res: ', res)


Output:


Device Spec:  /job:gfg2/replica:5/task:2/device:GPU:1
Device Spec2:  /job:gfg2/replica:5/task:2/device:CPU:2
Res:  False

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32475 POSTS0 COMMENTS
Milvus
119 POSTS0 COMMENTS
Nango Kala
6847 POSTS0 COMMENTS
Nicole Veronica
11977 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12064 POSTS0 COMMENTS
Shaida Kate Naidoo
6986 POSTS0 COMMENTS
Ted Musemwa
7220 POSTS0 COMMENTS
Thapelo Manthata
6933 POSTS0 COMMENTS
Umr Jansen
6912 POSTS0 COMMENTS