Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:50:42

0001 #ifndef BOOST_QVM_DETAIL_COFACTOR_IMPL_HPP_INCLUDED
0002 #define BOOST_QVM_DETAIL_COFACTOR_IMPL_HPP_INCLUDED
0003 
0004 // Copyright 2008-2022 Emil Dotchevski and Reverge Studios, Inc.
0005 
0006 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0007 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0008 
0009 #include <boost/qvm/detail/determinant_impl.hpp>
0010 #include <boost/qvm/mat_traits.hpp>
0011 #include <boost/qvm/static_assert.hpp>
0012 
0013 namespace boost { namespace qvm {
0014 
0015 namespace
0016 qvm_detail
0017     {
0018     template <class A>
0019     BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
0020     typename deduce_mat<A>::type
0021     cofactor_impl( A const & a )
0022         {
0023         BOOST_QVM_STATIC_ASSERT(mat_traits<A>::rows==mat_traits<A>::cols);
0024         int const N=mat_traits<A>::rows;
0025         typedef typename mat_traits<A>::scalar_type T;
0026         T c[N-1][N-1];
0027         typedef typename deduce_mat<A>::type R;
0028         R b;
0029         for( int j=0; j!=N; ++j )
0030             {
0031             for( int i=0; i!=N; ++i )
0032                 {
0033                 int i1=0;
0034                 for( int ii=0; ii!=N; ++ii )
0035                     {
0036                     if( ii==i )
0037                         continue;
0038                     int j1=0;
0039                     for( int jj=0; jj!=N; ++jj )
0040                         {
0041                         if( jj==j )
0042                             continue;
0043                         c[i1][j1] = mat_traits<A>::read_element_idx(ii,jj,a);
0044                         ++j1;
0045                         }
0046                     ++i1;
0047                     }
0048                 T det = determinant_impl(c);
0049                 if( (i+j)&1 )
0050                     det=-det;
0051                 write_mat_element_idx(i,j,b,det);
0052                 }
0053             }
0054         return b;
0055         }
0056     }
0057 
0058 } }
0059 
0060 #endif