8000 [C10] Add `Scalar::isUnsigned()` method (#159877) · pytorch/pytorch@882d50c · GitHub
[go: up one dir, main page]

Skip to content

Commit 882d50c

Browse files
malfetpytorchmergebot
authored andcommitted
[C10] Add Scalar::isUnsigned() method (#159877)
That returns true if Scalar hold unsigned integral value With the implications of `Tag::HAS_u` semantic. Pull Request resolved: #159877 Approved by: https://github.com/Skylion007, https://github.com/ezyang
1 parent b52a4d0 commit 882d50c

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

c10/core/Scalar.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,17 @@ class C10_API Scalar {
191191
isIntegral() const {
192192
return Tag::HAS_i == tag || Tag::HAS_si == tag || Tag::HAS_u == tag;
193193
}
194+
194195
bool isIntegral(bool includeBool) const {
195196
return Tag::HAS_i == tag || Tag::HAS_si == tag || Tag::HAS_u == tag ||
196197
(includeBool && isBoolean());
197198
}
198199

200+
// See Note [Meaning of HAS_u]
201+
bool isUnsigned() const {
202+
return Tag::HAS_u == tag || (Tag::HAS_i == tag && v.i >= 0);
203+
}
204+
199205
bool isComplex() const {
200206
return Tag::HAS_z == tag;
201207
}

0 commit comments

Comments
 (0)
0