Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-15 08:51:14

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