|
Boost : |
From: François Duranleau (duranlef_at_[hidden])
Date: 2006-11-11 18:03:39
On Fri, 10 Nov 2006, Jason Hise wrote:
> On 11/10/06, François Duranleau <duranlef_at_[hidden]> wrote:
>> On Fri, 10 Nov 2006, Jason Hise wrote:
>>
>> I agree on your stand about matrix vs vector types as being distinct, but
>> I don't agree that a matrix is just composed of rows of elements. It could
>> also be columns of elements. Which is it? A matrix should be left as a two
>> dimensional array (conceptually), either row-major or column-major or the
>> exact layout could be a parameter, as for boost::multi_array, except this
>> time maybe as a template parameter.
>
> Maybe. I have to wonder though if this flexibility adds
> functionality, or just room for confusion. I've heard of doing
> elementary row opeerations, but I have not heard of doing elementary
> column operations. I would think that a standardized means of storage
> and accesss would make code clearer, but I will concede this point if
> you can show me use cases where this flexibility comes in handy for
> client code.
I can think of a few.
One is when you do graphics with OpenGL (I don't know how it is with other
APIs). The latter uses column-major format for matrices. Thus if you need
to often interface with OpenGL, it's better (faster) if you're internal
representation is in the same order (as a result, I often see matrix
implementations in column-major order instead of standard C ordering in
the graphics community).
Another one, still in graphics (or actually, any applications dealing with
geometry), concerns rotation matrices. If you have a basis of three
orthonormal vectors (assuming 3D here), you can get a rotation matrix by
assign two vectors as the columns or rows of a 3x3 matrix, depending on
the direction of the transformation (local coordinates to world or
vice-versa). It is also often useful to extract back those vectors
(columns or rows).
Also, when you do some linear solving, if you want to implement a scheme
with full pivoting (rows and columns), you have more than row operations.
Concerning the cost of that flexibility, well, after posting my previous
reply, I went back to my matrix implementation and see what I had to
change to had a choice of ordering as a template parameter. I was
surprised that I had only a few changes to do. The only thing that poses
some problem is when applying an operator on two matrices of different
ordering: what should be the returned ordering type?
-- François Duranleau LIGUM, Université de Montréal
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk