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

Function tensor__gt__method

paddle/fluid/pybind/eager_math_op_patch.cc:908–999  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

906 if (PyComplex_Check(other_obj)) {
907 eager_gil_scoped_release guard;
908 other_tensor = full_ad_func(
909 {1}, value, DataType::COMPLEX64, self_tensor.place());
910 } else {
911 eager_gil_scoped_release guard;
912 other_tensor = full_ad_func(self_tensor.shape(),
913 value,
914 self_tensor.dtype(),
915 self_tensor.place());
916 }
917 }
918 const phi::distributed::ProcessMesh* mesh = nullptr;
919 if (InputsContainDistTensor(&mesh, self_tensor, other_tensor)) {
920 ConvertAllInputsToDistTensor(mesh, self_tensor, other_tensor);
921 }
922 }
923
924 // 3. calculation: other / self == self.reciprocal() * other
925 VLOG(6) << "Calling reciprocal_ad_func and multiply_ad_func in "
926 "tensor__rdiv__method";
927 {
928 eager_gil_scoped_release guard;
929 if (_supported_int_dtype_.find(self_tensor.dtype()) !=
930 _supported_int_dtype_.end()) {
931 // torch's reciprocal promotes integral/bool tensors to float32.
932 self_tensor = cast_ad_func(self_tensor, DataType::FLOAT32);
933 }
934 Tensor recip = reciprocal_ad_func(self_tensor);
935 if (_supported_int_dtype_.find(other_tensor.dtype()) !=
936 _supported_int_dtype_.end()) {
937 other_tensor = cast_ad_func(other_tensor, recip.dtype());
938 }
939 ret = multiply_ad_func(recip, other_tensor);
940 }
941 return ToPyObject(ret);
942 } else {
943 // ======================= original implementation =======================
944 // 1. scalar exists cases
945 // there is no scalar_div function for __rdiv__ and __rtruediv__
946 if (PyFloat_Check(other_obj) || PyCheckInteger(other_obj) ||
947 IsNumpyType(other_obj)) {
948 if (_supported_int_dtype_.find(self_tensor.dtype()) !=
949 _supported_int_dtype_.end()) {
950 eager_gil_scoped_release guard;
951 self_tensor = cast_ad_func(self_tensor, DataType::FLOAT32);
952 }
953 } else if (PyComplex_Check(other_obj)) {
954 if (is_support_complex(self_tensor.dtype()) == false) {
955 eager_gil_scoped_release guard;
956 self_tensor = cast_ad_func(
957 self_tensor,
958 promoteTypes(self_tensor.dtype(), DataType::COMPLEX64));
959 }
960 }
961
962 // 2. create or get tensor for other_obj
963 Tensor other_tensor;
964 if (PyCheckTensor(other_obj)) {
965 auto& self_tensor_ref_addr = self->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