From: yu.dongliang <18588496441@163.com> Date: Sun, 1 Sep 2024 18:50:43 +0000 (+0800) Subject: mat_mul_strassen() X-Git-Url: http://baseworks.info/?a=commitdiff_plain;h=5722b589e37c7df39fa63cfae3dcd1913798a158;p=mat.git mat_mul_strassen() --- diff --git a/mat.c b/mat.c index 91d572a..64c9f99 100644 --- a/mat.c +++ b/mat.c @@ -258,45 +258,50 @@ void mat_mul_strassen(mat_t* m, mat_t* m0, mat_t* m1, int n_min) mat_mul_strassen(p3, t0, e, n_min); mat_sub(u, p1, p3); - mat_free(p1); // p4 = d * (g - e) - mat_t* p4 = mat_alloc(0, 0, n, NULL); + mat_t* p4 = p1; + p1 = NULL; + mat_sub(t0, g, e); mat_mul_strassen(p4, d, t0, n_min); // t = p3 + p4 mat_add(t, p3, p4); - mat_sub(r, p4, p2); - mat_free(p2); - mat_free(p3); - mat_free(p4); - +// mat_free(p2); +// mat_free(p3); +// mat_free(p4); // tmp mat t1 - mat_t* t1 = mat_alloc(0, 0, n, NULL); + mat_t* t1 = p2; + mat_t* p5 = p3; + mat_t* p6 = p4; + p2 = NULL; + p3 = NULL; + p4 = NULL; //p5 = (a + d) * (e + h) - mat_t* p5 = mat_alloc(0, 0, n, NULL); mat_add(t0, a, d); mat_add(t1, e, h); mat_mul_strassen(p5, t0, t1, n_min); + //p6 = (b - d) * (g + h) - mat_t* p6 = mat_alloc(0, 0, n, NULL); mat_sub(t0, b, d); mat_add(t1, g, h); mat_mul_strassen(p6, t0, t1, n_min); + // r = p5 + p4 - p2 + p6 mat_add(r, r, p5); mat_add(r, r, p6); - mat_free(p6); - //p7 = (a - c) * (e + f) - mat_t* p7 = mat_alloc(0, 0, n, NULL); + mat_t* p7 = p6; + p6 = NULL; + mat_sub(t0, a, c); mat_add(t1, e, f); mat_mul_strassen(p7, t0, t1, n_min); + // u = p5 + p1 -p3 -p7 mat_add(u, u, p5); mat_sub(u, u, p7);