dolfin team mailing list archive
-
dolfin team
-
Mailing list archive
-
Message #03019
Re: [HG] Split la unit tests into separate files.
On Fri, Aug 11, 2006 at 04:59:09PM +0200, Johan Jansson wrote:
> On Fri, Aug 11, 2006 at 02:42:49PM +0200, Anders Logg wrote:
> > Could we define a GenericMatrixElement in the same way as we have
> > defined a PETScMatrixElement to allow access according to
> >
> > a = A(i, j)
> > A(i, j) = a
> >
> > ?
> >
> > This will be *slow* for PETSc, but fast for uBlas. The question is if
> > we can do this without introducing any overhead when indexing a
> > matrix that is known to be a uBlasMatrix at compile-time.
> >
> > /Anders
>
> I don't like this kind of workaround (i.e. MatrixElement,
> VectorElement) for just defining an operator. Here's my suggestion:
>
> Let's define functions getelement()/setelement() for GenericVector and
> GenericMatrix. The implementation for PETSc will be slow but for dense
> uBlas very fast.
>
> We can then define nice operators in Python for these functions with
> __getitem__()/__setitem__():
>
> def __setitem__(self, i, a):
> if(isinstance(i, int)):
> self.setelement(i, a)
> elif(isinstance(i, tuple)):
> self.setelement(i[0], i[1], a)
>
> In C++, the uBlas indexing interface already exists, so we can use that.
>
> What do you think?
>
> Johan
Sounds good. This would add a [] operator in the Python interface. In
the C++ interface, we have (). But I guess there's no way to have the
same interface in both Python and C++. In Python, we can't use ()
since we can't differentiate between access and assignment and in C++,
we can't use [] for matrices. Is that correct?
I'd also suggest we name the functions just get()/set() in
GenericVector and GenericMatrix.
/Anders
References