Skip to content

FIX: Make array_view.size return 0 for empty arrays #5264

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

Closed
wants to merge 1 commit into from

Conversation

jkseppan
Copy link
Member

This is an API change that seems somewhat illogical to me, but it probably avoids errors like #5185 without fixes like #5241, which seems more puzzling to me. What I mean by illogical is that a sequence with a nonzero number of zero-sized elements is presented as having length 0. But making it consistent in that corner case is probably more puzzling to code using array_view than returning the actual number of empty elements.

@mdboom
Copy link
Member

mdboom commented Oct 19, 2015

I had proposed doing something like this in #5185 (comment), but @tacaswell thought that didn't seem quite right. I guess I understand the objection from a purity point of view, but on the other hand most of the C++ code assumes a fix size for all the dimensions past the first one (i.e. an array of bounding boxes is always Nx2x2, so if it's passed an array of 1x0x1, I'm fine with it behaving as if it's 0x2x2). And handling the special case of "a zero in any dimension" in one place (the size method) as it's done here is much better than handling it everywhere that uses array_view.

For completeness, we should still do something like half of #5246, which also fixes this bug but checks the expected lower dimensions. But with this, we wouldn't need to revert the ensure_3d -> atleast_3d change. I'm going to create a new PR that combines this one with that one so it can all be tested together.

@mdboom mdboom added this to the next point release (1.5.0) milestone Oct 19, 2015
@jkseppan
Copy link
Member Author

Closing in favor of #5274.

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.

2 participants