Added proposed multi_index_select version#34
Added proposed multi_index_select version#34bcsaldias wants to merge 6 commits intoharvardnlp:masterfrom
Conversation
|
Ouch! I accidentally sent two different functions on the same PR. I have a proposal that I'd love you can give feedback on it. So it's called multi_index_select(tensor, dims, indices). Basically, dims refers to the name of dimensions to be indexed by indices; dims must be names of tensor dimensions (no particular order required). |
|
This looks great. the isalphanum stuff could go right in if you wanted to send a separate PR. One minor thing: I want to move all the asserts to RuntimeError's. That was my fault, but let's do that for future PRs. A couple requests on multi_index:
|
I see multi-index-select as a flexible function, where you can say "I have this index, say [[3, 1], [2, 2]], where each element's dimensions correspond to 'dimc' and 'dimb' respectively, and want to index tensor T whose dimensions are (dima, dimb, dimc, dimd)." In this scenario, we would get tensor of dimension (2, dima, dimd). Ex: Is it ways too flexible? I feel like this approach takes great advantage of the abstraction of dimensions proposed by namedtensor. I could definitively develop other approaches but wanted to propose this idea first. |
|
Yes, I mostly agree with this, I think we are on the same page. However, I would 1) like indices to be a named tensor too not a list, 2) have an argument that says which is the dimension with the indices, 3) not be a different function than index_select. tensor.shape -> OrderedDict([("dima", 5), ("dimb", 4), ("dimc", 3), ("dimd", 7)]) where the standard index_select is a special case tensor.shape -> OrderedDict([("dima", 5), ("dimb", 4), ("dimc", 3), ("dimd", 7)]) |
|
Yes, that makes total sense.
Thanks for the feedback. |
This PR also fixes the nonzero method default dimension names.