void test_transpose_readonly(MatrixT view) { typedef typename MatrixT::value_type T; // Check that view is initialized check_matrix(view, 0); length_type const size1 = view.size(1); typename MatrixT::const_transpose_type trans = view.transpose(); test_assert(trans.size(0) == view.size(1)); test_assert(trans.size(1) == view.size(0)); for (index_type idx0=0; idx0<trans.size(0); ++idx0) for (index_type idx1=0; idx1<trans.size(1); ++idx1) { T expected = T(idx1 * size1 + idx0 + 0); test_assert(equal(trans.get(idx0, idx1), expected)); test_assert(equal(trans.get(idx0, idx1), view. get(idx1, idx0))); } // Check that view is unchanged check_matrix(view, 0); }
bool WHeadPositionCorrection::computeInverseOperation( MatrixT* const g, const MatrixT& lf ) const { WLTimeProfiler profiler( CLASS, __func__, true ); const float snr = 25; const MatrixT noiseCov = MatrixT::Identity( lf.rows(), lf.rows() ); // Leafield transpose matrix const MatrixT LT = lf.transpose(); // WinvLT = W^-1 * LT SpMatrixT w = SpMatrixT( lf.cols(), lf.cols() ); w.setIdentity(); w.makeCompressed(); SparseLU< SpMatrixT > spSolver; spSolver.compute( w ); if( spSolver.info() != Eigen::Success ) { wlog::error( CLASS ) << "spSolver.compute( weighting ) not succeeded: " << spSolver.info(); return false; } const MatrixT WinvLT = spSolver.solve( LT ); // needs dense matrix, returns dense matrix if( spSolver.info() != Eigen::Success ) { wlog::error( CLASS ) << "spSolver.solve( LT ) not succeeded: " << spSolver.info(); return false; } wlog::debug( CLASS ) << "WinvLT " << WinvLT.rows() << " x " << WinvLT.cols(); // LWL = L * W^-1 * LT const MatrixT LWL = lf * WinvLT; wlog::debug( CLASS ) << "LWL " << LWL.rows() << " x " << LWL.cols(); // alpha = sqrt(trace(LWL)/(snr * num_sensors)); double alpha = sqrt( LWL.trace() / ( snr * lf.rows() ) ); // G = W^-1 * LT * inv( (L W^-1 * LT) + alpha^2 * Cn ) const MatrixT toInv = LWL + pow( alpha, 2 ) * noiseCov; const MatrixT inv = toInv.inverse(); *g = WinvLT * inv; WAssertDebug( g->rows() == lf.cols() && g->cols() == lf.rows(), "Dimension of G and L does not match." ); return true; }