Multiply a 3D matrix with a 2D matrix

前端 未结 10 1309
盖世英雄少女心
盖世英雄少女心 2020-11-28 09:29

Suppose I have an AxBxC matrix X and a BxD matrix Y.

Is there a non-loop method by which I can multiply

10条回答
  •  孤独总比滥情好
    2020-11-28 09:47

    I highly recommend you use the MMX toolbox of matlab. It can multiply n-dimensional matrices as fast as possible.

    The advantages of MMX are:

    1. It is easy to use.
    2. Multiply n-dimensional matrices (actually it can multiply arrays of 2-D matrices)
    3. It performs other matrix operations (transpose, Quadratic Multiply, Chol decomposition and more)
    4. It uses C compiler and multi-thread computation for speed up.

    For this problem, you just need to write this command:

    C=mmx('mul',X,Y);
    

    here is a benchmark for all possible methods. For more detail refer to this question.

        1.6571 # FOR-loop
        4.3110 # ARRAYFUN
        3.3731 # NUM2CELL/FOR-loop/CELL2MAT
        2.9820 # NUM2CELL/CELLFUN/CELL2MAT
        0.0244 # Loop Unrolling
        0.0221 # MMX toolbox  <===================
    

提交回复
热议问题