← Back to team overview

dolfin team mailing list archive

Re: operator() or operator[]

 

mpic++ -o dolfin/la/PETScVector.os -c -Wall -pipe -ansi -DDEBUG -g -Werror -DNDEBUG -O2 -DHAS_MPI=1 -DMPICH_IGNORE_CXX_SEEK -DPACKAGE_VERSION=\"0.7.2\" -DHAS_PETSC=1 -DHAS_SCOTCH=1 -DHAS_UMFPACK=1 -DHAS_GTS=1 -fPIC -I. -I/scratch/buildbot/local/include -I/usr/include/libxml2 -I/scratch/buildbot/local/petsc-2.3.3-p11/bmake/linux-gnu-c-debug -I/scratch/buildbot/local/petsc-2.3.3-p11/include -I/scratch/buildbot/local/include -I/scratch/buildbot/local/scotch_5.0/bin -I/usr/include/suitesparse -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include dolfin/la/PETScVector.cpp
dolfin/la/PETScVector.cpp: In member function ‘void dolfin::PETScVector::copy(const dolfin::uBlasVector&, dolfin::uint, dolfin::uint, dolfin::uint)’:
dolfin/la/PETScVector.cpp:402: error: no match for ‘operator[]’ in ‘y[(i + off2)]’

ilmar

Anders Logg wrote:
On Fri, Apr 11, 2008 at 01:34:24PM +0200, Martin Sandve Alnæs wrote:
2008/4/11, Anders Logg <logg@xxxxxxxxx>:
On Fri, Apr 11, 2008 at 12:23:15PM +0100, Garth N. Wells wrote:
 >
 >
 > Anders Logg wrote:
 > > Which one do we want to use for element access in vectors and
 > > matrices. It looks like operator() is now implemented for uBlasVector,
 > > but isn't operator[] more natural to use?
 > >
 >
 > Much the same to me. We've used (.,.) for matrices, so it seems natural
 > to use (.) for vectors.
 >
 > Garth


We could use [] for matrices also I guess.

 Then it will look the same as numpy.
It's useful to index vectors with [], since the code will be similar
for regular arrays.

I forgot something important, namely that operator[] expects exactly
one argument, so we can't do A[i, j] for matrices.

Maybe then it's better to have () both for vectors and matrices?



References