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

Refactor out index wrangling code #68

Open
kyonifer opened this issue Oct 13, 2018 · 2 comments
Open

Refactor out index wrangling code #68

kyonifer opened this issue Oct 13, 2018 · 2 comments

Comments

@kyonifer
Copy link
Owner

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.

@drmoose
Copy link
Contributor

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.

@peastman
Copy link
Contributor

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants