Ejemplo n.º 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);
                }
            }
        }
Ejemplo n.º 2
0
        public void SetColumn()
        {
            var m1 = new ColumnWiseMatrix(10, 5, 1.2345f);

            m1.Print();
            DeviceManager.CheckDeviceSanity();
            var _m1 = m1.Get <float>();

            var v1 = new Vector(10, 2.3456f);

            v1.Print();
            DeviceManager.CheckDeviceSanity();
            var _v1 = v1.Get <float>();

            m1.Set(v1, 3);

            for (int j = 0; j < m1.nCols; ++j)
            {
                var col = m1.Get <float>(j);
                DeviceManager.CheckDeviceSanity();

                Assert.AreEqual(col.Count, m1.nRows);
                if (j != 3)
                {
                    for (int i = 0; i < m1.nRows; ++i)
                    {
                        Assert.IsTrue(Math.Abs(col[i] - _m1[i + m1.nRows * j]) <= 1e-7);
                    }
                }
                else
                {
                    for (int i = 0; i < m1.nRows; ++i)
                    {
                        Assert.IsTrue(Math.Abs(col[i] - _v1[i]) <= 1e-7);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public void GetColumn()
        {
            var m1 = new ColumnWiseMatrix(10, 5, 1.2345f);

            m1.Print();
            DeviceManager.CheckDeviceSanity();

            for (int j = 0; j < m1.nCols; ++j)
            {
                var col = m1.Get <float>(j);
                DeviceManager.CheckDeviceSanity();

                Assert.AreEqual(col.Count, m1.nRows);
                for (int i = 0; i < m1.nRows; ++i)
                {
                    Assert.IsTrue(Math.Abs(col[i] - 1.2345f) <= 1e-7);
                }
            }
        }