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

overwrite Base.maybeview? #155

Open
putianyi889 opened this issue Jul 20, 2023 · 1 comment
Open

overwrite Base.maybeview? #155

putianyi889 opened this issue Jul 20, 2023 · 1 comment

Comments

@putianyi889
Copy link
Contributor

putianyi889 commented Jul 20, 2023

motivation is from #153

Taking a view intends to minimize allocation. However, for some lazy arrays, allocating a concrete subarray could be more efficient. The proposal is as follows

maybeview(A::AbstractArray, args...) = maybeview(MemoryLayout(A), A, args...)
maybeview(::MemoryLayout, A, args...) = view(A, args...)
maybeview(::AbstractLazyLayout, A, args...) = A[args...] # at LazyArrays.jl
@dlfivefifty
Copy link
Member

From the views.jl:

# maybeview is like getindex, but returns a view for slicing operations
# (while remaining equivalent to getindex for scalar indices and non-array types)

So your proposal would be inconsistent with the definition. But we could call it something else.

Btw I've started not using the same function name with extra arguments (following some good changes from @jishnub) so I would call this:

maybeview(A::AbstractArray, args...) = maybeview_layout(MemoryLayout(A), A, args...)
maybeview_layout(::MemoryLayout, A, args...) = view(A, args...)
maybeview_layout(::AbstractLazyLayout, A, args...) = A[args...] # at LazyArrays.jl

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

No branches or pull requests

2 participants