You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The above code is hackish and it becomes to keep track whether to offset the index by 1 in an optimisation pass or not. The reason of confusion is,
We are setting lower bound as 1 and upper bound as size in both Python and Fortran.
We offsetting indices by 1 only in Python.
We only have ASR while performing an optimisation pass. In Python we set lower and upper bounds same as Fortran but we offset index by 1 only in Python. Hence no clear differences between the two.
I suggest doing the following,
Set lower bound as 0 and upper bound as size - 1 in Python. In Fortran its provided by the user and default setting in LFortran is correct.
Don't offset indices by 1 in any LCompiler.
In an optimisation pass set the bounds of the loop (which we are creating manually in an optimisation pass) always to 0 + lower_bound(dimension) and size - 1 + lower_bound(dimension). In Python lower_bound(dimension) is always 0, so no worries. In Fortran lower_bound(dimension) is by default 1 so loop bounds will transform to 1 and size automatically.
I discovered this problem while working on #675 and I can fix it in #675 itself.
As discussed there, I think we should move to (size, start_index) representation of arrays. I don't have an opinion whether we should get rid of start_index, which would mean adjusting/offsetting all array indexing (there are pros/cons of doing that). So first let's keep the start_index. We should not offset any indices (that's the whole point of storing start_index in the first place).
Well, my main concern is offsetting indices. Either you always do it in an optimisation pass or you never do it because once an ASR is formed you never know whether the source was Python or Fortran. So offsetting indices should never be done in any frontend irrespective of which array representation we are using.
Anyways would it be okay if I remove offsetting indices by 1 in LPython? Let me know.
lpython/src/lpython/semantics/python_ast_to_asr.cpp
Lines 887 to 896 in 4591db8
lpython/src/lpython/semantics/python_ast_to_asr.cpp
Lines 866 to 870 in 4591db8
The above code is hackish and it becomes to keep track whether to offset the index by 1 in an optimisation pass or not. The reason of confusion is,
1
and upper bound assize
in both Python and Fortran.1
only in Python.I suggest doing the following,
0
and upper bound assize - 1
in Python. In Fortran its provided by the user and default setting in LFortran is correct.1
in any LCompiler.0 + lower_bound(dimension)
andsize - 1 + lower_bound(dimension)
. In Pythonlower_bound(dimension)
is always0
, so no worries. In Fortranlower_bound(dimension)
is by default1
so loop bounds will transform to1
andsize
automatically.I discovered this problem while working on #675 and I can fix it in #675 itself.
@certik Please let me know what you think.
The text was updated successfully, but these errors were encountered: