6.6 Vector Views (.NET, C#, CSharp, VB, Visual Basic, F#)
A variety of methods are providing for returning vector views of the data referenced by a matrix. The returned vector and the matrix share the data, so care must be exercised when modifying values. If after constructing a different view of an object's data you want your own private view that you can modify without affecting any other objects, simply invoke the DeepenThisCopy() method on the vector:
Code Example – C# matrix
var A = new DoubleMatrix( 8, 8, 1, 1 );
DoubleVector v = A.Diagonal();
v.DeepenThisCopy();
Code Example – VB matrix
Dim A As New DoubleMatrix(8, 8, 1.0, 1.0)
Dim V As DoubleVector = A.Diagonal()
V.DeepenThisCopy()
Member functions Row() and Column() return vector views of a specified row or column. For instance:
Code Example – C# matrix
var A = new DoubleMatrix( "3x3 [1 2 3 4 5 6 7 8 9]" );
DoubleVector row1 = A.Row( 1 );
DoubleVector col0 = A.Col( 0 );
Code Example – VB matrix
Dim A As New DoubleMatrix("3x3 [1 2 3 4 5 6 7 8 9]")
Dim Row1 As DoubleVector = A.Row(1)
Dim Col0 As DoubleVector = A.Col(0)
The Diagonal() member function returns a vector view of a diagonal of a matrix. If no diagonal is specified, a vector view of the main diagonal is returned. For example, this code increments every element along the main diagonal:
Code Example – C# matrix
var A = new FloatMatrix( 5, 8 );
A.Diagonal()++;
Code Example – VB matrix
Dim A As New FloatMatrix(5, 8)
A.Diagonal().Increment()
The Slice() member function returns a vector view of an arbitrary slice of a matrix. The parameters are:
● the starting row
● the starting column
● the number of elements
● the row stride
● the column stride
The slice begins at the starting row and column, and extends for the number of elements. The increment between successive elements in the vector is row stride rows and column stride columns. For example, this code returns a view of the diagonal from the bottom left corner to the top right of a 3x3 matrix:
Code Example – C# matrix
var A = new DoubleMatrix( "3x3 [1 2 3 4 5 6 7 8 9]" );
DoubleVector v = A.Slice( 2, 0, 3, -1, 1 );
Code Example – VB matrix
Dim A As New DoubleMatrix("3x3 [1 2 3 4 5 6 7 8 9]")
Dim V As DoubleVector = A.Slice(2, 0, 3, -1, 1)