ParaMonte Fortran 2.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
pm_matrixTrace::getMatTrace Interface Reference

Generate and return the trace of an input square matrix of type integer, complex, or real of arbitrary kind.
More...

Detailed Description

Generate and return the trace of an input square matrix of type integer, complex, or real of arbitrary kind.

See the documentation of pm_matrixTrace for more details.

Parameters
[in]mat: The input non-zero-order matrix of shape (1 : ndim * (ndim - 1) / 2 or (1:ndim, 1:ndim) of,
  1. type integer of kind any supported by the processor (e.g., IK, IK8, IK16, IK32, or IK64),
  2. type complex of kind any supported by the processor (e.g., CK, CK32, CK64, or CK128),
  3. type real of kind any supported by the processor (e.g., RK, RK32, RK64, or RK128),
containing the matrix whose trace is to be computed.
It can be of rank 1 (of shape (1 : ndim * (ndim - 1) / 2) if and only if the input argument mat is present and set to lfpack.
[in]pack: The input scalar that can be,
  1. the constant lfpack signifying the linear full packing of the input matrix.
  2. the constant rdpack signifying the rectangular default packing of the input matrix.
  3. the constant rfpack signifying the rectangular full packing of the input matrix.
(optional, default = rdpack)
[in]subset: The input scalar that can be,
  1. the constant uppDia signifying the storage of the upper-diagonal subset of original matrix in the input matrix.
  2. the constant lowDia signifying the storage of the lower-diagonal subset of original matrix in the input matrix.
(optional. It must be present if and only if the input argument is present and set to either lfpack or rfpack.)
Returns
trace : The output scalar of the same type and kind as the input matrix mat, containing the trace of the input square matrix.


Possible calling interfaces

use pm_matrixTrace, only: lfpack, rdpack, rfpack, uppDia, lowDia
trace = getMatTrace(mat)
trace = getMatTrace(mat, pack) ! pack = rdpack
trace = getMatTrace(mat, pack, subset) ! pack = rdpack/lfpack, subset = uppDia/lowDia
!
Generate and return the trace of an input square matrix of type integer, complex, or real of arbitrar...
This module contains procedures and generic interfaces for computing the additive or multiplicative t...
Warning
The input matrix must correspond to a square matrix or a triangular subset of a non-zero-order square matrix.
These conditions are verified only if the library is built with the preprocessor macro CHECK_ENABLED=1.
The pure procedure(s) documented herein become impure when the ParaMonte library is compiled with preprocessor macro CHECK_ENABLED=1.
By default, these procedures are pure in release build and impure in debug and testing builds.
See also
getMatTrace
getMatMulTrace
getMatMulTraceLog
pm_matrixPack
pm_matrixSubset


Example usage

1program example
2
3 use iso_fortran_env, only: output_unit
4 use pm_kind, only: SK, IK, LK, CK, RK
6 use pm_matrixCopy, only: getMatCopy, rdpack, rfpack, lfpack
8 use pm_distUnif, only: getUnifRand
9 use pm_io, only: display_type
10
11 implicit none
12
13 integer(IK) :: ndim, itry, ntry = 5
14
15 type(display_type) :: disp
16 disp = display_type(file = "main.out.F90")
17
18 block
19 integer, allocatable :: mat(:,:), rfp(:,:), lfp(:) ! all integer kinds are supported.
20 do itry = 1, ntry
21 call disp%skip()
22 call disp%show("ndim = getUnifRand(1, 7)")
23 ndim = getUnifRand(1, 7)
24 call disp%show("mat = getUnifRand(1, 9, ndim, ndim)")
25 mat = getUnifRand(1, 9, ndim, ndim)
26 call disp%show("mat")
27 call disp%show( mat )
28 call disp%show("getMatTrace(mat)")
29 call disp%show( getMatTrace(mat) )
30 call disp%show("getMatTrace(getMatCopy(rdpack, mat, rdpack, subset = uppDia))")
31 call disp%show( getMatTrace(getMatCopy(rdpack, mat, rdpack, subset = uppDia)) )
32 call disp%show("getMatTrace(getMatCopy(rdpack, mat, rdpack, subset = lowDia))")
33 call disp%show( getMatTrace(getMatCopy(rdpack, mat, rdpack, subset = lowDia)) )
34 call disp%show("getMatTrace(getMatCopy(lfpack, mat, rdpack, lowDia), lfpack, lowDia)")
35 call disp%show( getMatTrace(getMatCopy(lfpack, mat, rdpack, lowDia), lfpack, lowDia) )
36 call disp%skip()
37 end do
38 end block
39
40end program example
Generate and return a scalar or a contiguous array of rank 1 of length s1 of randomly uniformly distr...
This is a generic method of the derived type display_type with pass attribute.
Definition: pm_io.F90:11726
This is a generic method of the derived type display_type with pass attribute.
Definition: pm_io.F90:11508
Generate and return a copy of a desired subset of the input source matrix of arbitrary shape (:) or (...
This module contains classes and procedures for computing various statistical quantities related to t...
This module contains classes and procedures for input/output (IO) or generic display operations on st...
Definition: pm_io.F90:252
type(display_type) disp
This is a scalar module variable an object of type display_type for general display.
Definition: pm_io.F90:11393
This module defines the relevant Fortran kind type-parameters frequently used in the ParaMonte librar...
Definition: pm_kind.F90:268
integer, parameter RK
The default real kind in the ParaMonte library: real64 in Fortran, c_double in C-Fortran Interoperati...
Definition: pm_kind.F90:543
integer, parameter LK
The default logical kind in the ParaMonte library: kind(.true.) in Fortran, kind(....
Definition: pm_kind.F90:541
integer, parameter CK
The default complex kind in the ParaMonte library: real64 in Fortran, c_double_complex in C-Fortran I...
Definition: pm_kind.F90:542
integer, parameter IK
The default integer kind in the ParaMonte library: int32 in Fortran, c_int32_t in C-Fortran Interoper...
Definition: pm_kind.F90:540
integer, parameter SK
The default character kind in the ParaMonte library: kind("a") in Fortran, c_char in C-Fortran Intero...
Definition: pm_kind.F90:539
This module contains procedures and generic interfaces relevant to copying (diagonal or upper/lower t...
This module contains abstract and concrete derived types that are required for compile-time resolutio...
type(lowDia_type), parameter lowDia
This is a scalar parameter object of type lowDia_type that is exclusively used to request lower-diago...
type(uppLowDia_type), parameter uppLowDia
This is a scalar parameter object of type uppLowDia_type that is exclusively used to request full dia...
type(uppLow_type), parameter uppLow
This is a scalar parameter object of type uppLow_type that is exclusively used to request upper-lower...
type(uppDia_type), parameter uppDia
This is a scalar parameter object of type uppDia_type that is exclusively used to request upper-diago...
type(dia_type), parameter dia
This is a scalar parameter object of type dia_type that is exclusively used to request unit (or Ident...
Generate and return an object of type display_type.
Definition: pm_io.F90:10282

Example Unix compile command via Intel ifort compiler
1#!/usr/bin/env sh
2rm main.exe
3ifort -fpp -standard-semantics -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
4./main.exe

Example Windows Batch compile command via Intel ifort compiler
1del main.exe
2set PATH=..\..\..\lib;%PATH%
3ifort /fpp /standard-semantics /O3 /I:..\..\..\include main.F90 ..\..\..\lib\libparamonte*.lib /exe:main.exe
4main.exe

Example Unix / MinGW compile command via GNU gfortran compiler
1#!/usr/bin/env sh
2rm main.exe
3gfortran -cpp -ffree-line-length-none -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
4./main.exe

Example output
1
2ndim = getUnifRand(1, 7)
3mat = getUnifRand(1, 9, ndim, ndim)
4mat
5+6, +4, +6, +6
6+4, +2, +7, +5
7+1, +6, +5, +3
8+5, +5, +7, +6
10+19
11getMatTrace(getMatCopy(rdpack, mat, rdpack, subset = uppDia))
12+19
13getMatTrace(getMatCopy(rdpack, mat, rdpack, subset = lowDia))
14+19
15getMatTrace(getMatCopy(lfpack, mat, rdpack, lowDia), lfpack, lowDia)
16+23
17
18
19ndim = getUnifRand(1, 7)
20mat = getUnifRand(1, 9, ndim, ndim)
21mat
22+6, +7, +3
23+3, +9, +5
24+1, +1, +9
25getMatTrace(mat)
26+24
27getMatTrace(getMatCopy(rdpack, mat, rdpack, subset = uppDia))
28+24
29getMatTrace(getMatCopy(rdpack, mat, rdpack, subset = lowDia))
30+24
31getMatTrace(getMatCopy(lfpack, mat, rdpack, lowDia), lfpack, lowDia)
32+8
33
34
35ndim = getUnifRand(1, 7)
36mat = getUnifRand(1, 9, ndim, ndim)
37mat
38+3, +6, +1, +8
39+6, +2, +2, +3
40+7, +2, +9, +5
41+5, +6, +3, +9
42getMatTrace(mat)
43+23
44getMatTrace(getMatCopy(rdpack, mat, rdpack, subset = uppDia))
45+23
46getMatTrace(getMatCopy(rdpack, mat, rdpack, subset = lowDia))
47+23
48getMatTrace(getMatCopy(lfpack, mat, rdpack, lowDia), lfpack, lowDia)
49+17
50
51
52ndim = getUnifRand(1, 7)
53mat = getUnifRand(1, 9, ndim, ndim)
54mat
55+1, +3
56+5, +7
57getMatTrace(mat)
58+8
59getMatTrace(getMatCopy(rdpack, mat, rdpack, subset = uppDia))
60+8
61getMatTrace(getMatCopy(rdpack, mat, rdpack, subset = lowDia))
62+8
63getMatTrace(getMatCopy(lfpack, mat, rdpack, lowDia), lfpack, lowDia)
64+6
65
66
67ndim = getUnifRand(1, 7)
68mat = getUnifRand(1, 9, ndim, ndim)
69mat
70+1, +6, +5
71+7, +2, +3
72+3, +3, +2
73getMatTrace(mat)
74+5
75getMatTrace(getMatCopy(rdpack, mat, rdpack, subset = uppDia))
76+5
77getMatTrace(getMatCopy(rdpack, mat, rdpack, subset = lowDia))
78+5
79getMatTrace(getMatCopy(lfpack, mat, rdpack, lowDia), lfpack, lowDia)
80+7
81
82
Test:
test_pm_matrixTrace


Final Remarks


If you believe this algorithm or its documentation can be improved, we appreciate your contribution and help to edit this page's documentation and source file on GitHub.
For details on the naming abbreviations, see this page.
For details on the naming conventions, see this page.
This software is distributed under the MIT license with additional terms outlined below.

  1. If you use any parts or concepts from this library to any extent, please acknowledge the usage by citing the relevant publications of the ParaMonte library.
  2. If you regenerate any parts/ideas from this library in a programming environment other than those currently supported by this ParaMonte library (i.e., other than C, C++, Fortran, MATLAB, Python, R), please also ask the end users to cite this original ParaMonte library.

This software is available to the public under a highly permissive license.
Help us justify its continued development and maintenance by acknowledging its benefit to society, distributing it, and contributing to it.

Author:
Amir Shahmoradi, April 23, 2017, 1:36 AM, Institute for Computational Engineering and Sciences (ICES), University of Texas at Austin

Definition at line 161 of file pm_matrixTrace.F90.


The documentation for this interface was generated from the following file: