| 368 | } |
| 369 | |
| 370 | static PyObject* tensor__sub__method(TensorObject* self, |
| 371 | PyObject* args, |
| 372 | PyObject* kwargs) { |
| 373 | phi::RecordEvent pythonc_record_event( |
| 374 | "__sub__ pybind_patch_func", phi::TracerEventType::UserDefined, 1); |
| 375 | |
| 376 | EAGER_TRY |
| 377 | VLOG(6) << "Running Eager tensor__sub__method"; |
| 378 | |
| 379 | SetPythonStack(); |
| 380 | |
| 381 | // Set Device ID |
| 382 | auto place = egr::Controller::Instance().GetExpectedPlace(); |
| 383 | SetDevice(place); |
| 384 | |
| 385 | Tensor ret; |
| 386 | |
| 387 | Tensor self_tensor = self->tensor; |
| 388 | PyObject* other_obj = PyTuple_GET_ITEM(args, 0); |
| 389 | // 1. scalar exists cases |
| 390 | if (PyFloat_Check(other_obj) || PyCheckInteger(other_obj) || |
| 391 | IsNumpyType(other_obj)) { |
| 392 | if (PyFloat_Check(other_obj)) { |
| 393 | if (_supported_int_dtype_.find(self_tensor.dtype()) != |
| 394 | _supported_int_dtype_.end()) { |
| 395 | eager_gil_scoped_release guard; |
| 396 | self_tensor = cast_ad_func(self_tensor, DataType::FLOAT32); |
| 397 | } |
| 398 | } else if (PyCheckInteger(other_obj) && |
| 399 | self_tensor.dtype() == DataType::BOOL) { |
| 400 | eager_gil_scoped_release guard; |
| 401 | self_tensor = cast_ad_func(self_tensor, DataType::INT64); |
| 402 | } |
| 403 | |
| 404 | double other = CastPyArg2Double(other_obj, "__sub__", 0); |
| 405 | { |
| 406 | eager_gil_scoped_release guard; |
| 407 | ret = CallScalarFunction(self_tensor, other, "sub"); |
| 408 | } |
| 409 | |
| 410 | return ToPyObject(ret); |
| 411 | } else if (PyComplex_Check(other_obj)) { |
| 412 | if (is_support_complex(self_tensor.dtype()) == false) { |
| 413 | eager_gil_scoped_release guard; |
| 414 | self_tensor = cast_ad_func( |
| 415 | self_tensor, promoteTypes(self_tensor.dtype(), DataType::COMPLEX64)); |
| 416 | } |
| 417 | } |
| 418 | |
| 419 | // 2. create or get tensor for other_obj |
| 420 | Tensor other_tensor; |
| 421 | if (PyCheckTensor(other_obj)) { |
| 422 | auto& self_tensor_ref_addr = self->tensor; |
| 423 | auto& other_tensor_ref_addr = CastPyArg2Tensor(other_obj, 0); |
| 424 | const phi::distributed::ProcessMesh* mesh = nullptr; |
| 425 | if (InputsContainDistTensor( |
| 426 | &mesh, self_tensor_ref_addr, other_tensor_ref_addr)) { |
| 427 | ConvertAllInputsToDistTensor( |
nothing calls this directly
no test coverage detected