00001 #ifndef DEF_BMATRIX
00002 #define DEF_BMATRIX
00003 #include <assert.h>
00004 #include "iotools.h"
00005 #include "matrix.h"
00006 struct vector;
00007 struct ivector;
00008
00009
00010
00011 #ifdef DEBUG_BMATRIX
00012 static unsigned long Acbm;
00013 #endif
00014
00015 struct bmatrix
00016
00017
00018
00019
00020
00021 {
00022 long m;
00023 long n;
00024 long tm, tn;
00025 matrix *a;
00026 ivector row;
00027 ivector col;
00028
00029 bmatrix() {m = n = 0; a = NULL;};
00030 bmatrix(long m, long n);
00031 bmatrix(const bmatrix &mat);
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 matrix* operator [] (long i) const
00042 {
00043 #ifdef DEBUG_BMATRIX
00044 if (i >= m)
00045 print_err("block row index %ld is out of range <0,%ld>", __FILE__, __LINE__, __func__, i, m-1);
00046
00047 assert(i < m);
00048 #endif
00049 return (&a[i * n]);
00050 };
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 matrix& operator () (long i, long j) const
00063 {
00064 #ifdef DEBUG_BMATRIX
00065 if (i >= m)
00066 print_err("block row index %ld is out of range <0,%ld>", __FILE__, __LINE__, __func__, i, m-1);
00067
00068 if (j >= n)
00069 print_err("block column index %ld is out of range <0,%ld>", __FILE__, __LINE__, __func__, i, n-1);
00070
00071 assert((i < m) && (j < n));
00072 #endif
00073 return (a[i * n + j]);
00074 };
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085 double& operator () (long i, long j, long k, long l) const
00086 {
00087 #ifdef DEBUG_BMATRIX
00088 if (i >= m)
00089 print_err("block row index %ld is out of range <0,%ld>", __FILE__, __LINE__, __func__, i, m-1);
00090
00091 if (j >= n)
00092 print_err("block column index %ld is out of range <0,%ld>", __FILE__, __LINE__, __func__, i, n-1);
00093
00094 assert((i < m) && (j < n));
00095 #endif
00096 return (a[i * n + j][k][l]);
00097 };
00098
00099
00100 long gen_indices();
00101
00102
00103 long give_totm() const;
00104
00105
00106 long give_totn() const;
00107
00108
00109 void give_totid(long i, long j, long k, long l, long &ti, long &tj) const;
00110
00111
00112 void give_locid(long ti, long tj, long &i, long &j, long &k, long &l) const;
00113
00114
00115 ~bmatrix();
00116 };
00117
00118
00119
00120
00121
00122 long allocm(long m, long n, bmatrix &mat);
00123
00124
00125 long copym(const bmatrix &src, bmatrix &dest);
00126
00127
00128 long fillm(double c, bmatrix &mat);
00129 long fillrow(double c, long i, matrix &bmat);
00130 long fillcol(double c, long i, matrix &bmat);
00131
00132
00133 long destrm(bmatrix &mat);
00134
00135
00136 long addm(const bmatrix &a, const bmatrix &b, bmatrix &c);
00137
00138
00139 long subm(const bmatrix &a, const bmatrix &b, bmatrix &c);
00140
00141
00142 void tensprd (vector &a,vector &b,matrix &c);
00143
00144
00145 long mxm(const bmatrix &a, const bmatrix &b, bmatrix &c);
00146
00147
00148 long cmulm(double c, bmatrix &a);
00149
00150 #endif