Skip to content
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

Make LoDTensor::lod_element return start and end offset of sequence #4918

Merged
merged 2 commits into from
Oct 19, 2017

Conversation

wanghaoshuang
Copy link
Contributor

fix #4917

@@ -78,7 +78,7 @@ class LoDTensor : public Tensor {
*/
size_t lod_element(size_t level, size_t elem) const {
PADDLE_ENFORCE_LT(level, NumLevels());
PADDLE_ENFORCE_LT(elem, NumElements(level));
PADDLE_ENFORCE_LE(elem, NumElements(level));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

貌似应该是 LT

比如某个 level 为 [0 1 2 3 4 5]

  • NumElements 为 5
  • 可以取的 elem 范围为 0, 1, 2, 3, 4,从0开始

Copy link
Contributor Author

@wanghaoshuang wanghaoshuang Oct 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我看lod_element的实现,是取每个element的start position,我希望能取到end position。如果要取最后一个element的end position, 我就需要level的最后一个值。
现在lod是存储的elem start吧?#3746 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0-th level | |
1-th level | | | | |
2-th level | | | | | | | | | |
NumElements(0, 0) get 2 but i hope 4
NumElements(0, 1) get 3 but i hope 6

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

或者我们添加一个方法LoDTensor::sizeof(level, elem) ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getLength() ? 或者类似跟长度相关的
操作单位是 sequence

@wanghaoshuang wanghaoshuang changed the title fix LoDTensor::lod_element to get last element in level Make LoDTensor::lod_element return start and end offset of sequence Oct 19, 2017
@wanghaoshuang wanghaoshuang merged commit c8c4ba0 into PaddlePaddle:develop Oct 19, 2017
@wanghaoshuang wanghaoshuang deleted the fix_lod branch October 19, 2017 06:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LoDTensor::lod_element can't get last element
2 participants