Big Chungus

    Big Chungus

    3 months ago
    Does anyone know if multik has something like np.roll() for d2Array?
    Pavel Gorgulov

    Pavel Gorgulov

    3 months ago
    Unfortunately, there is no such method in multik
    Big Chungus

    Big Chungus

    3 months ago
    Are you aware of any alternatives for kotlin?
    Or any articles that would allow me to implement one myself?
    Pavel Gorgulov

    Pavel Gorgulov

    3 months ago
    For any dimension?
    Big Chungus

    Big Chungus

    3 months ago
    I'm working with d2Array
    Pavel Gorgulov

    Pavel Gorgulov

    3 months ago
    roll
    without specifying an axis, it’s just a shift. You can use Collections.rotate:
    fun D2Array<Int>.roll(n: Int): D2Array<Int> {
        val data = this.toList().also { Collections.rotate(it, n) }
        return D2Array(MemoryViewIntArray(data.toIntArray()), shape = this.shape.clone(), dim = this.dim)
    }
    or use
    sliceArray
    fun D2Array<Int>.roll(n: Int): D2Array<Int> {
        val newData = this.data.getIntArray().let { it.sliceArray(size - n until size) + it.sliceArray(0 until size - n) }
        return D2Array(MemoryViewIntArray(newData), shape = this.shape.clone(), dim = this.dim)
    }
    Big Chungus

    Big Chungus

    3 months ago
    I do need an axis though 😄 Here's what I'm trying to do
    img = np.roll(img, dy, axis=0)
     img = np.roll(img, dx, axis=1)
    img is a 2d array
    Pavel Gorgulov

    Pavel Gorgulov

    3 months ago
    with axes are more complicated There are no functions from kotlin for this, here need to work with
    strides
    Big Chungus

    Big Chungus

    3 months ago
    Might sound a bit dense, but what do axes mean in 2darray context here?
    Pavel Gorgulov

    Pavel Gorgulov

    3 months ago
    Same as in numpy, axis(1) by columns or axis(0) by rows
    Big Chungus

    Big Chungus

    3 months ago
    🤦‍♂️ so basically dimensions. Thought so...
    altavir

    altavir

    3 months ago
    In KMathe it is planed to do that with virtual buffers. But manipulating strides is a more performant solution. I wonder if roll have a lot of uses outside numpy paradigm (I meant when you can't work with elements in a cycle). @Big Chungus could you explain the problem you are solving.
    Big Chungus

    Big Chungus

    3 months ago
    Not sure I can. I'm basically getting my feet wet with OpenCV and image transformations. Here's a PY algorithm I'm trying to reproduce to shift image https://stackoverflow.com/a/53140617
    Also kmath seems massive, but the missing docs makes it extremey hard to get started (I've been trying for the entire day today 😄 )
    altavir

    altavir

    3 months ago
    Yeah, a lot of holes in it and too many experiments so far. For simple 2d manipulation Multik could be better so far.