Ejemplo n.º 1
0
        public void KroneckerProduct()
        {
            Vector u = new Vector(128, 0.01);

            DeviceManager.CheckDeviceSanity();
            var _u = u.Get <float>();

            Vector v = new Vector(64, 0.02);

            DeviceManager.CheckDeviceSanity();
            var _v = v.Get <float>();

            var A = ColumnWiseMatrix.KroneckerProduct(u, v, 2.0);

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

            for (int i = 0; i < A.nRows; ++i)
            {
                for (int j = 0; j < A.nCols; ++j)
                {
                    double expected = 2.0 * _u[i] * _v[j];
                    double err      = Math.Abs(expected - _A[i, j]);
                    Assert.IsTrue(err <= 5e-4, String.Format("i({0}) j({1}) err({2})", i, j, err));
                }
            }
        }