diff --git a/stuff/printing.hh b/stuff/printing.hh index c2d64c0a952220f9abc21767e70cd53682d19edb..71d9d9c3b6e8de6871a31ad1a118c1c102c6d9e3 100644 --- a/stuff/printing.hh +++ b/stuff/printing.hh @@ -105,17 +105,20 @@ void printSparseRowMatrixMatlabStyle(const T& arg, const std::string name, strea template <class MatrixType, class stream> void printISTLMatrixMatlabStyle(const MatrixType& arg, const std::string name, stream& out) { - typedef typename MatrixType::ConstRowIterator ConstRowIteratorType; - typedef typename MatrixType::ConstColIterator ConstColIteratorType; - - ConstRowIteratorType rowEnd = arg.end(); - for (ConstRowIteratorType row = arg.begin(); row != rowEnd; ++row) { - ConstColIteratorType colEnd = row->end(); - for (ConstColIteratorType col = row->begin(); col != colEnd; ++col) { - const int rowIndex = row.index() + 1; - const int colIndex = col.index() + 1; - out << name << "(" << rowIndex << "," << colIndex << ")=" << std::setprecision(matlab_output_precision) << (*col) - << ";\n"; + const int I = arg.N(); + const int J = arg.M(); + typedef typename MatrixType::block_type BlockType; + + out << boost::format("\n%s =sparse( %d, %d );") % name % (I * BlockType::rows) % (J * BlockType::cols) << std::endl; + for (unsigned ii = 0; ii < I; ++ii) { + for (unsigned jj = 0; jj < J; ++jj) { + if (arg.exists(ii, jj)) { + const auto& block = arg[ii][jj]; + for (int i = 0; i < block.N(); ++i) + for (int j = 0; j < block.M(); ++j) + out << name << "(" << i + 1 << "," << j + 1 << ")=" << std::setprecision(matlab_output_precision) + << block[i][j] << ";\n"; + } } } }