Kotlin / multik

Multidimensional array library for Kotlin
https://kotlin.github.io/multik/
Apache License 2.0
646 stars 39 forks source link

"All elements" and "to the end"/"from the start" indexing #143

Closed 9SMTM6 closed 2 years ago

9SMTM6 commented 2 years ago

There doesnt seem to be an easy way to do the equivalent of

cube = np.random.random((30, 30, 30))
xy_plane = cube[:, :, 2]

you will need to manually add the limits to the earlier elements making it a lot less readable.

I understand that that specific syntax probably isnt possible in Kotlin, but I would appreciate a way to "ignore" some axes with less verbosity, like a method, where you can pass just the data for dimension3 or similar, and the remaining axes will be included in their entirety.

devcrocod commented 2 years ago

There is a way:

val cube = mk.rand<Float>(30, 30, 30)
val xy_plane = cube[Slice.bounds, Slice.bounds, 2]

Or yes, as you say, pass all borders manually:

val cube = mk.rand<Float>(30, 30, 30)
val xy_plane = cube[0..30, 0..30, 2]

This api is not very informative and I don't like it, maybe it will change. Also, with the appearance of open-ended ranges in Kotlin, they will also appear in multik.

9SMTM6 commented 2 years ago

Ah, that looks like exactly what I'm looking for.

Yeah, if you mean numpys general API, thats also a bit annoying at times, its difficult to find documentation because there is no obvious way to search for it, Kotlin/specifically Multiks inherits that, though perhaps to a lesser degree, as there is often an operator method.

Anyways, I think perhaps other people would also appreciate that bit in the Readme, but thats your decision, If I find another obvious place to document it I'll let you know, otherwise I'd consider this solved.