Kotlin / multik

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

any plan to add `power` function like numpy? #162

Open kylooh opened 1 year ago

kylooh commented 1 year ago

I'd like to hava a power function just like numpy.

Behavoirs:

case 1:

array [1, 2, 3, 4, 5] power number 2 returns [1, 4, 9, 16, 25]

case 2:

array [1, 2, 3, 4, 5] power array [1, 1, 2, 2, 1] returns [1, 2, 9, 16, 5]

case 3:

array [1, 2, 3, 4, 5] power array of [[1, 1, 2, 2, 1], [2, 2, 1, 1, 2]] returns [[1, 2, 9, 16, 5], [1, 4, 3, 4, 25]]

Guys, do you have any plan for this one? Or it is just a not such reasonable case for library design. Or there is already one simliar function with different name.

Thx.

devcrocod commented 1 year ago

There is a pow function, but it raises the entire matrix to the power. It makes sense to add the function you described to the library

tklinchik commented 6 months ago

@devcrocod Where can I find matrix power feature you referenced?

devcrocod commented 6 months ago

mk.linalg.pow(ndarray, n) - https://kotlin.github.io/multik/multik-core/org.jetbrains.kotlinx.multik.api.linalg/-lin-alg/pow.html?query=abstract%20fun%20%3CT%20:%20Number%3E%20pow(mat:%20MultiArray%3CT,%20D2%3E,%20n:%20Int):%20NDArray%3CT,%20D2%3E

tklinchik commented 6 months ago

Thanks. Any plans to support power to float/double besides just int? What about in-place?

devcrocod commented 5 months ago

Any plans to support power to float/double besides just int?

Yes, it is planned

What about in-place?

I'm avoiding using inplace operations for now, as it creates a lot of problems. I tried to add a new API for such operations, but I see that it is not used, so I will remove it in subsequent releases