
Ublas : 
Subject: [ublas] New *diag* operation (and related types)
From: Marco Guazzone (marco.guazzone_at_[hidden])
Date: 20091004 17:50:57
Dear all,
I needed a diag operation like the Matlab's diag function and
Mathematica DiagonalMatrix function.
Since I've not found it in uBLAS I've decided to implemet it.
Basically it allows both the creation of a *generalized* diagonal matrix
* M = diag(v,k) ==> Create a square diagonal matrix M with vector V
being the kth diagonal
* M = diag(v,k,l) ==> Like the above, but M has layout l (e.g., column major)
* M = diag(v,m,n,k) ==> Create a rectangular diagonal matrix M of size
mXn with vector V being the kth diagonal
* M = diag(v,m,n,k,l) ==> Like the above, but M has layout l (e.g.,
column major)
and the creation of a *diagonal* view:
* v = diag(M,k) ==> Create a diagonal view of the kth diagonal of matrix M
See the docs inside code for more about them (if you have Doxygen you
can even type: $ make apidoc)
The version of *diag* which returns a matrix, returns a new type which
I've called *generalized_diagonal_matrix*.
I've not used a banded_matrix since for avoid to allocated useless
space in case of subdiagonal/superdiagonal matrices; In fact
banded_matrix suppose to store element from lower >= 0 subdiagonal to
upper>=0 superdiagonal; so if you implement a kth subdiagonal of
MxN matrix with a banded_matrix you have to create an object like this
banded_matrix(M,N,k,0), which allocated space even for zero elements.
NOTE: Digging inside uBLAS code I've noticed an "undocumented" type
for diagonal matrices; it is in banded.hpp and is called guess
what..."diagonal_matrix". However it is only for ordinary diagonal
matrices (not for subdiagonal or superdiagonal matrices) and is
based on banded_matrix. So I've not used it.
Even for the version of *diag* returning the diagonal of a matrix,
I've created a new matrix proxy called *matrix_diagonal* in the spirit
of existent proxy, like matrix_row, matrix_column,...
I would like to know the opinion of ublas community, possible
hints/comments/suggestions
And obviously your opinion about to add all of this hell into the
official uBLAS! ;)
Thank you very much for your feedback!!
Cheers,
PS: for running the test cases I've included in the attached, unzip
the archive and type: "make". All the binary files are in
libs/numeric/ublas/test
 Marco