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