File: testMatrix.cc

package info (click to toggle)
clhep 2.1.4.1%2Bdfsg-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 10,012 kB
  • sloc: cpp: 50,094; sh: 6,694; makefile: 2,694; perl: 28
file content (832 lines) | stat: -rwxr-xr-x 16,185 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
// -*- C++ -*-
// $Id: testMatrix.cc,v 1.3 2003/08/13 20:00:12 garren Exp $
//
// This file is a part of the CLHEP - a Class Library for High Energy Physics.
//
// This is a small program for testing the classes from the HEP Matrix module.
//

#include "CLHEP/Matrix/defs.h"
#include "CLHEP/Matrix/Matrix.h"
#include "CLHEP/Matrix/SymMatrix.h"
#include "CLHEP/Matrix/DiagMatrix.h"
#include "CLHEP/Matrix/Vector.h"
#include "CLHEP/Random/Random.h"
#include "CLHEP/Random/JamesRandom.h"
#include "CLHEP/Random/RandFlat.h"
#include <iostream>
#include <iomanip>

using std::cout;
using std::endl;

using namespace CLHEP;

#define PRINTOUT

int matrix_test1(const HepGenMatrix&m) {
  //
  // test of virtual finctions.
  //
  static int dum = 0;
  dum += m.num_col();
  return 0;
}

//
// test function
//
double neg(double f, int, int) {
  return -f;
}

double absf(double f, int, int) {
  return fabs(f);
}

double negv(double f, int) {
  return -f;
}

void matrix_test2(const HepSymMatrix&m, HepSymMatrix &n) {
  n = m.sub(2,5);
}


void matrix_test() {
  //
  // complete test of all functions in Matrix.cc
  //
  cout << "Starting Matrix tests" << endl;
  {
    // Test of HepMatrix()
    HepMatrix a;
  }

  {
    // Test of HepMatrix(p,q)
    HepMatrix a(3,5);
    HepMatrix b(4,5,0);
    cout << "4x5 matrix initialized to zero " << b;
    HepMatrix c(3,3,1);
    cout << "3x3 matrix initialized to identity " << c;
  }

  {
    // Test of HepMatrix(p,q,Random)
    HepRandom r;
    r.setTheSeed(31);
    HepMatrix a(3,3,r);
    cout << "3x3 matrix initialized with Random " << a;
    // Test of HepMatrix(const HepMatrix&);
    HepMatrix b(a);
    cout << "matrix initialized to the previous matrix " << b;
  }

  {
    // Test of sub matrix
    HepRandom r;
    r.setTheSeed(31);
    HepMatrix a(8,5,r);
    HepMatrix b = a.sub(2,6,3,5);
    cout << "8x5 matrix" << a;
    cout << "sub matrix (2-6 x 3-5 of the previous matrix." << b;
    HepMatrix c(2,3,0);
    a.sub(4,3,c);
    cout << "embedding sub matrix at 4,3" << a;
    // Test of dsum
    HepMatrix d(3,2,r);
    cout << "dsum" << dsum(a,d);
  }

  {
    // m += m1;
    HepRandom r;
    r.setTheSeed(31);
    HepMatrix a(5,5,r);
    HepMatrix b(5,5,r);
    cout << "a" << a;
    cout << "b" << b;
    cout << "a += b" << (a+=b);
    HepMatrix c;
    c = a + b;
    cout << "a + b" << c;
  }

  {
    // test of T();
    HepRandom r;
    r.setTheSeed(31);
    HepMatrix a(5,3,r);
    HepMatrix b = a.T();
    cout << "a" << a;
    cout << "a.T" << b;
  }

  cout << "End of Matrix tests" << endl;
  
}

