← Back to team overview

dolfin team mailing list archive

Re: Vector to numpy array and vice verse

 

On fr., 2008-08-08 at 09:50 +0200, Martin Sandve Alnæs wrote:
> How would you do this? The way the dolfin.Function class is created
> destroys the documentation of constructor signatures, which in my
> opinion is really really bad.
> 
> You could just add:
> 
> def as_vector(x):
>     v = Vector(len(x))
>     v.set(x)
>     return v
> 
> then we can do
> x = zeros(10)
> v = as_vector(x)
> 
> and the dolfin.Function constructor can just as easily do this step.
> 

We could add something like this to the SWIG interface file. 

%extend dolfin::Vector {
  %pythoncode %{

    def __init__(self, v): 
      a = Vector(len(v)) 
      a.set(v)
      return a
  %}
}


This might remove other constructors ? I'm not exactly sure how SWIG 
deal with constructors both in Python and C++. 

Kent



Follow ups

References