[Bf-committers] Change Representation and Initialisation of Matrices to Conform with Standard Notation

Andrew Hale trumanblending at gmail.com
Fri Dec 9 13:57:46 CET 2011


Also, note that MatLab stores arrays in column major format but still uses
matrix[row, column] for indexing entries.

On Fri, Dec 9, 2011 at 11:50 PM, Andrew Hale <trumanblending at gmail.com>wrote:

> Hi Brecht,
>
> So it currently prints columns as rows? This is how users become confused.
> This can be fixed as I propose or by changing the repr function. Changing
> the repr function will at least make the printed form of the matrix
> consistent with it's behaviour in multiplications, if we change the repr
> then the column will be indexed first. This is fine but that would need to
> be documented very well because this is not ordinarily the case in math as
> you point out. Although more involved, the patch I proposed fixes the repr
> issue, while allowing the user to index matices in Python by the
> matrix[row][column] notation.
>
> Thanks,
> Andrew
>
>
> On Fri, Dec 9, 2011 at 11:28 PM, Brecht Van Lommel <
> brechtvanlommel at pandora.be> wrote:
>
>> Hi Andrew,
>>
>> I don't think this is the right interpretation, I think column major
>> storage does explain the behavior, and it's not clear to me what is
>> wrong assuming that this is the case.
>>
>> In python and blender C code, matrices are accessed as
>> matrix[column][row]. When printing the matrix in python, it will print
>> a list of columns. A python __repr__ implementation for Matrix could
>> make this print better.
>>
>> Brecht.
>>
>> On Fri, Dec 9, 2011 at 12:37 PM, Andrew Hale <trumanblending at gmail.com>
>> wrote:
>> > Hi Ton,
>> >
>> > I will try to explain better (this is a devilish topic). The problem
>> here
>> > is how matrices are accessed in Python and how the matrix product is
>> > formed. The method of indexing matrices is shown in [1], [2] and [3].
>> This
>> > method has the method of accessing matrices as
>> > matrix[row_index][column_index], this is the method used in Python
>> > currently. However, when the product of a matrix and vector is formed
>> > according to normal matrix rules for a matrix times a column vector (see
>> > [4] and [5]) the result is incorrect. Also see the patch tracker entry
>> for
>> > an example of how the matrix multiplication in Python is incorrect.
>> >
>> > The reason that the multiplication is not being calculated correctly is
>> > that the way matrices are printed an how they are stored is different.
>> > Because of this in Python when we access matrix[i][j] element, we're
>> > accessing element matrix[j][i] in C. Hence the product matrix*vector is
>> > actually computed as matrix^T * vector of what is shown on screen.
>> matrix^T
>> > is the matrix transpose, i.e. rows/columns switched.
>> >
>> > Thanks,
>> > Andrew
>> >
>> > [1] http://mathworld.wolfram.com/Matrix.html
>> > [2]
>> http://www.mathworks.com.au/help/techdoc/math/f1-85462.html#f1-85488
>> > [3]
>> >
>> http://en.wikipedia.org/wiki/Index_notation#Index_notation_in_mathematics
>> > [4] http://mathworld.wolfram.com/MatrixMultiplication.html
>> > [5]
>> http://en.wikipedia.org/wiki/Matrix_multiplication#Matrix_multiplication
>> >
>> > On Fri, Dec 9, 2011 at 9:01 PM, Ton Roosendaal <ton at blender.org> wrote:
>> >
>> >> Hi Andrew,
>> >>
>> >> Can you provide evidence for who is spreading, supporting or enforcing
>> >> this "Standard Notation"?
>> >>
>> >> Apart from that - especially when this standard appears disputable -
>> >> we can much better ensure we are 100% clear about it in docs. Look at
>> >> this wonderful Panda3d page:
>> >>
>> >> http://www.panda3d.org/manual/index.php/Matrix_Representation
>> >>
>> >> I rather see this approach for us!
>> >>
>> >> -Ton-
>> >>
>> >>
>> ------------------------------------------------------------------------
>> >> Ton Roosendaal  Blender Foundation   ton at blender.org
>> www.blender.org
>> >> Blender Institute   Entrepotdok 57A  1018AD Amsterdam   The Netherlands
>> >>
>> >> On 8 Dec, 2011, at 7:05, Andrew Hale wrote:
>> >>
>> >> > Hi All,
>> >> >
>> >> > I have written a patch which rectifies a cause of confusion among
>> >> > Blender
>> >> > uses when starting out with matrices and vectors. The patch ensures
>> >> > consistency between the matrix representation and matrix/vector
>> >> > products so
>> >> > that they behave in the way that people familiar with math expect.
>> >> > This is
>> >> > achieved by adjusting pythons access to the internal storage, while
>> >> > keeping
>> >> > the internal data the same. Note that this does not interfere with
>> how
>> >> > matrices are stored internally or how matrix products, additions etc
>> >> > are
>> >> > performed internally.
>> >> >
>> >> > The patch can be found here:
>> >> >
>> >>
>> http://projects.blender.org/tracker/index.php?func=detail&aid=29534&group_id=9&atid=127along
>> >> > with a more in depth explanation.
>> >> >
>> >> > Thanks,
>> >> > Andrew
>> >> > _______________________________________________
>> >> > Bf-committers mailing list
>> >> > Bf-committers at blender.org
>> >> > http://lists.blender.org/mailman/listinfo/bf-committers
>> >>
>> >> _______________________________________________
>> >> Bf-committers mailing list
>> >> Bf-committers at blender.org
>> >> http://lists.blender.org/mailman/listinfo/bf-committers
>> >>
>> > _______________________________________________
>> > Bf-committers mailing list
>> > Bf-committers at blender.org
>> > http://lists.blender.org/mailman/listinfo/bf-committers
>> _______________________________________________
>> Bf-committers mailing list
>> Bf-committers at blender.org
>> http://lists.blender.org/mailman/listinfo/bf-committers
>>
>
>


More information about the Bf-committers mailing list