1 //Copyright (c) 2008-2016 Emil Dotchevski and Reverge Studios, Inc.
3 //Distributed under the Boost Software License, Version 1.0. (See accompanying
4 //file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 #ifndef UUID_3DCF6B90AE0E11DE9A315BE555D89593
7 #define UUID_3DCF6B90AE0E11DE9A315BE555D89593
9 #include <boost/qvm/inline.hpp>
10 #include <boost/qvm/mat_traits_array.hpp>
11 #include <boost/qvm/static_assert.hpp>
29 BOOST_QVM_INLINE_TRIVIAL
30 typename mat_traits<M>::scalar_type
31 determinant_impl_( M const & a, det_size<2> )
34 mat_traits<M>::template read_element<0,0>(a) * mat_traits<M>::template read_element<1,1>(a) -
35 mat_traits<M>::template read_element<1,0>(a) * mat_traits<M>::template read_element<0,1>(a);
38 template <class M,int N>
39 BOOST_QVM_INLINE_RECURSION
40 typename mat_traits<M>::scalar_type
41 determinant_impl_( M const & a, det_size<N> )
43 typedef typename mat_traits<M>::scalar_type T;
46 for( int j1=0; j1!=N; ++j1 )
48 for( int i=1; i!=N; ++i )
51 for( int j=0; j!=N; ++j )
55 m[i-1][j2] = mat_traits<M>::read_element_idx(i,j,a);
59 T d=determinant_impl_(m,det_size<N-1>());
62 det += mat_traits<M>::read_element_idx(0,j1,a) * d;
68 BOOST_QVM_INLINE_TRIVIAL
69 typename mat_traits<M>::scalar_type
70 determinant_impl( M const & a )
72 BOOST_QVM_STATIC_ASSERT(mat_traits<M>::rows==mat_traits<M>::cols);
73 return determinant_impl_(a,det_size<mat_traits<M>::rows>());