New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix auto exponent issue for torch.pow #49809
Changes from all commits
a664fa9
1a8bdbd
25d6c5c
c0a1675
eebd3a9
faf8ce3
1165f60
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,6 +88,45 @@ class C10_API Scalar { | |
|
||
Scalar operator-() const; | ||
Scalar conj() const; | ||
Scalar log() const; | ||
|
||
template<typename T, typename std::enable_if<!c10::is_complex<T>::value, int>::type = 0> | ||
bool equal(T num) const { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When comparing a Scalar against a C++ number should people always use equal? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not very familiar with c++ semantic, why is it different from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To compare a scalar to a number, we first have to obtain the stored value in the scalar which usually is done by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Offline conversation: add a special case for bool There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ho you cannot template the Given that using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if (isComplex()) { | ||
auto val = v.z; | ||
return (val.real() == num) && (val.imag() == T()); | ||
} else if (isFloatingPoint()) { | ||
return v.d == num; | ||
} else if (isIntegral(/*includeBool=*/false)) { | ||
return v.i == num; | ||
} else { | ||
// boolean scalar does not equal to a non boolean value | ||
return false; | ||
} | ||
} | ||
|
||
template<typename T, typename std::enable_if<c10::is_complex<T>::value, int>::type = 0> | ||
bool equal(T num) const { | ||
if (isComplex()) { | ||
return v.z == num; | ||
} else if (isFloatingPoint()) { | ||
return (v.d == num.real()) && (num.imag() == T()); | ||
} else if (isIntegral(/*includeBool=*/false)) { | ||
return (v.i == num.real()) && (num.imag() == T()); | ||
} else { | ||
// boolean scalar does not equal to a non boolean value | ||
return false; | ||
} | ||
} | ||
|
||
bool equal(bool num) const { | ||
if (isBoolean()) { | ||
return static_cast<bool>(v.i) == num; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
ScalarType type() const { | ||
if (isComplex()) { | ||
return ScalarType::ComplexDouble; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a bool case to be worried about here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no because scalar only stores double, complex, or int. In case a scalar is initialized with bool, it saves a flag indicating it is bool and saves the value as an int