This file is indexed.

/usr/include/root/Math/SMatrix.icc is in libroot-math-smatrix-dev 5.34.30-0ubuntu8.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
// @(#)root/smatrix:$Id$
// Authors: T. Glebe, L. Moneta    2005  

#ifndef ROOT_Math_SMatrix_icc
#define ROOT_Math_SMatrix_icc
// ********************************************************************
//
// source:
//
// type:      source code
//
// created:   21. Mar 2001
//
// author:    Thorsten Glebe
//            HERA-B Collaboration
//            Max-Planck-Institut fuer Kernphysik
//            Saupfercheckweg 1
//            69117 Heidelberg
//            Germany
//            E-mail: T.Glebe@mpi-hd.mpg.de
//
// Description: SMatrix implementation file
//
// changes:
// 21 Mar 2001 (TG) creation
// 26 Mar 2001 (TG) place_in_row(), place_in_col() added
// 03 Apr 2001 (TG) invert() added
// 07 Apr 2001 (TG) CTOR from SVertex (dyadic product) added
// 09 Apr 2001 (TG) CTOR from array added
// 25 Mai 2001 (TG) row(), col() added
// 11 Jul 2001 (TG) added #include Functions.hh
// 11 Jan 2002 (TG) added operator==(), operator!=()
// 14 Jan 2002 (TG) added more operator==(), operator!=(), operator>(), operator<()
//
// ********************************************************************
#include <iostream>
#include <iomanip>
#include <assert.h>
//#ifndef ROOT_Math_Dsinv
//#include "Math/Dsinv.h"
//#endif
//#include "Math/Dsinv_array.h"
//#include "Math/Dsfact.h"

#ifndef ROOT_Math_Dfact
#include "Math/Dfact.h"
#endif
#ifndef ROOT_Math_Dinv
#include "Math/Dinv.h"
#endif
#ifndef ROOT_Math_Functions
#include "Math/Functions.h"
#endif
#ifndef ROOT_Math_HelperOps
#include "Math/HelperOps.h"
#endif
#ifndef ROOT_Math_StaticCheck
#include "Math/StaticCheck.h"
#endif







