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

ARROW-13877: [C++] Support FixedSizeList in generic list kernels #11127

Closed
wants to merge 4 commits into from

Conversation

lidavidm
Copy link
Member

@lidavidm lidavidm commented Sep 9, 2021

No description provided.

@github-actions
Copy link

github-actions bot commented Sep 9, 2021

const uint8_t* bitmap = input->GetValues<uint8_t>(0, 0);
for (int32_t i = 0; i < input->length; i++) {
if (!bitmap || BitUtil::GetBit(bitmap, input->offset + i)) {
std::fill(out_indices, out_indices + slot_length,
Copy link
Contributor

Choose a reason for hiding this comment

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

Move the if (!bitmap) check outside of the loop.

Copy link
Contributor

@edponce edponce Sep 10, 2021

Choose a reason for hiding this comment

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

Also, you can batch copies by tracking the number of consecutive valid bits, and then perform a std::fill when an invalid bit is encountered.

Copy link
Member Author

Choose a reason for hiding this comment

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

You can't batch copies because different slots have different values.

Copy link
Member Author

Choose a reason for hiding this comment

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

Also I would expect the branch predictor to make the difference moot here anyways; if we move !bitmap outside the loop, we would have to add a separate loop to fill the output array.

Copy link
Member

Choose a reason for hiding this comment

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

Also, if you wanted to do that, it would be much better to call VisitSetBitRuns...

Copy link
Member

@pitrou pitrou left a comment

Choose a reason for hiding this comment

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

Looks nice! A couple comment.

/// Note that it's different from `values()` in that it takes into
/// consideration null elements (they are skipped, thus copying may be needed).
Result<std::shared_ptr<Array>> Flatten(
MemoryPool* memory_pool = default_memory_pool()) const;
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a test for this method?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

const uint8_t* bitmap = input->GetValues<uint8_t>(0, 0);
for (int32_t i = 0; i < input->length; i++) {
if (!bitmap || BitUtil::GetBit(bitmap, input->offset + i)) {
std::fill(out_indices, out_indices + slot_length,
Copy link
Member

Choose a reason for hiding this comment

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

Also, if you wanted to do that, it would be much better to call VisitSetBitRuns...

auto expected = ArrayFromJSON(out_ty, "[0, null, 2, 3, 0, 42]");
CheckVectorUnary("list_flatten", input, expected);

// Construct a list with a non-empty null slot
Copy link
Member

Choose a reason for hiding this comment

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

For a fixed size list, this doesn't test anything special ;-)

Copy link
Member Author

Choose a reason for hiding this comment

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

D'oh, thanks for catching this!

auto expected = ArrayFromJSON(int32(), "[0, 0, 2, 2, 3, 3, 4, 4]");
CheckVectorUnary("list_parent_indices", input, expected);

// Construct a list with a non-empty null slot
Copy link
Member

Choose a reason for hiding this comment

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

Same here.

@pitrou pitrou closed this in 2fb8201 Sep 16, 2021
ViniciusSouzaRoque pushed a commit to s1mbi0se/arrow that referenced this pull request Oct 20, 2021
Closes apache#11127 from lidavidm/arrow-13877

Authored-by: David Li <li.davidm96@gmail.com>
Signed-off-by: Antoine Pitrou <antoine@python.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants