8000 [C10] Add `Scalar::isUnsigned()` method by malfet · Pull Request #159877 · pytorch/pytorch · GitHub
[go: up one dir, main page]

Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions c10/core/Scalar.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,17 @@ class C10_API Scalar {
isIntegral() const {
return Tag::HAS_i == tag || Tag::HAS_si == tag || Tag::HAS_u == tag;
}

bool isIntegral(bool includeBool) const {
return Tag::HAS_i == tag || Tag::HAS_si == tag || Tag::HAS_u == tag ||
(includeBool && isBoolean());
}

// See Note [Meaning of HAS_u]
bool isUnsigned() const {
return Tag::HAS_u == tag || (Tag::HAS_i == tag && v.i >= 0);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this is fine. But you might want an alternative that tells you if it fits in 64-bit int or not, since that's what you are probably actually interested in when you do the IValue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's kind of my debate: should I create some sort of semantically weird is64bitUnsigned API here, or check it on the caller side. I'm leaning towards later...


bool isComplex() const {
return Tag::HAS_z == tag;
}
Expand Down
Loading
0