[Trilinos-Users] Calculating properties of CrsMatrices

Pate Motter pate.motter at colorado.edu
Sat Feb 7 16:21:28 MST 2015


Hi, 

I am very new to Trilinos and am trying to calculate various properties of sparse matrices. Currently, to calculate the maximum row variance I am reading in a Matrix Market file to a CrsMatrix object. I then use getGlobalRowCopy to view each row individually and calculate the variance using the given entries of that row. 

My two questions are:
1) The above does not seem efficient, what would be the best way to use Trilinos to view each row's entries and work with them? 
2) For calculating the column variance, is there a preferred manner to access each column? I can view each row individually, but it doesn't seem that an equivalent exists for columns. 

Thank you,
Pate Motter

void calcRowVariance(RCP<MAT> &A) {
int dim = A->getGlobalNumCols();
Teuchos::Array<int> indices(dim);
Teuchos::Array<double> values(dim);
std::size_t numEntries = 0;
double mean, sum, variance, maxVariance = 0.0;

for (int row = 0; row < dim; row++) {
mean = 0.0; variance = 0.0;
A->getGlobalRowCopy(row, indices, values, numEntries);
for (int col = 0; col < numEntries; col++) {
mean += values[col];
} 
mean /= dim;
for (int col = 0; col < numEntries; col++) {
variance += (values[col] - mean) * (values[col] - mean);
}
variance /= dim;
if (variance > maxVariance) maxVariance = variance;
}
std::cout << maxVariance << std::endl;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://software.sandia.gov/pipermail/trilinos-users/attachments/20150207/6ae3bc6b/attachment.html>


More information about the Trilinos-Users mailing list