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

Problem multiplying element by element two matrices

Tags: None
(comma "," separated)
jsanz
Registered Member
Posts
9
Karma
0
OS
Hello everyone,

I have to matrices I want to multiply element by element. The matrix A with dimensions 128x60 and the matrix B with dimensions is 7680x1 (as you might notice 7680=128x60). The thing is that when I do this in debug
Code: Select all
 A.array() * B.array()

An assert is raised saying the dimensions do not match.

Digging on the web and having a look to eigen API I have found two possible solutions.
  • The first approach is to do some resizing. I can't resize A because is a constant member of a class and making such a thing will make my code not thread safe (it is being used as a matrix in other places). I can resize B but then I have to resize it back to its original size. This could be an option.
  • The second solution is creating a Map with the size i like. This way I don't have to resize it back the matrix. So doing
    Code: Select all
    Map<Matrix> mapA (A.data, A.rows()*A.cols(), 1)

    This is working and is the thing i am doing right now

So my question is, Is there a more elegant way to achieve this?

Last edited by jsanz on Wed Sep 17, 2014 8:12 am, edited 1 time in total.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
No better solution yet, but at some point we should offer a reshape and 'view as vector' feature.
jsanz
Registered Member
Posts
9
Karma
0
OS
Good to know.

Thanks Gael for you quick answer.


Bookmarks



Who is online

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