<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Tue, Jun 26, 2018 at 9:38 AM Eric Wieser <<a href="mailto:wieser.eric%2Bnumpy@gmail.com">wieser.eric+numpy@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="m_-4430689050897346975markdown-here-wrapper" style="font-size:1em;font-family:Helvetica,arial,freesans,clean,sans-serif;color:rgb(34,34,34);background-color:rgb(255,255,255);border:none;line-height:1.2"><blockquote style="margin:1em 0px;border-left:4px solid rgb(221,221,221);padding:0px 1em;color:rgb(119,119,119);quotes:none">
<p style="margin:1em 0px">We can expose some of the internals</p>
</blockquote>
</div></div><div dir="ltr"><div class="m_-4430689050897346975markdown-here-wrapper" style="font-size:1em;font-family:Helvetica,arial,freesans,clean,sans-serif;color:rgb(34,34,34);background-color:rgb(255,255,255);border:none;line-height:1.2"><p style="margin:1em 0px">These could be expressed as methods on the internal indexing objects I proposed in the first reply to this thread, which has seen no responses.</p>
<p style="margin:1em 0px">I think Hameer Abbasi is looking for something like <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">OrthogonalIndexer(...).to_vindex() -> VectorizedIndexer</code> such that <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">arr.oindex[ind]</code> selects the same elements as <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">arr.vindex[OrthogonalIndexer(ind).to_vindex()]</code></p>
<p style="margin:1em 0px">Eric</p></div></div></blockquote><div><br></div><div>It is probably worth noting that xarray already uses very similar classes internally for keeping track of indexing operations. See BasicIndexer, OuterIndexer and VectorizedIndexer:</div><div><a href="https://github.com/pydata/xarray/blob/v0.10.7/xarray/core/indexing.py#L295-L428">https://github.com/pydata/xarray/blob/v0.10.7/xarray/core/indexing.py#L295-L428</a><br></div><div><br></div><div>This turns out to be pretty convenient model even when not using subclassing. In xarray, we use them internally in various "partial duck array" classes that do some lazy computation upon indexing with __getitem__. It's nice to simply be able to forward on Indexer objects rather than implement separate vindex/oindex methods.</div><div><br></div><div>We also have utility functions for converting between different forms, e.g., from OuterIndexer to VectorizedIndexer:</div><div><div><a href="https://github.com/pydata/xarray/blob/v0.10.7/xarray/core/indexing.py#L654">https://github.com/pydata/xarray/blob/v0.10.7/xarray/core/indexing.py#L654</a><br></div></div><div><br></div><div>I guess this is a case for using such classes internally in NumPy, and possibly for exposing them publicly as well.</div></div></div>