[Trilinos-Users] Epetra python interface

maxsimg at nist.gov maxsimg at nist.gov
Fri Jun 1 08:51:16 MDT 2007


I have gotten the methods there to work now, but I still have some questions. 

For example, to do something like set all of the entries above the diagonal, I
would have to manually iterate through all the rows in the matrix, in Python,
doing calls to InsertGlobalValues for each row - and that is inefficient, since
doing the looping in python has very large overhead costs. I have been able to
set a submatrix of the sparse matrix to a pre-made dense matrix - however, I
don't think this helps in the situation where I want to set, say, all of the
elements on the diagonal. I was wondering whether there would be some way of
passing in, say, a vector of row indices i, a vector of column indices j, and a
vector of values V, all of the same length, to then have the value of the matrix
elements in positions (i_k, j_k) set to V_k. This would allow the iteration to
be done efficiently in the underlying c++ code instead of having it done
explicitly in python, avoiding the performance penalty. Is there some way of
doing this? Or some other way of inserting values that would prevent the need
for explicit Python looping? (Either for summing into, replacing, or inserting
values - the interfaces available seem consistent.)  

-Maxsim Gibiansky

Quoting Bill Spotz <wfspotz at sandia.gov>:

> Maxsim,
> 
> I provided the wrappers for Epetra.FECrsMatrix, but haven't tested it  
> much yet.  However, the auto-generated documentation seems useful:
> 
> $ python
> Python 2.5.1 (r251:54863, May 27 2007, 17:33:37)
> [GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
>  >>> from PyTrilinos import Epetra
>  >>> help(Epetra.FECrsMatrix.SumIntoGlobalValues)
> 
> Help on method SumIntoGlobalValues in module Epetra:
> 
> SumIntoGlobalValues(*args) unbound Epetra.FECrsMatrix method
>      SumIntoGlobalValues(self, int GlobalRow, int NumEntries, double  
> Values, int Indices) -> int
>      SumIntoGlobalValues(self, int row, PyObject values, PyObject  
> indices) -> int
>      SumIntoGlobalValues(self, int numIndices, int indices, double  
> values, int format=COLUMN_MAJOR) -> int
>      SumIntoGlobalValues(self, int numIndices, int indices, double  
> values) -> int
>      SumIntoGlobalValues(self, int numRows, int rows, int numCols,  
> int cols, double values,
>          int format=COLUMN_MAJOR) -> int
>      SumIntoGlobalValues(self, int numRows, int rows, int numCols,  
> int cols, double values) -> int
>      SumIntoGlobalValues(self, int numIndices, int indices, double  
> values, int format=ROW_MAJOR) -> int
>      SumIntoGlobalValues(self, int numIndices, int indices, double  
> values) -> int
>      SumIntoGlobalValues(self, int numRows, int rows, int numCols,  
> int cols, double values,
>          int format=ROW_MAJOR) -> int
>      SumIntoGlobalValues(self, int numRows, int rows, int numCols,  
> int cols, double values) -> int
>      SumIntoGlobalValues(self, Epetra_IntSerialDenseVector indices,  
> Epetra_SerialDenseMatrix values,
>          int format=COLUMN_MAJOR) -> int
>      SumIntoGlobalValues(self, Epetra_IntSerialDenseVector indices,  
> Epetra_SerialDenseMatrix values) -> int
>      SumIntoGlobalValues(self, Epetra_IntSerialDenseVector rows,  
> Epetra_IntSerialDenseVector cols,
>          Epetra_SerialDenseMatrix values,
>          int format=COLUMN_MAJOR) -> int
>      SumIntoGlobalValues(self, Epetra_IntSerialDenseVector rows,  
> Epetra_IntSerialDenseVector cols,
>          Epetra_SerialDenseMatrix values) -> int
> 
> 
> The last four calling signatures may be of interest to you since they  
> use serial dense vectors and matrices to specify more complicated  
> assignment operations.
> 
> On May 30, 2007, at 2:28 PM, maxsimg at nist.gov wrote:
> 
> > Hello everyone,
> >
> > I am trying to populate an epetra sparse matrix, using the python  
> > interfaces
> > available through PyTrilinos. Ideally, I would like to specify a  
> > list of row
> > indices, column indices, and values to insert (or sum into) the  
> > matrix. I've
> > tried to use some of the overloaded forms of InsertGlobalValues and
> > SumIntoGlobalValues, but some of the ones that I have tried give me
> > "NotImplementedError: Wrong number of arguments for overloaded  
> > function
> > 'FECrsMatrix_SumIntoGlobalValues'" and others don't support  
> > inserting into
> > multiple rows, so I'm not sure what to use and how. Would someone  
> > be able to
> > suggest what is a good way to populate a matrix through the  
> > available python
> > wrappers?
> >
> > Ideally, I'd like to do something like
> >
> > theMatrix.putGlobalValues(values, i, j)
> >
> > where i is a list of indices and j is a list of indices, where the  
> > lengths of
> > i,j, and values are the same.
> >
> > -Maxsim Gibiansky
> 
> ** Bill Spotz                                              **
> ** Sandia National Laboratories  Voice: (505)845-0170      **
> ** P.O. Box 5800                 Fax:   (505)284-5451      **
> ** Albuquerque, NM 87185-0370    Email: wfspotz at sandia.gov **
> 
> 
> 
> 






More information about the Trilinos-Users mailing list