← Back to team overview

dolfin team mailing list archive

Re: [Bug 783857] Re: uBLASSparseMatrix data deleted when object goes out of scope

 

On Thursday May 19 2011 03:00:47 Neilen Marais wrote:
> On Thu, May 19, 2011 at 11:38 AM, Garth Wells <783857@xxxxxxxxxxxxxxxxxx> 
wrote:
> > The usefulness of the deep copy is that we could then hide the shallow
> > copy. Having shallow copies is very dangerous. The danger is mitigated
> > in the C++ interface by the constness.
> 
> Would making the numpy array read-only not have the same effect as
> constness? To make a numpy array read only in python one would set
> 
> a = numpy.arange(3)
> a.flags.writeable = False
> 
> or, AFAIK you can set the flag NPY_WRITEABLE to false with the C API.
> 
> > I don't think that that a memory copy will be that expensive relative to
> > the cost of the typical operations that are performed on sparse
> > matrices.
> 
> Perhaps, but of course, it depends :) I'm also worried about memory
> use, particularly in the case where a system would be close to having
> to swap. All in, I think having the shallow copy available is useful,
> but a deep copy would work almost as well.

I can make deepcopy the default option and put in the shallow copy as an 
option together with setting the writable flag to False. I can also document 
that the user need to keep track of the original Matrix if he does a shallow 
copy.

Johan


** Changed in: dolfin
     Assignee: (unassigned) => Johan Hake (johan-hake)

** Changed in: dolfin
   Importance: Undecided => Medium

** Changed in: dolfin
       Status: New => Confirmed

** Changed in: dolfin
    Milestone: None => 0.9.12

-- 
You received this bug notification because you are a member of DOLFIN
Team, which is subscribed to DOLFIN.
https://bugs.launchpad.net/bugs/783857

Title:
  uBLASSparseMatrix data deleted when object goes out of scope

Status in DOLFIN:
  Confirmed

Bug description:
  This bug is similar to https://bugs.launchpad.net/dolfin/+bug/747273

  The following code produces the output:

  0.0333333333333
  1.8218374251e-316

  I.e. after deleting the uBLASSparseMatrix object the data members are
  freed even though there are other references to the data.

  
  from dolfin import *

  mesh = UnitTetrahedron()
  V = FunctionSpace(mesh, "Nedelec 1st kind H(curl)", 1)
  u = TrialFunction(V)
  v = TestFunction(V)
  m = inner(v,u)*dx
  M = uBLASSparseMatrix()
  assemble(m, tensor=M)
  row,col,data = M.data()
  print data[0]
  del M
  import gc
  gc.collect()
  print data[0]


Follow ups

References