Example #1
0
            public              StaticModInt <T>[][] Strassen(StaticModInt <T>[][] mat1, StaticModInt <T>[][] mat2)
            {
                Contract.Assert(default(T).Mod % 2 == 1);
                Contract.Assert(mat1.Length <= S);
                Contract.Assert(mat2.Length <= S);
                Contract.Assert(mat1[0].Length <= S);
                Contract.Assert(mat2[0].Length <= S);
                var a = ToVectorize(mat1);
                var b = ToVectorize(mat2);
                var c = new VectorizedStaticModInt <T> [S8 * S];

                var s = new VectorizedStaticModInt <T> [S8 * S * 3 / 2];
                var t = new VectorizedStaticModInt <T> [S8 * S * 3 / 2];
                var u = new VectorizedStaticModInt <T> [S8 * S * 3 / 2];

                PlaceS(S, 0, 0, s.AsSpan(), a);
                PlaceT(S, 0, 0, t.AsSpan(), b);
                for (int i = 0; i < S * S8; i++)
                {
                    s[i] = s[i].Itom();
                }
                for (int i = 0; i < S * S8; i++)
                {
                    t[i] = t[i].Itom();
                }

                StrassenImpl(S, s, t, u.AsSpan());

                for (int i = 0; i < S * S8; i++)
                {
                    u[i] = u[i].Mtoi();
                }
                PlaceRev(S, 0, 0, u.AsSpan(), c);
                return(ToMatrix(c, mat1.Length, mat2[0].Length));
            }