namespace ROOT { 

namespace Math { 



//==============================================================================
// Constructors
//==============================================================================
template <class T, unsigned int D1, unsigned int D2, class R>
SMatrix<T,D1,D2,R>::SMatrix() {
   // operator=(0);   // if operator=(T ) is defined
   for(unsigned int i=0; i<R::kSize; ++i) fRep.Array()[i] = 0;
}

//identity
template <class T, unsigned int D1, unsigned int D2, class R>
SMatrix<T,D1,D2,R>::SMatrix( SMatrixIdentity ) {
   for(unsigned int i=0; i<R::kSize; ++i)
      fRep.Array()[i] = 0;
   if (D1 <= D2) { 
      for(unsigned int i=0; i<D1; ++i)
         fRep[i*D2+i] = 1;
   }
   else { 
      for(unsigned int i=0; i<D2; ++i)
         fRep[i*D2+i] = 1;
   }
}

template <class T, unsigned int D1, unsigned int D2, class R>
SMatrix<T,D1,D2,R>::SMatrix(const SMatrix<T,D1,D2,R>& rhs) {
   fRep = rhs.fRep;
}


template <class T, unsigned int D1, unsigned int D2, class R>
template <class R2>
SMatrix<T,D1,D2,R>::SMatrix(const SMatrix<T,D1,D2,R2>& rhs) {
   operator=(rhs);
}


template <class T, unsigned int D1, unsigned int D2, class R>
template <class A, class R2>
SMatrix<T,D1,D2,R>::SMatrix(const Expr<A,T,D1,D2,R2>& rhs) {
   operator=(rhs);
}


//=============================================================================
// New Constructors from STL interfaces
//=============================================================================
template <class T, unsigned int D1, unsigned int D2, class R>
template <class InputIterator>
SMatrix<T,D1,D2,R>::SMatrix(InputIterator ibegin, InputIterator iend, bool triang, bool lower) {
   // assume iterator size == matrix size 
   for(unsigned int i=0; i<R::kSize; ++i) fRep.Array()[i] = 0;
   AssignItr<T,D1,D2,R>::Evaluate(*this,ibegin,iend,triang,lower); 
}

template <class T, unsigned int D1, unsigned int D2, class R>
template <class InputIterator>
SMatrix<T,D1,D2,R>::SMatrix(InputIterator ibegin, unsigned int size, bool triang, bool lower) {
   // assume iterator size <= matrix size (no check needed in AssignItr) 
   assert( size <= R::kSize);
   for(unsigned int i=0; i<R::kSize; ++i) fRep.Array()[i] = 0;
   AssignItr<T,D1,D2,R>::Evaluate(*this,ibegin,ibegin+size,triang,lower,false); 
}


//==============================================================================
// Assignment and operator= for scalar types for matrices of size 1 
// compiles only for matrices of size 1
//==============================================================================
template <class T, unsigned int D1, unsigned int D2, class R>
SMatrix<T,D1,D2,R>::SMatrix(const T&  rhs) {
   STATIC_CHECK( kSize == 1,SMatrix_NOT_of_size_1 );
   fRep[0] = rhs;
}

template <class T, unsigned int D1, unsigned int D2, class R>
SMatrix<T,D1,D2,R>& SMatrix<T,D1,D2,R>::operator=(const T&  rhs) {
   STATIC_CHECK( kSize == 1,SMatrix_NOT_of_size_1 );
   fRep[0] = rhs;
   return *this;
}

//=============================================================================
//=============================================================================

template <class T, unsigned int D1, unsigned int D2, class R>
template <class M>
SMatrix<T,D1,D2,R>& SMatrix<T,D1,D2,R>::operator=(const M&  rhs) {
   fRep = rhs.fRep;
   return *this;
}

template <class T, unsigned int D1, unsigned int D2, class R>
template <class A, class R2>
SMatrix<T,D1,D2,R>& SMatrix<T,D1,D2,R>::operator=(const Expr<A,T,D1,D2,R2>&  rhs) {
   
   Assign<T,D1,D2,A,R,R2>::Evaluate(*this, rhs);
   return *this;
}

//=============================================================================
// assign from an identity
template <class T, unsigned int D1, unsigned int D2, class R>
SMatrix<T,D1,D2,R>& SMatrix<T,D1,D2,R>::operator= ( SMatrixIdentity ) {
   for(unsigned int i=0; i<R::kSize; ++i)
      fRep.Array()[i] = 0;
   if (D1 <= D2) { 
      for(unsigned int i=0; i<D1; ++i)
         fRep[i*D2+i] = 1;
   }
   else { 
      for(unsigned int i=0; i<D2; ++i)
         fRep[i*D2+i] = 1;
   }
   return *this;
}



//=============================================================================
// operator+=
//=============================================================================
template <class T, unsigned int D1, unsigned int D2, class R>
SMatrix<T,D1,D2,R>& SMatrix<T,D1,D2,R>::operator+=(const T&  rhs) {
   // self-addition with a scalar value
   for(unsigned int i=0; i<R::kSize; ++i) {
      fRep.Array()[i] += rhs;
   }
   return *this;
}

template <class T, unsigned int D1, unsigned int D2, class R>
template <class R2>
SMatrix<T,D1,D2,R>& SMatrix<T,D1,D2,R>::operator+=(const SMatrix<T,D1,D2,R2>&  rhs) {
   // self-addition with another matrix (any representation) 
   // use operator+= of the representation object
   fRep += rhs.fRep;
   return *this;
}


template <class T, unsigned int D1, unsigned int D2, class R>
template <class A, class R2>
SMatrix<T,D1,D2,R>& SMatrix<T,D1,D2,R>::operator+=(const Expr<A,T,D1,D2,R2>&  rhs) {
   // self-addition with an expression
   PlusEquals<T,D1,D2,A,R,R2>::Evaluate(*this, rhs);
   return *this;
}


//==============================================================================
// operator-=
//==============================================================================
template <class T, unsigned int D1, unsigned int D2, class R>
SMatrix<T,D1,D2,R>& SMatrix<T,D1,D2,R>::operator-=(const T&  rhs) {
   // self-subtraction with a scalar value
   for(unsigned int i=0; i<R::kSize; ++i) {
      fRep.Array()[i] -= rhs;
   }
   return *this;
}

template <class T, unsigned int D1, unsigned int D2, class R>
template <class R2>
SMatrix<T,D1,D2,R>& SMatrix<T,D1,D2,R>::operator-=(const SMatrix<T,D1,D2,R2>&  rhs) {
   // self-subtraction with another matrix (any representation) 
   // use operator-= of the representation object
   fRep -= rhs.fRep;
   return *this;
}


template <class T, unsigned int D1, unsigned int D2, class R>
template <class A, class R2>
SMatrix<T,D1,D2,R>& SMatrix<T,D1,D2,R>::operator-=(const Expr<A,T,D1,D2,R2>&  rhs) {
   // self-subtraction with an expression
   MinusEquals<T,D1,D2,A,R,R2>::Evaluate(*this, rhs);
   return *this;
}

//==============================================================================
// operator*=
//==============================================================================
template <class T, unsigned int D1, unsigned int D2, class R>
SMatrix<T,D1,D2,R>& SMatrix<T,D1,D2,R>::operator*=(const T&  rhs) {
   // case of multiplication with a scalar 
   for(unsigned int i=0; i<R::kSize; ++i) {
      fRep.Array()[i] *= rhs;
   }
   return  *this;
} 

template <class T, unsigned int D1, unsigned int D2, class R>
template <class R2> 
SMatrix<T,D1,D2,R>& SMatrix<T,D1,D2,R>::operator*=(const SMatrix<T,D1,D2,R2>&  rhs) {
   // self-multiplication with another matrix (will work only for square matrices)
   // a temporary is needed and will be created automatically to store intermediate result
   return operator=(*this * rhs);
} 

template <class T, unsigned int D1, unsigned int D2, class R>
template <class A, class R2> 
SMatrix<T,D1,D2,R>& SMatrix<T,D1,D2,R>::operator*=(const Expr<A,T,D1,D2,R2>&  rhs) {
   // self-multiplication with an expression (will work only for square matrices)
   // a temporary is needed and will be created automatically to store intermediate result
   return operator=(*this * rhs);
} 


//==============================================================================
// operator/= (only for scalar values)
//==============================================================================
template <class T, unsigned int D1, unsigned int D2, class R>
SMatrix<T,D1,D2,R>& SMatrix<T,D1,D2,R>::operator/=(const T&  rhs) {
   // division with a scalar 
   for(unsigned int i=0; i<R::kSize; ++i) {
      fRep.Array()[i] /= rhs;
   }
   return  *this;
} 

//==============================================================================
// operator== (element wise comparison)
//==============================================================================
template <class T, unsigned int D1, unsigned int D2, class R>
bool SMatrix<T,D1,D2,R>::operator==(const T& rhs) const {
   bool rc = true;
   for(unsigned int i=0; i<R::kSize; ++i) {
      rc = rc && (fRep.Array()[i] == rhs);
   }
   return rc;
}

template <class T, unsigned int D1, unsigned int D2, class R>
template <class R2>
bool SMatrix<T,D1,D2,R>::operator==(const SMatrix<T,D1,D2,R2>& rhs) const {
   return fRep == rhs.fRep;
}

template <class T, unsigned int D1, unsigned int D2, class R>
template <class A, class R2>
bool SMatrix<T,D1,D2,R>::operator==(const Expr<A,T,D1,D2,R2>& rhs) const {
   bool rc = true;
   for(unsigned int i=0; i<D1*D2; ++i) {
      rc = rc && (fRep[i] == rhs.apply(i));
   }
   return rc;
}

//==============================================================================
// operator!= (element wise comparison)
//==============================================================================
template <class T, unsigned int D1, unsigned int D2, class R>
inline bool SMatrix<T,D1,D2,R>::operator!=(const T& rhs) const {
   return !operator==(rhs);
}

template <class T, unsigned int D1, unsigned int D2, class R>
inline bool SMatrix<T,D1,D2,R>::operator!=(const SMatrix<T,D1,D2,R>& rhs) const {
   return !operator==(rhs);
}

template <class T, unsigned int D1, unsigned int D2, class R>
template <class A, class R2>
inline bool SMatrix<T,D1,D2,R>::operator!=(const Expr<A,T,D1,D2,R2>& rhs) const {
   return !operator==(rhs);
}


//==============================================================================
// operator> (element wise comparison)
//==============================================================================
template <class T, unsigned int D1, unsigned int D2, class R>
bool SMatrix<T,D1,D2,R>::operator>(const T& rhs) const {
   bool rc = true;
   for(unsigned int i=0; i<D1*D2; ++i) {
      rc = rc && (fRep[i] > rhs);
   }
   return rc;
}

template <class T, unsigned int D1, unsigned int D2, class R>
template <class R2>
bool SMatrix<T,D1,D2,R>::operator>(const SMatrix<T,D1,D2,R2>& rhs) const {
   bool rc = true;
   for(unsigned int i=0; i<D1*D2; ++i) {
      rc = rc && (fRep[i] > rhs.fRep[i]);
   }
   return rc;
}

template <class T, unsigned int D1, unsigned int D2, class R>
template <class A, class R2>
bool SMatrix<T,D1,D2,R>::operator>(const Expr<A,T,D1,D2,R2>& rhs) const {
   bool rc = true;
   for(unsigned int i=0; i<D1*D2; ++i) {
      rc = rc && (fRep[i] > rhs.apply(i));
   }
   return rc;
}

//==============================================================================
// operator< (element wise comparison)
//==============================================================================
template <class T, unsigned int D1, unsigned int D2, class R>
bool SMatrix<T,D1,D2,R>::operator<(const T& rhs) const {
   bool rc = true;
   for(unsigned int i=0; i<D1*D2; ++i) {
      rc = rc && (fRep[i] < rhs);
   }
   return rc;
}

template <class T, unsigned int D1, unsigned int D2, class R>
template <class R2>
bool SMatrix<T,D1,D2,R>::operator<(const SMatrix<T,D1,D2,R2>& rhs) const {
   bool rc = true;
   for(unsigned int i=0; i<D1*D2; ++i) {
      rc = rc && (fRep[i] < rhs.fRep[i]);
   }
   return rc;
}

template <class T, unsigned int D1, unsigned int D2, class R>
template <class A, class R2>
bool SMatrix<T,D1,D2,R>::operator<(const Expr<A,T,D1,D2,R2>& rhs) const {
   bool rc = true;
   for(unsigned int i=0; i<D1*D2; ++i) {
      rc = rc && (fRep[i] < rhs.apply(i));
   }
   return rc;
}


//==============================================================================
// invert
//==============================================================================
template <class T, unsigned int D1, unsigned int D2, class R>
inline bool SMatrix<T,D1,D2,R>::Invert() {
   STATIC_CHECK( D1 == D2,SMatrix_not_square); 
   return Inverter<D1,D2>::Dinv((*this).fRep);
}

// invert returning a new matrix
template <class T, unsigned int D1, unsigned int D2, class R>
inline SMatrix<T,D1,D2,R> SMatrix<T,D1,D2,R>::Inverse(int & ifail) const {
   SMatrix<T,D1,D2,R> tmp(*this);
   bool ok = tmp.Invert();
   ifail = 0; 
   if (!ok) ifail = 1;  
   return tmp;
}

// fast inversion
template <class T, unsigned int D1, unsigned int D2, class R>
inline bool SMatrix<T,D1,D2,R>::InvertFast() {
   STATIC_CHECK( D1 == D2,SMatrix_not_square); 
   return FastInverter<D1,D2>::Dinv((*this).fRep);
}

// fast inversion returning a new matrix
template <class T, unsigned int D1, unsigned int D2, class R>
inline SMatrix<T,D1,D2,R> SMatrix<T,D1,D2,R>::InverseFast(int & ifail) const {
   SMatrix<T,D1,D2,R> tmp(*this);
   bool ok = tmp.InvertFast();
   ifail = 0; 
   if (!ok) ifail = 1;  
   return tmp;
}

// Choleski inversion for symmetric and positive defined matrices 
template <class T, unsigned int D1, unsigned int D2, class R>
inline bool SMatrix<T,D1,D2, R>::InvertChol() {
   STATIC_CHECK( D1 == D2,SMatrix_not_square); 
   return CholInverter<D1>::Dinv((*this).fRep);
}

template <class T, unsigned int D1, unsigned int D2, class R>
inline SMatrix<T,D1,D2, R>  SMatrix<T,D1,D2, R>::InverseChol(int &ifail) const {
   SMatrix<T,D1,D2,R > tmp(*this);
   bool ok = tmp.InvertChol();
   ifail = 0; 
   if (!ok) ifail = 1;  
   return tmp;
}



//==============================================================================
// det
//==============================================================================
template <class T, unsigned int D1, unsigned int D2, class R>
inline bool SMatrix<T,D1,D2,R>::Det(T& det) {
   STATIC_CHECK( D1 == D2,SMatrix_not_square); 
   //  return Dfact<SMatrix<T,D1,D1>, D1, D1>(*this,det);
   //return Dfact<R, D1, D1>(fRep, det);
   return Determinant<D1,D2>::Dfact(fRep, det);
}
template <class T, unsigned int D1, unsigned int D2, class R>
inline bool SMatrix<T,D1,D2,R>::Det2(T& det) const {
   SMatrix<T,D1,D2,R> tmp(*this);
   return tmp.Det(det);
}


//==============================================================================
// place_in_row
//==============================================================================
template <class T, unsigned int D1, unsigned int D2, class R>
template <unsigned int D>
SMatrix<T,D1,D2,R>& SMatrix<T,D1,D2,R>::Place_in_row(const SVector<T,D>& rhs,
                                                     unsigned int row,
                                                     unsigned int col) {
   
   assert(col+D <= D2);
   
   for(unsigned int i=row*D2+col, j=0; j<D; ++i, ++j) {
      fRep[i] = rhs.apply(j);
   }
   return *this;
}

//==============================================================================
// place_in_row
//==============================================================================
template <class T, unsigned int D1, unsigned int D2, class R>
template <class A, unsigned int D>
SMatrix<T,D1,D2,R>& SMatrix<T,D1,D2,R>::Place_in_row(const VecExpr<A,T,D>& rhs,
                                                     unsigned int row,
                                                     unsigned int col) {
   
   assert(col+D <= D2);
   
   for(unsigned int i=row*D2+col, j=0; j<D; ++i, ++j) {
      fRep[i] = rhs.apply(j);
   }
   return *this;
}

//==============================================================================
// place_in_col
//==============================================================================
template <class T, unsigned int D1, unsigned int D2, class R>
template <unsigned int D>
SMatrix<T,D1,D2,R>& SMatrix<T,D1,D2,R>::Place_in_col(const SVector<T,D>& rhs,
                                                     unsigned int row,
                                                     unsigned int col) {
   
   assert(row+D <= D1);
   
   for(unsigned int i=row*D2+col, j=0; j<D; i+=D2, ++j) {
      fRep[i] = rhs.apply(j);
   }
   return *this;
}

//==============================================================================
// place_in_col
//==============================================================================
template <class T, unsigned int D1, unsigned int D2, class R>
template <class A, unsigned int D>
SMatrix<T,D1,D2,R>& SMatrix<T,D1,D2,R>::Place_in_col(const VecExpr<A,T,D>& rhs,
                                                     unsigned int row,
                                                     unsigned int col) {
   
   assert(row+D <= D1);
   
   for(unsigned int i=row*D2+col, j=0; j<D; i+=D2, ++j) {
      fRep[i] = rhs.apply(j);
   }
   return *this;
}

//==============================================================================
// place_at
//==============================================================================
template <class T, unsigned int D1, unsigned int D2, class R>
template <unsigned int D3, unsigned int D4, class R2>
SMatrix<T,D1,D2,R>& SMatrix<T,D1,D2,R>::Place_at(const SMatrix<T,D3,D4,R2>& rhs,
                                                 unsigned int row,
                                                 unsigned int col) {
   PlaceMatrix<T,D1,D2,D3,D4,R,R2>::Evaluate(*this,rhs,row,col);
   return *this;
}

//==============================================================================
// place_at
//==============================================================================
template <class T, unsigned int D1, unsigned int D2, class R>
template <class A, unsigned int D3, unsigned int D4, class R2>
SMatrix<T,D1,D2,R>& SMatrix<T,D1,D2,R>::Place_at(const Expr<A,T,D3,D4,R2>& rhs,
                                                 unsigned int row,
                                                 unsigned int col) {
   PlaceExpr<T,D1,D2,D3,D4,A,R,R2>::Evaluate(*this,rhs,row,col);
   return *this; 
}

//==============================================================================
// row
//==============================================================================
template <class T, unsigned int D1, unsigned int D2, class R>
SVector<T,D2> SMatrix<T,D1,D2,R>::Row(unsigned int therow) const {
   
   const unsigned int offset = therow*D2;
   
   /*static*/  SVector<T,D2> tmp;
   for(unsigned int i=0; i<D2; ++i) {
      tmp[i] = fRep[offset+i];
   }
   return tmp;
}

//==============================================================================
// col
//==============================================================================
template <class T, unsigned int D1, unsigned int D2, class R>
SVector<T,D1> SMatrix<T,D1,D2,R>::Col(unsigned int thecol) const {
   
   /*static */ SVector<T,D1> tmp;
   for(unsigned int i=0; i<D1; ++i) {
      tmp[i] = fRep[thecol+i*D2];
   }
   return tmp;
}

//==============================================================================
// print
//==============================================================================
template <class T, unsigned int D1, unsigned int D2, class R>
std::ostream& SMatrix<T,D1,D2,R>::Print(std::ostream& os) const {
   const std::ios_base::fmtflags prevFmt = os.setf(std::ios::right,std::ios::adjustfield);
   //  os.setf(ios::fixed);
   
   os << "[ ";
   for (unsigned int i=0; i < D1; ++i) {
      for (unsigned int j=0; j < D2; ++j) {
         os << std::setw(12) << fRep[i*D2+j];
         if ((!((j+1)%12)) && (j < D2-1))
            os << std::endl << "         ...";
      }
      if (i != D1 - 1)
         os << std::endl  << "  ";
   }
   os << " ]";
   
   if (prevFmt != os.flags() ) os.setf(prevFmt, std::ios::adjustfield);
   return os;
}

//==============================================================================
// Access functions
//==============================================================================
template <class T, unsigned int D1, unsigned int D2, class R>
inline T SMatrix<T,D1,D2,R>::apply(unsigned int i) const { return fRep[i]; }

template <class T, unsigned int D1, unsigned int D2, class R>
inline const T* SMatrix<T,D1,D2,R>::Array() const { return fRep.Array(); }

template <class T, unsigned int D1, unsigned int D2, class R>
inline T* SMatrix<T,D1,D2,R>::Array() { return fRep.Array(); }

//==============================================================================
// Operators
//==============================================================================
template <class T, unsigned int D1, unsigned int D2, class R>
inline const T& SMatrix<T,D1,D2,R>::operator()(unsigned int i, unsigned int j) const {
   return fRep(i,j);
}

template <class T, unsigned int D1, unsigned int D2, class R>
inline T& SMatrix<T,D1,D2,R>::operator()(unsigned int i, unsigned int j) {
   return fRep(i,j);
}

 
//==============================================================================
// Element access with At()
//==============================================================================
template <class T, unsigned int D1, unsigned int D2, class R>
inline const T& SMatrix<T,D1,D2,R>::At(unsigned int i, unsigned int j) const {
   assert(i < D1);
   assert(j < D2);
   return fRep(i,j);
}

template <class T, unsigned int D1, unsigned int D2, class R>
inline T& SMatrix<T,D1,D2,R>::At(unsigned int i, unsigned int j) {
   assert(i < D1);
   assert(j < D2);
   return fRep(i,j);
}

//==============================================================================
// STL interface
//==============================================================================
template <class T, unsigned int D1, unsigned int D2, class R>
inline T * SMatrix<T,D1,D2,R>::begin() {
   return fRep.Array();
}

template <class T, unsigned int D1, unsigned int D2, class R>
inline T * SMatrix<T,D1,D2,R>::end() {
   return fRep.Array() + R::kSize;
}

template <class T, unsigned int D1, unsigned int D2, class R>
inline const T * SMatrix<T,D1,D2,R>::begin() const {
   return fRep.Array();
}

template <class T, unsigned int D1, unsigned int D2, class R>
inline const T * SMatrix<T,D1,D2,R>::end() const {
   return fRep.Array() + R::kSize;
}


template <class T, unsigned int D1, unsigned int D2, class R>
template <class InputIterator>
void SMatrix<T,D1,D2,R>::SetElements(InputIterator ibegin, InputIterator iend, bool triang, bool lower) {
   // assume iterator size == matrix size when filling full matrix
   AssignItr<T,D1,D2,R>::Evaluate(*this,ibegin,iend,triang,lower); 
}

template <class T, unsigned int D1, unsigned int D2, class R>
template <class InputIterator>
void SMatrix<T,D1,D2,R>::SetElements(InputIterator ibegin, unsigned int size, bool triang, bool lower) {
   // assume iterator size <= matrix size  (no check to be done in AssignItr)
   assert( size <= R::kSize);
   AssignItr<T,D1,D2,R>::Evaluate(*this,ibegin,ibegin+size,triang,lower,false); 
}



//==============================================================================
// SubMatrices and slices of columns and rows
//==============================================================================
template <class T, unsigned int D1, unsigned int D2, class R>
template <class SubVector>  
SubVector SMatrix<T,D1,D2,R>::SubRow(unsigned int therow, unsigned int col0 ) const { 
   
   const unsigned int offset = therow*D2 + col0;
   
   STATIC_CHECK( SubVector::kSize <= D2,SVector_dimension_too_small); 
   assert(col0 + SubVector::kSize <= D2);
   
   SubVector tmp;
   for(unsigned int i=0; i<SubVector::kSize; ++i) {
      tmp[i] = fRep[offset+i];
   }
   return tmp;
}

template <class T, unsigned int D1, unsigned int D2, class R>
template <class SubVector>  
SubVector SMatrix<T,D1,D2,R>::SubCol(unsigned int thecol, unsigned int row0 ) const { 
   
   const unsigned int offset = thecol + row0*D1;
   
   STATIC_CHECK( SubVector::kSize <= D1,SVector_dimension_too_small); 
   assert(row0 + SubVector::kSize <= D1);
   
   SubVector tmp;
   for(unsigned int i=0; i<SubVector::kSize; ++i) {
      tmp[i] = fRep[offset+i*D1];
   }
   return tmp;
}

// submatrix
template <class T, unsigned int D1, unsigned int D2, class R>
template <class SubMatrix>  
SubMatrix SMatrix<T,D1,D2,R>::Sub(unsigned int row0, unsigned int col0) const { 
   
   SubMatrix tmp;
   RetrieveMatrix<T,SubMatrix::kRows, SubMatrix::kCols, D1, D2, typename SubMatrix::rep_type, R>::Evaluate
      (tmp,*this,row0,col0);
   return tmp;
}

//diagonal
template <class T, unsigned int D1, unsigned int D2, class R>
SVector<T,D1> SMatrix<T,D1,D2,R>::Diagonal( ) const { 
   
   // only for squared matrices
   STATIC_CHECK( D1 == D2,SMatrix_NOT_square );
   
   SVector<T,D1> tmp;
   for(unsigned int i=0; i<D1; ++i) {
      tmp[i] = fRep[ i*D2 + i];
   }
   return tmp;
}

//set diagonal
template <class T, unsigned int D1, unsigned int D2, class R>
template <class Vector> 
void SMatrix<T,D1,D2,R>::SetDiagonal( const Vector & v) { 
   
   // check size that size of vector is correct
   STATIC_CHECK( ( ( D1 <= D2) && Vector::kSize == D1 ) || 
                 ( ( D2 < D1 ) && Vector::kSize == D2 ), SVector_size_NOT_correct );
   
   
   for(unsigned int i=0; i<Vector::kSize; ++i) {
      fRep[ i*D2 + i] = v[i];
   }
}

// matrix trace
template <class T, unsigned int D1, unsigned int D2, class R>
T SMatrix<T,D1,D2,R>::Trace( ) const { 
   unsigned int diagSize = D1; 
   if (D2 < D1) diagSize = D2;  
   T trace = 0;
   for(unsigned int i=0; i< diagSize; ++i) {
      trace += fRep[ i*D2 + i] ;
   }
   return trace;
}

//upper block
template <class T, unsigned int D1, unsigned int D2, class R>
#ifndef UNSUPPORTED_TEMPLATE_EXPRESSION
SVector<T, D1 * (D2 +1)/2 >  SMatrix<T,D1,D2,R>::UpperBlock( ) const { 
#else
template <class SubVector>  
SubVector SMatrix<T,D1,D2,R>::UpperBlock( ) const { 
#endif
   // only for squared matrices
   STATIC_CHECK( D1 == D2,SMatrix_NOT_square );
   
#ifndef UNSUPPORTED_TEMPLATE_EXPRESSION
   SVector<T, D1 * (D2 +1)/2 >  tmp;
#else
   // N must be equal D1 *(D1 +1)/2
   STATIC_CHECK( SubVector::kSize == D1*(D1+1)/2,SVector_Wrong_Size );
   SubVector tmp;
#endif
   
   int k = 0;
   for(unsigned int i=0; i<D1; ++i) {
      for(unsigned int j=i; j<D2; ++j) {
         tmp[k] = fRep[ i*D2 + j];
         k++;
      }
   }
   return tmp;
}

//lower block
template <class T, unsigned int D1, unsigned int D2, class R>
#ifndef UNSUPPORTED_TEMPLATE_EXPRESSION
SVector<T, D1 * (D2 +1)/2 >  SMatrix<T,D1,D2,R>::LowerBlock( ) const { 
#else
template <class SubVector>  
SubVector SMatrix<T,D1,D2,R>::LowerBlock( ) const { 
#endif
   
   // only for squared matrices
   STATIC_CHECK( D1 == D2,SMatrix_NOT_square );
   
#ifndef UNSUPPORTED_TEMPLATE_EXPRESSION
   SVector<T, D1 * (D2 +1)/2 >  tmp;
#else
   // N must be equal D1 *(D1 +1)/2
   STATIC_CHECK( SubVector::kSize == D1*(D1+1)/2,SVector_Wrong_Size );
   SubVector tmp;
#endif
   
   int k = 0;
   for(unsigned int i=0; i<D1; ++i) {
      for(unsigned int j=0; j<=i; ++j) {
         tmp[k] = fRep[ i*D2 + j];
         k++;
      }
   }
   return tmp;
}

/// construct from upper/lower block

//lower block
template <class T, unsigned int D1, unsigned int D2, class R>
#ifndef UNSUPPORTED_TEMPLATE_EXPRESSION
SMatrix<T,D1,D2,R>::SMatrix(const SVector<T, D1*(D2+1)/2 >  & v, bool lower ) { 
#else
template <unsigned int N>  
SMatrix<T,D1,D2,R>::SMatrix(const SVector<T, N >  & v, bool lower ) {
#endif
   
   // only for squared matrices
   STATIC_CHECK( D1 == D2,SMatrix_NOT_square );
   
#ifdef UNSUPPORTED_TEMPLATE_EXPRESSION
   STATIC_CHECK( N == D1*(D1+1)/2,SVector_Wrong_Size );
#endif
   
   int k = 0;
   if (lower) { 
      // case of lower block 
      for(unsigned int i=0; i<D1; ++i) {
         for(unsigned int j=0; j<=i; ++j) {
            fRep[ i*D2 + j] = v[k];
            if ( i != j) fRep[ j*D2 + i] = v[k];
            k++;
         }
      }
   } else {
      // case of upper block 
      for(unsigned int i=0; i<D1; ++i) {
         for(unsigned int j=i; j<D2; ++j) {
            fRep[ i*D2 + j] = v[k];
            if ( i != j) fRep[ j*D2 + i] = v[k];
            k++;
         }
      }
   }
}


template <class T, unsigned int D1, unsigned int D2, class R>
bool SMatrix<T,D1,D2,R>::IsInUse( const T * p) const { 
   return p == fRep.Array(); 
} 




  }  // namespace Math

}  // namespace ROOT
          


#endif