mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
This is by no means comprehensive, but adds initial support for SymInt as a Scalar.
Things that don't work yet but need to:
- for some reason `torch.add(tensor, sym_int)` got matched to the `add.Tensor(Tensor self, Tensor other, *, Scalar alpha=1) -> Tensor` schema
- `x + sym_int` failed bc we tried to turn `x` into a sym int:
```
"__radd__",
[](c10::SymIntNode a, py::object b) -> c10::SymIntNode {
auto snb = toSymIntNode(a, b);
return a->add(snb);
})
```
- Many more things I'm sure
Pull Request resolved: https://github.com/pytorch/pytorch/pull/84958
Approved by: https://github.com/ezyang
46 lines
1.2 KiB
C++
46 lines
1.2 KiB
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()) {
|
|
TORCH_CHECK(!isSymbolic(), "NYI negate symbolic float");
|
|
return Scalar(-v.d);
|
|
} else if (isComplex()) {
|
|
TORCH_INTERNAL_ASSERT(!isSymbolic());
|
|
return Scalar(-v.z);
|
|
} else if (isIntegral(false)) {
|
|
TORCH_CHECK(!isSymbolic(), "NYI negate symbolic int");
|
|
return Scalar(-v.i);
|
|
}
|
|
TORCH_INTERNAL_ASSERT(false, "unknown ivalue tag ", static_cast<int>(tag));
|
|
}
|
|
|
|
Scalar Scalar::conj() const {
|
|
if (isComplex()) {
|
|
TORCH_INTERNAL_ASSERT(!isSymbolic());
|
|
return Scalar(std::conj(v.z));
|
|
} else {
|
|
return *this;
|
|
}
|
|
}
|
|
|
|
Scalar Scalar::log() const {
|
|
if (isComplex()) {
|
|
TORCH_INTERNAL_ASSERT(!isSymbolic());
|
|
return std::log(v.z);
|
|
} else if (isFloatingPoint()) {
|
|
TORCH_CHECK(!isSymbolic(), "NYI log symbolic float");
|
|
return std::log(v.d);
|
|
} else if (isIntegral(false)) {
|
|
TORCH_CHECK(!isSymbolic(), "NYI log symbolic int");
|
|
return std::log(v.i);
|
|
}
|
|
TORCH_INTERNAL_ASSERT(false, "unknown ivalue tag ", static_cast<int>(tag));
|
|
}
|
|
|
|
} // namespace c10
|