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

Refactor out index wrangling code #68

kyonifer opened this Issue Oct 13, 2018 · 2 comments


None yet
3 participants

kyonifer commented Oct 13, 2018

It may make sense to refactor out the code that converts linear indices into N-dimensional indices and vice versa into a separate object that could be re-used. See discussion in #47 for background.


This comment has been minimized.


drmoose commented Oct 13, 2018

Here's a sketch of the idea I was talking about in #47,

interface NDArrayShape {
    fun shape(): List<T>

interface NDArrayCursor: NDArrayShape, Collection<Int> {
    val linear: Int
    val pos: IntArray  // this would be implemented as lazy by { linearToIdx(linear) }

     // Collection<Int> would be implemented as calls to pos

/// and then codegen a bunch of these so that destructuring works
interface NDArrayCursor1: NDArrayCursor { fun component1() } 

And then use the NDArrayCursor in places that currently use IntArrays as indices, so that code that only needs linear can use it efficiently, and code that needs the full position can read it without having to compute it itself.


This comment has been minimized.


peastman commented Oct 14, 2018

If NDArrayCursor implements the [] operator, existing code that expects an IntArrayshould mostly continue to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment