PSyclone icon indicating copy to clipboard operation
PSyclone copied to clipboard

Convert array syntax (without ranges) to ranges and loops. Should there be a canonical form?

Open sergisiso opened this issue 3 years ago • 6 comments

The expressions: my_array = 2 my_array(:,:) = 2

do i = 1, size(my_array, 1)
    do j = 1, size(my_array, 2)
        my_array(i,j) = 2
    end do
end do

are all semantically equivalent (*well... with no order implied in the array forms). We have a transformation to transform the 2nd form to the 3rd form, but in some situations we also need to transform the 1st form to the 3rd (maybe by going 1st->2nd->3rd form).

And additional question is that our transfomations search and apply usually to just one of the forms, but we often would want to apply a transformation regardless of how the code it written. We can explore if it would make sense to consider one of them the canonical form and let the fparser_reader already transform it to the proper cannonical format. At least between the 1st and 2nd forms.

sergisiso avatar Jan 19 '22 11:01 sergisiso

That sounds like a good idea to me. This issue also has a bearing on the current duplication of functionality in the frontend where handler (_array_syntax_to_indexed) and the NemoArrayRange2Loop transformation.

arporter avatar Jan 27 '22 14:01 arporter

I agree. I see no reason to support two forms in PSyIR if we don't need to.

rupertford avatar Jan 27 '22 14:01 rupertford

I've just been stung by this problem in the PSyAD work too. I'd need the transformation from the 1st->2nd form as the problem is caused by the lack of any array notation in an assignment.

arporter avatar Apr 20 '22 07:04 arporter

Yes, it would be useful for PSyAD to have a transformation from 1st to 2nd form (or to deal with it when generating PSyIR if that is feasible).

rupertford avatar Aug 03 '22 16:08 rupertford

Created branch 1576_array_notatation_transformation

rupertford avatar Aug 03 '22 16:08 rupertford

I have the same snippet of code that you added in the transformation apply in my NEMO script. So this will also work for me to simplify the script. I can verify it works for NEMO when its ready.

I would scrap the "canonical form" idea in that I asked in this PR. It doesn't solve much because since we have DeferedType that can still appear in the scalar reference form means we still need to check the reference datatype to do any assumption about what scalar references syntax really are.

sergisiso avatar Aug 04 '22 08:08 sergisiso