[J3] Multiply subscripting a scalar in F2023, was RE: Is this legal in F202X? Rank agnosticism and scalars
Malcolm Cohen
malcolm at nag-j.co.jp
Wed Jan 25 05:22:19 UTC 2023
Hi Tom,
I think a simpler example shows the question, though not the motivation, viz
Program test
Integer :: x(0)
Real y
y = 3
Print *,y(@x)
End Program
You write
> but I’m not seeing anything in the text that allows us to use scalars in this context.
There is nothing explicit, I think.
> This constraint seems to strongly indicate the scalar case is not supported:
>
>C925 (R918) Exactly one part-ref shall have nonzero rank,
This is a constraint that determines whether a data-ref is an array section. Whatever else X(@Y) is, it is never going to be an array section! (Even when X is an array, X(@Y) will be scalar because it is an array element.)
So I do not see the relevance.
We do have
The rank of a data-ref is the rank of the part-ref with nonzero rank, if any; otherwise, the rank is zero.
Which says that the rank of X(@Y) is zero. Always, for any X and Y. That’s not all that helpful, as it’s the validity of the part-ref that is in question. But there is a helpful constraint for part-ref:
C913 (R912) If a section-subscript-list appears, the sum of the rank of part-ref , the sizes of the arrays in each
multiple subscript, and the number of subscripts, shall equal the rank of part-name.
All these are clearly zero (the rank of a part-ref is defined after C918, and is zero here), so the constraint is clearly satisfied.
So although I’m not seeing an explicit permission to attach a multiple-subscript to a scalar, I am also not seeing a prohibition. And as far as I can see, the semantics are there.
Carefully reading through the words we have, it’s possible that we need to do some improvement anyway. Clarifying that this is allowed for scalars is one of the improvements that should be made (whether as a NOTE, or maybe it will fall out of the normative text more obviously when that is improved).
I will also note that even if we had deliberately prohibited this in F202X (X==3), when it comes to F202Y (with TEMPLATEs) that decision could be changed in the light of the extra info from the TEMPLATE subgroup.
So don’t forget about this (the text does need improving), but no need to panic at this point, I think.
Cheers,
--
..............Malcolm Cohen, NAG Oxford/Tokyo.
From: J3 <j3-bounces at mailman.j3-fortran.org> On Behalf Of Clune, Thomas L. (GSFC-6101) via J3
Sent: Tuesday, January 24, 2023 4:09 AM
To: j3 <j3 at mailman.j3-fortran.org>
Cc: Clune, Thomas L. (GSFC-6101) <thomas.l.clune at nasa.gov>
Subject: [J3] Is this legal in F202X? Rank agnosticism and scalars
Suppose we have a template that is parameterized by rank N:
TEMPLATE TMPL(N)
INTEGER, CONSTANT :: N
CONTAINS
REAL FUNCTION FIRST_ELEMENT(A)
REAL, RANK(N), INTENT(IN) :: A
INTEGER :: idx(N)
idx = 1
PRINT*, A(@idx) ! is this legal for N=0
END REAL
END TEMPLATE
Now, consider the case for N = 0. Is the PRINT statement above legal? I recall discussing this issue when the multiple-subscript-triplet paper went in, but I’m not seeing anything in the text that allows us to use scalars in this context.
This constraint seems to strongly indicate the scalar case is not supported:
C925 (R918) Exactly one part-ref shall have nonzero rank, and either the final part-ref shall have a section
subscript-list with nonzero rank, another part-ref shall have nonzero rank, or the complex-part-designator
shall be an array.
* Tom
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20230125/e13437bd/attachment-0001.htm>
More information about the J3
mailing list