void symmatrix_test() {
  {
    // Test of HepSymMatrix()
    HepSymMatrix a;
  }

  {
    // Test of HepSymMatrix(p)
    HepSymMatrix a(3);
    HepSymMatrix b(4,0);
    cout << "4x4 Symmetric matrix initialuzed to zero " << b;
    HepSymMatrix c(3,1);
    cout << "3x3 Symmetric matrix initialized to identity "<< c;
  }

  {
    // Test of HepSymMatrix(p,Random)
    HepRandom r;
    r.setTheSeed(31);
    HepSymMatrix a(3,r);
    cout << "3x3 symmetric matrix initialized with Random " << a << endl;
    // Test of HepSymMatrix(const HepSymMatrix&);
    HepSymMatrix b(a);
    cout << "symmetric matrix initialized to the previous matrix " << b;
    HepMatrix c(b);
    cout << "matrix initialized to the previous symmetric matrix "
	 << c;
    //
    // Access to elements
    //
    double f = 3.8;
    double g = 22.5;
    cout << c(1,1) << " " << c[0][0] << endl;
    c(1,2) = f;
    c[2][1] = g;
    c(2,3) = f;
    c[1][2] = g;
    cout << c << endl;
    HepMatrix &d = c;
    cout << d(1,1) << " " << d[0][0] << endl;
    
  }

  {
    // Test of sub symmatrix
    HepRandom r;
    r.setTheSeed(31);
    HepSymMatrix a(5,r);
    HepSymMatrix b = a.sub(2,5);
    cout << "5x5 sym matrix" << a;
    cout << "sub sym matrix (2-5 x 2-5 of the previous sub matrix." << b;
    HepSymMatrix c(3,0);
    a.sub(2,c);
    cout << "embedding sub matrix at 2" << a;
  }
  {
    // m = m1 + s;
    HepRandom r;
    r.setTheSeed(31);
    HepMatrix a(5,5,r);
    HepSymMatrix b(5,r);
    cout << "a" << a;
    cout << "b(sym)" << b;
    cout << "a += b" << (a+=b);
    HepMatrix c = a + b;
    cout << "a + b" << c;
  }
  {
    // test of similarity(Matrix)
    HepRandom r;
    r.setTheSeed(31);
    HepMatrix a(5,3,r);
    HepSymMatrix b(3,r);
    HepSymMatrix c = b.similarity(a);
    cout << "a" << a;
    cout << "b" << b;
    cout << "c" << c;
  }
  {
    // test of similarityT(Matrix)
    HepRandom r;
    r.setTheSeed(31);
    HepMatrix a(3,5,r);
    HepSymMatrix b(3,r);
    HepSymMatrix c = b.similarityT(a);
    cout << "a" << a;
    cout << "b" << b;
    cout << "c" << c;
  }
  {
    // test of similarity(SymMatrix)
    HepRandom r;
    r.setTheSeed(31);
    HepSymMatrix a(3,r);
    HepSymMatrix b(3,r);
    HepSymMatrix c = b.similarity(a);
    cout << "a" << a;
    cout << "b" << b;
    cout << "c" << c;
  }
  {
    // test of similarity(Vector)
    HepRandom r;
    r.setTheSeed(31);
    HepVector a(3,r);
    HepSymMatrix b(3,r);
    double c = b.similarity(a);
    HepSymMatrix cc = b.similarity(HepMatrix(a.T()));
    cout << "a" << a;
    cout << "b" << b;
    cout << "c\t" << c << endl;
    cout << "c" << cc;
  }
  cout << "End of SymMatrix tests" << endl;
  
}

