I was asking for shared, reference counted array, shared between c++ and numpy
but I can live without it, just taking care of data scope by myself. So I need
to know when copying takes place. Thanks, Johan.
Jan
-----Original Message-----
From: "Johan Hake" <[email protected]>
Sent: 10/03/2014 11:08
To: "Jan Blechta" <[email protected]>
Cc: "FEniCS mailing list" <[email protected]>
Subject: Re: [FEniCS] Typemap for shared array
On Mon, Mar 10, 2014 at 10:25 AM, Jan Blechta <[email protected]>
wrote:
On Mon, 10 Mar 2014 09:55:57 +0100
Johan Hake <[email protected]> wrote:
> On Mon, Mar 10, 2014 at 9:27 AM, Jan Blechta
> <[email protected]>wrote:
>
> > On Mon, 10 Mar 2014 08:11:10 +0100
> > Johan Hake <[email protected]> wrote:
> >
> > > There are no way of passing the data without copying the values
> > > from the NumPy array to the std containers. The reason is that
> > > there are AFAIK not way of initializing these structures with
> > > external data and that is why we have added our own Array<Foo>
> > > wrapper of a contiguous array.
> >
> > Are data copied when initializing dolfin::Array<Foo> from numpy
> > array? If so, who owns the pointer Foo*? When is it destroyed?
> >
>
> It is pretty clear by reading the code. Array comes with two
> constructors one that owes (and creates its data) and one that takes
> an external data pointer and does not take ownership.
Yeah, I understand Array.h. Not so much the typemaps.
>
>
> > If data are not copied and Foo* points to data within numpy array,
> > user must take care for numpy array not to be garbage collect,
> > mustn't he?
> >
>
> Yes, but Array is mostly used to pass data in or out of methods. It
> is not used to store any data, which means that once the Array with
> the NumPy data is passed to DOLFIN it is destroyed. This all happens
> inside the Array<Foo>& typemap.
As far as I understand it, IN typemap works without copying but care
must be taken not to destroy numpy array with data prematurely (if
dolfin::Array is to be stored). On the other hand, OUT typemap copies
the data. Am I correct?
In the current Array typemaps that is the case, yes. But you can write an out
typemap that does not copy. You just need to make sure the NumPy array does not
take ownership. We do that on several places in DOLFIN for other types such as
std::vector<Foo>&
Not sure what this discussion has to do with your original request though...
Johan
Thanks,
Jan
>
> Johan
_______________________________________________
fenics mailing list
[email protected]
http://fenicsproject.org/mailman/listinfo/fenics