Пример #1
0
        public void Solve()
        {
            ColumnWiseMatrix A = GetInvertibleMatrix(128);

            DeviceManager.CheckDeviceSanity();
            var _A = A.GetMatrix <float>();

            ColumnWiseMatrix B = GetInvertibleMatrix(128, 2345);

            DeviceManager.CheckDeviceSanity();
            var _B = B.GetMatrix <float>();

            A.Solve(B);
            DeviceManager.CheckDeviceSanity();
            var _x = B.Get <float>();

            var BSanity  = A.Multiply(B);
            var _BSanity = BSanity.GetMatrix <float>();

            for (int i = 0; i < A.nRows; ++i)
            {
                for (int j = 0; j < A.nCols; ++j)
                {
                    double expected = _B[i, j];
                    Assert.IsTrue(Math.Abs(_BSanity[i, j] - expected) <= 5e-5);
                }
            }
        }
Пример #2
0
        public void Invert()
        {
            ColumnWiseMatrix A = GetInvertibleMatrix(128);

            DeviceManager.CheckDeviceSanity();

            ColumnWiseMatrix AMinus1 = new ColumnWiseMatrix(A);

            AMinus1.Invert();
            DeviceManager.CheckDeviceSanity();

            var eye      = A.Multiply(AMinus1);
            var _eye     = eye.GetMatrix <float>();
            var _A       = A.GetMatrix <float>();
            var _AMinus1 = AMinus1.GetMatrix <float>();

            for (int i = 0; i < A.nRows; ++i)
            {
                for (int j = 0; j < A.nCols; ++j)
                {
                    double expected = i == j ? 1.0 : 0.0;
                    Assert.IsTrue(Math.Abs(_eye[i, j] - expected) <= 5e-5);
                }
            }
        }