sgorsten / linalg

linalg.h is a single header, public domain, short vector math library for C++
The Unlicense
849 stars 68 forks source link

Impossible to create row vectors #17

Closed LudwikJaniuk closed 3 years ago

LudwikJaniuk commented 5 years ago

mat<T, 1, N> is not defined. transpose(vec<T, 3>()) does not work. I see no way to construct row vectors. But then, how do I multiply something with a row vector specifically?

sgorsten commented 5 years ago

vec<T,1> and mat<T,1,N> are defined in the v3 branch.

For the time being, since mul(v, m) isn't available, you can use mul(transpose(m), v) as a workaround.

I'm going to keep this issue open nonetheless to remind myself to implement the (row-)vector * matrix in the v3 branch. Thank you for your interest in linalg.

LudwikJaniuk commented 5 years ago

Great! I will use that branch for now. Linalg is fantastic for being so easy to use, but I was expecting it to be generic in dimensions. Will be waiting for that.

On Sat, 17 Nov 2018, 06:42 Sterling Orsten, notifications@github.com wrote:

vec<T,1> and mat<T,1,N> are defined in the v3 branch.

For the time being, since mul(v, m) isn't available, you can use mul(transpose(m), v) as a workaround.

I'm going to keep this issue open nonetheless to remind myself to implement the (row-)vector * matrix in the v3 branch. Thank you for your interest in linalg.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/sgorsten/linalg/issues/17#issuecomment-439590457, or mute the thread https://github.com/notifications/unsubscribe-auth/AGAbGaWec8T59fH06wvmKBsh1NDsb8p5ks5uv6GzgaJpZM4YnGkH .

LudwikJaniuk commented 5 years ago

Is it just me or is matrix multiplication missing from v3 tho?

sgorsten commented 3 years ago

Ah, looks like I forgot to follow up with you on this. My apologies.

I wound up back-porting most of the interesting functionality from the v3 branch onto v2 some time ago in a backwards-compatible way. Among this functionality was the vec<T,1> and mat<T,M,1> specializations needed for this sort of functionality.

For the time being, however, I think I will continue to omit vector x matrix multiplications. There are several parts of linalg, notably the matrix factory functions and the functions for round-tripping between rotation matrices and quaternions, which assume that transformations will be performed using column vectors. As I don't have a good mechanism in place to explicitly mark which functions depend on column semantics and which do not, it feels semantically clearest to continue to treat vec<T,M> as equivalent to mat<T,M,1> when it comes to matrix multiplication, etc.

However, there's nothing inconsistent about treating vec<T,M> the same way for the transpose(...) function, so I've added that overload. If you require row-vector x matrix multiplication for whatever reason, mul(tranpose(v), m) will carry out the desired operation, though it will yield a result which is a single-row matrix.

LudwikJaniuk commented 3 years ago

Thanks for following up :) Hopefully it will be useful for someone, even as I've personally moved on.