Grid
0.7.0
Tensor_determinant.h
Go to the documentation of this file.
1
/*************************************************************************************
2
3
Grid physics library, www.github.com/paboyle/Grid
4
5
Source file: ./lib/tensors/Tensor_determinant.h
6
7
Copyright (C) 2015
8
9
Author: neo <cossu@post.kek.jp>
10
11
This program is free software; you can redistribute it and/or modify
12
it under the terms of the GNU General Public License as published by
13
the Free Software Foundation; either version 2 of the License, or
14
(at your option) any later version.
15
16
This program is distributed in the hope that it will be useful,
17
but WITHOUT ANY WARRANTY; without even the implied warranty of
18
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
GNU General Public License for more details.
20
21
You should have received a copy of the GNU General Public License along
22
with this program; if not, write to the Free Software Foundation, Inc.,
23
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24
25
See the full license in the file "LICENSE" in the top level distribution directory
26
*************************************************************************************/
27
/* END LEGAL */
28
#ifndef GRID_MATH_DET_H
29
#define GRID_MATH_DET_H
30
31
NAMESPACE_BEGIN
(
Grid
);
32
34
// Determinant function for scalar, vector, matrix
36
accelerator_inline
ComplexF
Determinant
(
const
ComplexF
&arg){
return
arg;}
37
accelerator_inline
ComplexD
Determinant
(
const
ComplexD
&arg){
return
arg;}
38
accelerator_inline
RealF
Determinant
(
const
RealF
&arg){
return
arg;}
39
accelerator_inline
RealD
Determinant
(
const
RealD
&arg){
return
arg;}
40
41
template
<
class
vtype>
accelerator_inline
auto
Determinant
(
const
iScalar<vtype>
&r) ->
iScalar
<
decltype
(
Determinant
(r._internal))>
42
{
43
iScalar
<
decltype
(
Determinant
(r._internal))> ret;
44
ret.
_internal
=
Determinant
(r._internal);
45
return
ret;
46
}
47
48
template<class vtype,int N, typename std::enable_if< GridTypeMapper<vtype>::TensorLevel == 0 >
::type
* =
nullptr
>
49
accelerator_inline
iScalar<vtype>
Determinant
(
const
iMatrix<vtype,N>
&arg)
50
{
51
iMatrix<vtype,N>
ret(arg);
52
iScalar<vtype>
det = vtype(1.0);
53
/* Conversion of matrix to upper triangular */
54
for
(
int
i = 0; i < N; i++){
55
for
(
int
j = 0; j < N; j++){
56
if
(j>i){
57
vtype ratio = ret.
_internal
[j][i]/ret.
_internal
[i][i];
58
for
(
int
k = 0; k < N; k++){
59
ret.
_internal
[j][k] -= ratio * ret.
_internal
[i][k];
60
}
61
}
62
}
63
}
64
65
for
(
int
i = 0; i < N; i++)
66
det *= ret.
_internal
[i][i];
67
68
return
det;
69
}
70
71
NAMESPACE_END
(
Grid
);
72
73
#endif
accelerator_inline
#define accelerator_inline
Definition
Accelerator.h:608
NAMESPACE_BEGIN
#define NAMESPACE_BEGIN(A)
Definition
Namespace.h:35
NAMESPACE_END
#define NAMESPACE_END(A)
Definition
Namespace.h:36
ComplexF
std::complex< RealF > ComplexF
Definition
Simd.h:78
RealF
float RealF
Definition
Simd.h:60
ComplexD
std::complex< RealD > ComplexD
Definition
Simd.h:79
RealD
double RealD
Definition
Simd.h:61
Determinant
accelerator_inline ComplexF Determinant(const ComplexF &arg)
Definition
Tensor_determinant.h:36
iMatrix
Definition
Tensor_class.h:301
iMatrix::_internal
vtype _internal[N][N]
Definition
Tensor_class.h:303
iScalar
Definition
Tensor_class.h:77
iScalar::_internal
vtype _internal
Definition
Tensor_class.h:79
Grid
Definition
Deflation.h:31
type
Grid
tensors
Tensor_determinant.h
Generated by
1.16.1