I am trying to multiply the sub-matrix of a large (2x2m) matrix together (2x2), "text" after
A" Vectorized "fashion to eliminate the loop and increase speed, currently I resize for one (2x2xm), use the loop for:
n = 1: 1e5m = 1e4; A = rand ([2.22 m)); % ANA = is a function of new shape (A, 2, 2, []); B = eye (2); I for = 1: ii B = A (:,:, i) * b; Multiply the length of the end of% 2x2 The function is similar to the target @prod, but with the matrix multiplication instead of the element-wise scalar multiplication. @Multiprod looks closer, but takes two different ND matrix in the form of logic.
Thank you in advance, which I imagine a solution using several submatrices of a very large 2D array, or one or both for one or both A 2x2m {xn} array to finish.
I think you have to differentiate differently to multiply your matrix with the vector, as in the code below. This code also uses the loop, but I think that should be fast
mm = magic (2); M = MM; M1 = rot 90 (mm, 1); M2 = rot 90 (mm, 2); M3 = rot 90 (MM, 3); MBig1 = Cat (2, M 0, M1, M2, M3); Fprintf ('original matrix \ n') disp (MBig1) MBig2 = zero (size (MBig1,2)); MBig2 (1: 2, :) = MBig1; For k = 0: 3 c1 = k * 2 + 1; C2 = (K + 1) * 2 + 0; MBig2 (:, c1: c2) = circuthify (MBIG2 (:, C1: C2), [2 * k0]); End fprintf ('new look original matrix \ n') disp (MBig2) fprintf ('Checking [M * M * M 0 * M1 M 0 * M2 M * M3] In Direct Path \ N' ) Disp ([M * M * M * M1 M * M2 M * M3]) fprintf ('Checking [M * M * M * M1 M * M2 M * M3] vectorized way \ n ') disp (kron (eye (4), m) * MBig2) fprintf (' checking [m0 * m1 * m2 * m3] in direct way \ n Disp ([M0 * M1 * M2 * M3]) fprintf ('Vector containing vector checking [M0 * M1 * M2 * M3] \ n') R2 = MBig2; For k = 1: 3 r2 = r2 * circuits (mbig 2, - [2 2] * k); And Disp (R2) Output is
Basic Matrix 1 3 3 2 2 4 4 1 4 2 1 4 3 1 2 3 Rehepad Original Matrix 1 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 1 0 0 0 0 0 2 3 Direct way 13 9 6 14 11 7 10 10 12 16 14 16 14 18 20 10 Checking is being checked in [M * M * M * M1 M * M2 M * M3] M * M * M * M1 M * M2 M * M3] vectorized way 13 9 0 0 0 0 0 12 16 0 0 0 0 0 0 0 6 14 0 0 0 0 0 0 14 16 0 0 0 0 0 0 0 11 7 0 0 0 0 0 14 18 0 0 0 0 0 0 0 0 10 10 0 0 0 0 0 20 10 Checking [M 0 * M1 * M2 * M3] Direct way 292 168 448 292 In Checking [M * M1 * M2 * M3] Vector way 292 168 0 0 0 0 448 292 0 0 0 0 0 292 336 0 0 0 0 224 292 0 0 0 0 0 0 292 448 0 0 0 0 168 292 0 0 0 0 0 292 224 0 0 0 0 336 292
No comments:
Post a Comment