示例#1
0
 private static void AssertCompatibleCore(ICpuMatrix mat, ICpuVector src, ICpuVector dst)
 {
     AssertCompatible(src);
     AssertCompatible(dst);
     Contracts.Assert(mat.ColCount == src.VectorSize);
     Contracts.Assert(mat.RowCount == dst.VectorSize);
 }
示例#2
0
        /// <summary>
        /// Assert the compatibility of the underlying AlignedArray for the input vector in terms of alignment amount.
        /// </summary>
        /// <param name="values">The input vector</param>
        public static void AssertCompatible(ICpuVector values)
        {
#if DEBUG
            CpuAlignedVector vec = values as CpuAlignedVector;
            Contracts.AssertValue(vec);
            Contracts.Assert(vec.Items.CbAlign == SseUtils.CbAlign);
#endif
        }
        /// <summary>
        /// Assert the compatibility of the underlying AlignedArray for the input vector in terms of alignment amount.
        /// </summary>
        /// <param name="values">The input vector</param>
        public static void AssertCompatible(ICpuVector values)
        {
#if DEBUG
            CpuAlignedVector vec = values as CpuAlignedVector;
            Contracts.AssertValue(vec);
            Contracts.Assert((vec.Items.CbAlign % CpuMathUtils.GetVectorAlignment()) == 0);
#endif
        }
示例#4
0
        /// <summary>
        /// Matrix multiplication:
        /// if (add)
        ///     dst = mat * src
        /// else
        ///     dest += mat * src
        /// </summary>
        /// <param name="add">The addition flag</param>
        /// <param name="mat">The multiplier matrix</param>
        /// <param name="src">The source vector</param>
        /// <param name="dst">The destination vector</param>
        public static void MatTimesSrc(bool add, ICpuFullMatrix mat, ICpuVector src, ICpuVector dst)
        {
            bool colMajor = typeof(TMatrix) == typeof(CpuAlignedMatrixCol);

            AssertCompatible(mat, src, dst);
            var m = A(mat);

            SseUtils.MatTimesSrc(colMajor, add, m.Items, A(src).Items, A(dst).Items, m.RunCnt);
        }
        /// <summary>
        /// Matrix transpose multiplication:
        /// dst = mat' * src
        /// </summary>
        /// <param name="mat">The multiplier matrix</param>
        /// <param name="src">The source vector</param>
        /// <param name="dst">The destination vector</param>
        public static void MatTranTimesSrc(ICpuFullMatrix mat, ICpuVector src, ICpuVector dst)
        {
            bool colMajor = typeof(TMatrix) == typeof(CpuAlignedMatrixCol);

            AssertCompatible(mat, dst, src);
            var m = A(mat);

            CpuMathUtils.MatrixTimesSource(!colMajor, m.Items, A(src).Items, A(dst).Items, m.RunCnt);
        }
示例#6
0
        /// <summary>
        /// Asserts the following:
        /// 1. The compatibility of the underlying AlignedArray for mat in terms of alignment amount.
        /// 2. The compatibility of the underlying AlignedArray for src in terms of alignment amount.
        /// 3. The compatibility of the underlying AlignedArray for dst in terms of alignment amount.
        /// 4. The compatibility of the matrix-vector multiplication mat * src = dst.
        /// </summary>
        /// <param name="mat"></param>
        /// <param name="src"></param>
        /// <param name="dst"></param>
        public static void AssertCompatible(ICpuFullMatrix mat, ICpuVector src, ICpuVector dst)
        {
            // Also check the physical sizes.
            AssertCompatible(mat);
            AssertCompatibleCore(mat, src, dst);
            var m = A(mat);

            Contracts.Assert(m.ColCountPhy == A(src).Items.Size);
            Contracts.Assert(m.RowCountPhy == A(dst).Items.Size);
        }
示例#7
0
 private static CpuAlignedVector A(ICpuVector x)
 {
     AssertCompatible(x);
     return((CpuAlignedVector)x);
 }