Peter Smit
Peter Smit

Reputation: 28736

How can I obtain a LaVectorDouble object which is a submatrixview of a LaGenMatDouble?

We are using Lapack++ for our matrix calculations. One of the features is the use of submatrixviews; objects that refer to the same spot in memory.

Example:

  LaGenMatDouble W = LaGenMatDouble::rand(3,4);
  LaGenMatDouble A = W(LaIndex(0,2), LaIndex(1,3));
  LaGenMatDouble b = W(LaIndex(0,2), LaIndex(0,0));

A and b are now submatrices of W.

How can I make b a LaVectorDouble to be able to perform some calculations with it?

Upvotes: 1

Views: 233

Answers (2)

Peter Smit
Peter Smit

Reputation: 28736

The answer is to use the ref function.

LaVectorDouble b;
b.ref(W(LaIndex(0,2), LaIndex(0,0)));

All other functions are copying (like constructor, = and copy) or giving the wrong class (like the constructor with indices). The ref function is referencing to memory.

Upvotes: 0

nsanders
nsanders

Reputation: 12656

I suspect this routine does a deep-copy of the data:

http://lapackpp.sourceforge.net/html/classLaVectorDouble.html#be11700fe7c277501329b2d23f485630

This ref() routine might let you maintain the shared memory:

http://lapackpp.sourceforge.net/html/classLaVectorDouble.html#191850a7e8993a977a3a545b87dc7528

Upvotes: 1

Related Questions