Thread
#mathematics
    Pavel Gorgulov

    Pavel Gorgulov

    11 months ago
    message has been deleted
    altavir

    altavir

    11 months ago
    Looks nice. We can start connecting it to KMath tensor API. I found an inconsistency though. You try to follow numpy broadcasting rules. but
    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.
    Pavel Gorgulov

    Pavel Gorgulov

    11 months ago
    What makes you think that we are trying to comply with the numpy broadcasting rules?
    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.
    altavir

    altavir

    11 months ago
    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.
    Pavel Gorgulov

    Pavel Gorgulov

    11 months ago
    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.
    altavir

    altavir

    11 months ago
    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
    Pavel Gorgulov

    Pavel Gorgulov

    11 months ago
    Same type required
    altavir

    altavir

    11 months ago
    I mean that you can add any number to a Complex. And even sum different complex types
    Pavel Gorgulov

    Pavel Gorgulov

    11 months ago
    Yes, it is possible for this to be consistent with the numeric operations in Kotlin.