Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Language Reference error?

davidspurr
Beginner
1,034 Views
re: MERGE intrinsic function

Language Reference states that mask "Must be a logical array".

I assume the "array" bit is an error?

Does not make sense. Also, in the first example given, it is a scalar ("R = -3").

Cheers
David


0 Kudos
6 Replies
TimP
Honored Contributor III
1,034 Views

David,

MASK is a logicalarray of the same size as the other operands. If a scalar is provided, it is spread automatically, just as with other array operations.

That does look like a typo. (R == -3) would be a logical, promotable to a logical array.

0 Kudos
Steven_L_Intel1
Employee
1,034 Views
David is correct - the word "array" ought not to appear in the description of MASK. The only requirement is that MASK be of type LOGICAL. I will let our writers know.

The example is correct. It's essentially equivalent to:

IF (R < 0) THEN
result = 1.0
ELSE
result = 0.0
END IF

Think of MERGE as like the C "?" operator that can operate on arrays or scalars.
0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,034 Views
MADsblionel:
The only requirement is that MASK be of type LOGICAL.

...and of the same rank and shape as TSOURCE and FSOURCE, right?
0 Kudos
Steven_L_Intel1
Employee
1,034 Views
Technically, MERGE is an elemental function which operates on a scalar, or on each element of an array. The rules for elemental functions would require that all three arguments be of the same rank and shape, but the description of MERGE in the standard does not say so explicitly.
0 Kudos
davidspurr
Beginner
1,034 Views
No apparent technical reason why a scalar mask cannot be used when the first two arguments are arrays, and it is not hard to imagine situations where this would be useful.

But I assume if mask is an array, then it should be of the same rank and shape as the other arguments. Otherwise the intent would not be unambiguous (or even obvious), except in a few specific cases.

David
0 Kudos
Steven_L_Intel1
Employee
1,034 Views
The actual requirement is "For those elemental functions that have more than one argument, all actual arguments shall be conformable." A scalar is conformable with an array, so a scalar MASK is ok.
0 Kudos
Reply