예제 #1
0
        public void Multiply_MultiplyTwoTuples_EqualsExpectedTuple <T, TRing> (
            T hackForGenericParameter1,
            TRing hackForGenericParameter2,
            IDirectSum <T, TRing> tuple1,
            IDirectSum <T, TRing> tuple2,
            IDirectSum <T, TRing> expectedTuple)
            where TRing : IRing <T>, new()
        {
            var result = tuple1.Multiply(tuple2);

            Assert.AreEqual(expectedTuple, result);
        }
        /// <summary>
        /// Multiplies the vector power times.
        /// Multiplies the vector with itself power times.
        /// </summary>
        /// <param name="tuple">The vector.</param>
        /// <param name="power">The power.</param>
        /// <typeparam name="T">The type parameter.</typeparam>
        /// <typeparam name="TRing">The underlying structure.</typeparam>
        /// <returns>The vector^power.</returns>
        public static IDirectSum <T, TRing> Pow <T, TRing> (
            this IDirectSum <T, TRing> tuple,
            UInt32 power)
            where TRing : IRing <T>, new()
        {
            var result = tuple.ReturnNewInstance(tuple.Dimension);
            var ring   = new TRing();

            for (UInt32 i = 0; i < result.Dimension; i++)
            {
                result[i] = ring.One;
            }

            for (UInt32 i = 0; i < power; i++)
            {
                result = tuple.Multiply(result);
            }

            return(result);
        }