MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / tensor__rmod__method

Function tensor__rmod__method

paddle/fluid/pybind/eager_math_op_patch.cc:1203–1294  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1201 PyObject* kwargs) {
1202 phi::RecordEvent pythonc_record_event(
1203 "__mod__ pybind_patch_func", phi::TracerEventType::UserDefined, 1);
1204 EAGER_TRY
1205
1206 VLOG(6) << "Running Eager tensor__mod__method";
1207
1208 SetPythonStack();
1209
1210 // Set Device ID
1211 auto place = egr::Controller::Instance().GetExpectedPlace();
1212 SetDevice(place);
1213
1214 Tensor ret;
1215
1216 Tensor self_tensor = self->tensor;
1217 PyObject* other_obj = PyTuple_GET_ITEM(args, 0);
1218
1219 // 1. scalar exists cases
1220 // there is no scalar_mod function for __mod__ now
1221 if (PyFloat_Check(other_obj) || PyCheckInteger(other_obj) ||
1222 IsNumpyType(other_obj)) {
1223 if (PyFloat_Check(other_obj)) {
1224 if (_supported_int_dtype_.find(self_tensor.dtype()) !=
1225 _supported_int_dtype_.end()) {
1226 eager_gil_scoped_release guard;
1227 self_tensor = cast_ad_func(self_tensor, DataType::FLOAT32);
1228 }
1229 } else if (PyCheckInteger(other_obj) &&
1230 self_tensor.dtype() == DataType::BOOL) {
1231 eager_gil_scoped_release guard;
1232 self_tensor = cast_ad_func(self_tensor, DataType::INT64);
1233 }
1234 } else if (PyComplex_Check(other_obj)) {
1235 if (is_support_complex(self_tensor.dtype()) == false) {
1236 eager_gil_scoped_release guard;
1237 self_tensor = cast_ad_func(
1238 self_tensor, promoteTypes(self_tensor.dtype(), DataType::COMPLEX64));
1239 }
1240 }
1241
1242 // 2. create or get tensor for other_obj
1243 Tensor other_tensor;
1244 if (PyCheckTensor(other_obj)) {
1245 auto& self_tensor_ref_addr = self->tensor;
1246 auto& other_tensor_ref_addr = CastPyArg2Tensor(other_obj, 0);
1247 const phi::distributed::ProcessMesh* mesh = nullptr;
1248 if (InputsContainDistTensor(
1249 &mesh, self_tensor_ref_addr, other_tensor_ref_addr)) {
1250 ConvertAllInputsToDistTensor(
1251 mesh, self_tensor_ref_addr, other_tensor_ref_addr);
1252 }
1253 self_tensor = self_tensor_ref_addr;
1254 other_tensor = other_tensor_ref_addr;
1255 } else {
1256 if (IsNumpyArray(other_obj)) {
1257 py::object numpy_value =
1258 py::reinterpret_borrow<py::object>(py::handle(other_obj));
1259 other_tensor = paddle::empty({}, DataType::FLOAT32, place);
1260 InitTensorWithNumpyValue(numpy_value, place, &other_tensor);

Callers

nothing calls this directly

Calls 15

SetPythonStackFunction · 0.85
InstanceFunction · 0.85
is_support_complexFunction · 0.85
promoteTypesFunction · 0.85
PyCheckTensorFunction · 0.85
InputsContainDistTensorFunction · 0.85
CastPyArg2ScalarFunction · 0.85
GetExpectedPlaceMethod · 0.80
SetDeviceFunction · 0.70
PyCheckIntegerFunction · 0.70
IsNumpyTypeFunction · 0.70

Tested by

no test coverage detected