Mercurial > hg > segmenter-vamp-plugin
comparison armadillo-2.4.4/include/armadillo_bits/fn_det.hpp @ 0:8b6102e2a9b0
Armadillo Library
author | maxzanoni76 <max.zanoni@eecs.qmul.ac.uk> |
---|---|
date | Wed, 11 Apr 2012 09:27:06 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:8b6102e2a9b0 |
---|---|
1 // Copyright (C) 2008-2011 NICTA (www.nicta.com.au) | |
2 // Copyright (C) 2008-2011 Conrad Sanderson | |
3 // | |
4 // This file is part of the Armadillo C++ library. | |
5 // It is provided without any warranty of fitness | |
6 // for any purpose. You can redistribute this file | |
7 // and/or modify it under the terms of the GNU | |
8 // Lesser General Public License (LGPL) as published | |
9 // by the Free Software Foundation, either version 3 | |
10 // of the License or (at your option) any later version. | |
11 // (see http://www.opensource.org/licenses for more info) | |
12 | |
13 | |
14 //! \addtogroup fn_det | |
15 //! @{ | |
16 | |
17 | |
18 | |
19 //! determinant of mat | |
20 template<typename T1> | |
21 inline | |
22 arma_warn_unused | |
23 typename T1::elem_type | |
24 det | |
25 ( | |
26 const Base<typename T1::elem_type,T1>& X, | |
27 const bool slow = false, | |
28 const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0 | |
29 ) | |
30 { | |
31 arma_extra_debug_sigprint(); | |
32 | |
33 arma_ignore(junk); | |
34 | |
35 return auxlib::det(X, slow); | |
36 } | |
37 | |
38 | |
39 | |
40 //! determinant of diagmat | |
41 template<typename T1> | |
42 inline | |
43 arma_warn_unused | |
44 typename T1::elem_type | |
45 det | |
46 ( | |
47 const Op<T1, op_diagmat>& X, | |
48 const bool slow = false | |
49 ) | |
50 { | |
51 arma_extra_debug_sigprint(); | |
52 arma_ignore(slow); | |
53 | |
54 typedef typename T1::elem_type eT; | |
55 | |
56 const diagmat_proxy<T1> A(X.m); | |
57 | |
58 const uword A_n_elem = A.n_elem; | |
59 | |
60 eT val = eT(1); | |
61 | |
62 for(uword i=0; i<A_n_elem; ++i) | |
63 { | |
64 val *= A[i]; | |
65 } | |
66 | |
67 return val; | |
68 } | |
69 | |
70 | |
71 | |
72 //! determinant of inv(A), without doing the inverse operation | |
73 template<typename T1> | |
74 inline | |
75 arma_warn_unused | |
76 typename T1::elem_type | |
77 det | |
78 ( | |
79 const Op<T1,op_inv>& in, | |
80 const bool slow = false, | |
81 const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0 | |
82 ) | |
83 { | |
84 arma_extra_debug_sigprint(); | |
85 arma_ignore(junk); | |
86 | |
87 typedef typename T1::elem_type eT; | |
88 | |
89 eT tmp = det(in.m, slow); | |
90 arma_warn( (tmp == eT(0)), "det(): warning: denominator is zero" ); | |
91 | |
92 return eT(1) / tmp; | |
93 } | |
94 | |
95 | |
96 | |
97 //! determinant of trans(A) | |
98 template<typename T1> | |
99 inline | |
100 arma_warn_unused | |
101 typename T1::elem_type | |
102 det | |
103 ( | |
104 const Op<T1,op_htrans>& in, | |
105 const bool slow = false, | |
106 const typename arma_blas_type_only<typename T1::elem_type>::result* junk1 = 0, | |
107 const typename arma_not_cx<typename T1::elem_type>::result* junk2 = 0 | |
108 ) | |
109 { | |
110 arma_extra_debug_sigprint(); | |
111 arma_ignore(junk1); | |
112 arma_ignore(junk2); | |
113 | |
114 typedef typename T1::elem_type eT; | |
115 | |
116 const unwrap<T1> tmp(in.m); | |
117 const Mat<eT>& X = tmp.M; | |
118 | |
119 return det(X, slow); | |
120 } | |
121 | |
122 | |
123 | |
124 //! @} |