kotlin-numpy icon indicating copy to clipboard operation
kotlin-numpy copied to clipboard

Expression " A[i] * B[ p[i] ][ p ] " unexpectedly mutates vector p

Open stivens opened this issue 4 years ago • 0 comments

Hi,

Given function: `

fun objectiveFunction(p: KtNDArray<Long>): Double {
    var s = 0.0
    
    for (i in 0 until problemSize) {
        println("iter $i")
        println("p before: $p")
        val res = flowMatrix[i] * distanceMatrix[p[i]][p]
        println("res: $res")
        println("p after: $p")
        
        s += res.sum()!!
    }
    
    return s
}

`

We can observe strange output: `

$ QAP.of( "http://anjos.mgi.polymtl.ca/qaplib/data.d/nug12.dat" ).objectiveFunction(Random.permutation(12))

iter 0 p before: [ 4 2 1 5 3 8 6 10 0 7 9 11] res: [ 0 0 4 30 5 0 0 4 2 0 20 5] p after: [ 0 0 4 30 5 0 0 4 2 0 20 5] iter 1 p before: [ 0 0 4 30 5 0 0 4 2 0 20 5]

org.jetbrains.numkt.NumKtException: <class 'IndexError'>: index 30 is out of bounds for axis 0 with size 12

`

stivens avatar Oct 21 '20 16:10 stivens