Kotlin / multik

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

A way to apply transformations on sub-dimensions #142

Closed 9SMTM6 closed 2 years ago

9SMTM6 commented 2 years ago

I read the closed issue on broadcasting support, but while that link linked to broadcasting, it seemed to me that the OP was asking for something different.

But, more importantly, broadcasting has specific semantics attched to it, which I can see why you would not /could not support them in Kotlin. But a general way to apply some transformation to one dimension, eg. subtracting a vector from all entries in a matrix, seems warranted to me.

What I currently do is less efficient and only works on the first dimension:

fun <T>D2Array<T>.broadcastInplace(operation: (input: MultiArray<T, D1>) -> D1Array<T>) {
    for (idx in 0 until this.shape[0]) {
        this[idx] = operation(this[idx])
    }
}

At the very least a way to loop through different dimensions would be appreciated.

devcrocod commented 2 years ago

I'm still thinking about it. So far, I'm only considering the option of broadcasting with copying, because any inplace operations cause a lot of problems.

9SMTM6 commented 2 years ago

Yeah, I'd be able to live with that. This particular bit was just to closer match numpy, in which I had written the reference implementation of that algorithm, but at least I'd have found a way to live with copying. At least for now, performance isnt THAT critical yet.

Feel free to keep this open or close it how you like.