Hello everyone,
I have discovered some unexplainable behavior of "while" loop construction in delite.
Let us consider this simple piece of code
val length = 3
var state: Rep[DeliteArray[Int]] = darray_fromfunction(length, {x => 0}) //create array of given length filled with zeros
while ( darray_reduce[Int]( state, {(a,b) => a+b}, 0) < 30) { // check if sum of array elements is less then 30
state = darray_fromfunction(state.length, { i => state(i) + 1} ) // add 1 to each element
}
state //return state
I expect the loop iterate 9 times and get array with all elements equal to 9. But what I see in fact is (1,1,1), which means that the loop iterated only once.
If I modify the code in the following way:
val length = 3
var state: Rep[DeliteArray[Int]] = darray_fromfunction(length, {x => 0}) //create array of given length filled with zeros
while ( darray_reduce[Int]( state, {(a,b) => a+b}, 0) < 30) { // check if sum of array elements is less then 30
val p: Rep[Unit] = println("New iteration")
state = darray_fromfunction(state.length, { i => state(i) + 1} ) // add 1 to each element
}
state
then the programm goes into infinite loop and print "New iteration" infinitely.
Could you please point me on what I am doing wrong? Or, in case of I happened to hit unsupported scenario, provide me with some workaround in order I can use "while" constructions?
Thank you in advance,
Alexander Filippov