https://kotlinlang.org logo
#mathematics
Title
# mathematics
p

Pavel Gorgulov

10/11/2021, 6:46 PM
Multik 0.1 released with complex numbers, new linear algebra methods, improved performance and other features https://blog.jetbrains.com/kotlin/2021/10/multik-0-1-is-out/ Slack Conversation
👍 3
🎉 3
a

altavir

10/11/2021, 7:35 PM
Looks nice. We can start connecting it to KMath tensor API. I found an inconsistency though. You try to follow numpy broadcasting rules. but
Copy code
a = numpy.array([[1, 2, 3],[1, 2, 3]])
b = numpy.array([1, 2, 3])
a + b
will work in numpy and won't work in multik. I am not a fan of implicit broadcasting (and do not like numpy ideology in general), but one needs to be clear about that. In KMath I insisted that broadcasting is not possible in default algebras.
p

Pavel Gorgulov

10/12/2021, 12:19 PM
What makes you think that we are trying to comply with the numpy broadcasting rules?
Copy code
a = numpy.array([[1, 2, 3],[1, 2, 3]])
b = numpy.array([1, 2, 3])
a + b
This code will not work for us even at the compilation stage, since the dimensions are different. We introduced
Dimension
right from the start for this kind of checks.
a

altavir

10/12/2021, 12:59 PM
Broadcasting for single number obviously works. Therefor the question is how do you choose when to broadcast and when not to.
In my opinion, implicit broadcasting is one of the main problems in numpy. In Julia they do special broadcasting operation with
.
, but it solves the problem only for simple one-argument operations. When we started to think about how to apply specific broadcasting rules to specific cases, we came to the algebra-based model, we use now in KMath. We use different rules for different scopes.
p

Pavel Gorgulov

10/12/2021, 4:19 PM
Yes, ndarray operations with scalars are allowed. For several reasons: * these are quite frequent operations * no internal transformations occur for this * they are intuitive, unlike broadcasting two ndarrays * is a different object, not ndarray. That is, if we take and create ndarray with one elements, then the operation with another ndarray will be impossible due to different shapes. I agree that implicit broadcasting is a problem. Therefore, at the level of ndarrays, it is also impossible for us.
a

altavir

10/12/2021, 4:20 PM
What about types? I can check myself but what will happen if we will try to add a compex number to a ndarray of doubles or vise versa?
OK, I did not expect this:
But it works for complex numbers
p

Pavel Gorgulov

10/12/2021, 5:04 PM
Same type required
a

altavir

10/12/2021, 5:05 PM
I mean that you can add any number to a Complex. And even sum different complex types
p

Pavel Gorgulov

10/12/2021, 6:01 PM
Yes, it is possible for this to be consistent with the numeric operations in Kotlin.
2 Views