block_sparrse_matrix.h
#include "ldl_decomposition.h"
SMVS_NAMESPACE_BEGIN
template<int N>
void
BlockSparseMatrix<N>::invert_blocks_inplace(void)
{
for (std::size_t i = 0; i < this->values.size(); ++i)
{
std::array<double, N * N> b = values[i];
ldl_inverse(b.begin(), N);
bool nancheck = false;
for (int i = 0; i < N * N; ++i)
if (std::isnan(b[i]))
nancheck = true;
if(nancheck)
continue;
values[i] = b;
}
}
ldl_decomposition.h
SMVS_NAMESPACE_BEGIN
template<typename T>
void
ldl_inverse(T * A, int const size)
{
T * L = new T[size * size];
T * D = new T[size];
std::fill(L, L + size * size, 0.0);
std::fill(D, D + size, 0.0);
/* Factorize A into LDL^T */
for (int j = 0; j < size; ++j)
{
D[j] = A[j * size + j];
L[j * size + j] = 1.0;
for (int k = 0 ; k < j; ++k)
D[j] -= (L[j * size + k] * L[j * size + k]) * D[k];
if (D[j] == 0.0)
return;
for (int i = j+1; i < size; ++i)
{
L[i * size + j] = A[i * size + j];
for (int k = 0 ; k < j; ++k)
L[i * size + j] -= L[i * size + k] * D[k] * L[j * size + k];
L[i * size + j] /= D[j];
}
}
/* Invert L */
for (int i = 0; i < size; ++i)
for (int j = i+1; j < size; ++j)
{
T sum(0);
for (int k = i ; k < j; ++k)
sum -= L[j * size + k] * L[k * size + i];
L[j * size + i] = sum;
}
/* Invert D */
for (int i = 0; i < size; ++i)
D[i] = 1.0 / D[i];
/* Combine Matrices */
combine_ldl(L, D, size, A);
/* Cleanup memory */
delete[] L;
delete[] D;
}
我想让它在Windows上运行,但它是错误的。
Error C2672 'ldl_inverse': no matching overloaded function found
(compiling source file E:\mve\libs\smvsrecon\gauss_newton_step.cc)
Error C2784 'void smvs::ldl_inverse(T *,const int)': could not deduce
template argument for 'T *' from 'std::_Array_iterator<_Ty,16>'