1 //
2 //              LAPACK++ 1.1 Linear Algebra Package 1.1
3 //               University of Tennessee, Knoxvilee, TN.
4 //            Oak Ridge National Laboratory, Oak Ridge, TN.
5 //        Authors: J. J. Dongarra, E. Greaser, R. Pozo, D. Walker
6 //                 (C) 1992-1996 All Rights Reserved
7 //
8 //                             NOTICE
9 //
10 // Permission to use, copy, modify, and distribute this software and
11 // its documentation for any purpose and without fee is hereby granted
12 // provided that the above copyright notice appear in all copies and
13 // that both the copyright notice and this permission notice appear in
14 // supporting documentation.
15 //
16 // Neither the Institutions (University of Tennessee, and Oak Ridge National
17 // Laboratory) nor the Authors make any representations about the suitability
18 // of this software for any purpose.  This software is provided ``as is''
19 // without express or implied warranty.
20 //
21 // LAPACK++ was funded in part by the U.S. Department of Energy, the
22 // National Science Foundation and the State of Tennessee.
23 
24 #ifdef HAVE_CONFIG_H
25 # include <config.h>
26 #endif
27 
28 #include "arch.h"
29 #include "lafnames.h"
30 #include LA_PREFS_H
31 #include LA_GEN_MAT_FLOAT_H
32 #include LA_EXCEPTION_H
33 #include "mtmpl.h"
34 
35 // The rest of the "template function wrapper methods" are
36 // implemented in the file gmtmpl.cc .
37 
38 DLLIMPORT int LaGenMatFloat::debug_ = 0;     // turn off global deubg flag initially.
39 // use A.debug(1) to turn on/off,
40 // and A.debug() to check current status.
41 
42 DLLIMPORT int* LaGenMatFloat::info_ = new int;       // turn off info print flag.
43 
~LaGenMatFloat()44 LaGenMatFloat::~LaGenMatFloat()
45 { }
46 
LaGenMatFloat()47 LaGenMatFloat::LaGenMatFloat()
48     : v(0)
49 {
50     init(0, 0);
51 }
52 
LaGenMatFloat(int m,int n)53 LaGenMatFloat::LaGenMatFloat(int m, int n)
54     : v(m*n)
55 {
56     init(m, n);
57 }
58 
59 // modified constructor to support row ordering (jg)
LaGenMatFloat(value_type * d,int m,int n,bool row_ordering)60 LaGenMatFloat::LaGenMatFloat(value_type *d, int m, int n, bool row_ordering)
61     : v(d, m, n, row_ordering)
62 {
63     init(m, n);
64     if (debug())
65     {
66         std::cout << ">>> LaGenMatFloat::LaGenMatFloat(double *d, int m, int n)\n";
67     }
68 }
69 
LaGenMatFloat(const LaGenMatFloat & X)70 LaGenMatFloat::LaGenMatFloat(const LaGenMatFloat& X)
71     : v(0)
72 {
73     debug_ = X.debug_;
74     shallow_ = 0;  // do not perpeturate shallow copies, otherwise
75     //  B = A(I,J) does not work properly...
76 
77     if (X.shallow_)
78     {
79         v.ref(X.v);
80         dim[0] = X.dim[0];
81         dim[1] = X.dim[1];
82         sz[0] = X.sz[0];
83         sz[1] = X.sz[1];
84         ii[0] = X.ii[0];
85         ii[1] = X.ii[1];
86     }
87     else
88     {
89         if (X.debug())
90             std::cout << std::endl << "Data is being copied!\n" << std::endl;
91 
92         init(X.size(0), X.size(1));
93 
94         copy(X);
95     }
96 
97     if (debug())
98     {
99         std::cout << "*this: " << info() << std::endl;
100         std::cout << "<<< LaGenMatFloat::LaGenMatFloat(const LaGenMatFloat& X)\n";
101     }
102 }
103 
init(int m,int n)104 void LaGenMatFloat::init(int m, int n)
105 {
106     if (m && n)
107     {
108         ii[0](0, m - 1);
109         ii[1](0, n - 1);
110     }
111     dim[0] = m;
112     dim[1] = n;
113     sz[0] = m;
114     sz[1] = n;
115     *info_ = 0;
116     shallow_ = 0;
117 }
118 
119 // ////////////////////////////////////////
120 
ref(const LaGenMatFloat & s)121 LaGenMatFloat& LaGenMatFloat::ref(const LaGenMatFloat& s)
122 {
123     // handle trivial M.ref(M) case
124     if (this == &s) return *this;
125     else
126     {
127         ii[0] = s.ii[0];
128         ii[1] = s.ii[1];
129         dim[0] = s.dim[0];
130         dim[1] = s.dim[1];
131         sz[0] = s.sz[0];
132         sz[1] = s.sz[1];
133         shallow_ = 0;
134 
135         v.ref(s.v);
136 
137         return *this;
138     }
139 }
140 
operator ()(const LaIndex & II,const LaIndex & JJ) const141 LaGenMatFloat LaGenMatFloat::operator()(const LaIndex& II, const LaIndex& JJ) const
142 {
143     if (debug())
144     {
145         std::cout << ">>> LaGenMatFloat::operator(const LaIndex& const LaIndex&)\n";
146     }
147     LaIndex I, J;
148     mtmpl::submatcheck(*this, II, JJ, I, J);
149 
150     LaGenMatFloat tmp;
151 
152     int Idiff = (I.end() - I.start()) / I.inc();
153     int Jdiff = (J.end() - J.start()) / J.inc();
154 
155     tmp.dim[0] = dim[0];
156     tmp.dim[1] = dim[1];
157     tmp.sz[0] = Idiff + 1;
158     tmp.sz[1] = Jdiff + 1;
159 
160     tmp.ii[0].start() =  ii[0].start() + I.start() * ii[0].inc();
161     tmp.ii[0].inc() = ii[0].inc() * I.inc();
162     tmp.ii[0].end() = Idiff * tmp.ii[0].inc() + tmp.ii[0].start();
163 
164     tmp.ii[1].start() =  ii[1].start() + J.start() * ii[1].inc();
165     tmp.ii[1].inc() = ii[1].inc() * J.inc();
166     tmp.ii[1].end() = Jdiff * tmp.ii[1].inc() + tmp.ii[1].start();
167 
168     tmp.v.ref(v);
169     tmp.shallow_assign();
170 
171     if (debug())
172     {
173         std::cout << "    return value: " << tmp.info() << std::endl;
174         std::cout << "<<< LaGenMatFloat::operator(const LaIndex& const LaIndex&)\n";
175     }
176 
177     return tmp;
178 }
179 
operator ()(const LaIndex & II,const LaIndex & JJ)180 LaGenMatFloat LaGenMatFloat::operator()(const LaIndex& II, const LaIndex& JJ)
181 {
182     if (debug())
183     {
184         std::cout << ">>> LaGenMatFloat::operator(const LaIndex& const LaIndex&)\n";
185     }
186     LaIndex I, J;
187     mtmpl::submatcheck(*this, II, JJ, I, J);
188 
189     LaGenMatFloat tmp;
190 
191     int Idiff = (I.end() - I.start()) / I.inc();
192     int Jdiff = (J.end() - J.start()) / J.inc();
193 
194     tmp.dim[0] = dim[0];
195     tmp.dim[1] = dim[1];
196     tmp.sz[0] = Idiff + 1;
197     tmp.sz[1] = Jdiff + 1;
198 
199     tmp.ii[0].start() =  ii[0].start() + I.start() * ii[0].inc();
200     tmp.ii[0].inc() = ii[0].inc() * I.inc();
201     tmp.ii[0].end() = Idiff * tmp.ii[0].inc() + tmp.ii[0].start();
202 
203     tmp.ii[1].start() =  ii[1].start() + J.start() * ii[1].inc();
204     tmp.ii[1].inc() = ii[1].inc() * J.inc();
205     tmp.ii[1].end() = Jdiff * tmp.ii[1].inc() + tmp.ii[1].start();
206 
207     tmp.v.ref(v);
208     tmp.shallow_assign();
209 
210     if (debug())
211     {
212         std::cout << "    return value: " << tmp.info() << std::endl;
213         std::cout << "<<< LaGenMatFloat::operator(const LaIndex& const LaIndex&)\n";
214     }
215 
216     return tmp;
217 
218 }
219 
220 
221 // The rest of the "template function wrapper methods" are
222 // implemented in the file gmtmpl.cc .
223