2#ifndef vnl_adjugate_fixed_h_
3#define vnl_adjugate_fixed_h_
17#include <vnl/vnl_matrix_fixed.h>
18#include <vnl/vnl_vector_fixed.h>
19#include <vnl/vnl_matrix.h>
20#include <vnl/vnl_det.h>
34vnl_matrix_fixed<T,1,1>
vnl_adjugate(vnl_matrix_fixed<T,1,1>
const& m)
36 return vnl_matrix_fixed<T,1,1>(m(0,0));
51vnl_matrix_fixed<T,2,2>
vnl_adjugate(vnl_matrix_fixed<T,2,2>
const& m)
54 d[0] = m(1,1); d[1] = - m(0,1);
55 d[3] = m(0,0); d[2] = - m(1,0);
56 return vnl_matrix_fixed<T,2,2>(d);
71vnl_matrix_fixed<T,3,3>
vnl_adjugate(vnl_matrix_fixed<T,3,3>
const& m)
74 d[0] = (m(1,1)*m(2,2)-m(1,2)*m(2,1));
75 d[1] = (m(2,1)*m(0,2)-m(2,2)*m(0,1));
76 d[2] = (m(0,1)*m(1,2)-m(0,2)*m(1,1));
77 d[3] = (m(1,2)*m(2,0)-m(1,0)*m(2,2));
78 d[4] = (m(0,0)*m(2,2)-m(0,2)*m(2,0));
79 d[5] = (m(1,0)*m(0,2)-m(1,2)*m(0,0));
80 d[6] = (m(1,0)*m(2,1)-m(1,1)*m(2,0));
81 d[7] = (m(0,1)*m(2,0)-m(0,0)*m(2,1));
82 d[8] = (m(0,0)*m(1,1)-m(0,1)*m(1,0));
83 return vnl_matrix_fixed<T,3,3>(d);
98vnl_matrix_fixed<T,4,4>
vnl_adjugate(vnl_matrix_fixed<T,4,4>
const& m)
101 d[0] = m(1,1)*m(2,2)*m(3,3) - m(1,1)*m(2,3)*m(3,2) - m(2,1)*m(1,2)*m(3,3)
102 + m(2,1)*m(1,3)*m(3,2) + m(3,1)*m(1,2)*m(2,3) - m(3,1)*m(1,3)*m(2,2);
103 d[1] = -m(0,1)*m(2,2)*m(3,3) + m(0,1)*m(2,3)*m(3,2) + m(2,1)*m(0,2)*m(3,3)
104 - m(2,1)*m(0,3)*m(3,2) - m(3,1)*m(0,2)*m(2,3) + m(3,1)*m(0,3)*m(2,2);
105 d[2] = m(0,1)*m(1,2)*m(3,3) - m(0,1)*m(1,3)*m(3,2) - m(1,1)*m(0,2)*m(3,3)
106 + m(1,1)*m(0,3)*m(3,2) + m(3,1)*m(0,2)*m(1,3) - m(3,1)*m(0,3)*m(1,2);
107 d[3] = -m(0,1)*m(1,2)*m(2,3) + m(0,1)*m(1,3)*m(2,2) + m(1,1)*m(0,2)*m(2,3)
108 - m(1,1)*m(0,3)*m(2,2) - m(2,1)*m(0,2)*m(1,3) + m(2,1)*m(0,3)*m(1,2);
109 d[4] = -m(1,0)*m(2,2)*m(3,3) + m(1,0)*m(2,3)*m(3,2) + m(2,0)*m(1,2)*m(3,3)
110 - m(2,0)*m(1,3)*m(3,2) - m(3,0)*m(1,2)*m(2,3) + m(3,0)*m(1,3)*m(2,2);
111 d[5] = m(0,0)*m(2,2)*m(3,3) - m(0,0)*m(2,3)*m(3,2) - m(2,0)*m(0,2)*m(3,3)
112 + m(2,0)*m(0,3)*m(3,2) + m(3,0)*m(0,2)*m(2,3) - m(3,0)*m(0,3)*m(2,2);
113 d[6] = -m(0,0)*m(1,2)*m(3,3) + m(0,0)*m(1,3)*m(3,2) + m(1,0)*m(0,2)*m(3,3)
114 - m(1,0)*m(0,3)*m(3,2) - m(3,0)*m(0,2)*m(1,3) + m(3,0)*m(0,3)*m(1,2);
115 d[7] = m(0,0)*m(1,2)*m(2,3) - m(0,0)*m(1,3)*m(2,2) - m(1,0)*m(0,2)*m(2,3)
116 + m(1,0)*m(0,3)*m(2,2) + m(2,0)*m(0,2)*m(1,3) - m(2,0)*m(0,3)*m(1,2);
117 d[8] = m(1,0)*m(2,1)*m(3,3) - m(1,0)*m(2,3)*m(3,1) - m(2,0)*m(1,1)*m(3,3)
118 + m(2,0)*m(1,3)*m(3,1) + m(3,0)*m(1,1)*m(2,3) - m(3,0)*m(1,3)*m(2,1);
119 d[9] = -m(0,0)*m(2,1)*m(3,3) + m(0,0)*m(2,3)*m(3,1) + m(2,0)*m(0,1)*m(3,3)
120 - m(2,0)*m(0,3)*m(3,1) - m(3,0)*m(0,1)*m(2,3) + m(3,0)*m(0,3)*m(2,1);
121 d[10]= m(0,0)*m(1,1)*m(3,3) - m(0,0)*m(1,3)*m(3,1) - m(1,0)*m(0,1)*m(3,3)
122 + m(1,0)*m(0,3)*m(3,1) + m(3,0)*m(0,1)*m(1,3) - m(3,0)*m(0,3)*m(1,1);
123 d[11]= -m(0,0)*m(1,1)*m(2,3) + m(0,0)*m(1,3)*m(2,1) + m(1,0)*m(0,1)*m(2,3)
124 - m(1,0)*m(0,3)*m(2,1) - m(2,0)*m(0,1)*m(1,3) + m(2,0)*m(0,3)*m(1,1);
125 d[12]= -m(1,0)*m(2,1)*m(3,2) + m(1,0)*m(2,2)*m(3,1) + m(2,0)*m(1,1)*m(3,2)
126 - m(2,0)*m(1,2)*m(3,1) - m(3,0)*m(1,1)*m(2,2) + m(3,0)*m(1,2)*m(2,1);
127 d[13]= m(0,0)*m(2,1)*m(3,2) - m(0,0)*m(2,2)*m(3,1) - m(2,0)*m(0,1)*m(3,2)
128 + m(2,0)*m(0,2)*m(3,1) + m(3,0)*m(0,1)*m(2,2) - m(3,0)*m(0,2)*m(2,1);
129 d[14]= -m(0,0)*m(1,1)*m(3,2) + m(0,0)*m(1,2)*m(3,1) + m(1,0)*m(0,1)*m(3,2)
130 - m(1,0)*m(0,2)*m(3,1) - m(3,0)*m(0,1)*m(1,2) + m(3,0)*m(0,2)*m(1,1);
131 d[15]= m(0,0)*m(1,1)*m(2,2) - m(0,0)*m(1,2)*m(2,1) - m(1,0)*m(0,1)*m(2,2)
132 + m(1,0)*m(0,2)*m(2,1) + m(2,0)*m(0,1)*m(1,2) - m(2,0)*m(0,2)*m(1,1);
133 return vnl_matrix_fixed<T,4,4>(d);
150 assert(m.rows() == m.columns());
151 assert(m.rows() <= 4);
153 return vnl_matrix<T>(1,1, T(1)/m(0,0));
154 else if (m.rows() == 2)
155 return vnl_adjugate(vnl_matrix_fixed<T,2,2>(m)).as_ref();
156 else if (m.rows() == 3)
157 return vnl_adjugate(vnl_matrix_fixed<T,3,3>(m)).as_ref();
159 return vnl_adjugate(vnl_matrix_fixed<T,4,4>(m)).as_ref();
178 return vnl_matrix_fixed<T,1,1>(T(1)/m(0,0));
199 d[0] = m(1,1); d[2] = - m(0,1);
200 d[3] = m(0,0); d[1] = - m(1,0);
201 return vnl_matrix_fixed<T,2,2>(d);
222 d[0] = (m(1,1)*m(2,2)-m(1,2)*m(2,1));
223 d[3] = (m(2,1)*m(0,2)-m(2,2)*m(0,1));
224 d[6] = (m(0,1)*m(1,2)-m(0,2)*m(1,1));
225 d[1] = (m(1,2)*m(2,0)-m(1,0)*m(2,2));
226 d[4] = (m(0,0)*m(2,2)-m(0,2)*m(2,0));
227 d[7] = (m(1,0)*m(0,2)-m(1,2)*m(0,0));
228 d[2] = (m(1,0)*m(2,1)-m(1,1)*m(2,0));
229 d[5] = (m(0,1)*m(2,0)-m(0,0)*m(2,1));
230 d[8] = (m(0,0)*m(1,1)-m(0,1)*m(1,0));
231 return vnl_matrix_fixed<T,3,3>(d);
251 d[0] = m(1,1)*m(2,2)*m(3,3) - m(1,1)*m(2,3)*m(3,2) - m(2,1)*m(1,2)*m(3,3)
252 + m(2,1)*m(1,3)*m(3,2) + m(3,1)*m(1,2)*m(2,3) - m(3,1)*m(1,3)*m(2,2);
253 d[4] = -m(0,1)*m(2,2)*m(3,3) + m(0,1)*m(2,3)*m(3,2) + m(2,1)*m(0,2)*m(3,3)
254 - m(2,1)*m(0,3)*m(3,2) - m(3,1)*m(0,2)*m(2,3) + m(3,1)*m(0,3)*m(2,2);
255 d[8] = m(0,1)*m(1,2)*m(3,3) - m(0,1)*m(1,3)*m(3,2) - m(1,1)*m(0,2)*m(3,3)
256 + m(1,1)*m(0,3)*m(3,2) + m(3,1)*m(0,2)*m(1,3) - m(3,1)*m(0,3)*m(1,2);
257 d[12]= -m(0,1)*m(1,2)*m(2,3) + m(0,1)*m(1,3)*m(2,2) + m(1,1)*m(0,2)*m(2,3)
258 - m(1,1)*m(0,3)*m(2,2) - m(2,1)*m(0,2)*m(1,3) + m(2,1)*m(0,3)*m(1,2);
259 d[1] = -m(1,0)*m(2,2)*m(3,3) + m(1,0)*m(2,3)*m(3,2) + m(2,0)*m(1,2)*m(3,3)
260 - m(2,0)*m(1,3)*m(3,2) - m(3,0)*m(1,2)*m(2,3) + m(3,0)*m(1,3)*m(2,2);
261 d[5] = m(0,0)*m(2,2)*m(3,3) - m(0,0)*m(2,3)*m(3,2) - m(2,0)*m(0,2)*m(3,3)
262 + m(2,0)*m(0,3)*m(3,2) + m(3,0)*m(0,2)*m(2,3) - m(3,0)*m(0,3)*m(2,2);
263 d[9] = -m(0,0)*m(1,2)*m(3,3) + m(0,0)*m(1,3)*m(3,2) + m(1,0)*m(0,2)*m(3,3)
264 - m(1,0)*m(0,3)*m(3,2) - m(3,0)*m(0,2)*m(1,3) + m(3,0)*m(0,3)*m(1,2);
265 d[13]= m(0,0)*m(1,2)*m(2,3) - m(0,0)*m(1,3)*m(2,2) - m(1,0)*m(0,2)*m(2,3)
266 + m(1,0)*m(0,3)*m(2,2) + m(2,0)*m(0,2)*m(1,3) - m(2,0)*m(0,3)*m(1,2);
267 d[2] = m(1,0)*m(2,1)*m(3,3) - m(1,0)*m(2,3)*m(3,1) - m(2,0)*m(1,1)*m(3,3)
268 + m(2,0)*m(1,3)*m(3,1) + m(3,0)*m(1,1)*m(2,3) - m(3,0)*m(1,3)*m(2,1);
269 d[6] = -m(0,0)*m(2,1)*m(3,3) + m(0,0)*m(2,3)*m(3,1) + m(2,0)*m(0,1)*m(3,3)
270 - m(2,0)*m(0,3)*m(3,1) - m(3,0)*m(0,1)*m(2,3) + m(3,0)*m(0,3)*m(2,1);
271 d[10]= m(0,0)*m(1,1)*m(3,3) - m(0,0)*m(1,3)*m(3,1) - m(1,0)*m(0,1)*m(3,3)
272 + m(1,0)*m(0,3)*m(3,1) + m(3,0)*m(0,1)*m(1,3) - m(3,0)*m(0,3)*m(1,1);
273 d[14]= -m(0,0)*m(1,1)*m(2,3) + m(0,0)*m(1,3)*m(2,1) + m(1,0)*m(0,1)*m(2,3)
274 - m(1,0)*m(0,3)*m(2,1) - m(2,0)*m(0,1)*m(1,3) + m(2,0)*m(0,3)*m(1,1);
275 d[3] = -m(1,0)*m(2,1)*m(3,2) + m(1,0)*m(2,2)*m(3,1) + m(2,0)*m(1,1)*m(3,2)
276 - m(2,0)*m(1,2)*m(3,1) - m(3,0)*m(1,1)*m(2,2) + m(3,0)*m(1,2)*m(2,1);
277 d[7] = m(0,0)*m(2,1)*m(3,2) - m(0,0)*m(2,2)*m(3,1) - m(2,0)*m(0,1)*m(3,2)
278 + m(2,0)*m(0,2)*m(3,1) + m(3,0)*m(0,1)*m(2,2) - m(3,0)*m(0,2)*m(2,1);
279 d[11]= -m(0,0)*m(1,1)*m(3,2) + m(0,0)*m(1,2)*m(3,1) + m(1,0)*m(0,1)*m(3,2)
280 - m(1,0)*m(0,2)*m(3,1) - m(3,0)*m(0,1)*m(1,2) + m(3,0)*m(0,2)*m(1,1);
281 d[15]= m(0,0)*m(1,1)*m(2,2) - m(0,0)*m(1,2)*m(2,1) - m(1,0)*m(0,1)*m(2,2)
282 + m(1,0)*m(0,2)*m(2,1) + m(2,0)*m(0,1)*m(1,2) - m(2,0)*m(0,2)*m(1,1);
283 return vnl_matrix_fixed<T,4,4>(d);
302 assert(m.rows() == m.columns());
303 assert(m.rows() <= 4);
305 return vnl_matrix<T>(1,1, T(1)/m(0,0));
306 else if (m.rows() == 2)
307 return vnl_cofactor(vnl_matrix_fixed<T,2,2>(m)).as_ref();
308 else if (m.rows() == 3)
309 return vnl_cofactor(vnl_matrix_fixed<T,3,3>(m)).as_ref();
311 return vnl_cofactor(vnl_matrix_fixed<T,4,4>(m)).as_ref();
316vnl_vector_fixed<T,3>
vnl_cofactor_row1(vnl_vector_fixed<T,3>
const& row2, vnl_vector_fixed<T,3>
const& row3)
319 d[0] = (row2[1]*row3[2]-row2[2]*row3[1]);
320 d[1] = (row2[2]*row3[0]-row2[0]*row3[2]);
321 d[2] = (row2[0]*row3[1]-row2[1]*row3[0]);
322 return vnl_vector_fixed<T,3>(d);
vnl_vector_fixed< T, 3 > vnl_cofactor_row1(vnl_vector_fixed< T, 3 > const &row2, vnl_vector_fixed< T, 3 > const &row3)
vnl_matrix< T > vnl_adjugate_asfixed(vnl_matrix< T > const &m)
vnl_matrix_fixed< T, 1, 1 > vnl_adjugate(vnl_matrix_fixed< T, 1, 1 > const &m)
vnl_matrix_fixed< T, 1, 1 > vnl_cofactor(vnl_matrix_fixed< T, 1, 1 > const &m)