Manual Reference Pages  - parity (3fortran)

NAME

PARITY(3) - [ARRAY:REDUCTION] Array reduction by .NEQV. operation

SYNOPSIS

result = parity( mask [,dim] )

         logical(kind=KIND) function parity(mask, dim)

type(logical(kind=KIND)),intent(in) :: mask(..) type(integer(kind=**)),intent(in),optional :: dim

CHARACTERISTICS

o MASK is a logical array
o DIM is an integer scalar
o the result is of type logical with the same kind type parameter as MASK. It is a scalar if DIM does not appear; otherwise it is the rank and shape of MASK with the dimension specified by DIM removed.
o a kind designated as ** may be any supported kind for the type

DESCRIPTION

PARITY(3) calculates the parity array (i.e. the reduction using .neqv.) of MASK along dimension DIM if DIM is present and not 1. Otherwise, it returns the parity of the entire MASK array as a scalar.

OPTIONS

o MASK : Shall be an array of type logical.
o 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 MASK.

RESULT

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 MASK has rank one, PARITY (MASK, DIM) is equal to PARITY (MASK). Otherwise, the result is an array of parity values with dimension DIM dropped.

EXAMPLES

Sample program:

    program demo_parity
    implicit none
    logical, parameter :: T=.true., F=.false.
    logical :: x(3,4)
      ! basics
       print *, parity([T,F])
       print *, parity([T,F,F])
       print *, parity([T,F,F,T])
       print *, parity([T,F,F,T,T])
       x(1,:)=[T,T,T,T]
       x(2,:)=[T,T,T,T]
       x(3,:)=[T,T,T,T]
       print *, parity(x)
       print *, parity(x,dim=1)
       print *, parity(x,dim=2)
    end program demo_parity

Results:

     >  T
     >  T
     >  F
     >  T
     >  F
     >  T T T T
     >  F F F

STANDARD

Fortran 2008

SEE ALSO

o ALL(3) - Determines if all the values are true
o ANY(3) - Determines if any of the values in the logical array are [char46]true.
o COUNT(3) - Count true values in an array
o SUM(3) - Sum the elements of an array
o MAXVAL(3) - Determines the maximum value in an array or row
o MINVAL(3) - Minimum value of an array
o PRODUCT(3) - Product of array elements
o REDUCE(3) - General array reduction
fortran-lang intrinsic descriptions (license: MIT) @urbanjost


Nemo Release 3.1 parity (3fortran) April 28, 2024
Generated by manServer 1.08 from 562c1540-ff10-4a4a-ab47-e01e51d95e2a using man macros.