mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-07 12:21:27 +01:00
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/46596 1. Added `conj` method for scalar similar to numpy. 2. Updates backward formulas for add and sub to work correctly for R -> C cases and for the case when alpha is complex. 3. Enabled complex backward for nonzero (no formula update needed). Test Plan: Imported from OSS Reviewed By: glaringlee Differential Revision: D24529227 Pulled By: anjali411 fbshipit-source-id: da871309a6decf5a4ab5c561d5ab35fc66b5273d
25 lines
465 B
C++
25 lines
465 B
C++
#include <c10/core/Scalar.h>
|
|
|
|
namespace c10 {
|
|
|
|
Scalar Scalar::operator-() const {
|
|
TORCH_CHECK(!isBoolean(), "torch boolean negative, the `-` operator, is not suppported.");
|
|
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;
|
|
}
|
|
}
|
|
|
|
} // namespace c10
|