Suggestion for Kotlin Numpy Operator Syntax

Hi,

I don’t think that I can influence Jetbrains design team, but I will say my suggestion anyway before it is too late. For Kotlin Numpy elementwise operators, isn’t it better to use Matlab-like syntax?

For mulitplication, I think “.*” for elementwise and " * " for matrix product would look a lot clearer compared to the magical “@”. Or “.**” or “.^” would look better than “**” and clearer also.

What do you think?

Happy Coding!

Kotlin, luckily for us does not have broadcast operations. It means that operation logic is defined by the actual container type you are using (if container addition is defined as element-wise, it will be done element-wise, if not - it won’t work).
Broadcast simplifies simple operations, but tremendously complicates larger code and makes it really hard to understand. And Python style, where you do not know if you do one-to-one or one-to-many operation before seeing the result is the worst of all. Julia style, where you have special broadcast . operator is much better, but still is a terrible mess when it comes to multiple argument functions.
My current effort in kmath is to make many-to-many operations accessible inside specific scope. Meaning that normally you can’t add a number to a vector, but you can when you call the operation in a specific scope. which defines it.
If you really interested in the development of those features, please join us on kotlin slack #mathematics channel.

2 Likes