Rewriting 5x5 matrix multiplication in terms of 4x4 matrices

Discuss interdimensional programming, Java applets and so forth.

Rewriting 5x5 matrix multiplication in terms of 4x4 matrices

Postby quickfur » Fri Jul 16, 2021 3:27 pm

Is there an easy way to rewrite 5x5 matrix multiplications in terms of 4x4 (or smaller) matrices?

Background: I'm trying to implement 4D projections (5x5 matrix multiplications in homogenous coordinates) in the GPU, which has built-in support for 4x4 matrices but does not have 5x5 matrices. I could implement 5x5 matrices manually, but it would run slower than if I took advantage of built-in matrix types.

Are there any nice decompositions of 5x5 matrix multiplication into multiplications of smaller matrices?
quickfur
Pentonian
 
Posts: 3004
Joined: Thu Sep 02, 2004 11:20 pm
Location: The Great White North

Re: Rewriting 5x5 matrix multiplication in terms of 4x4 matr

Postby quickfur » Sat Jul 17, 2021 2:59 pm

I think I figured it out. I really only need 4x5 matrices in general, except for the 4D to 3D projection part, which can be done separately. Well strictly speaking these are 5x5 matrices where the bottom row is 0 0 0 ... 0 1. So let's denote such a matrix by A|a, where A is the upper left 4x4 submatrix and a is the last column of the 4x5 matrix. Then the following formula holds for products of these matrices:

A|a * B|b = (AB)|(Ab + a)

In other words, we can simulate these restricted 5x5 matrices by representing them as 4x4 matrices coupled with an extra 4D vector for its last column. The matrix product can then be simulated using the above formula, which requires only operations on 4x4 matrices and 4D vectors. (Addition and subtraction are of course trivially just the addition and subtraction of the 4x4 matrix and the attached column vectors.)
quickfur
Pentonian
 
Posts: 3004
Joined: Thu Sep 02, 2004 11:20 pm
Location: The Great White North

Re: Rewriting 5x5 matrix multiplication in terms of 4x4 matr

Postby Challenger007 » Tue Jul 20, 2021 11:43 am

Is it possible to add a program code for processing 5x5 matrices?
Challenger007
Dionian
 
Posts: 32
Joined: Thu Nov 12, 2020 2:51 pm

Re: Rewriting 5x5 matrix multiplication in terms of 4x4 matr

Postby quickfur » Tue Jul 20, 2021 3:18 pm

Challenger007 wrote:Is it possible to add a program code for processing 5x5 matrices?

Of course. But it would be slower than if I used the built-in 4x4 matrix operations, which are likely hardware-accelerated.
quickfur
Pentonian
 
Posts: 3004
Joined: Thu Sep 02, 2004 11:20 pm
Location: The Great White North

Re: Rewriting 5x5 matrix multiplication in terms of 4x4 matr

Postby mr_e_man » Thu Nov 07, 2024 2:11 am

I think CodeParade did this for 4D Golf.
ΓΔΘΛΞΠΣΦΨΩ αβγδεζηθϑικλμνξοπρϱσςτυϕφχψωϖ °±∓½⅓⅔¼¾×÷†‡• ⁰¹²³⁴⁵⁶⁷⁸⁹⁺⁻⁼⁽⁾₀₁₂₃₄₅₆₇₈₉₊₋₌₍₎
ℕℤℚℝℂ∂¬∀∃∅∆∇∈∉∋∌∏∑ ∗∘∙√∛∜∝∞∧∨∩∪∫≅≈≟≠≡≤≥⊂⊃⊆⊇ ⊕⊖⊗⊘⊙⌈⌉⌊⌋⌜⌝⌞⌟〈〉⟨⟩
mr_e_man
Tetronian
 
Posts: 538
Joined: Tue Sep 18, 2018 4:10 am


Return to Programming

Who is online

Users browsing this forum: No registered users and 1 guest

cron