This is an archive of the discontinued LLVM Phabricator instance.

Replacing `is` with `==` for the dtype check.
ClosedPublic

Authored by pashu123 on Dec 1 2022, 8:31 AM.

Details

Summary

a = np.ndarray([1,1]).astype(np.half)
a

array([[0.007812]], dtype=float16)

a.dtype

dtype('float16')

a.dtype == np.half

True

a.dtype == np.float16

True

a.dtype is np.float16

False

Checking with is leads to inconsistency in checking.

Diff Detail

Event Timeline

pashu123 created this revision.Dec 1 2022, 8:31 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 1 2022, 8:31 AM
pashu123 requested review of this revision.Dec 1 2022, 8:31 AM
silvas accepted this revision.EditedDec 1 2022, 9:56 AM

LGTM. Maybe add a comment with a link to here for context: https://stackoverflow.com/questions/26921836/correct-way-to-test-for-numpy-dtype

This revision is now accepted and ready to land.Dec 1 2022, 9:56 AM
pashu123 updated this revision to Diff 479350.Dec 1 2022, 10:24 AM

Link for more context.

pashu123 updated this revision to Diff 479351.Dec 1 2022, 10:26 AM

minor comment placement.

This revision was landed with ongoing or failed builds.Dec 1 2022, 6:34 PM
This revision was automatically updated to reflect the committed changes.