Skip to content

Treat zero-dimensional views as contiguous SubArrays #29895

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

Merged
merged 1 commit into from
Nov 2, 2018
Merged

Treat zero-dimensional views as contiguous SubArrays #29895

merged 1 commit into from
Nov 2, 2018

Conversation

mfsch
Copy link
Contributor

@mfsch mfsch commented Nov 1, 2018

This makes sure that zero-dimensional SubArrays (views of a single value) are indexed with IndexLinear and are a subtype of FastContiguousSubArray. This way, iscontiguous returns true for such a view.

The rationale for this is that iscontiguous can be used to decide whether a SubArray can be passed to a C function, as is done in the package MPI.jl. With the proposed changes, single values of an array can be sent and received with MPI by passing a zero-dimensional view to the MPI functions.

Fixes #29608

@@ -46,7 +46,7 @@ check_parent_index_match(parent, ::NTuple{N, Bool}) where {N} =
throw(BoundsError(T(parent, indices, offset1, stride1), I))

# This computes the linear indexing compatibility for a given tuple of indices
viewindexing() = IndexLinear()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The function viewindexing() is never called without an argument in Base, so I assume this line was meant as the fallback case for viewindexing(tail(I)). Changing the argument to an empty tuple provides the correct linear indexing if all indices are ScalarIndex.

@ararslan ararslan requested a review from mbauman November 2, 2018 07:30
@ararslan ararslan added the arrays [a, r, r, a, y, s] label Nov 2, 2018
@StefanKarpinski
Copy link
Member

If it's good enough for @timholy I suspect this is good to go, but @mbauman maybe you can take a quick look and hit merge if it looks good to you as well?

@mbauman
Copy link
Member

mbauman commented Nov 2, 2018

Thanks for doing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrays [a, r, r, a, y, s]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants