strassen

Strassen Vinograd Algorithm

牧云@^-^@ 提交于 2020-01-13 18:10:48
问题 I got a task to write a Strassen Vinograd algorithm in C++. I have written it twice, but first version of my code don't even works. The result is correct in the lower left corner of result matrix. And my second version is running slower than naive algorithm, even with N = 64+. So i need help, what am i doing wrong? Important note: i'm not allowed to use dinamic matrix in recursion and structures. In addition it is better to do the multiplication without copying, using the coordinates of the

Strassen Vinograd Algorithm

落爺英雄遲暮 提交于 2020-01-13 18:08:31
问题 I got a task to write a Strassen Vinograd algorithm in C++. I have written it twice, but first version of my code don't even works. The result is correct in the lower left corner of result matrix. And my second version is running slower than naive algorithm, even with N = 64+. So i need help, what am i doing wrong? Important note: i'm not allowed to use dinamic matrix in recursion and structures. In addition it is better to do the multiplication without copying, using the coordinates of the

Why is my Strassen Matrix multiplier so fast?

允我心安 提交于 2019-12-23 03:26:07
问题 As an experiment I implemented the Strassen Matrix Multiplication Algorithm to see if truly lead to faster code for large n. https://github.com/wcochran/strassen_multiplier/blob/master/mm.c To my surprise it was way faster for large n. For example, the n=1024 case took 17.20 seconds using the conventional method whereas it only took 1.13 seconds using the Strassen method (2x2.66 GHz Xeon). What -- a 15x speedup!? It should only be marginally faster. In fact, it seemed to be as good for even

Recursion in Strassen's Algorithm

纵然是瞬间 提交于 2019-12-22 18:37:17
问题 I'm wondering how you would make the recursive calls in Strassen's algorithm, and where exactly they're required. I understand that the 7 multipliers is more efficient than the 8 we would have otherwise, but I'm confused as to how these multipliers are calculated recursively. In particular, if we are following the divide and conquer paradigm, exactly which part of the matrices are we "dividing" and how are we going about doing that until we get to a base case in which we can conquer the

How to split a matrix into 4 blocks using numpy?

孤街浪徒 提交于 2019-12-18 04:45:07
问题 I'm implementing Strassen's Matrix Multiplication using python. In divide step, we divide a larger matrix into smaller sub-matrices. Is there a built-in numpy function to split a matrix? 回答1: Not exactly, but using array slicing notation you should be able to do it yourself pretty easily. >>> A = np.linspace(0,24,25).reshape([5,5,]) >>> A array([[ 0., 1., 2., 3., 4.], [ 5., 6., 7., 8., 9.], [ 10., 11., 12., 13., 14.], [ 15., 16., 17., 18., 19.], [ 20., 21., 22., 23., 24.]]) Make B the top

Strassen's algorithm for matrix multiplication

自闭症网瘾萝莉.ら 提交于 2019-12-17 22:05:39
问题 Can someone please explain strassen's algorithm for matrix multiplication in an intuitive way? I've gone through (well, tried to go through) the explanation in the book and wiki but it's not clicking upstairs. Any links on the web that use a lot of English rather than formal notation etc. would be helpful, too. Are there any analogies which might help me build this algorithm from scratch without having to memorize it? 回答1: Consider multiplying two 2x2 matrices, as follows: A B * E F = AE+BG

how to split matrix into 4 quadrants in python using numpy

六眼飞鱼酱① 提交于 2019-12-11 09:43:56
问题 I'm new to Python. I'm trying to implement Strassen's Algorithm. The size of the matrix will always be a power of 2 in my implementation. So, how do I divide the matrix into 4 equal sized quadrants? Thanks 回答1: >>> xs = np.arange(16) >>> xs array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) >>> xs.reshape(4, 4) array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11], [12, 13, 14, 15]]) >>> xs = xs.reshape(4, 4) >>> a, b, c, d = xs[:2, :2], xs[2:, :2], xs[:2, 2:], xs[2:, 2:] >>> print

Recursion in Strassen's Algorithm

半世苍凉 提交于 2019-12-06 04:48:10
I'm wondering how you would make the recursive calls in Strassen's algorithm, and where exactly they're required. I understand that the 7 multipliers is more efficient than the 8 we would have otherwise, but I'm confused as to how these multipliers are calculated recursively. In particular, if we are following the divide and conquer paradigm, exactly which part of the matrices are we "dividing" and how are we going about doing that until we get to a base case in which we can conquer the recursive parts separately? Thank you! We make recursive calls while calculating these 7 multipliers. At

Strassen Vinograd Algorithm

我与影子孤独终老i 提交于 2019-12-05 20:23:38
I got a task to write a Strassen Vinograd algorithm in C++. I have written it twice, but first version of my code don't even works. The result is correct in the lower left corner of result matrix. And my second version is running slower than naive algorithm, even with N = 64+. So i need help, what am i doing wrong? Important note: i'm not allowed to use dinamic matrix in recursion and structures. In addition it is better to do the multiplication without copying, using the coordinates of the corner element of the submatrices. Incorrect: #include "pch.h" #include<iostream> #include<cstdio>

Matrix multiplication: Strassen vs. Standard

风格不统一 提交于 2019-12-03 13:49:07
问题 I tried to implement the Strassen algorithm for matrix multiplication with C++, but the result isn't that, what I expected. As you can see strassen always takes more time then standard implementation and only with a dimension from a power of 2 is as fast as standard implementation. What went wrong? matrix mult_strassen(matrix a, matrix b) { if (a.dim() <= cut) return mult_std(a, b); matrix a11 = get_part(0, 0, a); matrix a12 = get_part(0, 1, a); matrix a21 = get_part(1, 0, a); matrix a22 =