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

Logical indexing per-dim #106

Closed
IanButterworth opened this issue Dec 5, 2019 · 3 comments · Fixed by #724
Closed

Logical indexing per-dim #106

IanButterworth opened this issue Dec 5, 2019 · 3 comments · Fixed by #724
Labels
cuda array Stuff about CuArray. enhancement New feature or request

Comments

@IanButterworth
Copy link
Contributor

Is your feature request related to a problem? Please describe.
Related to JuliaGPU/CuArrays.jl#290, it would be great to be able to logically index per-dim, i.e. without having to allocate the full index

Describe the solution you'd like

x[:, x[1, :] .> 3]

Describe alternatives you've considered
This approach works but allocates the index

reshape(x[repeat(view(x, 1, :) .> 3, size(x,1))], size(x,1), :)

If there was such a thing as a repeatview, this could be efficient. i.e. a view version of repeat

@IanButterworth
Copy link
Contributor Author

I made a suggestion issue in base for repeatview: JuliaLang/julia#34029

@IanButterworth
Copy link
Contributor Author

I tried an approach suggested in the issue above, but it's suboptimal in performance

using LazyArrays, FillArrays
function filterByRow(x::CuArray, row::Int; thresh=0.0)
    nrows, ncols = size(x)
    col_idxs = 1:ncols                               #idx of every col
    row_copy = Fill(true, 1, nrows)                  #trues of length nrows
    rep_idx_2D = LazyArray(@~ col_idxs .* row_copy)' #lazy copy of col_idxs to every row
    keep_cols = view(x, row, :) .> thresh            #cols to keep
    bool_idx = view(keep_cols,rep_idx_2D)            #logical index on elements to keep
    return reshape(x[bool_idx], nrows, :)            #keep and reshape
end

@maleadt maleadt transferred this issue from JuliaGPU/CuArrays.jl May 27, 2020
@maleadt maleadt added cuda array Stuff about CuArray. enhancement New feature or request labels May 27, 2020
@simeonschaub
Copy link

Describe the solution you'd like

x[:, x[1, :] .> 3]

Maybe, I am misunderstanding something here, but that already works for regular arrays, right? I was actually surprised this kind of mixed logical indexing doesn't work with CuArrays, so I ended up having to move my array to the cpu for this. How hard would it be to add support for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cuda array Stuff about CuArray. enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants