Skip to content

Commit 44e7951

Browse files
manuelcandalesfacebook-github-bot
authored andcommitted
SpecDB: Add casting utilities
Summary: Utility functions to return: - all dtypes that a given dtype can be casted to - all dtypes that can be casted to a given dtype Reviewed By: SS-JIA Differential Revision: D52919718 fbshipit-source-id: bb93b035a32df755f2f4879f99a411c95e04c56f
1 parent 9f37f74 commit 44e7951

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

specdb/dtypes.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,12 @@
1414
_floating_and_half = [torch.half] + _floating
1515
_complex = [torch.chalf, torch.cfloat, torch.cdouble]
1616
_quant = [torch.qint8, torch.quint8, torch.qint32, torch.quint4x2, torch.quint2x4]
17-
_all = [torch.bool] + _int + _floating + _complex + _quant
17+
_all = [torch.bool] + _int + _floating_and_half + _complex + _quant
18+
19+
20+
def can_cast_from(t):
21+
return [x for x in _all if torch.can_cast(t, x)]
22+
23+
24+
def can_cast_to(t):
25+
return [x for x in _all if torch.can_cast(x, t)]

0 commit comments

Comments
 (0)