Opened 13 years ago

#3510 new Feature Requests

Introduce new diag function for creating diagonal matrices and for returning the diagonal of a matrix

Reported by: marco.guazzone@… Owned by: Gunter
Milestone: Boost 1.41.0 Component: uBLAS
Version: Boost 1.40.0 Severity: Not Applicable
Keywords: Cc:

Description

Introduce a new diag free function in the spirit of the MATLAB's diag function and Mathematica's DiagonalMatrix function.

Basically it allows both the creation of a generalized diagonal matrix and the creation of a diagonal view of an existing matrix.

A generalized k-th diagonal matrix is a special kind of matrix which has all elements set to zero but the ones on its k-th diagonal. The integer k is the offset from the main diagonal, that is:

  • k = 0: the elements on the main diagonal can be different from zero.
  • k > 0: only the elements on the k-th upper diagonal can be different from zero.
  • k < 0: only the elements on the k-th lower diagonal can be different from zero.

A generalized diagonal matrix can be a rectangular matrix.

Here below is a list of the requested cases:

  • Create a square diagonal matrix M with vector V

being the k-th diagonal

M = diag(v,k)

  • Like the above, but M has layout l (e.g., column major) M = diag(v,k,l)
  • Create a rectangular diagonal matrix M of size mXn with vector V being the k-th diagonal M = diag(v,m,n,k)
  • Like the above, but M has layout l (e.g., column major) M = diag(v,m,n,k,l)
  • Create a diagonal view of the k-th diagonal of matrix M v = diag(M,k)

Attachments (1)

ublas_diag.zip (38.2 KB ) - added by marco.guazzone@… 13 years ago.
I've included a possible implementation. In addition to the diag operation, two new types are provided: (1) generalized_diagonal_matrix: a new matrix container representing a generalized diagonal matrix. (2) matrix_diagonal: a new matrix proxy representing the k-th diagonal of a given matrix.

Download all attachments as: .zip

Change History (1)

by marco.guazzone@…, 13 years ago

Attachment: ublas_diag.zip added

I've included a possible implementation. In addition to the diag operation, two new types are provided: (1) generalized_diagonal_matrix: a new matrix container representing a generalized diagonal matrix. (2) matrix_diagonal: a new matrix proxy representing the k-th diagonal of a given matrix.

Note: See TracTickets for help on using tickets.