This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Dot Product of matrices with unmatching lengths

Tags: None
(comma "," separated)
krisrose
Registered Member
Posts
6
Karma
0
Hi,

A quick question.

Is it possible to do a dot product of two matrices who follow the standard matrix multiplication rule of (nx4) * (4xn) but have an un matching amount of rows(n) and columns(n)?

My attempts so far have thrown Block, size == other.size() and Rhs != Lhs assertion failures depnding on the various methods used.

In python this code would roughly be and hss no issues working on unmatching rows and columns.

dot(e * d, j)

Thanks in advance,

Kris
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
What do you mean by "an un matching amount of rows(n) and columns(n)" ?? If you mean a product like: (6x4) * (4x9) then that's of course perfectly possible. Please show the failing line of code.
krisrose
Registered Member
Posts
6
Karma
0
Hi sorry,

Here is the offending method, I am fairly new to Eigen and C++ so have many dumb quesitons like this. :)

This is what makes sense to me when I think about what I am trying to achieve. The reconstructed matrix (recon) column(i) contains the products of every row & column in wZ and h at the current index(i).

wZ dimensions = (188x4)
h dimensions = (4x14838)

but we are taking one column and row at a time so (188x1) and (1x14838).

MatrixXd reconstruct(MatrixXd w, MatrixXd h, VectorXd z){

//reconstruct
MatrixXd wZ = w * z;
MatrixXd recon;

for (int i = 0; i < z.rows(); ++i){
wZ.transposeInPlace();
recon.col(i) = (wZ.col(i)).dot(h.row(i));

}

return recon;
}

Thanks for the help,

Kris
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
I still don't get it as there are too numerous flaws in your code:
- recon must be properly sized before filling it, like MatrixXd recon(rows,cols);
- wZ is transposed at each iterations, so you are taking a row/column for odd/even iterations...
- you do not need to transpose wZ at all, just use .row or .col
- .dot() performs a scalar product, it takes two vectors of the same length and return the sum of the pair-wise product of the coefficients. So it returns a scalar that you try to assign to a column vector...
- if you want to perform products like (188x1) * (1x14838), then this is called a outer product. In Eigen syntax, this is accomplished by: wZ.col(i) * h.row(i) .This returns a 188x14838. Again, this is not a vector, so it cannot be assigned to a column vector...


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]