sparse_block_matrix_test.cpp
Go to the documentation of this file.
00001 // g2o - General Graph Optimization
00002 // Copyright (C) 2011 R. Kuemmerle, G. Grisetti, W. Burgard
00003 // 
00004 // g2o is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU Lesser General Public License as published
00006 // by the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 // 
00009 // g2o is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU Lesser General Public License for more details.
00013 // 
00014 // You should have received a copy of the GNU Lesser General Public License
00015 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 
00017 #include "sparse_block_matrix.h"
00018 #include <iostream>
00019 
00020 using namespace std;
00021 using namespace g2o;
00022 using namespace Eigen;
00023 
00024 typedef SparseBlockMatrix< MatrixXd >
00025 SparseBlockMatrixX;
00026 
00027 std::ostream& operator << (std::ostream& os, const SparseBlockMatrixX::SparseMatrixBlock& m) {
00028   for (int i=0; i<m.rows(); i++){
00029     for (int j=0; j<m.cols(); j++)
00030       cerr << m(i,j) << " ";
00031     cerr << endl;
00032   }
00033   return os;
00034 }
00035 
00036 int main (int argc, char** argv){
00037   int rcol[] = {3,6,8,12};
00038   int ccol[] = {2,4,13};
00039   cerr << "creation" << endl;
00040   SparseBlockMatrixX* M=new SparseBlockMatrixX(rcol, ccol, 4,3);
00041 
00042   cerr << "block access" << endl;
00043 
00044   SparseBlockMatrixX::SparseMatrixBlock* b=M->block(0,0, true);
00045   cerr << b->rows() << " " << b->cols() << endl;
00046   for (int i=0; i<b->rows(); i++)
00047     for (int j=0; j<b->cols(); j++){
00048       (*b)(i,j)=i*b->cols()+j;
00049     }
00050 
00051 
00052   cerr << "block access 2" << endl;
00053   b=M->block(0,2, true);
00054   cerr << b->rows() << " " << b->cols() << endl;
00055   for (int i=0; i<b->rows(); i++)
00056     for (int j=0; j<b->cols(); j++){
00057       (*b)(i,j)=i*b->cols()+j;
00058     }
00059 
00060   b=M->block(3,2, true);
00061   cerr << b->rows() << " " << b->cols() << endl;
00062   for (int i=0; i<b->rows(); i++)
00063     for (int j=0; j<b->cols(); j++){
00064       (*b)(i,j)=i*b->cols()+j;
00065     }
00066 
00067   cerr << *M << endl;
00068 
00069   cerr << "SUM" << endl;
00070 
00071   SparseBlockMatrixX* Ms=0;
00072   M->add(Ms);
00073   M->add(Ms);
00074   cerr << *Ms;
00075   
00076   SparseBlockMatrixX* Mt=0;
00077   M->transpose(Mt);
00078   cerr << *Mt << endl;
00079 
00080   SparseBlockMatrixX* Mp=0;
00081   M->multiply(Mp, Mt);
00082   cerr << *Mp << endl;
00083   
00084   int iperm[]={3,2,1,0};
00085   SparseBlockMatrixX* PMp=0;
00086 
00087   Mp->symmPermutation(PMp,iperm, false);
00088   cerr << *PMp << endl;
00089 
00090   PMp->clear(true);
00091   Mp->block(3,0)->fill(0.);
00092   Mp->symmPermutation(PMp,iperm, true);
00093   cerr << *PMp << endl;
00094   
00095   
00096   
00097 }


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:32:45