12 #ifndef ROOT_TMatrixTSym
13 #define ROOT_TMatrixTSym
30 template<
class Element>
class TMatrixT;
31 template<
class Element>
class TMatrixTSymLazy;
32 template<
class Element>
class TVectorT;
34 template<
class Element>
class TMatrixTSym :
public TMatrixTBase<Element> {
38 Element fDataStack[TMatrixTBase<Element>::kSizeMax];
41 Element *New_m (Int_t size);
42 void Delete_m(Int_t size,Element*&);
43 Int_t Memcpy_m(Element *newp,
const Element *oldp,Int_t copySize,
44 Int_t newSize,Int_t oldSize);
45 void Allocate(Int_t nrows,Int_t ncols,Int_t row_lwb = 0,Int_t col_lwb = 0,Int_t init = 0,
50 enum {kWorkMax = 100};
51 enum EMatrixCreatorsOp1 { kZero,kUnit,kTransposed,kInverted,kAtA };
52 enum EMatrixCreatorsOp2 { kPlus,kMinus };
54 TMatrixTSym() { fElements = 0; }
55 explicit TMatrixTSym(Int_t nrows);
56 TMatrixTSym(Int_t row_lwb,Int_t row_upb);
57 TMatrixTSym(Int_t nrows,
const Element *data,Option_t *option=
"");
58 TMatrixTSym(Int_t row_lwb,Int_t row_upb,
const Element *data,Option_t *option=
"");
59 TMatrixTSym(
const TMatrixTSym<Element> &another);
60 template <
class Element2> TMatrixTSym(
const TMatrixTSym<Element2> &another)
62 R__ASSERT(another.IsValid());
63 Allocate(another.GetNrows(),another.GetNcols(),another.GetRowLwb(),another.GetColLwb());
67 TMatrixTSym(EMatrixCreatorsOp1 op,
const TMatrixTSym<Element> &prototype);
68 TMatrixTSym(EMatrixCreatorsOp1 op,
const TMatrixT <Element> &prototype);
69 TMatrixTSym(
const TMatrixTSym<Element> &a,EMatrixCreatorsOp2 op,
const TMatrixTSym<Element> &b);
70 TMatrixTSym(
const TMatrixTSymLazy<Element> &lazy_constructor);
72 virtual ~TMatrixTSym() { TMatrixTSym::Clear(); }
75 void TMult(
const TMatrixT <Element> &a);
76 void TMult(
const TMatrixTSym<Element> &a);
77 void Mult (
const TMatrixTSym<Element> &a) { TMult(a); }
79 void Plus (
const TMatrixTSym<Element> &a,
const TMatrixTSym<Element> &b);
80 void Minus(
const TMatrixTSym<Element> &a,
const TMatrixTSym<Element> &b);
82 virtual const Element *GetMatrixArray ()
const;
83 virtual Element *GetMatrixArray ();
84 virtual const Int_t *GetRowIndexArray()
const {
return 0; }
85 virtual Int_t *GetRowIndexArray() {
return 0; }
86 virtual const Int_t *GetColIndexArray()
const {
return 0; }
87 virtual Int_t *GetColIndexArray() {
return 0; }
89 virtual TMatrixTBase<Element> &SetRowIndexArray(Int_t * ) { MayNotUse(
"SetRowIndexArray(Int_t *)");
return *
this; }
90 virtual TMatrixTBase<Element> &SetColIndexArray(Int_t * ) { MayNotUse(
"SetColIndexArray(Int_t *)");
return *
this; }
92 virtual void Clear (Option_t * =
"") {
if (this->fIsOwner) Delete_m(this->fNelems,fElements);
95 virtual Bool_t IsSymmetric()
const {
return kTRUE; }
97 TMatrixTSym <Element> &Use (Int_t row_lwb,Int_t row_upb,Element *data);
98 const TMatrixTSym <Element> &Use (Int_t row_lwb,Int_t row_upb,
const Element *data)
const
99 {
return (
const TMatrixTSym<Element>&)
100 ((
const_cast<TMatrixTSym<Element> *
>(
this))->Use(row_lwb,row_upb,const_cast<Element *>(data))); }
101 TMatrixTSym <Element> &Use (Int_t nrows,Element *data);
102 const TMatrixTSym <Element> &Use (Int_t nrows,
const Element *data)
const;
103 TMatrixTSym <Element> &Use (TMatrixTSym<Element> &a);
104 const TMatrixTSym <Element> &Use (
const TMatrixTSym<Element> &a)
const;
106 TMatrixTSym <Element> &GetSub (Int_t row_lwb,Int_t row_upb,TMatrixTSym<Element> &target,Option_t *option=
"S")
const;
107 virtual TMatrixTBase<Element> &GetSub (Int_t row_lwb,Int_t row_upb,Int_t col_lwb,Int_t col_upb,
108 TMatrixTBase<Element> &target,Option_t *option=
"S")
const;
109 TMatrixTSym <Element> GetSub (Int_t row_lwb,Int_t row_upb,Int_t col_lwb,Int_t col_upb,Option_t *option=
"S")
const;
110 TMatrixTSym <Element> &SetSub (Int_t row_lwb,
const TMatrixTBase<Element> &source);
111 virtual TMatrixTBase<Element> &SetSub (Int_t row_lwb,Int_t col_lwb,
const TMatrixTBase<Element> &source);
113 virtual TMatrixTBase<Element> &SetMatrixArray(
const Element *data, Option_t *option=
"");
115 virtual TMatrixTBase<Element> &Shift (Int_t row_shift,Int_t col_shift);
116 virtual TMatrixTBase<Element> &ResizeTo (Int_t nrows,Int_t ncols,Int_t =-1);
117 virtual TMatrixTBase<Element> &ResizeTo (Int_t row_lwb,Int_t row_upb,Int_t col_lwb,Int_t col_upb,Int_t =-1);
118 inline TMatrixTBase<Element> &ResizeTo (
const TMatrixTSym<Element> &m) {
119 return ResizeTo(m.GetRowLwb(),m.GetRowUpb(),m.GetColLwb(),m.GetColUpb()); }
121 virtual Double_t Determinant ()
const;
122 virtual void Determinant (Double_t &d1,Double_t &d2)
const;
124 TMatrixTSym<Element> &Invert (Double_t *det=0);
125 TMatrixTSym<Element> &InvertFast (Double_t *det=0);
126 TMatrixTSym<Element> &Transpose (
const TMatrixTSym<Element> &source);
127 inline TMatrixTSym<Element> &T () {
return this->Transpose(*
this); }
128 TMatrixTSym<Element> &Rank1Update (
const TVectorT <Element> &v,Element alpha=1.0);
129 TMatrixTSym<Element> &Similarity (
const TMatrixT <Element> &n);
130 TMatrixTSym<Element> &Similarity (
const TMatrixTSym<Element> &n);
131 Element Similarity (
const TVectorT <Element> &v)
const;
132 TMatrixTSym<Element> &SimilarityT (
const TMatrixT <Element> &n);
135 inline Element operator()(Int_t rown,Int_t coln)
const;
136 inline Element &operator()(Int_t rown,Int_t coln);
139 inline const TMatrixTRow_const<Element> operator[](Int_t rown)
const {
return TMatrixTRow_const<Element>(*
this,rown); }
140 inline TMatrixTRow <Element> operator[](Int_t rown) {
return TMatrixTRow <Element>(*
this,rown); }
142 TMatrixTSym<Element> &operator= (
const TMatrixTSym <Element> &source);
143 TMatrixTSym<Element> &operator= (
const TMatrixTSymLazy<Element> &source);
144 template <
class Element2> TMatrixTSym<Element> &operator= (
const TMatrixTSym<Element2> &source)
146 if (!AreCompatible(*
this,source)) {
147 Error(
"operator=(const TMatrixTSym2 &)",
"matrices not compatible");
151 TObject::operator=(source);
152 const Element2 *
const ps = source.GetMatrixArray();
153 Element *
const pt = this->GetMatrixArray();
154 for (Int_t i = 0; i < this->fNelems; i++)
156 this->fTol = source.GetTol();
160 TMatrixTSym<Element> &operator= (Element val);
161 TMatrixTSym<Element> &operator-=(Element val);
162 TMatrixTSym<Element> &operator+=(Element val);
163 TMatrixTSym<Element> &operator*=(Element val);
165 TMatrixTSym &operator+=(
const TMatrixTSym &source);
166 TMatrixTSym &operator-=(
const TMatrixTSym &source);
168 TMatrixTBase<Element> &Apply(
const TElementActionT <Element> &action);
169 TMatrixTBase<Element> &Apply(
const TElementPosActionT<Element> &action);
171 virtual TMatrixTBase<Element> &Randomize (Element alpha,Element beta,Double_t &seed);
172 virtual TMatrixTSym <Element> &RandomizePD(Element alpha,Element beta,Double_t &seed);
174 const TMatrixT<Element> EigenVectors(TVectorT<Element> &eigenValues)
const;
176 ClassDef(TMatrixTSym,2)
186 template <> TClass *TMatrixTSym<double>::Class();
189 template <
class Element>
inline const Element *TMatrixTSym<Element>::GetMatrixArray()
const {
return fElements; }
190 template <
class Element>
inline Element *TMatrixTSym<Element>::GetMatrixArray() {
return fElements; }
192 template <
class Element>
inline TMatrixTSym<Element> &TMatrixTSym<Element>::Use (Int_t nrows,Element *data) {
return Use(0,nrows-1,data); }
193 template <
class Element>
inline const TMatrixTSym<Element> &TMatrixTSym<Element>::Use (Int_t nrows,
const Element *data)
const
194 {
return Use(0,nrows-1,data); }
195 template <
class Element>
inline TMatrixTSym<Element> &TMatrixTSym<Element>::Use (TMatrixTSym<Element> &a)
196 {
return Use(a.GetRowLwb(),a.GetRowUpb(),a.GetMatrixArray()); }
197 template <
class Element>
inline const TMatrixTSym<Element> &TMatrixTSym<Element>::Use (
const TMatrixTSym<Element> &a)
const
198 {
return Use(a.GetRowLwb(),a.GetRowUpb(),a.GetMatrixArray()); }
200 template <
class Element>
inline TMatrixTSym<Element> TMatrixTSym<Element>::GetSub (Int_t row_lwb,Int_t row_upb,Int_t col_lwb,Int_t col_upb,
201 Option_t *option)
const
203 TMatrixTSym<Element> tmp;
204 this->GetSub(row_lwb,row_upb,col_lwb,col_upb,tmp,option);
208 template <
class Element>
inline Element TMatrixTSym<Element>::operator()(Int_t rown,Int_t coln)
const
210 R__ASSERT(this->IsValid());
211 const Int_t arown = rown-this->fRowLwb;
212 const Int_t acoln = coln-this->fColLwb;
213 if (arown >= this->fNrows || arown < 0) {
214 Error(
"operator()",
"Request row(%d) outside matrix range of %d - %d",rown,this->fRowLwb,this->fRowLwb+this->fNrows);
215 return TMatrixTBase<Element>::NaNValue();
217 if (acoln >= this->fNcols || acoln < 0) {
218 Error(
"operator()",
"Request column(%d) outside matrix range of %d - %d",coln,this->fColLwb,this->fColLwb+this->fNcols);
219 return TMatrixTBase<Element>::NaNValue();
221 return (fElements[arown*this->fNcols+acoln]);
224 template <
class Element>
inline Element &TMatrixTSym<Element>::operator()(Int_t rown,Int_t coln)
226 R__ASSERT(this->IsValid());
227 const Int_t arown = rown-this->fRowLwb;
228 const Int_t acoln = coln-this->fColLwb;
229 if (arown >= this->fNrows || arown < 0) {
230 Error(
"operator()",
"Request row(%d) outside matrix range of %d - %d",rown,this->fRowLwb,this->fRowLwb+this->fNrows);
231 return TMatrixTBase<Element>::NaNValue();
233 if (acoln >= this->fNcols || acoln < 0) {
234 Error(
"operator()",
"Request column(%d) outside matrix range of %d - %d",coln,this->fColLwb,this->fColLwb+this->fNcols);
235 return TMatrixTBase<Element>::NaNValue();
237 return (fElements[arown*this->fNcols+acoln]);
240 template <
class Element> Bool_t operator== (
const TMatrixTSym<Element> &source1,
const TMatrixTSym<Element> &source2);
241 template <
class Element> TMatrixTSym<Element> operator+ (
const TMatrixTSym<Element> &source1,
const TMatrixTSym<Element> &source2);
242 template <
class Element> TMatrixTSym<Element> operator+ (
const TMatrixTSym<Element> &source1, Element val);
243 template <
class Element> TMatrixTSym<Element> operator+ ( Element val ,
const TMatrixTSym<Element> &source2);
244 template <
class Element> TMatrixTSym<Element> operator- (
const TMatrixTSym<Element> &source1,
const TMatrixTSym<Element> &source2);
245 template <
class Element> TMatrixTSym<Element> operator- (
const TMatrixTSym<Element> &source1, Element val);
246 template <
class Element> TMatrixTSym<Element> operator- ( Element val ,
const TMatrixTSym<Element> &source2);
247 template <
class Element> TMatrixTSym<Element> operator* (
const TMatrixTSym<Element> &source, Element val );
248 template <
class Element> TMatrixTSym<Element> operator* ( Element val,
const TMatrixTSym<Element> &source );
250 #if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >= 40600
251 #pragma GCC diagnostic push
252 #pragma GCC diagnostic ignored "-Weffc++"
254 template <
class Element> TMatrixTSym<Element> operator&& (
const TMatrixTSym<Element> &source1,
const TMatrixTSym<Element> &source2);
255 template <
class Element> TMatrixTSym<Element> operator|| (
const TMatrixTSym<Element> &source1,
const TMatrixTSym<Element> &source2);
256 #if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >= 40600
257 #pragma GCC diagnostic pop
259 template <
class Element> TMatrixTSym<Element> operator> (
const TMatrixTSym<Element> &source1,
const TMatrixTSym<Element> &source2);
260 template <
class Element> TMatrixTSym<Element> operator>= (
const TMatrixTSym<Element> &source1,
const TMatrixTSym<Element> &source2);
261 template <
class Element> TMatrixTSym<Element> operator<= (const TMatrixTSym<Element> &source1,
const TMatrixTSym<Element> &source2);
262 template <
class Element> TMatrixTSym<Element> operator< (const TMatrixTSym<Element> &source1,
const TMatrixTSym<Element> &source2);
264 template <
class Element> TMatrixTSym<Element> &Add (TMatrixTSym<Element> &target, Element scalar,
const TMatrixTSym<Element> &source);
265 template <
class Element> TMatrixTSym<Element> &ElementMult(TMatrixTSym<Element> &target,
const TMatrixTSym<Element> &source);
266 template <
class Element> TMatrixTSym<Element> &ElementDiv (TMatrixTSym<Element> &target,
const TMatrixTSym<Element> &source);