Ejemplo n.º 1
0
        public void LinSpace()
        {
            var m = ColumnWiseMatrix.LinSpace(10, 5, 0.0, 1.0);

            DeviceManager.CheckDeviceSanity();

            var _m = m.Get <float>();

            Assert.IsTrue(System.Math.Abs(_m[0] - 0.0) <= 1e-7);
            Assert.IsTrue(System.Math.Abs(_m[_m.Count - 1] - 1.0) <= 1e-7);
        }
Ejemplo n.º 2
0
        public void ColumnWiseArgAbsoluteMinMax()
        {
            ColumnWiseMatrix A = ColumnWiseMatrix.LinSpace(128, 64, -1, 1);
            var _A             = A.GetMatrix <float>();

            var min = A.ColumnWiseAbsoluteMinimumIndex().GetRaw <int>();
            var max = A.ColumnWiseAbsoluteMaximumIndex().GetRaw <int>();

            int[] _min = new int[A.nCols];
            int[] _max = new int[A.nCols];
            for (int j = 0; j < A.nCols; j++)
            {
                _min[j] = _A.Column(j).AbsoluteMinimumIndex();
                _max[j] = _A.Column(j).AbsoluteMaximumIndex();

                Assert.AreEqual(min[j] - 1, _min[j]);
                Assert.AreEqual(max[j] - 1, _max[j]);
            }
        }
Ejemplo n.º 3
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])));
                }
            }
        }