00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef __MMX_SERIES_MATRIX_HPP
00014 #define __MMX_SERIES_MATRIX_HPP
00015 #include <basix/vector.hpp>
00016 #include <algebramix/matrix.hpp>
00017 #include <algebramix/series.hpp>
00018 #include <algebramix/series_vector.hpp>
00019
00020 namespace mmx {
00021 #define TMPL template<typename C, typename V, typename U>
00022 #define TMPLWU template<typename C, typename V, typename W, typename U>
00023 #define Series series<C,V>
00024 #define Matrix matrix<C,U>
00025 #define Series_rep series_rep<C,V>
00026 #define Series_matrix series<Matrix,V>
00027 #define Matrix_series matrix<Series,U>
00028 #define Polynomial polynomial<C, typename series_polynomial_helper<C,V>::PV>
00029
00030
00031
00032
00033
00034 template<typename C, typename V>
00035 struct series_variant_helper<matrix<C,V> > {
00036 typedef typename series_variant_helper<C>::SV SV;
00037 };
00038
00039
00040
00041
00042
00043 STYPE_TO_TYPE(TMPL,as_matrix_type,Series_matrix,Matrix_series);
00044
00045 TMPL
00046 class matrix_access_series_rep: public Series_rep {
00047 Series_matrix f;
00048 nat i, j;
00049 public:
00050 matrix_access_series_rep (const Series_matrix& f2, nat i2, nat j2):
00051 Series_rep (get_format1 (CF(f2))), f (f2), i (i2), j (j2) {}
00052 syntactic expression (const syntactic& z) const {
00053 return access (flatten (f, z), flatten (i), flatten (j)); }
00054 void Increase_order (nat l) {
00055 Series_rep::Increase_order (l);
00056 increase_order (f, l); }
00057 C next () { return f[this->n](i,j); }
00058 };
00059
00060 TMPL Series
00061 access (const Series_matrix& f, nat i, nat j) {
00062 return (Series_rep*) new matrix_access_series_rep<C,V,U> (f, i, j);
00063 }
00064
00065 TMPL Matrix_series
00066 as_matrix (const Series_matrix& f) {
00067 nat nr= rows (f[0]), nc= cols (f[0]);
00068 Matrix_series m (Series (0), nr, nc);
00069 for (nat i=0; i<nr; i++)
00070 for (nat j=0; j<nc; j++)
00071 m (i, j)= access (f, i, j);
00072 return m;
00073 }
00074
00075 TMPL syntactic
00076 flatten (const Matrix_series& m, const syntactic& z) {
00077 syntactic g;
00078 nat i, j, nr= rows (m), nc= cols (m);
00079 matrix<syntactic,U> r (g, nr, nc);
00080 for (i=0; i<nr; i++)
00081 for (j=0; j<nc; j++)
00082 r (i, j)= flatten (m (i, j), z);
00083 return flatten (r);
00084 }
00085
00086 TMPL format<Matrix >
00087 get_matrix_format (const Matrix_series& m) {
00088 format<Series > fm1= CF(m);
00089 format<C> fm2= get_format1 (fm1);
00090 C zero= promote (0, fm2);
00091 Matrix r (zero, rows (m), cols (m));
00092 return get_format (r);
00093 }
00094
00095 TMPL
00096 class matrix_series_rep: public series_rep<Matrix,V> {
00097 const Matrix_series m;
00098 public:
00099 matrix_series_rep (const Matrix_series& m2):
00100 series_rep<Matrix,V> (get_matrix_format (m2)), m (m2) {}
00101 syntactic expression (const syntactic& z) const {
00102 return flatten (m, z); }
00103 void Increase_order (nat l) {
00104 series_rep<Matrix,V>::Increase_order (l);
00105 for (nat i=0; i<rows(m); i++)
00106 for (nat j=0; j<cols(m); j++)
00107 increase_order (m (i, j), l); }
00108 Matrix next () {
00109 nat i, j, nr= rows (m), nc= cols (m);
00110 Matrix coeff (C (0), nr, nc);
00111 for (i=0; i<nr; i++)
00112 for (j=0; j<nc; j++)
00113 coeff (i, j)= m (i, j) [this->n];
00114 return coeff; }
00115 };
00116
00117 TMPL Series_matrix
00118 as_series (const Matrix_series& m) {
00119 return (series_rep<Matrix,V>*) new matrix_series_rep<C,V,U> (m);
00120 }
00121
00122 TMPL Series_matrix
00123 from_matrix (const Matrix_series& m) {
00124 return (series_rep<Matrix,V>*) new matrix_series_rep<C,V,U> (m);
00125 }
00126
00127 TMPL matrix<Polynomial >
00128 range (const Matrix_series& m, nat start, nat end) {
00129 C zero= promote (0, get_format1 (CF (m)));
00130 matrix<Polynomial > r (zero, rows (m), cols (m));
00131 for (nat i=0; i<rows(m); i++)
00132 for (nat j=0; j<cols(m); j++)
00133 r (i, j)= range (m (i, j), start, end);
00134 return r;
00135 }
00136
00137
00138
00139
00140
00141 TMPL Series_matrix
00142 solve_matrix_lde_init (const Series_matrix& f, const Matrix& c) {
00143 return unary_recursive_series<solve_matrix_lde_op> (f, c);
00144 }
00145
00146 TMPL Matrix_series
00147 solve_lde (const Matrix_series& f) {
00148 ASSERT (is_square_matrix (f), "square matrix expected");
00149 Matrix c (C(1), rows (f), cols (f));
00150 return as_matrix (solve_matrix_lde_init (as_series (f), c));
00151 }
00152
00153 TMPL Matrix_series
00154 solve_lde_init (const Matrix_series& f, const Matrix& c) {
00155 ASSERT (is_square_matrix (f), "square matrix expected");
00156 ASSERT (rows (f) == rows (c), "unequal matrix dimensions");
00157 return as_matrix (solve_matrix_lde_init (as_series (f), c));
00158 }
00159
00160 #undef Polynomial
00161 #undef Series_matrix
00162 #undef Matrix_series
00163 #undef Matrix
00164 #undef Series
00165 #undef Series_rep
00166 #undef TMPLWU
00167 #undef TMPL
00168 }
00169 #endif // __MMX_SERIES_MATRIX_HPP