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

Skip to content

Commit b5248dc

Browse files
committed
[C10] Add Scalar::isUnsigned() method
That returns true if Scalar hold unsigned integral value With the implications of `Tag::HAS_u` semantic. ghstack-source-id: 4b6248f Pull Request resolved: #159877
1 parent 510e8b4 commit b5248dc

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