LINEAR++ library: AFF to LAPACK
matrixtest.cc
Go to the documentation of this file.
1 
34 #define MATRIXTEST_VERSION \
35  "MATRIXTEST V1.0 test matrix functions and operators"
36 
37 #include <iostream>
38 #include <tfxx/commandline.h>
39 #include <linearxx/operators.h>
40 #include <aff/shaper.h>
41 
42 using std::cout;
43 using std::cerr;
44 using std::endl;
45 
46 struct Options {
47  bool verbose;
48  int nsize;
49 }; // struct Options
50 
52 
53 void dump(const Tmatrix::Tcoc& m)
54 {
55  const int width=10;
56  const int precision=5;
57  cout.width(width);
58  cout << " ";
59  for (int i=m.first(1); i<=m.last(1); ++i)
60  {
61  cout.width(width);
62  cout << i;
63  }
64  cout << endl;
65  for (int j=m.first(0); j<=m.last(0); ++j)
66  {
67  cout.width(width);
68  cout << j;
69  for (int i=m.first(1); i<=m.last(1); ++i)
70  {
71  cout.width(width);
72  cout.precision(precision);
73  cout << m(j,i);
74  }
75  cout << endl;
76  }
77 } // void dump(const Tmatrix::Tcoc& m)
78 
79 #define DUMP( M ) cout << "matrix " << #M << ":" << endl; dump(M);
80 
81 /*======================================================================*/
82 
83 int main(int iargc, char* argv[])
84 {
85 
86  // define usage information
87  char usage_text[]=
88  {
90  "usage: matrixtest" "\n"
91  " or: matrixtest --help|-h" "\n"
92  };
93 
94  // define full help text
95  char help_text[]=
96  {
97  "\n"
98  };
99 
100  // define commandline options
101  using namespace tfxx::cmdline;
102  static Declare options[]=
103  {
104  // 0: print help
105  {"help",arg_no,"-"},
106  // 1: verbose mode
107  {"v",arg_no,"-"},
108  {NULL}
109  };
110 
111  // no arguments? print usage...
112  if (iargc<2)
113  {
114  cerr << usage_text << endl;
115  exit(0);
116  }
117 
118  // collect options from commandline
119  Commandline cmdline(iargc, argv, options);
120 
121  // help requested? print full help text...
122  if (cmdline.optset(0))
123  {
124  cerr << usage_text << endl;
125  cerr << help_text << endl;
126  exit(0);
127  }
128 
129  /*
130  // dummy operation: print option settings
131  for (int iopt=0; iopt<2; iopt++)
132  {
133  cout << "option: '" << options[iopt].opt_string << "'" << endl;
134  if (cmdline.optset(iopt)) { cout << " option was set"; }
135  else { cout << "option was not set"; }
136  cout << endl;
137  cout << " argument (string): '" << cmdline.string_arg(iopt) << "'" << endl;
138  cout << " argument (int): '" << cmdline.int_arg(iopt) << "'" << endl;
139  cout << " argument (long): '" << cmdline.long_arg(iopt) << "'" << endl;
140  cout << " argument (float): '" << cmdline.float_arg(iopt) << "'" << endl;
141  cout << " argument (double): '" << cmdline.double_arg(iopt) << "'" << endl;
142  cout << " argument (bool): '";
143  if (cmdline.bool_arg(iopt))
144  { cout << "true"; } else { cout << "false"; }
145  cout << "'" << endl;
146  }
147  while (cmdline.extra()) { cout << cmdline.next() << endl; }
148 
149  // dummy operation: print rest of command line
150  while (cmdline.extra()) { cout << cmdline.next() << endl; }
151  */
152  Tmatrix A(aff::Shaper(1,4)(1,3));
153  Tmatrix B(aff::Shaper(1,3)(1,5));
154  A=2;
155  A(1,3)=-5;
156  B=3;
157  B(1,5)=-11;
158  DUMP(A);
159  DUMP(B);
162  DUMP(linear::op::dotNxM(A,B));
163 }
164 
165 /* ----- END OF matrixtest.cc ----- */
linear::TDmatrix Tmatrix
Definition: lsqexample.cc:56
#define DUMP(M)
Definition: matrixtest.cc:79
aff::Array< double > TDmatrix
Definition: matrix.h:46
TDmatrix transposeNxM(const TDmatrix::Tcoc &A)
calculate transpose of NxM matrix.
Definition: transpose.cc:44
linear::TDmatrix Tmatrix
Definition: matrixtest.cc:51
int nsize
Definition: lapacktest.cc:53
matrix and vector operators (prototypes)
void dump(const Tmatrix::Tcoc &m)
Definition: matrixtest.cc:53
bool verbose
Definition: lapacktest.cc:52
TDmatrix dotNxM(const TDmatrix::Tcoc &A, const TDmatrix::Tcoc &B)
dot product for NxM matrices.
Definition: dot.cc:45
int main(int iargc, char *argv[])
Definition: matrixtest.cc:83
#define MATRIXTEST_VERSION
Definition: matrixtest.cc:34