I’m trying to verify something and hope people here can provide an answer or guidance.
arr2d = merge(1,0, mask2d)
Note that tsource
and fsource
are not arrays, but mask
and result
are arrays. The above works in gfortran. However, in ifort it doesn’t appear to work. Does ifort require all 3 arguments to be the same size and rank?
From the standard interpretation document, J3/24-007,
Seems to work just like the standard says: Compiler Explorer. Which version of ifort are you using? (Note: ifort has been deprecated)
The single word that clarifies this IMO is that MERGE is ELEMENTAL. So the arrays all have to be the same shape and dimensions (the definition of merge also requires TSOURCE and FSOURCE to be of the same type and kind, but that is a separate matter), but other arguments may still be scalar by definition. Seems like you are not violating that; even though it is a usage I have not seen before. The scalars should be spread to the size of the logical mask as far as I see it.
That is not the case. Elemental is defined as:
independent scalar application of an action or operation to elements of an array or corresponding elements of a set of conformable arrays and scalars, or possessing the capability of elemental operation
Note 1 to entry: Combination of scalar and array operands or arguments combine the scalar operand(s) with each element of the array operand(s).
So you can have some scalar arguments (tsource and fsource) and an array argument (mask).
That is what I meant to imply. When elemental everything can be scalar, but arguments may be arrays as well, but if any argument is an array, all arguments that are arrays must have the same shape is my interpretation. So I was saying that was a legal call. One is an array (the logical mask) and the others are scalars so it should behave like all are arrays of the size and shape of the logical array as if the scalars were duplicated and used to populate an array of the same size. So to me that looks like a legal call to turn an array of logical values into an array of 1s and 0s.
If you leave out the word ELEMENTAL from the standard definition above it seems very unclear what size everything has to be. All the same? At least as big as the MASK? No bigger than TSOURCE? The rules for elemental procedures clarifies all that.
1 Like
Thank you for clarifying and linking to Compiler Explorer. It must be a bug elsewhere and something I’m doing wrong with gdb when I’m not seeing the expected results deep in the program.
Yes, I’m using an old compiler, either comp/intel/19.1… or 2021.4. But it isn’t a compiler issue based on this conversation and Compiler Explorer.
Sorry for the misunderstanding, just like you say, the array arguments must match in shape - be conformable.
I tried those two in compiler explorer and both worked.
If I can recall correctly, there was a thread on Discourse that Fortran support in gdb would really need some enhancements in ways it interacts with some of the newer Fortran syntax elements. Maybe elemental procedures are one of those lacking areas.
Sorry, I’m not a (fortran) programmer.