Fortran Wiki parity

Description

Calculates the parity (i.e. the reduction using .xor.) of mask along dimension dim.

Standard

Fortran 2008 and later

Class

Transformational function?

Syntax

result = parity(mask[, dim])

Arguments

• mask - Shall be an array of type logical.
• dim - (Optional) shall be a scalar of type integer with a value in the range from 1 to n, where n equals the rank of array.

Return value

The result is of the same type as mask.

If dim is absent, a scalar with the parity of all elements in mask is returned: .true. if an odd number of elements are .true. and .false. otherwise. If dim is present, an array of rank $n-1$, where $n$ equals the rank of mask, and a shape similar to that of mask with dimension dim dropped is returned.

Example

program test_parity
logical :: x(2) = [ .true., .false. ]
print *, parity(x) ! T
end program

category: intrinsics