pytorch/c10/core/Scalar.cpp
Samuel Marks 8aad66a7bd [c10/**] Fix typos (#49815)
Summary:
All pretty minor. I avoided renaming `class DestructableMock` to `class DestructibleMock` and similar such symbol renames (in this PR).

Pull Request resolved: https://github.com/pytorch/pytorch/pull/49815

Reviewed By: VitalyFedyunin

Differential Revision: D25734507

Pulled By: mruberry

fbshipit-source-id: bbe8874a99d047e9d9814bf92ea8c036a5c6a3fd
2021-01-01 02:11:56 -08:00

34 lines
644 B
C++

#include <c10/core/Scalar.h>
namespace c10 {
Scalar Scalar::operator-() const {
TORCH_CHECK(!isBoolean(), "torch boolean negative, the `-` operator, is not supported.");
if (isFloatingPoint()) {
return Scalar(-v.d);
} else if (isComplex()) {
return Scalar(-v.z);
} else {
return Scalar(-v.i);
}
}
Scalar Scalar::conj() const {
if (isComplex()) {
return Scalar(std::conj(v.z));
} else {
return *this;
}
}
Scalar Scalar::log() const {
if (isComplex()) {
return std::log(v.z);
} else if (isFloatingPoint()) {
return std::log(v.d);
} else {
return std::log(v.i);
}
}
} // namespace c10