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
9Author: 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
32
34// Determinant function for scalar, vector, matrix
38accelerator_inline RealF Determinant( const RealF &arg){ return arg;}
39accelerator_inline RealD Determinant( const RealD &arg){ return arg;}
40
41template<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
48template<class vtype,int N, typename std::enable_if< GridTypeMapper<vtype>::TensorLevel == 0 >::type * =nullptr>
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
72
73#endif
#define accelerator_inline
#define NAMESPACE_BEGIN(A)
Definition Namespace.h:35
#define NAMESPACE_END(A)
Definition Namespace.h:36
std::complex< RealF > ComplexF
Definition Simd.h:78
float RealF
Definition Simd.h:60
std::complex< RealD > ComplexD
Definition Simd.h:79
double RealD
Definition Simd.h:61
accelerator_inline ComplexF Determinant(const ComplexF &arg)
vtype _internal[N][N]
vtype _internal