void diagmatrix_test() { 
  {
    // Test of HepDiagMatrix()
    HepDiagMatrix a;
  }

  {
    // Test of HepDiagMatrix(p)
    HepDiagMatrix a(3);
    HepDiagMatrix b(4,0);
    cout << "4x4 diagonal matrix initialized to zero " << b;
    HepDiagMatrix c(3,1);
    cout << "3x3 diagonal matrix initialized to identity " << c;
  }

  {
    // Test of HepDiagMatrix(p,Random)
    HepRandom r;
    r.setTheSeed(31);
    HepDiagMatrix a(3,r);
    cout << "3x3 diagonal matrix initialized to Random " << a;
    // Test of HepDiagMatrix(const HepDiagMatrix&);
    HepDiagMatrix b(a);
    cout << "diagonal matrix initialized to the previous matrix " << b;
    HepMatrix c(b);
    cout << "matrix initialized to the previous diagonal matrix "
	 << c;
    HepSymMatrix d(b);
    cout << "Symmetric matrix initialized to the previous diagonal matrix "
	 << d;
  }

  {
    // Test of sub diagmatrix
    HepRandom r;
    r.setTheSeed(31);
    HepDiagMatrix a(8,r);
    HepDiagMatrix b = a.sub(2,5);
    cout << "8x8 diag matrix" << a;
    cout << "sub diag matrix (2-5 x 2-5 of the previous diag matrix." << b;
    HepDiagMatrix c(3,0);
    a.sub(2,c);
    cout << "embedding sub matrix at 2" << a;
  }
  {
    // m = m1 + s;
    HepRandom r;
    r.setTheSeed(31);
    HepMatrix a(5,5,r);
    HepDiagMatrix b(5,r);
    cout << "a" << a;
    cout << "b(diag)" << b;
    cout << "a += b" << (a+=b);
    HepMatrix c = a + b;
    cout << "a + b" << c;
  }

  cout << "End of DiagMatrix tests" << endl;
}

void vector_test() {
  {
    // Test of HepVector()
    HepVector a;
  }

  {
    // Test of HepVector(p)
    HepVector a(3);
    HepVector b(4,0);
    cout << "4 vector initialized to zero "<< b;
    HepVector c(3,1);
    cout << "3 vector initialized to identity " << c;
  }

  {
    // Test of HepVector(p,Random)
    HepRandom r;
    r.setTheSeed(31);
    HepVector a(3,r);
    cout << "3 vector initialized to Random " << a;
    // Test of HepVector(const HepVector&);
    HepVector b(a);
    cout << "Vector initialized to the previous vector " << b;
    HepMatrix c(b);
    cout << "matrix initialized to the previous vector "
	 << c;
    HepVector d(c);
    cout << "Vector initialized to the previous matrix "
	 << d;    
  }

  {
    // Test of sub diagmatrix
    HepRandom r;
    r.setTheSeed(31);
    HepVector a(8,r);
    HepVector b = a.sub(2,5);
    cout << "8 vector" << a;
    cout << "sub vector (2-5 of the previous vector." << b;
    HepVector c(3,0);
    a.sub(2,c);
    cout << "embedding sub vector at 2 " << a;
  }
  {
    // m = m1 + s;
    HepRandom r;
    r.setTheSeed(31);
    HepMatrix a(5,1,r);
    HepVector b(5,r);
    cout << "a" << a;
    cout << "b(vector)" << b;
    cout << "a += b" << (a+=b);
    HepMatrix c = a + b;
    cout << "a + b" << c;
  }

  cout << "End of Vector tests" << endl;
}

