48 using Teuchos::SetScientific;
52 typedef Teuchos::ScalarTraits<ScalarType> STS;
56 SetScientific<ScalarType> sci (om->stream (
Warnings));
75 const ScalarType zero = STS::zero();
92 RCP<DM> dm1 = DMT::Create(numrows,numcols);
95 int checknumrows = DMT::GetNumRows(*dm1);
96 int checknumcols = DMT::GetNumCols(*dm1);
97 if( checknumrows != numrows || checknumcols != numcols){
99 <<
"*** ERROR *** DenseMatTraits::GetNumRows or GetNumCols" << endl
100 <<
"Returned incorrect value." << endl;
104 DMT::SyncDeviceToHost(*dm1);
106 for(
int i = 0; i<numrows; i++){
107 for(
int j = 0; j<numcols; j++){
108 ScalarType val = DMT::ValueConst(*dm1,i,j);
111 <<
"*** ERROR *** DenseMatTraits::Create(-,-,true)" << endl
112 <<
"Did not initialize to zero!" << endl;
119 DMT::Value(*dm1,0,0) = (ScalarType)5.0;
120 if(DMT::ValueConst(*dm1,0,0) != (ScalarType)5.0){
122 <<
"*** ERROR *** DenseMatTraits::Value" << endl
123 <<
"Does not give write access to matrix values!!" << endl;
128 DMT::SyncHostToDevice(*dm1);
131 RCP<DM> dm2 = DMT::Create(numrows, numcols,
false);
132 DMT::PutScalar(*dm2,(ScalarType)47.2);
133 DMT::SyncDeviceToHost(*dm2);
134 if( DMT::ValueConst(*dm2,0,0) != (ScalarType)47.2){
136 <<
"*** ERROR *** DenseMatTraits::PutScalar " << endl
137 <<
"Value at dm2 0,0 is: " << DMT::ValueConst(*dm2,0,0) << endl;
140 DMT::PutScalar(*dm2);
141 DMT::SyncDeviceToHost(*dm2);
142 if( DMT::ValueConst(*dm2,0,0) != zero){
144 <<
"*** ERROR *** DenseMatTraits::" << endl
145 <<
"PutScalar default args failed" << endl;
150 int stride = DMT::GetStride(*dm2);
151 if (stride != numrows) {
153 <<
"*** ERROR *** DenseMatTraits::" << endl
154 <<
"Stride failed" << endl;
159 DMT::Randomize(*dm2);
160 DMT::SyncDeviceToHost(*dm2);
161 ScalarType tmpVal = DMT::ValueConst(*dm1,numrows-1,numcols-1) + DMT::ValueConst(*dm2,numrows-1,numcols-1);
162 ScalarType tmpVal2 = DMT::ValueConst(*dm1,0,0) + DMT::ValueConst(*dm2,0,0);
164 DMT::SyncDeviceToHost(*dm1);
165 if(DMT::ValueConst(*dm1,numrows-1,numcols-1) != tmpVal ||
166 DMT::ValueConst(*dm1,0,0) != tmpVal2){
168 <<
"*** ERROR *** DenseMatTraits::" << endl
169 <<
"Add failed" << endl;
174 DMT::Assign(*dm1,*dm2);
175 DMT::Scale(*dm1,2.0);
176 DMT::SyncDeviceToHost(*dm1);
177 if(DMT::ValueConst(*dm1,1,1) != (ScalarType)DMT::ValueConst(*dm2,1,1)*(ScalarType)2.0){
179 <<
"*** ERROR *** DenseMatTraits::" << endl
180 <<
"Assign or scale failed" << endl;
184 RCP<DM> dm3 = DMT::Subview(*dm1, numrows-1, numcols-1, 1, 1);
185 DMT::SyncDeviceToHost(*dm3);
186 if(DMT::ValueConst(*dm3,0,0) != DMT::ValueConst(*dm1,1,1)){
188 <<
"*** ERROR *** DenseMatTraits::" << endl
189 <<
"Subview failed" << endl;
192 if(DMT::GetNumRows(*dm3) != numrows-1 ||
193 DMT::GetNumCols(*dm3) != numcols-1){
195 <<
"*** ERROR *** DenseMatTraits::" << endl
196 <<
"Subview gives wrong dimensions." << endl;
200 ScalarType testVal = 237.1;
201 DMT::Value(*dm3,0,0) = testVal;
202 if(DMT::ValueConst(*dm3,0,0) != DMT::ValueConst(*dm1,1,1) ||
203 DMT::ValueConst(*dm3,0,0) != testVal){
205 <<
"*** ERROR *** DenseMatTraits::" << endl
206 <<
"Subview did not edit value or did not edit original." << endl;
210 RCP<DM> dm4 = DMT::SubviewCopy(*dm1, numrows-2, numcols-2, 2, 2);
211 if(DMT::ValueConst(*dm4,0,0) != DMT::ValueConst(*dm1,2,2)){
213 <<
"*** ERROR *** DenseMatTraits::" << endl
214 <<
"SubviewCopy failed" << endl;
217 if(DMT::GetNumRows(*dm4) != numrows-2 ||
218 DMT::GetNumCols(*dm4) != numcols-2){
220 <<
"*** ERROR *** DenseMatTraits::" << endl
221 <<
"SubviewCopy gives wrong dimensions." << endl;
225 DMT::Value(*dm4,0,0) = testVal-(ScalarType)5;
226 if(DMT::ValueConst(*dm4,0,0) == DMT::ValueConst(*dm1,2,2) ||
227 DMT::ValueConst(*dm4,0,0) != testVal-(ScalarType)5){
229 <<
"*** ERROR *** DenseMatTraits::" << endl
230 <<
"SubviewCopy is incorrect. Possible view but not copy." << endl;
234 RCP<DM> dm5 = DMT::Subview(*dm3, 1, 1);
235 DMT::Value(*dm5,0,0) = testVal-(ScalarType)10;
236 if (DMT::ValueConst(*dm3,0,0) != DMT::ValueConst(*dm5,0,0) ||
237 DMT::ValueConst(*dm1,1,1) != (testVal-(ScalarType)10)) {
239 <<
"*** ERROR *** DenseMatTraits::" << endl
240 <<
"Subview of a subview is incorrect. Possibly can't take hierarchical subviews." << endl;
250 DMT::Reshape(*dm2, numrows+5, numcols+5);
251 if(DMT::GetNumRows(*dm2) != numrows+5 ||
252 DMT::GetNumCols(*dm2) != numcols+5){
254 <<
"*** ERROR *** DenseMatTraits::" << endl
255 <<
"Reshape test 1 gives wrong dimensions." << endl;
259 DMT::Reshape(*dm2, numrows-2, numcols-2);
260 if(DMT::GetNumRows(*dm2) != numrows-2 ||
261 DMT::GetNumCols(*dm2) != numcols-2){
263 <<
"*** ERROR *** DenseMatTraits::" << endl
264 <<
"Reshape test 2 gives wrong dimensions." << endl;
268 DMT::Reshape(*dm2, numrows+5, numcols+5,
true);
269 if(DMT::GetNumRows(*dm2) != numrows+5 ||
270 DMT::GetNumCols(*dm2) != numcols+5){
272 <<
"*** ERROR *** DenseMatTraits::" << endl
273 <<
"Reshape test 3 gives wrong dimensions." << endl;
276 if(DMT::ValueConst(*dm2,0,0) != zero || DMT::ValueConst(*dm2,numrows+4,numcols+4) != zero){
278 <<
"*** ERROR *** DenseMatTraits::" << endl
279 <<
"Reshape test 3 does not init to zero." << endl;
284 DMT::SyncDeviceToHost( *dm2 );
285 ScalarType * testPtr = DMT::GetRawHostPtr(*dm2);
288 <<
"*** ERROR *** DenseMatTraits::" << endl
289 <<
"GetRawHostPtr returns NULL." << endl;
292 RCP<const DM> cdm2 = DMT::SubviewConst(*dm2, DMT::GetNumRows(*dm2), DMT::GetNumCols(*dm2));
293 if(DMT::GetNumRows(*cdm2) != numrows+5 ||
294 DMT::GetNumCols(*cdm2) != numcols+5){
296 <<
"*** ERROR *** DenseMatTraits::" << endl
297 <<
"SubviewConst did not create the right size matrix." << endl;
300 const ScalarType * testPtr2 = DMT::GetConstRawHostPtr(*cdm2);
303 <<
"*** ERROR *** DenseMatTraits::" << endl
304 <<
"GetConstRawHostPtr returns NULL." << endl;
309 DMT::NormFrobenius(*dm2);