-
Jesper Andersson authoredJesper Andersson authored
SpMat.h 42.51 KiB
//
// Declarations/template-bodies for sparse matrix class SpMat
//
// SpMat.h
//
// Implements bare-bones sparse matrix class.
// Main considerations has been efficiency when constructing
// from Compressed Column format, when multiplying with vector,
// transposing and multiplying with a vector and when concatenating.
// Other operations which have not been prioritised such as
// for example inserting elements in a random order may be
// a bit slow.
//
//
// Jesper Andersson, FMRIB Image Analysis Group
//
// Copyright (C) 2007 University of Oxford
//
#ifndef SpMat_h
#define SpMat_h
#include <vector>
#include <fstream>
#include <iomanip>
#include <boost/shared_ptr.hpp>
#include "newmat.h"
#include "cg.h"
#include "bicg.h"
#include "miscmaths.h"
namespace MISCMATHS {
class SpMatException: public std::exception
{
private:
std::string m_msg;
public:
SpMatException(const std::string& msg) throw(): m_msg(msg) {}
virtual const char * what() const throw() {
return string("SpMat::" + m_msg).c_str();
}
~SpMatException() throw() {}
};
enum MatrixType {UNKNOWN, ASYM, SYM, SYM_POSDEF};
template<class T>
class Preconditioner;
template<class T>
class Accumulator;
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//
// Class SpMat:
// Interface includes:
// Multiplication with scalar: A*=s, B=s*A, B=A*s, A and B SpMat
// Multiplication with vector: b=A*x, A SpMat, b and x ColumnVector
// Transpose and mul with vector: b=A.trans_mult(x), A SpMat, b and x ColumnVector
// Multiplication with sparse matrix: C=A*B, A, B and C SpMat
// Addition with sparse matrix: A+=B, C=A+B, A, B and C SpMat
// Horisontal concatenation: A|=B, C=A|B, A, B and C SpMat
// Vertical concatenation: A&=B, C=A&B, A, B and C SpMat
//
// Multiplications and addition with NEWMAT matrices are
// accomplished through type-conversions. For example
// A = B*SpMat(C), A and B SpMat, C NEWMAT