15#ifndef TBCI_CRMATRIX_H
16#define TBCI_CRMATRIX_H
18#include "tbci/matrix_sig.h"
19#include "tbci/matrix.h"
20#include "tbci/vector.h"
25#if !defined(NO_GD) && !defined(AUTO_DECL)
26# include "tbci/crmatrix_gd.h"
32#ifndef TBCI_DISABLE_EXCEPT
39 :
NumErr(
"Error in crmatrix library") {}
50# pragma interface "crmatrix.h"
90 static const char*
mat_info () {
return (
"CRMatrix"); }
100 inline const T&
operator () (
unsigned int row,
unsigned int column)
const;
101 inline const T&
get (
unsigned int row,
unsigned int column)
const
102 {
return (*
this) (row, column); }
105 T&
setval (
unsigned int row,
unsigned int column);
107 {
return setval (row, column); }
115 void set_row(
T* value,
unsigned int row,
unsigned int count,
unsigned int*
index);
120 unsigned int size()
const;
123 inline void resize(
unsigned int newRows,
unsigned int newColumns);
173 allocate (mat.rows(), mat.columns());
175 for (
unsigned j = 0; j <
n_cols; ++j)
176 (*
this) (
i, j) = mat(
i, j);
184 for (
unsigned int j=0; j<
rowSize[row]; j++)
230 unsigned int* newIndex =
new unsigned int[
rowSize[row]+1];
238 newComp[j] =
comp[row][j];
242 newIndex[j] = column;
247 newComp[
i+1] =
comp[row][
i];
273 unsigned int* newIndex =
new unsigned int[
rowSize[row]+1];
282 newComp[j] =
comp[row][j];
286 unsigned int pos_store(j);
287 newIndex[j] = column;
293 newComp[
i+1] =
comp[row][
i];
306 comp[row][pos_store]=0;
307 return comp[row][pos_store];
316 for (
unsigned int j=0; j<
n_cols; j++)
317 RowVec.
set((*
this)(row,j),j);
326 unsigned int count = 0;
328 for (j=0; j<v.
size(); j++)
329 if (v(j) != 0.0) count++;
339 colIndex[row] =
new unsigned int[count];
341 comp[row] =
new T[row];
351 for (j=0; j<v.
size(); j++)
355 comp[row][count] = v(j);
389 colIndex[row] =
new unsigned int[count];
391 comp[row] =
new T[row];
400 for (
unsigned int j=0; j<count; j++)
403 comp[row][j] = value[j];
411 if (
this == &m)
return *
this;
436 for (
unsigned int j=0; j<
rowSize[
i]; j++)
457 for (
unsigned int j=0; j<
n_cols; ++j)
458 if ((*
this)(
i,j) != cm(
i,j))
470 for (
unsigned int j=0; j<
n_cols; ++j)
471 if ((*
this)(
i,j) != (
T)0)
472 res.setval(-(*
this)(
i,j),
i,j);
485 for (
unsigned int j=0; j<
rowSize[
i]; ++j)
497 return (this->
operator * (v));
508 for (
unsigned int j=0; j<
rowSize[
i]; ++j)
524 for (
unsigned int j=0; j<
rowSize[
i]; ++j)
539 for (
unsigned int i=0;
i<this->n_rows; ++
i) {
541 for (
unsigned int j=0; j<this->rowSize[
i]; ++j)
542 var += this->comp[
i][j] * v[this->colIndex[
i][j]];
558 for (
unsigned int j=0; j<
rowSize[
i]; ++j) {
588 for (
unsigned int i=0;
i<this->n_rows; ++
i)
589 for (
unsigned int j=0; j<this->rowSize[
i]; ++j)
590 res.comp[
i][j] = this->comp[
i][j] * z;
601 for (
unsigned int j=0; j<
rowSize[
i]; ++j)
609{
return m.
mult (z); }
617 for (
unsigned int j=0; j<
rowSize[
i]; ++j)
628 for (
unsigned int j=0; j<this->rowSize[
i]; ++j)
629 res.comp[
i][j] = this->comp[
i][j] / z;
639 for (
unsigned int j=0; j<
rowSize[
i]; j++)
702 for (
unsigned int j=0; j<
rowSize[
i]; ++j) {
719 for (
unsigned int j=0; j<
rowSize[
i]; ++j)
726{
return fill ((
T)0); }
733 for (
unsigned int i = 0;
i <
n_cols; ++
i)
751 for (
unsigned r = 0; r <
rows(); ++r)
753 m(
c,r) = (*this)(r,
c);
775 for (
unsigned int i = 0;
i < m.
rows(); ++
i) {
777 for (
unsigned int j = 0; j < m.
columns(); ++j)
778 stream << m(
i,j) <<
"\t";
781 return stream <<
STD__ flush;
long int Vector< T > & index
#define BCHK(cond, exc, txt, ind, rtval)
#define BCHKNR(cond, exc, txt, ind)
CRMatErr(const CRMatErr &ce)
CRMatErr(const char *t, const long i=0)
C++ class for sparse matrices using compressed row storage.
CRMatrix< T > & transpose()
CRMatrix< T > & setval(const T &z, unsigned int row, unsigned int column)
element access (write)
unsigned int size() const
void set_row(const Vector< T > &v, unsigned int row)
unsigned int columns() const
CRMatrix< T > & setunit(const T &=(T) 1)
set CSCMatrix to val times the unit matrix
T aligned_value_type TALIGN(MIN_ALIGN2)
CRMatrix< T > & clear()
set all elements defined to zero
bool operator==(const CRMatrix< T > &m) const
void copy(const CRMatrix< T > &m)
CRMatrix< T > & fill(const T &)
set all defined element to a val
TVector< T > get_row(unsigned int row) const
CRMatrix< T > & operator=(const CRMatrix< T > &m)
void MatVecMult(Vector< T > &res, const Vector< T > &v) const
void resize(unsigned int newRows, unsigned int newColumns)
CRMatrix< T > & operator*=(const T &z)
CRMatrix< T > operator-() const
TVector< T > transMult(const Vector< T > &v) const
CRMatrix< T > & operator/=(const T &z)
CRMatrix< T > & swap(CRMatrix< T > &)
void allocate(unsigned int rows, unsigned int columns)
unsigned int rows() const
bool operator!=(const CRMatrix< T > &m) const
CRMatrix(const CRMatrix< T > &m)
static const char * mat_info()
CRMatrix(unsigned int rows, unsigned int columns)
const T & operator()(unsigned int row, unsigned int column) const
element access (read)
CRMatrix< T > mult(const T &z) const
TVector< T > operator*(const Vector< T > &v) const
const T & get(unsigned int row, unsigned int column) const
CRMatrix< T > transposed_copy() const
Inefficient! Use transMult if possible.
CRMatrix< T > operator/(const T &z) const
T get(const unsigned long i) const HOT
unsigned long size() const
Temporary Base Class Idiom: Class TVector is used for temporary variables.
unsigned long size() const
T & set(const T &val, const unsigned long i) const
void MatVecMult(Vector< T > &res, const CRMatrix< T > &m, const Vector< T > &v)
CRMatrix< T > transpose(const CRMatrix< T > &crm)
STD__ ostream & operator<<(STD__ ostream &stream, const CRMatrix< T > &m)
const unsigned TMatrix< T > * res