algebramix_doc 0.3
/Users/mourrain/Devel/mmx/algebramix/glue/glue_matrix_integer.cpp
Go to the documentation of this file.
00001 
00002 #include <numerix/integer.hpp>
00003 #include <basix/vector.hpp>
00004 #include <basix/int.hpp>
00005 #include <algebramix/vector_unrolled.hpp>
00006 #include <algebramix/vector_simd.hpp>
00007 #include <numerix/rational.hpp>
00008 #include <algebramix/permutation.hpp>
00009 #include <basix/row_tuple.hpp>
00010 #include <algebramix/matrix.hpp>
00011 #include <algebramix/matrix_ring_naive.hpp>
00012 #include <algebramix/matrix_integer.hpp>
00013 #include <algebramix/matrix_quotient.hpp>
00014 #include <basix/tuple.hpp>
00015 #include <basix/alias.hpp>
00016 #include <basix/glue.hpp>
00017 
00018 #define int_literal(x) as_int (as_string (x))
00019 #define identity_matrix_integer identity_matrix<integer>
00020 #define hilbert_matrix_rational hilbert_matrix<rational>
00021 
00022 namespace mmx {
00023   template<typename C> matrix<C>
00024   matrix_new (const vector<row_tuple<C> >& t) {
00025     if (N(t) == 0) return matrix<C> ();
00026     nat i, j, rows= N(t), cols= N(t[0]);
00027     C dummy= 0;
00028     matrix<C> r (dummy, rows, cols);
00029     for (i=0; i<rows; i++) {
00030       ASSERT (N(t[i]) == cols, "unequal row lengths");
00031       for (j=0; j<cols; j++)
00032         r(i,j)= t[i][j];
00033     }
00034     return r;
00035   }
00036 
00037   template<typename C> matrix<C>
00038   matrix_new (const vector<C>& t) {
00039     nat j, rows= 1, cols= N(t);
00040     C dummy= 0;
00041     matrix<C> r (dummy, rows, cols);
00042     for (j=0; j<cols; j++)
00043       r(0,j)= t[j];
00044     return r;
00045   }
00046 
00047   template<typename C> vector<generic>
00048   wrap_column_reduced_echelon_with_permutation (const matrix<C>& m) {
00049     permutation permut;
00050     generic tp=as<generic> (column_reduced_echelon (m, permut));
00051     return vec (tp, as<generic> (permut));
00052   }
00053 
00054   template<typename C> vector<generic>
00055   wrap_column_reduced_echelon_with_transform (const matrix<C>& m) {
00056     matrix<C> k;
00057     generic tp=as<generic> (column_reduced_echelon (m, k));
00058     return vec (tp, as<generic> (k));
00059   }
00060 
00061   template<typename C> vector<generic>
00062   wrap_row_reduced_echelon_with_transform (const matrix<C>& m) {
00063     matrix<C> k;
00064     generic tp=as<generic> (row_reduced_echelon (m, k));
00065     return vec (tp, as<generic> (k));
00066   }
00067 }
00068 
00069 
00070 namespace mmx {
00071   static vector<int>
00072   GLUE_1 (const vector<integer> &arg_1) {
00073     return as<vector<int> > (arg_1);
00074   }
00075   
00076   static vector<integer>
00077   GLUE_2 (const vector<int> &arg_1) {
00078     return as<vector<integer> > (arg_1);
00079   }
00080   
00081   static generic
00082   GLUE_3 (const integer &arg_1, const integer &arg_2) {
00083     return integer_pow (arg_1, arg_2);
00084   }
00085   
00086   static matrix<integer>
00087   GLUE_4 (const int &arg_1) {
00088     return identity_matrix_integer (arg_1);
00089   }
00090   
00091   static row_tuple<integer>
00092   GLUE_5 (const tuple<integer> &arg_1) {
00093     return row_tuple<integer > (as_vector (arg_1));
00094   }
00095   
00096   static matrix<integer>
00097   GLUE_6 (const tuple<integer> &arg_1) {
00098     return matrix_new (as_vector (arg_1));
00099   }
00100   
00101   static matrix<integer>
00102   GLUE_7 (const tuple<row_tuple<integer> > &arg_1) {
00103     return matrix_new (as_vector (arg_1));
00104   }
00105   
00106   static matrix<integer>
00107   GLUE_8 (const tuple<row_tuple<integer> > &arg_1) {
00108     return matrix_new (as_vector (arg_1));
00109   }
00110   
00111   static int
00112   GLUE_9 (const matrix<integer> &arg_1) {
00113     return N (arg_1);
00114   }
00115   
00116   static int
00117   GLUE_10 (const matrix<integer> &arg_1) {
00118     return rows (arg_1);
00119   }
00120   
00121   static int
00122   GLUE_11 (const matrix<integer> &arg_1) {
00123     return cols (arg_1);
00124   }
00125   
00126   static integer
00127   GLUE_12 (const matrix<integer> &arg_1, const int &arg_2, const int &arg_3) {
00128     return arg_1 (arg_2, arg_3);
00129   }
00130   
00131   static alias<integer>
00132   GLUE_13 (const alias<matrix<integer> > &arg_1, const int &arg_2, const int &arg_3) {
00133     return alias_access<integer > (arg_1, arg_2, arg_3);
00134   }
00135   
00136   static matrix<integer>
00137   GLUE_14 (const matrix<integer> &arg_1, const int &arg_2, const int &arg_3, const int &arg_4, const int &arg_5) {
00138     return range (arg_1, arg_2, arg_3, arg_4, arg_5);
00139   }
00140   
00141   static vector<integer>
00142   GLUE_15 (const matrix<integer> &arg_1, const int &arg_2) {
00143     return row (arg_1, arg_2);
00144   }
00145   
00146   static vector<integer>
00147   GLUE_16 (const matrix<integer> &arg_1, const int &arg_2) {
00148     return column (arg_1, arg_2);
00149   }
00150   
00151   static matrix<integer>
00152   GLUE_17 (const matrix<integer> &arg_1) {
00153     return transpose (arg_1);
00154   }
00155   
00156   static matrix<integer>
00157   GLUE_18 (const matrix<integer> &arg_1, const matrix<integer> &arg_2) {
00158     return horizontal_join (arg_1, arg_2);
00159   }
00160   
00161   static matrix<integer>
00162   GLUE_19 (const matrix<integer> &arg_1, const matrix<integer> &arg_2) {
00163     return vertical_join (arg_1, arg_2);
00164   }
00165   
00166   static matrix<integer>
00167   GLUE_20 (const integer &arg_1, const int &arg_2, const int &arg_3) {
00168     return fill_matrix (arg_1, arg_2, arg_3);
00169   }
00170   
00171   static matrix<integer>
00172   GLUE_21 (const integer &arg_1, const int &arg_2) {
00173     return jordan_matrix (arg_1, arg_2);
00174   }
00175   
00176   static matrix<integer>
00177   GLUE_22 (const vector<integer> &arg_1) {
00178     return toeplitz_matrix (arg_1);
00179   }
00180   
00181   static matrix<integer>
00182   GLUE_23 (const vector<integer> &arg_1) {
00183     return hankel_matrix (arg_1);
00184   }
00185   
00186   static matrix<integer>
00187   GLUE_24 (const vector<integer> &arg_1, const vector<integer> &arg_2) {
00188     return tensor_matrix (arg_1, arg_2);
00189   }
00190   
00191   static matrix<integer>
00192   GLUE_25 (const vector<integer> &arg_1) {
00193     return vandermonde (arg_1);
00194   }
00195   
00196   static matrix<integer>
00197   GLUE_26 (const matrix<integer> &arg_1) {
00198     return -arg_1;
00199   }
00200   
00201   static matrix<integer>
00202   GLUE_27 (const matrix<integer> &arg_1) {
00203     return square (arg_1);
00204   }
00205   
00206   static matrix<integer>
00207   GLUE_28 (const matrix<integer> &arg_1, const matrix<integer> &arg_2) {
00208     return arg_1 + arg_2;
00209   }
00210   
00211   static matrix<integer>
00212   GLUE_29 (const matrix<integer> &arg_1, const matrix<integer> &arg_2) {
00213     return arg_1 - arg_2;
00214   }
00215   
00216   static matrix<integer>
00217   GLUE_30 (const matrix<integer> &arg_1, const matrix<integer> &arg_2) {
00218     return arg_1 * arg_2;
00219   }
00220   
00221   static matrix<integer>
00222   GLUE_31 (const integer &arg_1, const matrix<integer> &arg_2) {
00223     return arg_1 + arg_2;
00224   }
00225   
00226   static matrix<integer>
00227   GLUE_32 (const matrix<integer> &arg_1, const integer &arg_2) {
00228     return arg_1 + arg_2;
00229   }
00230   
00231   static matrix<integer>
00232   GLUE_33 (const integer &arg_1, const matrix<integer> &arg_2) {
00233     return arg_1 - arg_2;
00234   }
00235   
00236   static matrix<integer>
00237   GLUE_34 (const matrix<integer> &arg_1, const integer &arg_2) {
00238     return arg_1 - arg_2;
00239   }
00240   
00241   static matrix<integer>
00242   GLUE_35 (const integer &arg_1, const matrix<integer> &arg_2) {
00243     return arg_1 * arg_2;
00244   }
00245   
00246   static matrix<integer>
00247   GLUE_36 (const matrix<integer> &arg_1, const integer &arg_2) {
00248     return arg_1 * arg_2;
00249   }
00250   
00251   static vector<integer>
00252   GLUE_37 (const matrix<integer> &arg_1, const vector<integer> &arg_2) {
00253     return arg_1 * arg_2;
00254   }
00255   
00256   static vector<integer>
00257   GLUE_38 (const vector<integer> &arg_1, const matrix<integer> &arg_2) {
00258     return arg_1 * arg_2;
00259   }
00260   
00261   static row_tuple<generic>
00262   GLUE_39 (const row_tuple<integer> &arg_1) {
00263     return as<row_tuple<generic> > (arg_1);
00264   }
00265   
00266   static matrix<generic>
00267   GLUE_40 (const matrix<integer> &arg_1) {
00268     return as<matrix<generic> > (arg_1);
00269   }
00270   
00271   void
00272   glue_matrix_integer () {
00273     static bool done = false;
00274     if (done) return;
00275     done = true;
00276     call_glue (string ("glue_vector_integer"));
00277     call_glue (string ("glue_matrix_generic"));
00278     define_converter (":>", GLUE_1, PENALTY_INCLUSION);
00279     define_converter (":>", GLUE_2, PENALTY_CAST);
00280     define ("^", GLUE_3);
00281     define_type<row_tuple<integer> > (gen (lit ("Row"), lit ("Integer")));
00282     define_type<matrix<integer> > (gen (lit ("Matrix"), lit ("Integer")));
00283     define ("identity_matrix", GLUE_4);
00284     define ("(.)", GLUE_5);
00285     define ("matrix", GLUE_6);
00286     define ("matrix", GLUE_7);
00287     define ("[]", GLUE_8);
00288     define ("#", GLUE_9);
00289     define ("rows", GLUE_10);
00290     define ("columns", GLUE_11);
00291     define (".[]", GLUE_12);
00292     define (".[]", GLUE_13);
00293     define (".[]", GLUE_14);
00294     define ("row", GLUE_15);
00295     define ("column", GLUE_16);
00296     define ("transpose", GLUE_17);
00297     define ("horizontal_join", GLUE_18);
00298     define ("vertical_join", GLUE_19);
00299     define ("fill_matrix", GLUE_20);
00300     define ("jordan_matrix", GLUE_21);
00301     define ("toeplitz_matrix", GLUE_22);
00302     define ("hankel_matrix", GLUE_23);
00303     define ("tensor_matrix", GLUE_24);
00304     define ("vandermonde", GLUE_25);
00305     define ("-", GLUE_26);
00306     define ("square", GLUE_27);
00307     define ("+", GLUE_28);
00308     define ("-", GLUE_29);
00309     define ("*", GLUE_30);
00310     define ("+", GLUE_31);
00311     define ("+", GLUE_32);
00312     define ("-", GLUE_33);
00313     define ("-", GLUE_34);
00314     define ("*", GLUE_35);
00315     define ("*", GLUE_36);
00316     define ("*", GLUE_37);
00317     define ("*", GLUE_38);
00318     define_converter (":>", GLUE_39, PENALTY_PROMOTE_GENERIC);
00319     define_converter (":>", GLUE_40, PENALTY_PROMOTE_GENERIC);
00320   }
00321 }
 All Classes Namespaces Files Functions Variables Typedefs Friends Defines