Extract values of a tensor

Asked by Nicolas Verdon

Hi everybody,

Always with my problem of compilation time, I try to "optimize" my code "manually"...
As I have tensors that are obtained with sums of other tensors, I would like to exctract the values of the tensors to define a new tensor.

More precisely, it is possible to extract the values of the vector u using:

u.vector().array()

and then it is possible to define a vector v from these values.
I would like to do the same with the tensors.

I would like to know if it is possible and if yes, how can we do that ?

Thanks,
Nicolas Verdon

Question information

Language:
English Edit question
Status:
Answered
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Anders Logg (logg) said :
#1

On Wed, Mar 28, 2012 at 01:10:54PM -0000, Nicolas Verdon wrote:
> New question #191930 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/191930
>
> Hi everybody,
>
>
> Always with my problem of compilation time, I try to "optimize" my code "manually"...
> As I have tensors that are obtained with sums of other tensors, I would like to exctract the values of the tensors to define a new tensor.
>
> More precisely, it is possible to extract the values of the vector u using:
>
> u.vector().array()
>
> and then it is possible to define a vector v from these values.
> I would like to do the same with the tensors.
>
> I would like to know if it is possible and if yes, how can we do that ?

You can set values by

u.vector()[:] = some_array

but then you need to know how the values are stored for the
tensor. This varies for different element types and different tensor
dimensions.

--
Anders

Can you help with this problem?

Provide an answer of your own, or ask Nicolas Verdon for more information if necessary.

To post a message you must log in.