-
Notifications
You must be signed in to change notification settings - Fork 5.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change the invoking method of settiem from numpy to set_value op when value isn't tensor #35701
Conversation
… value is not tensor
Thanks for your contribution! |
paddle/fluid/pybind/imperative.cc
Outdated
|
||
// cast numpy type form S to T, this may allocate new memory | ||
template <class T, class S> | ||
static py::array_t<T> cast_numpy_type(py::array_t<S> array) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
paddle/fluid/pybind/imperative.cc
Outdated
} | ||
|
||
template <class T> | ||
static py::array_t<T> cast_numpy_array(const py::object &array) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
paddle/fluid/pybind/imperative.cc
Outdated
"Currently, VarBase.__getitem__() only allows None or integers in " | ||
"slice item, but received %s.", | ||
"Currently, slice indices only allows None, integers, and " | ||
"int of tensor or numpy in slice item, but received %s.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
int of tensor
表述有点奇怪
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
paddle/fluid/pybind/imperative.cc
Outdated
"Currently, VarBase.__getitem__() only allows None or integers in " | ||
"slice item, but received %s.", | ||
"Currently, slice indices only allows None, integers, and " | ||
"int of tensor or numpy in slice item, but received %s.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -408,13 +500,36 @@ static int _PySlice_GetIndices(PySliceObject *r, Py_ssize_t length, | |||
} else { | |||
if (PyCheckInteger(r->stop) || IsNumpyType(r->stop)) { | |||
*stop = PyLong_AsLong(r->stop); | |||
} else if (PyCheckTensor(r->stop)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这几段代码相似度很高,可以整合吗
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. 已整合
paddle/fluid/pybind/imperative.cc
Outdated
@@ -554,7 +669,7 @@ static void ParseIndexingSlice( | |||
|
|||
} else { | |||
PADDLE_THROW(platform::errors::InvalidArgument( | |||
"Currently, VarBase.__getitem__() only allows indexing " | |||
"Currently, VarBase.__indices__() only allows indexing " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
VarBase可以改为Tensor了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
… value isn't tensor (PaddlePaddle#35701) * Change the invoking method of settiem from numpy to set_value op when value is not tensor * fix the check logic for inplace in setitem * fix the unittest problem caused by setitem doesn't support fp16 * modify some code format in setitem
PR types
Others
PR changes
APIs
Describe
Change the invoking method of settiem from numpy to set_value op when value isn't tensor
当执行如下代码时:( 右边的值为非tensor)
修改前的setitem由numpy完成底层逻辑处理
修改后的setitem由set_value op完成底层逻辑处理