예제 #1
0
        public void AddMatrix()
        {
            ColumnWiseMatrix m1 = ColumnWiseMatrix.LinSpace(100, 20, -1.0, 1.0);

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

            ColumnWiseMatrix m2 = ColumnWiseMatrix.RandomGaussian(m1.nRows, m1.nCols, 1234);

            DeviceManager.CheckDeviceSanity();
            var _m2 = m2.GetMatrix <float>();

            var m3 = m1 + m2;

            DeviceManager.CheckDeviceSanity();
            var _m3 = m3.GetMatrix <float>();

            for (int i = 0; i < m1.nRows; ++i)
            {
                for (int j = 0; j < m1.nCols; ++j)
                {
                    Assert.IsTrue(Math.Abs(_m3[i, j] - _m1[i, j] - _m2[i, j]) <= 3e-7, String.Format("i({0}) j({1}) err({2})", i, j, Math.Abs(_m3[i, j] - _m1[i, j] - _m2[i, j])));
                }
            }

            var m4 = ColumnWiseMatrix.Add(m1, m2, alpha: 2.0);

            DeviceManager.CheckDeviceSanity();
            var _m4 = m4.GetMatrix <float>();

            for (int i = 0; i < m1.nRows; ++i)
            {
                for (int j = 0; j < m1.nCols; ++j)
                {
                    Assert.IsTrue(Math.Abs(_m4[i, j] - _m1[i, j] - 2.0 * _m2[i, j]) <= 5e-7, String.Format("i({0}) j({1}) err({2})", i, j, Math.Abs(_m4[i, j] - _m1[i, j] - 2.0 * _m2[i, j])));
                }
            }
        }