-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Support gettiem by Bool index #35026
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
Conversation
|
|
||
| PADDLE_ENFORCE_EQ(index_dim[0] != 0, true, | ||
| platform::errors::InvalidArgument( | ||
| "The length of Input(Index) can't be 0.")); |
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.
length -> dimension ? 其他维度可以是0吗
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.
目前IndexSelectOp只支持一维的index索引,所以这里只需判断第0维的长度
| } | ||
| } | ||
| if (all_bool) { | ||
| if (list_size != shape[0]) { |
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.
why not use PADDLE_ENFORCE_EQ directly
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.
这里会在setitem支持Bool类型索引的PR中改为使用PADDLE_ENFORCE_EQ
| } | ||
| } | ||
| } else { | ||
| for (int j = 0; j < list_size; ++j) { |
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.
why this branch no need check?
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.
当索引中存在整数时,整个index索引list将会以整数类型进行处理,整数list类型的索引没有长度限制,所以没有进行check
| PyObject *list_item = PyList_GetItem(slice_item, j); | ||
| if (PyCheckInteger(list_item)) { | ||
| list_select_idxs->push_back( | ||
| static_cast<int>(PyLong_AsLong(list_item))); |
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 only can be 0 or 1?
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.
当索引中存在整数时,bool类型的True和False分别会被替换为整数类型的1和0进行处理
| dim += rank - specified_dims; | ||
| } else if (slice_item == Py_None) { | ||
| none_axes->push_back(dim); | ||
| } else if (PyList_Check(slice_item)) { |
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.
是否需要检测tuple的情况,例如:index=(False,True),tensor[index]
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.
chenwhql
left a comment
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

PR types
New features
PR changes
APIs
Describe
Support gettiem by Bool index
Example: