8 TRMatrix::TRMatrix(
const TRMatrix &S, Int_t NI, Int_t NJ, Int_t I, Int_t J){
9 if (NI == 0) NI = S.NI();
10 if (NJ == 0) NJ = S.NJ();
11 if (NI > S.NI()) NI = S.NI();
12 if (NJ > S.NJ()) NJ = S.NJ();
13 if (I == 0) {
::Error(
"TRMatrix::TRMatrix(const TRMatrix &)",
"index i %d out of bounds (size: %d, this: %p)",
14 I, S.NI(),
this); I = 1;}
15 if (J == 0) {
::Error(
"TRMatrix::TRMatrix(const TRMatrix &)",
"index j %d out of bounds (size: %d, this: %p)",
16 J, S.NJ(),
this); J = 1;}
17 if (I+NI-1 > S.NI()) {
::Error(
"TRMatrix::TRMatrix(const TRMatrix &)",
"index i %d out of bounds (size: %d, this: %p)",
18 I+NI-1, S.NI(),
this); I = 1;}
19 if (J+NJ-1 > S.NJ()) {
::Error(
"TRMatrix::TRMatrix(const TRMatrix &)",
"index j %d out of bounds (size: %d, this: %p)",
20 J+NJ-1, S.NJ(),
this); J = 1;}
24 const Double_t *Array = S.GetArray();
25 for (
int i = 0; i < fNrows; i++)
26 for (
int j = 0; j < fNcols; j++)
27 fArray[j + i*fNcols] = Array[J+j-1 + (I+i-1)*S.NJ()];
31 if (
this != &rhs) SetMatrix(rhs.GetNrows(),rhs.GetNcols(),rhs.GetArray());
35 TRMatrix::TRMatrix(Int_t nrows,Int_t ncols,Double_t a0, ...) :
36 TRArray(nrows*ncols), fNrows(nrows), fNcols(ncols) {
40 void TRMatrix::SetMatrix(Int_t nrows,Int_t ncols,
const Double_t *array) {
41 fNrows = nrows; fNcols = ncols; Set(fNrows*fNcols,array);
44 TRMatrix::TRMatrix(ETRMatrixCreatorsOp kop,Int_t nrows):
45 TRArray(nrows*nrows), fNrows(nrows), fNcols(nrows) {
50 for (
int i=0; i<fNrows; i++) fArray[i+fNrows*i] = 1;
53 Error(
"TRMatrix(ETRMatrixCreatorsOp)",
"operation %d not yet implemented", kop);
57 TRMatrix::TRMatrix(
const TRMatrix& A, ETRMatrixCreatorsOp kop) {
60 fNrows = A.GetNcols();
61 fNcols = A.GetNrows();
66 Error(
"TRMatrix(ETRMatrixCreatorsOp)",
"operation %d not yet implemented", kop);
74 NI = A.GetNrows(); fNrows = NI;
76 assert (NJ == B.GetNrows());
77 NK = B.GetNcols(); fNcols = NK;
79 TCL::mxmpy(A.GetArray(),B.GetArray(),fArray,NI,NJ,NK);
82 NI = A.GetNrows(); fNrows = NI;
84 assert (NJ == B.GetNcols());
85 NK = B.GetNrows(); fNcols = NK;
87 TCL::mxmpy1(A.GetArray(),B.GetArray(),fArray,NI,NJ,NK);
90 NI = A.GetNcols(); fNrows = NI;
92 assert (NJ == B.GetNrows());
93 NK = B.GetNcols(); fNcols = NK;
95 TCL::mxmpy2(A.GetArray(),B.GetArray(),fArray,NI,NJ,NK);
98 NI = A.GetNcols(); fNrows = NI;
100 assert (NJ == B.GetNcols());
101 NK = B.GetNrows(); fNcols = NK;
103 TCL::mxmpy3(A.GetArray(),B.GetArray(),fArray,NI,NJ,NK);
109 assert (NJ == B.GetNcols());
111 TCL::mxmlrt(A.GetArray(),B.GetArray(),fArray,NI,NJ);
115 NJ = A.GetNrows(); fNrows = NJ; fNcols = NJ;
116 assert (NI == B.GetNcols());
118 TCL::mxmltr(A.GetArray(),B.GetArray(),fArray,NJ,NI);
122 Error(
"TRMatrix(ETRMatrixCreatorsOp)",
"operation %d not yet implemented", kop);
127 void TRMatrix::Add(
const TRMatrix& A, ETRMatrixCreatorsOp kop,
const TRMatrix& B) {
133 assert (NJ == B.GetNrows());
135 assert(NI == fNrows && NK == fNcols);
136 TCL::mxmad(A.GetArray(),B.GetArray(),fArray,NI,NJ,NK);
141 assert (NJ == B.GetNcols());
143 assert(NI == fNrows && NK == fNcols);
144 TCL::mxmad1(A.GetArray(),B.GetArray(),fArray,NI,NJ,NK);
149 assert (NJ == B.GetNrows());
151 assert(NI == fNrows && NK == fNcols);
152 TCL::mxmad2(A.GetArray(),B.GetArray(),fArray,NI,NJ,NK);
157 assert (NJ == B.GetNcols());
159 assert(NI == fNrows && NK == fNcols);
160 TCL::mxmad3(A.GetArray(),B.GetArray(),fArray,NI,NJ,NK);
164 Error(
"TRMatrix(ETRMatrixCreatorsOp)",
"operation %d not yet implemented", kop);
168 void TRMatrix::Substruct(
const TRMatrix& A, ETRMatrixCreatorsOp kop,
const TRMatrix& B) {
174 assert (NJ == B.GetNrows());
176 assert(NI == fNrows && NK == fNcols);
177 TCL::mxmub(A.GetArray(),B.GetArray(),fArray,NI,NJ,NK);
182 assert (NJ == B.GetNcols());
184 assert(NI == fNrows && NK == fNcols);
185 TCL::mxmub1(A.GetArray(),B.GetArray(),fArray,NI,NJ,NK);
190 assert (NJ == B.GetNrows());
192 assert(NI == fNrows && NK == fNcols);
193 TCL::mxmub2(A.GetArray(),B.GetArray(),fArray,NI,NJ,NK);
198 assert (NJ == B.GetNcols());
200 assert(NI == fNrows && NK == fNcols);
201 TCL::mxmub3(A.GetArray(),B.GetArray(),fArray,NI,NJ,NK);
205 Error(
"TRMatrix(ETRMatrixCreatorsOp)",
"operation %d not yet implemented", kop);
215 assert(M == S.GetNrows());
219 TCL::trsa(S.GetArray(),A.GetArray(),fArray,M,N);
224 assert(M == S.GetNrows());
228 TCL::trsat(S.GetArray(),A.GetArray(),fArray,M,N);
231 Error(
"TRMatrix SxA (ETRMatrixCreatorsOp)",
"operation %d not yet implemented", kop);
241 assert(N == S.GetNrows());
245 TCL::tras(A.GetArray(),S.GetArray(),fArray,M,N);
250 assert(N == S.GetNrows());
254 TCL::trats(A.GetArray(),S.GetArray(),fArray,M,N);
257 Error(
"TRMatrix AxS (ETRMatrixCreatorsOp)",
"operation %d not yet implemented", kop);
262 Int_t M = S.GetNcols();
269 std::ostream& operator<<(std::ostream& s,
const TRMatrix &target) {
270 Int_t Nrows = target.GetNrows();
271 Int_t Ncols = target.GetNcols();
272 const Double_t *Array = target.GetArray();
273 s <<
"Rectangular Matrix Size \t[" << Nrows <<
"," << Ncols <<
"]" << std::endl;
275 s.setf(std::ios::fixed,std::ios::scientific);
276 s.setf(std::ios::showpos);
277 for (
int i = 0; i< Nrows; i++) {
279 for (
int j = Ncols-1; j >= 0; j--)
if (Array[j + i*Ncols] == 0.0) {Nzeros++;}
else break;
280 if (Nzeros == 1) Nzeros = 0;
281 for (
int j = 0; j < Ncols-Nzeros; j++) s << Form(
"%10.3f",Array[j + i*Ncols]);
282 if (Nzeros) s << Form(
"%8i*0",Nzeros);
285 s.unsetf(std::ios::showpos);
291 void TRMatrix::Print(Option_t *opt)
const {
if (opt) {}; std::cout << *
this << std::endl;}
static float * mxtrp(const float *a, float *b, int i, int j)
static float * trsat(const float *s, const float *a, float *b, int m, int n)
static float * trsa(const float *s, const float *a, float *b, int m, int n)
static float * trats(const float *a, const float *s, float *b, int m, int n)
static float * tras(const float *a, const float *s, float *b, int m, int n)
static float * trupck(const float *u, float *s, int m)