Beispiel #1
0
        public static BlockMatrix <N, double> Pow <N>(this BlockMatrix <N, double> A, int exp)
            where N : ITypeNat, new()
        {
            if (exp == 1)
            {
                return(A);
            }

            var B = A.Replicate();
            var X = BlockMatrix.Alloc <N, double>();

            mkl.gemm(A, B, ref X);
            if (exp == 2)
            {
                return(X);
            }

            var i = exp;

            while (--i > 2)
            {
                mkl.gemm(X, X, ref X);
            }

            return(X);
        }
Beispiel #2
0
        /// <summary>
        /// Creates a complete multiplication table
        /// </summary>
        /// <param name="min">The minimum operand value</param>
        /// <param name="max">The maximum operand value</param>
        public static BlockMatrix <N7, byte> products()
        {
            var dst = BlockMatrix.Alloc <N7, byte>();

            products(1, (byte)0b111, ref dst.Unblocked[0]);
            return(dst);
        }
Beispiel #3
0
        /// <summary>
        /// Creates an N^2 multiplication table for the values [1...N]
        /// </summary>
        /// <typeparam name="N">The table order</typeparam>
        public static BlockMatrix <N, ushort> products <N>(N n = default)
            where N : ITypeNat, new()
        {
            var dst = BlockMatrix.Alloc <N, ushort>();

            products(1, (ushort)n.value, ref dst.Unblocked[0]);
            return(dst);
        }
Beispiel #4
0
        public static BlockMatrix <M, N, T> Mul <M, K, N, T>(BlockMatrix <M, K, T> A, BlockMatrix <K, N, T> B)
            where M : ITypeNat, new()
            where K : ITypeNat, new()
            where N : ITypeNat, new()
            where T : unmanaged
        {
            var X = BlockMatrix.Alloc <M, N, T>();

            Mul(A, B, ref X);
            return(X);
        }
Beispiel #5
0
 /// <summary>
 /// Computes the full multiplication table for GF512
 /// </summary>
 /// <param name="dst">The target matrix</param>
 public static ref BlockMatrix <N512, ushort> products(out BlockMatrix <N512, ushort> dst)
 {
     dst = BlockMatrix.Alloc <N512, ushort>();
     for (ushort i = 1; i < 512; i++)
     {
         for (ushort j = 1; j < 512; j++)
         {
             dst[i, j] = Gf512.mul(i, j);
         }
     }
     return(ref dst);
 }
Beispiel #6
0
 /// <summary>
 /// Computes the full multiplication table for GF256
 /// </summary>
 /// <param name="dst">The target matrix</param>
 public static ref BlockMatrix <N256, byte> products(out BlockMatrix <N256, byte> dst)
 {
     dst = BlockMatrix.Alloc <N256, byte>();
     for (uint i = 1; i < 256; i++)
     {
         for (uint j = 1; j < 256; j++)
         {
             dst[i, j] = Gf256.mul((byte)i, (byte)j);
         }
     }
     return(ref dst);
 }
Beispiel #7
0
        void MarkovMatrix <N, T>(int count, N n = default, T rep = default)
            where N : ITypeNat, new()
            where T : struct
        {
            var tol    = .0001;
            var radius = closed(1 - tol, 1 + tol);
            var m      = BlockMatrix.Alloc(n, rep);

            for (var i = 0; i < count; i++)
            {
                Random.MarkovMat(ref m);
                VerifyRightStochastic(m);
            }
        }
Beispiel #8
0
        public static BlockMatrix <N, T> Map <N, S, T>(this BlockMatrix <N, S> A, Func <S, T> f)
            where N : ITypeNat, new()
            where T : struct
            where S : struct
        {
            var src  = A.Unblocked;
            var dstM = BlockMatrix.Alloc <N, T>();
            var dst  = dstM.Unblocked;

            for (var i = 0; i < dst.Length; i++)
            {
                dst[i] = f(src[i]);
            }
            return(dstM);
        }
Beispiel #9
0
        void MarkovMatMulF64 <N>(int count, N n = default)
            where N : ITypeNat, new()
        {
            var m1 = BlockMatrix.Alloc(n, 0d);
            var m2 = BlockMatrix.Alloc(n, 0d);
            var m3 = BlockMatrix.Alloc(n, 0d);

            for (var i = 0; i < count; i++)
            {
                Random.MarkovMat(ref m1);
                Random.MarkovMat(ref m2);
                m1.Mul(m2, ref m3);
                VerifyRightStochastic(m3);
            }
        }