Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TMatrixTLazy.cxx
Go to the documentation of this file.
1// @(#)root/matrix:$Id$
2// Authors: Fons Rademakers, Eddy Offermann Nov 2003
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12/** \class TMatrixTLazy
13 \ingroup Matrix
14
15 Templates of Lazy Matrix classes.
16~~~
17 TMatrixTLazy
18 TMatrixTSymLazy
19 THaarMatrixT
20 THilbertMatrixT
21 THilbertMatrixTSym
22~~~
23*/
24
25#include "TMatrixT.h"
26#include "TMatrixTSym.h"
27#include "TMatrixTLazy.h"
28#include "TMath.h"
29
30
31
32////////////////////////////////////////////////////////////////////////////////
33
34template<class Element>
36 : TMatrixTLazy<Element>(1<<order, no_cols == 0 ? 1<<order : no_cols)
37{
38 if (order <= 0)
39 Error("THaarMatrixT","Haar order(%d) should be > 0",order);
40 if (no_cols < 0)
41 Error("THaarMatrixT","#cols(%d) in Haar should be >= 0",no_cols);
42}
43
44////////////////////////////////////////////////////////////////////////////////
45/// Create an orthonormal (2^n)*(no_cols) Haar (sub)matrix, whose columns
46/// are Haar functions. If no_cols is 0, create the complete matrix with
47/// 2^n columns. Example, the complete Haar matrix of the second order is:
48/// column 1: [ 1 1 1 1]/2
49/// column 2: [ 1 1 -1 -1]/2
50/// column 3: [ 1 -1 0 0]/sqrt(2)
51/// column 4: [ 0 0 1 -1]/sqrt(2)
52/// Matrix m is assumed to be zero originally.
53
54template<class Element>
56{
57 R__ASSERT(m.IsValid());
58 const Int_t no_rows = m.GetNrows();
59 const Int_t no_cols = m.GetNcols();
60
61 if (no_rows < no_cols) {
62 Error("MakeHaarMat","#rows(%d) should be >= #cols(%d)",no_rows,no_cols);
63 return;
64 }
65 if (no_cols <= 0) {
66 Error("MakeHaarMat","#cols(%d) should be > 0",no_cols);
67 return;
68 }
69
70 // It is easier to calculate a Haar matrix when the elements are stored
71 // column-wise . Since we are row-wise, the transposed Haar is calculated
72
74 Element *cp = mtr.GetMatrixArray();
75 const Element *m_end = mtr.GetMatrixArray()+no_rows*no_cols;
76
77 Element norm_factor = 1/TMath::Sqrt((Element)no_rows);
78
79 // First row is always 1 (up to normalization)
80 Int_t j;
81 for (j = 0; j < no_rows; j++)
82 *cp++ = norm_factor;
83
84 // The other functions are kind of steps: stretch of 1 followed by the
85 // equally long stretch of -1. The functions can be grouped in families
86 // according to their order (step size), differing only in the location
87 // of the step
92 Element *ccp = cp+step_position;
93 for (j = 0; j < step_length; j++)
94 *ccp++ = norm_factor;
95 for (j = 0; j < step_length; j++)
96 *ccp++ = -norm_factor;
97 }
98 step_length /= 2;
100 }
101
102 R__ASSERT(step_length != 0 || cp == m_end);
104
105 m.Transpose(mtr);
106}
107
108////////////////////////////////////////////////////////////////////////////////
109
110template<class Element>
115
116////////////////////////////////////////////////////////////////////////////////
117
118template<class Element>
120 : TMatrixTLazy<Element>(no_rows,no_cols)
121{
122 if (no_rows <= 0)
123 Error("THilbertMatrixT","#rows(%d) in Hilbert should be > 0",no_rows);
124 if (no_cols <= 0)
125 Error("THilbertMatrixT","#cols(%d) in Hilbert should be > 0",no_cols);
126}
127
128////////////////////////////////////////////////////////////////////////////////
129
130template<class Element>
133{
134 if (row_upb < row_lwb)
135 Error("THilbertMatrixT","row_upb(%d) in Hilbert should be >= row_lwb(%d)",row_upb,row_lwb);
136 if (col_upb < col_lwb)
137 Error("THilbertMatrixT","col_upb(%d) in Hilbert should be >= col_lwb(%d)",col_upb,col_lwb);
138}
139
140////////////////////////////////////////////////////////////////////////////////
141/// Make a Hilbert matrix. Hilb[i,j] = 1/(i+j+1),
142/// i,j=0...max-1 (matrix need not be a square one).
143
144template<class Element>
146{
147 R__ASSERT(m.IsValid());
148 const Int_t no_rows = m.GetNrows();
149 const Int_t no_cols = m.GetNcols();
150
151 if (no_rows <= 0) {
152 Error("MakeHilbertMat","#rows(%d) should be > 0",no_rows);
153 return;
154 }
155 if (no_cols <= 0) {
156 Error("MakeHilbertMat","#cols(%d) should be > 0",no_cols);
157 return;
158 }
159
160 Element *cp = m.GetMatrixArray();
161 for (Int_t i = 0; i < no_rows; i++)
162 for (Int_t j = 0; j < no_cols; j++)
163 *cp++ = 1.0/(i+j+1.0);
164}
165
166////////////////////////////////////////////////////////////////////////////////
167
168template<class Element>
173
174////////////////////////////////////////////////////////////////////////////////
175
176template<class Element>
178 : TMatrixTSymLazy<Element>(no_rows)
179{
180 if (no_rows <= 0)
181 Error("THilbertMatrixTSym","#rows(%d) in Hilbert should be > 0",no_rows);
182}
183
184////////////////////////////////////////////////////////////////////////////////
185
186template<class Element>
189{
190 if (row_upb < row_lwb)
191 Error("THilbertMatrixTSym","row_upb(%d) in Hilbert should be >= row_lwb(%d)",row_upb,row_lwb);
192}
193
194////////////////////////////////////////////////////////////////////////////////
195/// Make a Hilbert matrix. Hilb[i,j] = 1/(i+j+1),
196/// i,j=0...max-1 (matrix must be square).
197
198template<class Element>
200{
201 R__ASSERT(m.IsValid());
202 const Int_t no_rows = m.GetNrows();
203 if (no_rows <= 0) {
204 Error("MakeHilbertMat","#rows(%d) should be > 0",no_rows);
205 return;
206 }
207
208 Element *cp = m.GetMatrixArray();
209 for (Int_t i = 0; i < no_rows; i++)
210 for (Int_t j = 0; j < no_rows; j++)
211 *cp++ = 1.0/(i+j+1.0);
212}
213
214////////////////////////////////////////////////////////////////////////////////
215
216template<class Element>
221
222template class TMatrixTLazy <Float_t>;
223template class TMatrixTSymLazy <Float_t>;
224template class THaarMatrixT <Float_t>;
225template class THilbertMatrixT <Float_t>;
226template class THilbertMatrixTSym<Float_t>;
227
228template class TMatrixTLazy <Double_t>;
229template class TMatrixTSymLazy <Double_t>;
230template class THaarMatrixT <Double_t>;
231template class THilbertMatrixT <Double_t>;
232template class THilbertMatrixTSym<Double_t>;
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
Definition TError.h:125
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:208
void MakeHaarMat(TMatrixT< Element > &m)
Create an orthonormal (2^n)*(no_cols) Haar (sub)matrix, whose columns are Haar functions.
void MakeHilbertMat(TMatrixT< Element > &m)
Make a Hilbert matrix.
void FillIn(TMatrixT< Element > &m) const override
void FillIn(TMatrixTSym< Element > &m) const override
void FillIn(TMatrixT< Element > &m) const override
Templates of Lazy Matrix classes.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1071
Double_t Sqrt(Double_t x)
Returns the square root of x.
Definition TMath.h:673
TMarker m
Definition textangle.C:8