int main() {
//
// Test of HepMatrix
//
  cout << std::setiosflags(std::ios::fixed) << std::setw(10);
  matrix_test();
  symmatrix_test();
  diagmatrix_test();
  vector_test();
  
  //
  // Test of default constructor
  //
  HepMatrix m;
  //
  // Test of constructors.
  //
  HepMatrix d(3,3,1);
  HepMatrix e(3,3,0);
  HepMatrix f(5,3);
  HepMatrix g(f);
  matrix_test1(g);
  //
  // Test of constructor with a Random object.
  //
  HepRandom r;
  r.setTheSeed(31);
  HepMatrix a(3,3,r);
#if defined(PRINTOUT)
 cout << a << endl;
#endif
  HepMatrix b(3,5,r);
  matrix_test1(b);
#if defined(PRINTOUT)
 cout << b << endl;
#endif

  HepSymMatrix dds(3,r);
  HepMatrix ddm(dds);
  HepDiagMatrix ddd(3,r);
  HepMatrix ddmd(ddd);
  HepVector ddv(3,r);
  HepMatrix ddmv(ddv);
#if defined(PRINTOUT)
 cout << "nraw=" << b.num_row() << " ncol=" << b.num_col() << endl;
#endif
#if defined(PRINTOUT)
 cout << "b(1,1)=" << b(1,1) << " b(2,1)=" << b(2,1) << endl;
#endif
  b(2,3) = 1.0;

  b /= 3.0;
  b *= 6.0;

  HepSymMatrix sm(3,r);
  HepDiagMatrix dm(3,r);
  HepVector vvm(3,r);

  d += e;  
  d += sm;
  d += dm;
  ddmv += vvm;

  a -= e;
  a -= sm;
  a -= dm;
  ddmv -= vvm;

  d = sm;
  d = dm;
  d = a;
  ddmv = vvm;

  e = d.apply(neg);

  a = d.T();
  
  e = b.sub(1,2,3,2);
  
  b.sub(1,3,e);

  swap(a,d);
  
  m = d * a;
  m = d * sm;
  m = d * dm;
  m = sm * d;
#if defined(PRINTOUT)
 cout << "Dm=" << dm << " d = " << d << endl;
#endif
  m = dm * d;
  m = sm * sm;
  m = dm * dm;

  //
  // SymMatrix
  //
  HepSymMatrix s;
  HepSymMatrix ss(6);
  HepSymMatrix si(6,1);
  HepSymMatrix sz(6,0);
  HepSymMatrix sr(6,r);
  HepSymMatrix sc(sr);
  HepSymMatrix scd(dm);

  matrix_test1(si);
#if defined(PRINTOUT)
 cout << "nraw=" << sr.num_row() << " ncol=" << sr.num_col() << endl;
#endif
#if defined(PRINTOUT)
 cout << "sr(1,1)=" << sr(1,1) << " sr(2,1)=" << sr(2,1) << endl;
#endif

  sr(4,3) = r();
  sr.fast(3,1) = r();
  
  s.assign(d);
#if defined(PRINTOUT)
 cout << "d=" << d << "s=" << s << endl;  
#endif
  ss.assign(sc);

  ss *= 0.5;
  ss /= 0.2;

  HepDiagMatrix ddds(ss.num_row(),r);
  ss += si;
  ss += ddds;
  ss -= sr;
  ss -= ddds;
  ss = ddds;

  s = sr;
  s = ss.T();
  s.apply(neg);
  HepMatrix mm(6,4,r);
  ss = s.similarityT(mm);
  
  HepMatrix mt(8,6,r);
  ss = s.similarity(mt);

  s.assign(d);
  
  s = sr.sub(2,5);

  ss.sub(2,s);
  s = ss.sub(2,7);

  m = s * sr;
  m = s * m;
  m = m * s;
  
  HepVector v(6,r);
  s = vT_times_v(v);
  
  //
  // Test of HepDiagMatrix
  //

  HepDiagMatrix dt;
  HepDiagMatrix dn(6);
  HepDiagMatrix di(6,1);
  HepDiagMatrix dz(6,0);
  HepDiagMatrix dr(6,r);
  HepDiagMatrix dc(dr);

  matrix_test1(dr);
#if defined(PRINTOUT)
 cout << "Nr=" << di.num_row() << " Nc=" << dz.num_col() << endl;
#endif
#if defined(PRINTOUT)
 cout << "dr(1,1)=" << dr(1,1) << endl;
#endif

  dr(4,4) = r();
  dr.fast(2,2) = r();

  dt.assign(m);
  dt.assign(s);
  dt.assign(dc);
  
  dr *= 3.0;
  dr /= 3.0;
  
  dr += dt;
  dr -= di;
  
  dt = dz;
  
  dz = dt.T();
  di = dt.apply(neg);
  
  s = dr.similarityT(mm);  
  s = dr.similarity(mt);
#if defined(PRINTOUT)
 cout << "sim=" << dr.similarity(v);
#endif

  dt = dr.sub(2,5);
  dz.sub(3,dt);

  //
  // Test of HepVector
  //

  HepVector vt;
  HepVector vp(6);
  HepVector vz(6,0);
  HepVector vi(6,1);
  HepVector vr(6,r);
  HepVector vc(vr);
#if defined(PRINTOUT)
 cout << "vz=" << vz << "vi=" << vi << endl;
#endif

  HepVector vm(HepMatrix(6,1,r));
  HepVector vs(HepSymMatrix(1,r));
  HepVector vd(HepDiagMatrix(1,r));
#if defined(PRINTOUT)
 cout << "Nr=" << vr.num_row() << endl;
#endif
#if defined(PRINTOUT)
 cout << "vr(3)=" << vr(3) << endl;
#endif

  vr(2) = r();
  
  vi *= 2.5;
  vi /= 2.5;
  
  vm += HepMatrix(6,1,r);
  vs += HepSymMatrix(1,r);
  vd += HepDiagMatrix(1,r);
  vi += vr;
  
  vm -= HepMatrix(6,1,r);
  vs -= HepSymMatrix(1,r);
  vd -= HepDiagMatrix(1,r);  
  vi -= vc;
  
  vm = HepMatrix(6,1,r);
  vs = HepSymMatrix(1,r);
  vd = HepDiagMatrix(1,r);
  vt = vc;
  
  vt = vc.apply(negv);
  vt = vc.sub(2,5);
  vc.sub(3,vt);
#if defined(PRINTOUT)
 cout << "Normsq=" << vc.normsq() << "Norm=" << vc.norm() << endl;
#endif
  
  m = vc.T();

  swap(vc,vr);
  
  vt = sr * vr;
  vt = dr * vr;
  vt = mt * vr;
  f = vr * m;

  //
  // Test of other operators
  //

  f = 3.5 * m;
  s = 3.5 * ss;
  dt = 3.5 * dr;
  vt = 3.5 * vr;

  f = m * 3.6;
  s = ss * 3.6;
  dt = dr * 3.6;
  vt = vr * 3.6;

  f = m / 3.6;
  s = ss / 3.6;
  dt = dr / 3.6;
  vt = vr / 3.6;

  d = HepMatrix(6,3,r);
  e = HepMatrix(6,3,r);
  m = d + e;
  d = HepMatrix(6,6,r);
  m = d + sr;
  m = d + dr;
  
  m = sr + d;
  m = dr + d;
  
  s = sr + si;
  dt = dr + di;
  
  s = dr + sr;
  s = sr + dr;

  e = HepMatrix(6,1,r);

  v = e + vr;
  
  v = vr + e;

  v = vr + vz;


  d = HepMatrix(6,3,r);
  e = HepMatrix(6,3,r);
  m = d - e;
  d = HepMatrix(6,6,r);
  dr = HepDiagMatrix(6,r);
  m = d - sr;
  m = d - dr;
  
  m = sr - d;
  m = dr - d;
  
  s = sr - si;
  dt = dr - di;
  
  s = dr - sr;
  s = sr - dr;

  e = HepMatrix(6,1,r);

  v = e - vr;
  
  v = vr - e;

  v = vr - vz;
  
  //
  // Test of Matrix inversion
  //

  m = HepMatrix(6,6,r);
//  a = m;
  int inv;
  a = m.inverse(inv);
#if defined(PRINTOUT)
 cout << "Inv=" << inv << endl;
#endif
  if(inv==0) {
#if defined(PRINTOUT)
    HepMatrix am(a * m), ma(m * a);
    cout << "a*m=" << am.apply(absf) << "m*a=" << ma.apply(absf) << endl;
#endif
  }

  v = HepVector(6,r);

  vt = solve(m, v);
#if defined(PRINTOUT)
 cout << "m*vt=" << m*vt << "v=" << v << endl;
#endif
  

  ss = HepSymMatrix(6,r);
//  s = ss;
  s = ss.inverse(inv);
#if defined(PRINTOUT)
 cout << "Inv=" << inv << endl;
#endif
  if(inv==0) {
#if defined(PRINTOUT)
    HepMatrix sss(s*ss), ssss(ss*s);
    cout << sss.apply(absf) << ssss.apply(absf) << endl;
#endif
  }
  
#if defined(PRINTOUT)
 cout << "Before diag:ss=" << ss << endl;
  s = ss;
#endif
  m = diagonalize(&ss);
#if defined(PRINTOUT)
  cout << "m=" << m << endl;
#endif
#if defined(PRINTOUT)
  cout << "ss=" << ss << endl;
  cout << "Sim" << ss.similarity(m) << endl;
  HepSymMatrix diff(ss.similarity(m) - s);
  cout << "Diff" << diff.apply(absf) << endl;
#endif

  m = HepMatrix(6,6,r);
  a = qr_inverse(m);
#if defined(PRINTOUT)
  HepMatrix am(a * m), ma(m * a);
  cout << am.apply(absf) << ma.apply(absf) << endl;
#endif
#if defined(PRINTOUT)
 cout << "Norm 1 =" << norm1(m) << endl;
#endif
#if defined(PRINTOUT)
 cout << "Norm 2 =" << norm(m) << endl;
#endif
#if defined(PRINTOUT)
 cout << "Norm i =" << norm_infinity(m) << endl;
#endif

  m = HepMatrix(8,6,r);
#if defined(PRINTOUT)
 cout << "m=" << m << endl;
#endif
  a = qr_decomp(&m);
#if defined(PRINTOUT)
 cout << "a=" << a  << "m=" << m << endl;
#endif
#if defined(PRINTOUT)
 cout << "a*m=" << a*m << endl;
#endif
  
  m = HepMatrix(8,8,r);
  v = HepVector(8,r);
  vt = qr_solve(m,v);
#if defined(PRINTOUT)
 cout << "v=" << v << " m*vt=" << m*vt << endl;
#endif

  m = HepMatrix(8,8,r);
  a = HepMatrix(8,3,r);
  b = qr_solve(m,a);
#if defined(PRINTOUT)
 cout << "v=" << a << " m*b=" << m*b << endl;
#endif
#if defined(PRINTOUT)
 cout << "Test was successful" << endl;
#endif

  //
  // Some useful things it can do.
  //
  // Spherisity
//  HepUniformRandomAB ab(-1,1);
  HepJamesRandom Myengine;
  RandFlat ab(Myengine);
  HepVector p[10];
  int i;
  for(i=0;i<10;i++) {
    p[i] = HepVector(3,ab);
    p[i] *= 2.0;
    p[i](1) -= 1;
    p[i](2) -= 1;
    p[i](3) -= 1;
  }
  HepSymMatrix sp(3,0);
  for(i=0;i<10;i++) {
    double psq = p[i].normsq();
    sp(1,1) += psq - p[i](1)*p[i](1);
    sp(2,2) += psq - p[i](2)*p[i](2);
    sp(3,3) += psq - p[i](3)*p[i](3);
    sp(2,1) -= p[i](2)*p[i](1);
    sp(3,1) -= p[i](3)*p[i](1);
    sp(3,2) -= p[i](3)*p[i](2);
  }
  HepMatrix spd = diagonalize(&sp);
  cout << "sp=" << sp << " spd=" << spd << endl;
  HepSymMatrix spps(7,r);
  HepSymMatrix sppss(spps);
  cout << "condition = " << condition(spps) << endl;
  HepMatrix sb = diagonalize(&spps);
  HepSymMatrix sppssdiff(sppss - spps.similarity(sb));
  cout << "spps=" << spps << "sppss - sim = " << sppssdiff.apply(absf)
       << endl;
  return 0;
}