I'm a physicist who's not particularly good at linear algebra so please accept my apologies if this is standard textbook stuff that I'm just unaware of.
I have two real rectangular matrices $A_{mxn} B_{mxn},$ where $m>n$ whose entries are $\pm1,0$. As a concrete example, take
$$ A = \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \\ 1 & -1 & 1 \\ 1 & 0 & 1 \end{bmatrix}, B = \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \\ 1 & -1& 0 \\ 1 & 0 & 1 \end{bmatrix} $$ My goal is to find matrices D, P, M such that B = DPAM, where P is a permutation matrix and D is a diagonal matrix with entries $\pm1$. For example, with A, B as above I can write $$ B = \begin{bmatrix} 1 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 0 & 1 \end{bmatrix}\begin{bmatrix} 0 & 0 & 0 & 0 & 1 \\ 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 0 & 1 \end{bmatrix} A \begin{bmatrix} 1 & 0 & -1 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix} $$
Essentially I want to find a linear transformation M such that when I form the product X=BM I obtain a matrix X which is just a row-permutation P of A. I also want to allow for the possibility that rows in PX will differ by an overall minus sign from the rows in A, so I introduce this diagonal matrix D.
In fact, I am not interesting in knowing the explicit details of the transformation (i.e. M). Given two matrices A,B I want to know whether the transformation exists and if it does, what is the determinant of D.
I'm a bit stumped so any help would be greatly appreciated.