multik icon indicating copy to clipboard operation
multik copied to clipboard

A way to apply transformations on sub-dimensions

Open 9SMTM6 opened this issue 1 year ago • 2 comments

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.

9SMTM6 avatar Aug 12 '22 10:08 9SMTM6

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.

devcrocod avatar Aug 12 '22 14:08 devcrocod

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.

9SMTM6 avatar Aug 12 '22 15:08 9SMTM6