Пример #1
0
        /// <summary>
        /// Strassen のアルゴリズムで行列の積を求める。
        /// </summary>
        public static ArrayMatrix <StaticModInt <T>, StaticModIntOperator <T> > Strassen <T>(
            this ArrayMatrix <StaticModInt <T>, StaticModIntOperator <T> > mat1,
            ArrayMatrix <StaticModInt <T>, StaticModIntOperator <T> > mat2) where T : struct, IStaticMod
        {
            if (mat1.kind != ArrayMatrixKind.Normal || mat2.kind != ArrayMatrixKind.Normal)
            {
                return(mat1 * mat2);
            }

            var impl = new Impl <T>(Math.Max(Math.Max(mat1.Value.Length, mat2.Value.Length), Math.Max(mat1.Value[0].Length, mat2.Value[0].Length)));
            var rt   = impl.Strassen(mat1.Value, mat2.Value);

            return(new ArrayMatrix <StaticModInt <T>, StaticModIntOperator <T> >(rt));
        }
Пример #2
0
        private ArrayMatrix <T, TOp> Add(ArrayMatrix <T, TOp> other)
        {
            Contract.Assert(Value.Length == other.Value.Length);
            Contract.Assert(Value[0].Length == other.Value[0].Length);
            var otherArr = other.Value;
            var arr      = CloneArray(Value);

            for (int i = 0; i < arr.Length; i++)
            {
                for (int j = 0; j < arr[i].Length; j++)
                {
                    arr[i][j] = op.Add(arr[i][j], otherArr[i][j]);
                }
            }
            return(new ArrayMatrix <T, TOp>(arr));
        }