@@ -393,22 +393,30 @@ def test_complex():
393393 assert isinstance (complex (cirq .GridQubit (row = 1 , col = 2 )), complex )
394394
395395
396- def test_numpy_index ():
397- np5 , np6 , np3 = [np .int64 (i ) for i in [5 , 6 , 3 ]]
396+ @pytest .mark .parametrize ('dtype' , (np .int8 , np .int64 , float , np .float64 ))
397+ def test_numpy_index (dtype ):
398+ np5 , np6 , np3 = [dtype (i ) for i in [5 , 6 , 3 ]]
398399 q = cirq .GridQubit (np5 , np6 )
399- hash (q ) # doesn't throw
400+ assert hash (q ) == hash ( cirq . GridQubit ( 5 , 6 ))
400401 assert q .row == 5
401402 assert q .col == 6
402403 assert q .dimension == 2
403- assert isinstance (q .row , int )
404- assert isinstance (q .col , int )
405404 assert isinstance (q .dimension , int )
406405
407406 q = cirq .GridQid (np5 , np6 , dimension = np3 )
408- hash (q ) # doesn't throw
407+ assert hash (q ) == hash ( cirq . GridQid ( 5 , 6 , dimension = 3 ))
409408 assert q .row == 5
410409 assert q .col == 6
411410 assert q .dimension == 3
412- assert isinstance (q .row , int )
413- assert isinstance (q .col , int )
414411 assert isinstance (q .dimension , int )
412+
413+
414+ @pytest .mark .parametrize ('dtype' , (float , np .float64 ))
415+ def test_non_integer_index (dtype ):
416+ # Not supported type-wise, but is used in practice, so behavior needs to be preserved.
417+ q = cirq .GridQubit (dtype (5.5 ), dtype (6.5 ))
418+ assert hash (q ) == hash (cirq .GridQubit (5.5 , 6.5 ))
419+ assert q .row == 5.5
420+ assert q .col == 6.5
421+ assert isinstance (q .row , dtype )
422+ assert isinstance (q .col , dtype )
0 commit comments