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

Function TensorInit

paddle/fluid/pybind/eager.cc:825–1229  ·  view source on GitHub ↗

We should have init function with signature: * 1. * def __init__ () * 2. * (should have at least five parameter, five parameters create DenseTensor, * seven parameters create DistTensor) * def __init__ ( * ** dtype: paddle::DataType, * ** dims: vector , * ** name: std::string, * ** type: paddle::framework::proto::VarType::DENSE_TENSOR, * ** persistable: bool, * ** process_mesh: phi

Source from the content-addressed store, hash-verified

823 * ** name: std::string)
824 * **/
825int TensorInit(PyObject* self, PyObject* args, PyObject* kwargs) {
826 EAGER_TRY
827 SetPythonStack();
828 // set a flag to record use kwargs or not
829 bool flag_kwargs = false;
830 if (kwargs && PyDict_Size(kwargs) > 0) flag_kwargs = true;
831
832 // all kwargs
833 PyObject* kw_zero_copy = nullptr;
834 PyObject* kw_persistable = nullptr;
835 PyObject* kw_stop_gradient = nullptr;
836
837 PyObject* kw_value = nullptr; // receive PyArray or Tensor
838 PyObject* kw_place = nullptr;
839 PyObject* kw_name = nullptr;
840 PyObject* kw_dims = nullptr;
841 PyObject* kw_dtype = nullptr;
842 PyObject* kw_type = nullptr;
843 PyObject* kw_process_mesh = nullptr;
844 PyObject* kw_placements = nullptr;
845
846 // the keywords argument
847 static char* kwlist[] = {const_cast<char*>("value"), // NOLINT
848 const_cast<char*>("place"),
849 const_cast<char*>("persistable"),
850 const_cast<char*>("zero_copy"),
851 const_cast<char*>("name"),
852 const_cast<char*>("stop_gradient"),
853 const_cast<char*>("dims"),
854 const_cast<char*>("dtype"),
855 const_cast<char*>("type"),
856 const_cast<char*>("process_mesh"),
857 const_cast<char*>("placements"),
858 nullptr};
859
860 // 'O' Store a Python object (without any conversion) in a C object pointer,
861 // '|' Indicates that the remaining arguments in the Python argument list are
862 // optional.
863 // PyArg_ParseTupleAndKeywords can Parse the parameters of a function that
864 // takes both positional and keyword parameters into local variables,
865 // which enhance case2, case3, case4, case5, case6, case7.
866 bool flag_ = PyArg_ParseTupleAndKeywords(args,
867 kwargs,
868 "|OOOOOOOOOOO",
869 kwlist,
870 &kw_value,
871 &kw_place,
872 &kw_persistable,
873 &kw_zero_copy,
874 &kw_name,
875 &kw_stop_gradient,
876 &kw_dims,
877 &kw_dtype,
878 &kw_type,
879 &kw_process_mesh,
880 &kw_placements);
881
882 // helper map

Callers

nothing calls this directly

Calls 14

EmptyTensorInitializerFunction · 0.85
InstanceFunction · 0.85
AutoInitTensorByPyArrayFunction · 0.85
AutoInitTensorByTensorFunction · 0.85
CastPyArg2DataTypeFunction · 0.85
CastPyArg2VectorOfIntFunction · 0.85
CastPyArg2ProtoTypeFunction · 0.85
CastPyArg2ProcessMeshFunction · 0.85
GetExpectedPlaceMethod · 0.80
CastPyArg2AttrStringFunction · 0.70
CastPyArg2AttrBooleanFunction · 0.70

Tested by

no test coverage detected