27 template<
class Element>
class TVectorT :
public TObject {
32 Element *fElements{
nullptr};
35 enum {kWorkMax = 100};
37 Element fDataStack[kSizeMax];
38 Bool_t fIsOwner{kTRUE};
40 Element* New_m (Int_t size);
41 void Delete_m(Int_t size,Element*&);
42 Int_t Memcpy_m(Element *newp,
const Element *oldp,Int_t copySize,
43 Int_t newSize,Int_t oldSize);
45 void Allocate(Int_t nrows,Int_t row_lwb = 0,Int_t init = 0);
47 enum EVectorStatusBits {
53 TVectorT() : fNrows(0), fRowLwb(0), fElements(0), fDataStack (), fIsOwner(kTRUE) { }
54 explicit TVectorT(Int_t n);
55 TVectorT(Int_t lwb,Int_t upb);
56 TVectorT(Int_t n,
const Element *elements);
57 TVectorT(Int_t lwb,Int_t upb,
const Element *elements);
58 TVectorT(
const TVectorT <Element> &another);
59 TVectorT(
const TMatrixTRow_const <Element> &mr);
60 TVectorT(
const TMatrixTColumn_const<Element> &mc);
61 TVectorT(
const TMatrixTDiag_const <Element> &md);
62 template <
class Element2> TVectorT(
const TVectorT<Element2> &another)
64 R__ASSERT(another.IsValid());
65 Allocate(another.GetUpb()-another.GetLwb()+1,another.GetLwb());
69 TVectorT(Int_t lwb,Int_t upb,Double_t iv1, ...);
71 virtual ~TVectorT() { TVectorT::Clear(); }
73 inline Int_t GetLwb ()
const {
return fRowLwb; }
74 inline Int_t GetUpb ()
const {
return fNrows+fRowLwb-1; }
75 inline Int_t GetNrows ()
const {
return fNrows; }
76 inline Int_t GetNoElements()
const {
return fNrows; }
78 inline Element *GetMatrixArray () {
return fElements; }
79 inline const Element *GetMatrixArray ()
const {
return fElements; }
81 inline void Invalidate () { SetBit(kStatus); }
82 inline void MakeValid () { ResetBit(kStatus); }
83 inline Bool_t IsValid ()
const {
return !TestBit(kStatus); }
84 inline Bool_t IsOwner ()
const {
return fIsOwner; }
85 inline void SetElements(
const Element *elements) { R__ASSERT(IsValid());
86 memcpy(fElements,elements,fNrows*
sizeof(Element)); }
87 inline TVectorT<Element> &Shift (Int_t row_shift) { fRowLwb += row_shift;
return *
this; }
88 TVectorT<Element> &ResizeTo (Int_t lwb,Int_t upb);
89 inline TVectorT<Element> &ResizeTo (Int_t n) {
return ResizeTo(0,n-1); }
90 inline TVectorT<Element> &ResizeTo (
const TVectorT<Element> &v) {
return ResizeTo(v.GetLwb(),v.GetUpb()); }
92 TVectorT<Element> &Use (Int_t lwb,Int_t upb,Element *data);
93 const TVectorT<Element> &Use (Int_t lwb,Int_t upb,
const Element *data)
const
94 {
return (
const TVectorT<Element>&)(
const_cast<TVectorT<Element> *
>(
this))->Use(lwb,upb,const_cast<Element *>(data)); }
95 TVectorT<Element> &Use (Int_t n,Element *data);
96 const TVectorT<Element> &Use (Int_t n,
const Element *data)
const ;
97 TVectorT<Element> &Use (TVectorT<Element> &v);
98 const TVectorT<Element> &Use (
const TVectorT<Element> &v)
const ;
100 TVectorT<Element> &GetSub (Int_t row_lwb,Int_t row_upb,TVectorT<Element> &target,Option_t *option=
"S")
const;
101 TVectorT<Element> GetSub (Int_t row_lwb,Int_t row_upb,Option_t *option=
"S")
const;
102 TVectorT<Element> &SetSub (Int_t row_lwb,
const TVectorT<Element> &source);
104 TVectorT<Element> &Zero();
105 TVectorT<Element> &Abs ();
106 TVectorT<Element> &Sqr ();
107 TVectorT<Element> &Sqrt();
108 TVectorT<Element> &Invert();
109 TVectorT<Element> &SelectNonZeros(
const TVectorT<Element> &select);
111 Element Norm1 ()
const;
112 Element Norm2Sqr()
const;
113 Element NormInf ()
const;
114 Int_t NonZeros()
const;
115 Element Sum ()
const;
116 Element Min ()
const;
117 Element Max ()
const;
119 inline const Element &operator()(Int_t index)
const;
120 inline Element &operator()(Int_t index);
121 inline const Element &operator[](Int_t index)
const {
return (*
this)(index); }
122 inline Element &operator[](Int_t index) {
return (*
this)(index); }
124 TVectorT<Element> &operator= (
const TVectorT <Element> &source);
125 TVectorT<Element> &operator= (
const TMatrixTRow_const <Element> &mr);
126 TVectorT<Element> &operator= (
const TMatrixTColumn_const <Element> &mc);
127 TVectorT<Element> &operator= (
const TMatrixTDiag_const <Element> &md);
128 TVectorT<Element> &operator= (
const TMatrixTSparseRow_const <Element> &md);
129 TVectorT<Element> &operator= (
const TMatrixTSparseDiag_const<Element> &md);
130 template <
class Element2> TVectorT<Element> &operator= (
const TVectorT<Element2> &source)
132 if (!AreCompatible(*
this,source)) {
133 Error(
"operator=(const TVectorT2 &)",
"vectors not compatible");
137 TObject::operator=(source);
138 const Element2 *
const ps = source.GetMatrixArray();
139 Element *
const pt = GetMatrixArray();
140 for (Int_t i = 0; i < this->fNrows; i++)
145 TVectorT<Element> &operator= (Element val);
146 TVectorT<Element> &operator+=(Element val);
147 TVectorT<Element> &operator-=(Element val);
148 TVectorT<Element> &operator*=(Element val);
150 TVectorT<Element> &operator+=(
const TVectorT <Element> &source);
151 TVectorT<Element> &operator-=(
const TVectorT <Element> &source);
152 TVectorT<Element> &operator*=(
const TMatrixT <Element> &a);
153 TVectorT<Element> &operator*=(
const TMatrixTSym <Element> &a);
154 TVectorT<Element> &operator*=(
const TMatrixTSparse<Element> &a);
156 Bool_t operator==(Element val)
const;
157 Bool_t operator!=(Element val)
const;
158 Bool_t operator< (Element val)
const;
159 Bool_t operator<=(Element val)
const;
160 Bool_t operator> (Element val)
const;
161 Bool_t operator>=(Element val)
const;
163 Bool_t MatchesNonZeroPattern(
const TVectorT<Element> &select);
164 Bool_t SomePositive (
const TVectorT<Element> &select);
165 void AddSomeConstant (Element val,
const TVectorT<Element> &select);
167 void Randomize (Element alpha,Element beta,Double_t &seed);
169 TVectorT<Element> &Apply(
const TElementActionT <Element> &action);
170 TVectorT<Element> &Apply(
const TElementPosActionT<Element> &action);
172 void Add(
const TVectorT<Element> &v);
173 void Add(
const TVectorT<Element> &v1,
const TVectorT<Element> &v2);
174 void Clear(Option_t * =
"") {
if (fIsOwner) Delete_m(fNrows,fElements);
177 void Draw (Option_t *option=
"");
178 void Print(Option_t *option=
"")
const;
191 template <> TClass *TVectorT<double>::Class();
194 template<
class Element>
inline TVectorT<Element> &TVectorT<Element>::Use (Int_t n,Element *data) {
return Use(0,n-1,data); }
195 template<
class Element>
inline const TVectorT<Element> &TVectorT<Element>::Use (Int_t n,
const Element *data)
const {
return Use(0,n-1,data); }
196 template<
class Element>
inline TVectorT<Element> &TVectorT<Element>::Use (TVectorT &v)
198 R__ASSERT(v.IsValid());
199 return Use(v.GetLwb(),v.GetUpb(),v.GetMatrixArray());
201 template<
class Element>
inline const TVectorT<Element> &TVectorT<Element>::Use (
const TVectorT &v)
const
203 R__ASSERT(v.IsValid());
204 return Use(v.GetLwb(),v.GetUpb(),v.GetMatrixArray());
206 template<
class Element>
inline TVectorT<Element> TVectorT<Element>::GetSub (Int_t row_lwb,Int_t row_upb,Option_t *option)
const
209 this->GetSub(row_lwb,row_upb,tmp,option);
213 template<
class Element>
inline const Element &TVectorT<Element>::operator()(Int_t ind)
const
217 R__ASSERT(IsValid());
218 const Int_t aind = ind-fRowLwb;
219 if (aind >= fNrows || aind < 0) {
220 Error(
"operator()",
"Request index(%d) outside vector range of %d - %d",ind,fRowLwb,fRowLwb+fNrows);
221 return TMatrixTBase<Element>::NaNValue();
224 return fElements[aind];
226 template<
class Element>
inline Element &TVectorT<Element>::operator()(Int_t ind)
230 R__ASSERT(IsValid());
231 const Int_t aind = ind-fRowLwb;
232 if (aind >= fNrows || aind < 0) {
233 Error(
"operator()",
"Request index(%d) outside vector range of %d - %d",ind,fRowLwb,fRowLwb+fNrows);
234 return TMatrixTBase<Element>::NaNValue();
237 return fElements[aind];
240 template<
class Element> Bool_t operator== (
const TVectorT <Element> &source1,
const TVectorT <Element> &source2);
241 template<
class Element> TVectorT<Element> operator+ (
const TVectorT <Element> &source1,
const TVectorT <Element> &source2);
242 template<
class Element> TVectorT<Element> operator- (
const TVectorT <Element> &source1,
const TVectorT <Element> &source2);
243 template<
class Element> Element operator* (
const TVectorT <Element> &source1,
const TVectorT <Element> &source2);
244 template<
class Element> TVectorT<Element> operator* (
const TMatrixT <Element> &a,
const TVectorT <Element> &source);
245 template<
class Element> TVectorT<Element> operator* (
const TMatrixTSym <Element> &a,
const TVectorT <Element> &source);
246 template<
class Element> TVectorT<Element> operator* (
const TMatrixTSparse<Element> &a,
const TVectorT <Element> &source);
247 template<
class Element> TVectorT<Element> operator* ( Element val,
const TVectorT <Element> &source);
248 template<
class Element>
250 TVectorT<Element> operator* (
const TVectorT <Element> &source, Element val) {
return val * source; }
252 template<
class Element> Element Dot (
const TVectorT <Element> &source1,
const TVectorT <Element> &source2);
253 template <
class Element1,
class Element2>
254 TMatrixT<Element1> OuterProduct(
const TVectorT <Element1> &v1,
const TVectorT <Element2> &v2);
255 template <
class Element1,
class Element2,
class Element3>
256 TMatrixT<Element1> &OuterProduct( TMatrixT <Element1> &target,
const TVectorT <Element2> &v1,
const TVectorT <Element3> &v2);
257 template <
class Element1,
class Element2,
class Element3>
258 Element1 Mult (
const TVectorT <Element1> &v1,
const TMatrixT <Element2> &m,
const TVectorT <Element3> &v2);
260 template<
class Element> TVectorT<Element> &Add ( TVectorT <Element> &target, Element scalar,
const TVectorT <Element> &source);
261 template<
class Element> TVectorT<Element> &Add ( TVectorT <Element> &target, Element scalar,
const TMatrixT <Element> &a,
262 const TVectorT<Element> &source);
263 template<
class Element> TVectorT<Element> &Add ( TVectorT <Element> &target, Element scalar,
const TMatrixTSym <Element> &a,
264 const TVectorT<Element> &source);
265 template<
class Element> TVectorT<Element> &Add ( TVectorT <Element> &target, Element scalar,
const TMatrixTSparse<Element> &a,
266 const TVectorT<Element> &source);
267 template<
class Element> TVectorT<Element> &AddElemMult ( TVectorT <Element> &target, Element scalar,
const TVectorT <Element> &source1,
268 const TVectorT <Element> &source2);
269 template<
class Element> TVectorT<Element> &AddElemMult ( TVectorT <Element> &target, Element scalar,
const TVectorT <Element> &source1,
270 const TVectorT <Element> &source2,
const TVectorT <Element> &select);
271 template<
class Element> TVectorT<Element> &AddElemDiv ( TVectorT <Element> &target, Element scalar,
const TVectorT <Element> &source1,
272 const TVectorT <Element> &source2);
273 template<
class Element> TVectorT<Element> &AddElemDiv ( TVectorT <Element> &target, Element scalar,
const TVectorT <Element> &source1,
274 const TVectorT <Element> &source2,
const TVectorT <Element> &select);
275 template<
class Element> TVectorT<Element> &ElementMult ( TVectorT <Element> &target,
const TVectorT <Element> &source);
276 template<
class Element> TVectorT<Element> &ElementMult ( TVectorT <Element> &target,
const TVectorT <Element> &source,
const TVectorT <Element> &select);
277 template<
class Element> TVectorT<Element> &ElementDiv ( TVectorT <Element> &target,
const TVectorT <Element> &source);
278 template<
class Element> TVectorT<Element> &ElementDiv ( TVectorT <Element> &target,
const TVectorT <Element> &source,
const TVectorT <Element> &select);
280 template<
class Element1,
class Element2> Bool_t AreCompatible(
const TVectorT<Element1> &v1,
const TVectorT<Element2> &v2,Int_t verbose=0);
282 template<
class Element1,
class Element2> Bool_t AreCompatible(
const TMatrixT<Element1> &m,
const TVectorT<Element2> &v, Int_t verbose=0);
283 template<
class Element1,
class Element2> Bool_t AreCompatible(
const TVectorT<Element1> &v,
const TMatrixT<Element2> &m, Int_t verbose=0);
285 template<
class Element>
void Compare (
const TVectorT <Element> &source1,
const TVectorT <Element> &source2);
286 template<
class Element> Bool_t VerifyVectorValue (
const TVectorT <Element> &m, Element val,Int_t verbose, Element maxDevAllow);
287 template<
class Element> Bool_t VerifyVectorValue (
const TVectorT <Element> &m, Element val,Int_t verbose)
288 {
return VerifyVectorValue(m,val,verbose,Element(0.0)); }
289 template<
class Element> Bool_t VerifyVectorValue (
const TVectorT <Element> &m, Element val)
290 {
return VerifyVectorValue(m,val,1,Element(0.0)); }
291 template<
class Element> Bool_t VerifyVectorIdentity (
const TVectorT <Element> &m1,
const TVectorT <Element> &m2, Int_t verbose, Element maxDevAllow);
292 template<
class Element> Bool_t VerifyVectorIdentity (
const TVectorT <Element> &m1,
const TVectorT <Element> &m2, Int_t verbose)
293 {
return VerifyVectorIdentity(m1,m2,verbose,Element(0.0)); }
294 template<
class Element> Bool_t VerifyVectorIdentity (
const TVectorT <Element> &m1,
const TVectorT <Element> &m2)
295 {
return VerifyVectorIdentity(m1,m2,1,Element(0.0)); }