Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Right-multiplication by permutation matrix is inconsistent with representation #198

Open
gvissers opened this issue Jul 24, 2018 · 0 comments

Comments

@gvissers
Copy link

Right multiplication of a matrix by a permutation permutes the columns of said matrix. The permutation that is performed however, corresponds to the transpose (inverse) of the permutation matrix, which leads to unexpected results. Consider the simple sample program:

extern crate rulinalg;

fn main()
{
    let p = rulinalg::matrix::PermutationMatrix::from_array(vec![1, 2, 0]).unwrap();
    let i = rulinalg::matrix::Matrix::<u32>::identity(3);

    println!("p.as_matrix() =\n{}", p.as_matrix());
    println!("p*i =\n{}", &p * &i);
    println!("i*p =\n{}", &i * &p);
}

The output of this program is

p.as_matrix() =
⎡0 0 1⎤
⎢1 0 0⎥
⎣0 1 0⎦
p*i =
⎡0 0 1⎤
⎢1 0 0⎥
⎣0 1 0⎦
i*p =
⎡0 1 0⎤
⎢0 0 1⎥
⎣1 0 0⎦

So left multiplying the identity matrix by a permutation gives its matrix representation (as per as_matrix()), but right multiplication results in the transpose matrix.

I can see how this happens (the same permutation is simply applied to the columns when right-multiplying), but for matrix multiplication this is not what I would expect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant