[foreign-memaccess] RFR: JDK-8241866:Add API to reshape sequence layouts

Henry Jen henryjen at openjdk.java.net
Mon Mar 30 19:18:03 UTC 2020


On Mon, 30 Mar 2020 17:34:40 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

> https://docs.scipy.org/doc/numpy/reference/generated/numpy.reshape.html
> 
> As in Python, clients can use _at most_ one `-1` dimension value, and that dimension value will be inferred by
> remaining dimensions.
> The changes also add the `flatten` method, which does the opposite - e.g. take a sequence layout, whose element layout
> could be other nested sequence layouts and flatten everything into an outermost sequence layout (where element count is
> adjusted as needed).  These routines are fairly general and helpful and I found myself in need for something similar
> when writing code doing parallel processing of memory segments, but there are many other possible use cases.

One minor nit, otherwise looks good to me

src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/SequenceLayout.java line 214:

> 213:         while (elemLayout instanceof SequenceLayout) {
> 214:             count = count * ((SequenceLayout)elemLayout).elementCount().getAsLong();
> 215:             elemLayout = ((SequenceLayout)elemLayout).elementLayout();

Should we throw same UOE here if no elementCount() or just let the NoSuchElementException pass through?

-------------

PR: https://git.openjdk.java.net/panama-foreign/pull/75


More information about the panama-dev mailing list