41 return c > other.
c || (c == other.
c && r > other.
r);
45 MarginalCovarianceCholesky::MarginalCovarianceCholesky() :
46 _n(0), _Ap(0), _Ai(0), _Ax(0), _perm(0)
64 for (
int r = 0; r < n; ++r) {
65 const int& sc =
_Ap[r];
66 assert(r ==
_Ai[sc] &&
"Error in CCS storage of L");
76 LookupMap::const_iterator foundIt =
_map.find(idx);
77 if (foundIt !=
_map.end()) {
78 return foundIt->second;
83 const int& sc =
_Ap[r];
84 const int& ec =
_Ap[r+1];
85 for (
int j = sc+1; j < ec; ++j) {
86 const int& rr =
_Ai[j];
93 const double& diagElem =
_diag[r];
94 result = diagElem * (diagElem - s);
96 result = -s *
_diag[r];
106 vector<MatrixElem> elemsToCompute;
107 for (
size_t i = 0; i < blockIndices.size(); ++i) {
108 int nbase = blockIndices[i];
109 int vdim = nbase - base;
110 for (
int rr = 0; rr < vdim; ++rr)
111 for (
int cc = rr; cc < vdim; ++cc) {
122 sort(elemsToCompute.begin(), elemsToCompute.end());
125 for (
size_t i = 0; i < elemsToCompute.size(); ++i) {
132 for (
size_t i = 0; i < blockIndices.size(); ++i) {
133 int nbase = blockIndices[i];
134 int vdim = nbase - base;
135 double* cov = covBlocks[i];
136 for (
int rr = 0; rr < vdim; ++rr)
137 for (
int cc = rr; cc < vdim; ++cc) {
143 LookupMap::const_iterator foundIt =
_map.find(idx);
144 assert(foundIt !=
_map.end());
145 cov[rr*vdim + cc] = foundIt->second;
147 cov[cc*vdim + rr] = foundIt->second;
159 rowBlockIndices.size(),
160 rowBlockIndices.size(),
true);
162 vector<MatrixElem> elemsToCompute;
163 for (
size_t i = 0; i < blockIndices.size(); ++i) {
164 int blockRow=blockIndices[i].first;
165 int blockCol=blockIndices[i].second;
167 assert(blockRow < (
int)rowBlockIndices.size());
169 assert(blockCol < (
int)rowBlockIndices.size());
174 MatrixXd *block=spinv.
block(blockRow, blockCol,
true);
176 for (
int iRow=0; iRow<block->rows(); ++iRow)
177 for (
int iCol=0; iCol<block->cols(); ++iCol){
189 sort(elemsToCompute.begin(), elemsToCompute.end());
192 for (
size_t i = 0; i < elemsToCompute.size(); ++i) {
198 for (
size_t i = 0; i < blockIndices.size(); ++i) {
199 int blockRow=blockIndices[i].first;
200 int blockCol=blockIndices[i].second;
204 MatrixXd *block=spinv.
block(blockRow, blockCol);
206 for (
int iRow=0; iRow<block->rows(); ++iRow)
207 for (
int iCol=0; iCol<block->cols(); ++iCol){
215 LookupMap::const_iterator foundIt =
_map.find(idx);
216 assert(foundIt !=
_map.end());
217 (*block)(iRow, iCol) = foundIt->second;
LookupMap _map
hash look up table for the already computed entries
void setCholeskyFactor(int n, int *Lp, int *Li, double *Lx, int *permInv)
SparseMatrixBlock * block(int r, int c, bool alloc=false)
returns the block at location r,c. if alloc=true he block is created if it does not exist ...
int * _Ai
row indices of the CCS storage
int * _Ap
column pointer of the CCS storage
void computeCovariance(double **covBlocks, const std::vector< int > &blockIndices)
double * _Ax
values of the cholesky factor
~MarginalCovarianceCholesky()
int colBaseOfBlock(int c) const
where does the col at block-col r starts?
MatrixElem(int r_, int c_)
int _n
L is an n X n matrix.
int * _perm
permutation of the cholesky factor. Variable re-ordering for better fill-in
std::vector< double > _diag
cache 1 / H_ii to avoid recalculations
bool operator<(const MatrixElem &other) const
int rowBaseOfBlock(int r) const
where does the row at block-row r starts?
Sparse matrix which uses blocks.
double computeEntry(int r, int c)
int computeIndex(int r, int c) const
compute the index used for hashing