예제 #1
0
파일: structarr.cs 프로젝트: z77ma/runtime
    public static void Init2DMatrix(out ArrayStruct m, out int[][] refm)
    {
        int i, j, temp;

        i = 0;

        m    = new ArrayStruct(size);
        refm = new int[size][];

        for (int k = 0; k < refm.Length; k++)
        {
            refm[k] = new int[size];
        }

        while (i < size)
        {
            j = 0;
            while (j < size)
            {
                temp        = rand.Next();
                m.a2d[i, j] = temp - (temp / 120) * 120 - 60;
                refm[i][j]  = temp - (temp / 120) * 120 - 60;
                j++;
            }
            i++;
        }
    }
예제 #2
0
        public void TestFixedLenghtArrays()
        {
            FlatBufferBuilder builder = new FlatBufferBuilder(100);

            float a;

            int[] b = new int[15];
            sbyte c;

            int[,]  d_a = new int[2, 2];
            TestEnum[] d_b = new TestEnum[2];
            TestEnum[,] d_c = new TestEnum[2, 2];

            a = 0.5f;
            for (int i = 0; i < 15; i++)
            {
                b[i] = i;
            }
            c         = 1;
            d_a[0, 0] = 1;
            d_a[0, 1] = 2;
            d_a[1, 0] = 3;
            d_a[1, 1] = 4;
            d_b[0]    = TestEnum.B;
            d_b[1]    = TestEnum.C;
            d_c[0, 0] = TestEnum.A;
            d_c[0, 1] = TestEnum.B;
            d_c[1, 0] = TestEnum.C;
            d_c[1, 1] = TestEnum.B;

            Offset <ArrayStruct> arrayOffset = ArrayStruct.CreateArrayStruct(
                builder, a, b, c, d_a, d_b, d_c);

            // Create a table with the ArrayStruct.
            ArrayTable.StartArrayTable(builder);
            ArrayTable.AddA(builder, arrayOffset);
            Offset <ArrayTable> tableOffset = ArrayTable.EndArrayTable(builder);

            ArrayTable.FinishArrayTableBuffer(builder, tableOffset);

            ArrayTable table = ArrayTable.GetRootAsArrayTable(builder.DataBuffer);

            Assert.AreEqual(table.A?.A, 0.5f);
            for (int i = 0; i < 15; i++)
            {
                Assert.AreEqual(table.A?.B(i), i);
            }
            Assert.AreEqual(table.A?.C, (sbyte)1);
            Assert.AreEqual(table.A?.D(0).A(0), 1);
            Assert.AreEqual(table.A?.D(0).A(1), 2);
            Assert.AreEqual(table.A?.D(1).A(0), 3);
            Assert.AreEqual(table.A?.D(1).A(1), 4);
            Assert.AreEqual(table.A?.D(0).B, TestEnum.B);
            Assert.AreEqual(table.A?.D(1).B, TestEnum.C);
            Assert.AreEqual(table.A?.D(0).C(0), TestEnum.A);
            Assert.AreEqual(table.A?.D(0).C(1), TestEnum.B);
            Assert.AreEqual(table.A?.D(1).C(0), TestEnum.C);
            Assert.AreEqual(table.A?.D(1).C(1), TestEnum.B);
        }
예제 #3
0
        public WlArray()
        {
            ArrayStruct astruct = new ArrayStruct();

            array = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(ArrayStruct)));
            Marshal.StructureToPtr(astruct, array, false);
            wl_array_init(array);
        }
예제 #4
0
 public static void InnerProduct2D(out int res, ref ArrayStruct a2d, ref ArrayStruct b, int row, int col)
 {
     int i;
     res = 0;
     i = 0;
     while (i < size)
     {
         res = res + a2d.a2d[row, i] * b.a2d[i, col];
         i++;
     }
 }
예제 #5
0
파일: structarr.cs 프로젝트: z77ma/runtime
    public static void InnerProduct3D(out int res, ref ArrayStruct a3d, ref ArrayStruct b, int row, int col)
    {
        int i;

        res = 0;
        i   = 0;
        while (i < size)
        {
            res = res + a3d.a3d[row, size - 2, i] * b.a3d[i, size - 2, col];
            i++;
        }
    }
예제 #6
0
        public void ReadArrayTStructTest()
        {
            MemoryBufferAddressSpace dataSource = new MemoryBufferAddressSpace(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 });
            Reader      reader = new Reader(dataSource);
            ArrayStruct s      = reader.Read <ArrayStruct>(1);

            Assert.Equal(3, s.array.Length);
            Assert.Equal(0x0302, s.array[0]);
            Assert.Equal(0x0504, s.array[1]);
            Assert.Equal(0x0706, s.array[2]);
            Assert.Equal(0x0d0c0b0a, s.X);
        }
예제 #7
0
파일: structarr.cs 프로젝트: z77ma/runtime
    public static void InnerProduct2D(out int res, ref ArrayStruct a2d, ref ArrayStruct b, int row, int col)
    {
        int i;

        res = 0;
        i   = 0;
        while (i < size)
        {
            res = res + a2d.a2d[row, i] * b.a2d[i, col];
            i++;
        }
    }
예제 #8
0
        ArrayStruct ConvertArray(Array arr)
        {
            ArrayStruct array = new ArrayStruct();
            Type        t     = arr.GetType().GetElementType();

            array.NativeElementType = GetTypeMarker(t);
            array.ElementType       = GetTypeRef(t);
            array.Values            = new ValueStruct[arr.Length];
            for (int i = 0; i < arr.Length; i++)
            {
                array.Values[i] = Convert(arr.GetValue(i));
            }
            return(array);
        }
예제 #9
0
        void WriteArray(ArrayStruct array)
        {
            TypeStruct ts = types.GetValue(array.ElementType);

            writer.Write((byte)array.NativeElementType);
            WriteVInt(array.ElementType);
            WriteVInt((uint)array.Values.Length);
            bool b = !TypeMarkerUtil.IsFinal(array.NativeElementType);

            foreach (var x in array.Values)
            {
                WriteValue(x, b);
            }
        }
예제 #10
0
    public static void Init3DMatrix(ref ArrayStruct m, int[][] refm)
    {
        int i, j, temp;
        i = 0;

        while (i < size)
        {
            j = 0;
            while (j < size)
            {
                temp = rand.Next();
                m.a3d[i, size - 2, j] = temp - (temp / 120) * 120 - 60;
                refm[i][j] = temp - (temp / 120) * 120 - 60;
                j++;
            }
            i++;
        }
    }
예제 #11
0
파일: structarr.cs 프로젝트: z77ma/runtime
    public static void Init3DMatrix(ref ArrayStruct m, int[][] refm)
    {
        int i, j, temp;

        i = 0;

        while (i < size)
        {
            j = 0;
            while (j < size)
            {
                temp = rand.Next();
                m.a3d[i, size - 2, j] = temp - (temp / 120) * 120 - 60;
                refm[i][j]            = temp - (temp / 120) * 120 - 60;
                j++;
            }
            i++;
        }
    }
예제 #12
0
    public static void Init2DMatrix(out ArrayStruct m, out int[][] refm)
    {
        int i, j, temp;
        i = 0;

        m = new ArrayStruct(size);
        refm = new int[size][];

        for (int k = 0; k < refm.Length; k++)
            refm[k] = new int[size];

        while (i < size)
        {
            j = 0;
            while (j < size)
            {
                temp = rand.Next();
                m.a2d[i, j] = temp - (temp / 120) * 120 - 60;
                refm[i][j] = temp - (temp / 120) * 120 - 60;
                j++;
            }
            i++;
        }
    }
예제 #13
0
    public static int Main()
    {
        bool pass = false;

        rand = new Random();
        size = rand.Next(5, 10);

        Console.WriteLine();
        Console.WriteLine("2D Array");
        Console.WriteLine("Element manipulation of {0} by {0} matrices with different arithmatic operations", size);
        Console.WriteLine("Matrix is member of struct, element stores random double");
        Console.WriteLine("array set/get, ref/out param are used");

        ima = new ArrayStruct(size);
        double[][] refa2d = new double[size][];

        Init2DMatrix(out ima.a2d, out refa2d);

        int m = 0;
        int n;

        while (m < size)
        {
            n = 0;
            while (n < size)
            {
                Process2DArray(ref ima.a2d);
                ProcessJagged2DArray(ref refa2d);
                n++;
            }
            m++;
        }

        for (int i = 0; i < size; i++)
        {
            pass = true;
            for (int j = 0; j < size; j++)
                if (ima.a2d[i, j] != refa2d[i][j])
                    if (!Double.IsNaN(ima.a2d[i, j]) || !Double.IsNaN(refa2d[i][j]))
                    {
                        Console.WriteLine("i={0}, j={1}, ima.a2d[i,j] {2}!=refa2d[i][j] {3}", i, j, ima.a2d[i, j], refa2d[i][j]);
                        pass = false;
                    }
        }

        if (pass)
        {
            try
            {
                ima.a2d[size, size] = 5;
                pass = false;
            }
            catch (IndexOutOfRangeException)
            { }
        }

        Console.WriteLine();
        Console.WriteLine("3D Array");
        Console.WriteLine("Element manipulation of 3D matrice with different arithmatic operations, size is {0}", size);
        Console.WriteLine("Matrix is member of struct, element stores random double");

        ima = new ArrayStruct(size);
        double[][] refa3d = new double[size][];
        for (int k = 0; k < refa3d.Length; k++)
            refa3d[k] = new double[size];

        Init3DMatrix(ima.a3d, refa3d);

        m = 0;
        n = 0;

        while (m < size)
        {
            n = 0;
            while (n < size)
            {
                Process3DArray(ima.a3d);
                ProcessJagged3DArray(refa3d);
                n++;
            }
            m++;
        }

        for (int i = 0; i < size; i++)
        {
            pass = true;
            for (int j = 0; j < size; j++)
                if (ima.a3d[i, 0, j] != refa3d[i][j])
                    if (!Double.IsNaN(ima.a3d[i, 0, j]) || !Double.IsNaN(refa3d[i][j]))
                    {
                        Console.WriteLine("i={0}, j={1}, ima.a3d[i,0,j] {2}!=refa3d[i][j] {3}", i, j, ima.a3d[i, 0, j], refa3d[i][j]);
                        pass = false;
                    }
        }

        if (pass)
        {
            try
            {
                ima.a3d[size, size, size] = 5;
                pass = false;
            }
            catch (IndexOutOfRangeException)
            { }
        }

        Console.WriteLine();

        if (pass)
        {
            Console.WriteLine("PASSED");
            return 100;
        }
        else
        {
            Console.WriteLine("FAILED");
            return 1;
        }
    }
예제 #14
0
    public static int Main()
    {
        bool pass = false;

        rand = new Random();
        size = rand.Next(2, 10);

        Console.WriteLine();
        Console.WriteLine("2D Array");
        Console.WriteLine("Testing inner product of {0} by {0} matrices", size);
        Console.WriteLine("the matrices are members of Struct");
        Console.WriteLine("Matrix element stores random integer");
        Console.WriteLine("array set/get, ref/out param are used");

        ima = new ArrayStruct(size);
        imb = new ArrayStruct(size);
        imr = new ArrayStruct(size);

        int[][] refa2d = new int[size][];
        int[][] refb2d = new int[size][];
        int[][] refr2d = new int[size][];
        for (int k = 0; k < refr2d.Length; k++)
        {
            refr2d[k] = new int[size];
        }

        Init2DMatrix(out ima, out refa2d);
        Init2DMatrix(out imb, out refb2d);

        int m = 0;
        int n = 0;

        while (m < size)
        {
            n = 0;
            while (n < size)
            {
                InnerProduct2D(out imr.a2d[m, n], ref ima, ref imb, m, n);
                InnerProduct2DRef(out refr2d[m][n], ref refa2d, ref refb2d, m, n);
                n++;
            }
            m++;
        }

        for (int i = 0; i < size; i++)
        {
            pass = true;
            for (int j = 0; j < size; j++)
            {
                if (imr.a2d[i, j] != refr2d[i][j])
                {
                    Console.WriteLine("i={0}, j={1}, imr.a2d[i,j] {2}!=refr2d[i][j] {3}", i, j, imr.a2d[i, j], refr2d[i][j]);
                    pass = false;
                }
            }
        }

        Console.WriteLine();
        Console.WriteLine("3D Array");
        Console.WriteLine("Testing inner product of one slice of two 3D matrices, size is {0}", size);
        Console.WriteLine("the matrices are members of Struct, matrix element stores random integer");

        ima = new ArrayStruct(size);
        imb = new ArrayStruct(size);
        imr = new ArrayStruct(size);
        for (int i = 0; i < size; i++)
        {
            for (int j = 0; j < size; j++)
            {
                imr.a3d[i, j, size - 2] = 1;
            }
        }

        int[][] refa3d = new int[size][];
        int[][] refb3d = new int[size][];
        int[][] refr3d = new int[size][];
        for (int k = 0; k < refa3d.Length; k++)
        {
            refa3d[k] = new int[size];
        }
        for (int k = 0; k < refb3d.Length; k++)
        {
            refb3d[k] = new int[size];
        }
        for (int k = 0; k < refr3d.Length; k++)
        {
            refr3d[k] = new int[size];
        }

        Init3DMatrix(ref ima, refa3d);
        Init3DMatrix(ref imb, refb3d);

        m = 0;
        n = 0;

        while (m < size)
        {
            n = 0;
            while (n < size)
            {
                InnerProduct3D(out imr.a3d[m, n, size - 2], ref ima, ref imb, m, n);
                InnerProduct3DRef(out refr3d[m][n], refa3d, refb3d, m, n);
                n++;
            }
            m++;
        }

        for (int i = 0; i < size; i++)
        {
            pass = true;
            for (int j = 0; j < size; j++)
            {
                if (imr.a3d[i, j, size - 2] != refr3d[i][j])
                {
                    Console.WriteLine("i={0}, j={1}, imr.a3d[i,j,size-2] {2}!=refr3d[i][j] {3}", i, j, imr.a3d[i, j, size - 2], refr3d[i][j]);
                    pass = false;
                }
            }
        }

        Console.WriteLine();

        if (pass)
        {
            Console.WriteLine("PASSED");
            return(100);
        }
        else
        {
            Console.WriteLine("FAILED");
            return(1);
        }
    }
예제 #15
0
 public static void InnerProduct3D(out int res, ref ArrayStruct a3d, ref ArrayStruct b, int row, int col)
 {
     int i;
     res = 0;
     i = 0;
     while (i < size)
     {
         res = res + a3d.a3d[row, size - 2, i] * b.a3d[i, size - 2, col];
         i++;
     }
 }
예제 #16
0
 private static extern void SegmentCodes([MarshalAs(UnmanagedType.LPStr)] string path, [Out] out ArrayStruct result, [In, Out] ref IntPtr code);
예제 #17
0
    public static int Main()
    {
        bool pass = false;

        rand = new Random();
        size = rand.Next(2, 10);

        Console.WriteLine();
        Console.WriteLine("2D Array");
        Console.WriteLine("Testing inner product of {0} by {0} matrices", size);
        Console.WriteLine("the matrices are members of Struct");
        Console.WriteLine("Matrix element stores random integer");
        Console.WriteLine("array set/get, ref/out param are used");

        ima = new ArrayStruct(size);
        imb = new ArrayStruct(size);
        imr = new ArrayStruct(size);

        int[][] refa2d = new int[size][];
        int[][] refb2d = new int[size][];
        int[][] refr2d = new int[size][];
        for (int k = 0; k < refr2d.Length; k++)
            refr2d[k] = new int[size];

        Init2DMatrix(out ima, out refa2d);
        Init2DMatrix(out imb, out refb2d);

        int m = 0;
        int n = 0;

        while (m < size)
        {
            n = 0;
            while (n < size)
            {
                InnerProduct2D(out imr.a2d[m, n], ref ima, ref imb, m, n);
                InnerProduct2DRef(out refr2d[m][n], ref refa2d, ref refb2d, m, n);
                n++;
            }
            m++;
        }

        for (int i = 0; i < size; i++)
        {
            pass = true;
            for (int j = 0; j < size; j++)
                if (imr.a2d[i, j] != refr2d[i][j])
                {
                    Console.WriteLine("i={0}, j={1}, imr.a2d[i,j] {2}!=refr2d[i][j] {3}", i, j, imr.a2d[i, j], refr2d[i][j]);
                    pass = false;
                }
        }

        Console.WriteLine();
        Console.WriteLine("3D Array");
        Console.WriteLine("Testing inner product of one slice of two 3D matrices, size is {0}", size);
        Console.WriteLine("the matrices are members of Struct, matrix element stores random integer");

        ima = new ArrayStruct(size);
        imb = new ArrayStruct(size);
        imr = new ArrayStruct(size);
        for (int i = 0; i < size; i++)
            for (int j = 0; j < size; j++)
                imr.a3d[i, j, size - 2] = 1;

        int[][] refa3d = new int[size][];
        int[][] refb3d = new int[size][];
        int[][] refr3d = new int[size][];
        for (int k = 0; k < refa3d.Length; k++)
            refa3d[k] = new int[size];
        for (int k = 0; k < refb3d.Length; k++)
            refb3d[k] = new int[size];
        for (int k = 0; k < refr3d.Length; k++)
            refr3d[k] = new int[size];

        Init3DMatrix(ref ima, refa3d);
        Init3DMatrix(ref imb, refb3d);

        m = 0;
        n = 0;

        while (m < size)
        {
            n = 0;
            while (n < size)
            {
                InnerProduct3D(out imr.a3d[m, n, size - 2], ref ima, ref imb, m, n);
                InnerProduct3DRef(out refr3d[m][n], refa3d, refb3d, m, n);
                n++;
            }
            m++;
        }

        for (int i = 0; i < size; i++)
        {
            pass = true;
            for (int j = 0; j < size; j++)
                if (imr.a3d[i, j, size - 2] != refr3d[i][j])
                {
                    Console.WriteLine("i={0}, j={1}, imr.a3d[i,j,size-2] {2}!=refr3d[i][j] {3}", i, j, imr.a3d[i, j, size - 2], refr3d[i][j]);
                    pass = false;
                }
        }

        Console.WriteLine();

        if (pass)
        {
            Console.WriteLine("PASSED");
            return 100;
        }
        else
        {
            Console.WriteLine("FAILED");
            return 1;
        }
    }
예제 #18
0
    public static int TestEntryPoint()
    {
        bool pass = false;

        int seed = Environment.GetEnvironmentVariable("CORECLR_SEED") switch
        {
            string seedStr when seedStr.Equals("random", StringComparison.OrdinalIgnoreCase) => new Random().Next(),
            string seedStr when int.TryParse(seedStr, out int envSeed) => envSeed,
            _ => DefaultSeed
        };

        rand = new Random(seed);
        size = rand.Next(5, 10);

        Console.WriteLine();
        Console.WriteLine("2D Array");
        Console.WriteLine("Random seed: {0}; set environment variable CORECLR_SEED to this value to reproduce", seed);
        Console.WriteLine("Element manipulation of {0} by {0} matrices with different arithmatic operations", size);
        Console.WriteLine("Matrix is member of struct, element stores random double");
        Console.WriteLine("array set/get, ref/out param are used");

        ima = new ArrayStruct(size);
        double[][] refa2d = new double[size][];

        Init2DMatrix(out ima.a2d, out refa2d);

        int m = 0;
        int n;

        while (m < size)
        {
            n = 0;
            while (n < size)
            {
                Process2DArray(ref ima.a2d);
                ProcessJagged2DArray(ref refa2d);
                n++;
            }
            m++;
        }

        for (int i = 0; i < size; i++)
        {
            pass = true;
            for (int j = 0; j < size; j++)
            {
                if (ima.a2d[i, j] != refa2d[i][j])
                {
                    if (!Double.IsNaN(ima.a2d[i, j]) || !Double.IsNaN(refa2d[i][j]))
                    {
                        Console.WriteLine("i={0}, j={1}, ima.a2d[i,j] {2}!=refa2d[i][j] {3}", i, j, ima.a2d[i, j], refa2d[i][j]);
                        pass = false;
                    }
                }
            }
        }

        if (pass)
        {
            try
            {
                ima.a2d[size, size] = 5;
                pass = false;
            }
            catch (IndexOutOfRangeException)
            { }
        }

        Console.WriteLine();
        Console.WriteLine("3D Array");
        Console.WriteLine("Element manipulation of 3D matrice with different arithmatic operations, size is {0}", size);
        Console.WriteLine("Matrix is member of struct, element stores random double");

        ima = new ArrayStruct(size);
        double[][] refa3d = new double[size][];
        for (int k = 0; k < refa3d.Length; k++)
        {
            refa3d[k] = new double[size];
        }

        Init3DMatrix(ima.a3d, refa3d);

        m = 0;
        n = 0;

        while (m < size)
        {
            n = 0;
            while (n < size)
            {
                Process3DArray(ima.a3d);
                ProcessJagged3DArray(refa3d);
                n++;
            }
            m++;
        }

        for (int i = 0; i < size; i++)
        {
            pass = true;
            for (int j = 0; j < size; j++)
            {
                if (ima.a3d[i, 0, j] != refa3d[i][j])
                {
                    if (!Double.IsNaN(ima.a3d[i, 0, j]) || !Double.IsNaN(refa3d[i][j]))
                    {
                        Console.WriteLine("i={0}, j={1}, ima.a3d[i,0,j] {2}!=refa3d[i][j] {3}", i, j, ima.a3d[i, 0, j], refa3d[i][j]);
                        pass = false;
                    }
                }
            }
        }

        if (pass)
        {
            try
            {
                ima.a3d[size, size, size] = 5;
                pass = false;
            }
            catch (IndexOutOfRangeException)
            { }
        }

        Console.WriteLine();

        if (pass)
        {
            Console.WriteLine("PASSED");
            return(100);
        }
        else
        {
            Console.WriteLine("FAILED");
            return(1);
        }
    }
}
예제 #19
0
    public static int Main()
    {
        bool pass = false;

        rand = new Random();
        size = rand.Next(5, 10);

        Console.WriteLine();
        Console.WriteLine("2D Array");
        Console.WriteLine("Element manipulation of {0} by {0} matrices with different arithmatic operations", size);
        Console.WriteLine("Matrix is member of struct, element stores random double");
        Console.WriteLine("array set/get, ref/out param are used");

        ima = new ArrayStruct(size);
        double[][] refa2d = new double[size][];

        Init2DMatrix(out ima.a2d, out refa2d);

        int m = 0;
        int n;

        while (m < size)
        {
            n = 0;
            while (n < size)
            {
                Process2DArray(ref ima.a2d);
                ProcessJagged2DArray(ref refa2d);
                n++;
            }
            m++;
        }

        for (int i = 0; i < size; i++)
        {
            pass = true;
            for (int j = 0; j < size; j++)
            {
                if (ima.a2d[i, j] != refa2d[i][j])
                {
                    if (!Double.IsNaN(ima.a2d[i, j]) || !Double.IsNaN(refa2d[i][j]))
                    {
                        Console.WriteLine("i={0}, j={1}, ima.a2d[i,j] {2}!=refa2d[i][j] {3}", i, j, ima.a2d[i, j], refa2d[i][j]);
                        pass = false;
                    }
                }
            }
        }

        if (pass)
        {
            try
            {
                ima.a2d[size, size] = 5;
                pass = false;
            }
            catch (IndexOutOfRangeException)
            { }
        }

        Console.WriteLine();
        Console.WriteLine("3D Array");
        Console.WriteLine("Element manipulation of 3D matrice with different arithmatic operations, size is {0}", size);
        Console.WriteLine("Matrix is member of struct, element stores random double");

        ima = new ArrayStruct(size);
        double[][] refa3d = new double[size][];
        for (int k = 0; k < refa3d.Length; k++)
        {
            refa3d[k] = new double[size];
        }

        Init3DMatrix(ima.a3d, refa3d);

        m = 0;
        n = 0;

        while (m < size)
        {
            n = 0;
            while (n < size)
            {
                Process3DArray(ima.a3d);
                ProcessJagged3DArray(refa3d);
                n++;
            }
            m++;
        }

        for (int i = 0; i < size; i++)
        {
            pass = true;
            for (int j = 0; j < size; j++)
            {
                if (ima.a3d[i, 0, j] != refa3d[i][j])
                {
                    if (!Double.IsNaN(ima.a3d[i, 0, j]) || !Double.IsNaN(refa3d[i][j]))
                    {
                        Console.WriteLine("i={0}, j={1}, ima.a3d[i,0,j] {2}!=refa3d[i][j] {3}", i, j, ima.a3d[i, 0, j], refa3d[i][j]);
                        pass = false;
                    }
                }
            }
        }

        if (pass)
        {
            try
            {
                ima.a3d[size, size, size] = 5;
                pass = false;
            }
            catch (IndexOutOfRangeException)
            { }
        }

        Console.WriteLine();

        if (pass)
        {
            Console.WriteLine("PASSED");
            return(100);
        }
        else
        {
            Console.WriteLine("FAILED");
            return(1);
        }
    }
예제 #20
0
파일: structarr.cs 프로젝트: z77ma/runtime
    public static int Main()
    {
        bool pass = false;

        int seed = Environment.GetEnvironmentVariable("CORECLR_SEED") switch
        {
            string seedStr when seedStr.Equals("random", StringComparison.OrdinalIgnoreCase) => new Random().Next(),
            string seedStr when int.TryParse(seedStr, out int envSeed) => envSeed,
            _ => DefaultSeed
        };

        rand = new Random(seed);
        size = rand.Next(2, 10);

        Console.WriteLine();
        Console.WriteLine("2D Array");
        Console.WriteLine("Random seed: {0}; set environment variable CORECLR_SEED to this value to reproduce", seed);
        Console.WriteLine("Testing inner product of {0} by {0} matrices", size);
        Console.WriteLine("the matrices are members of Struct");
        Console.WriteLine("Matrix element stores random integer");
        Console.WriteLine("array set/get, ref/out param are used");

        ima = new ArrayStruct(size);
        imb = new ArrayStruct(size);
        imr = new ArrayStruct(size);

        int[][] refa2d = new int[size][];
        int[][] refb2d = new int[size][];
        int[][] refr2d = new int[size][];
        for (int k = 0; k < refr2d.Length; k++)
        {
            refr2d[k] = new int[size];
        }

        Init2DMatrix(out ima, out refa2d);
        Init2DMatrix(out imb, out refb2d);

        int m = 0;
        int n = 0;

        while (m < size)
        {
            n = 0;
            while (n < size)
            {
                InnerProduct2D(out imr.a2d[m, n], ref ima, ref imb, m, n);
                InnerProduct2DRef(out refr2d[m][n], ref refa2d, ref refb2d, m, n);
                n++;
            }
            m++;
        }

        for (int i = 0; i < size; i++)
        {
            pass = true;
            for (int j = 0; j < size; j++)
            {
                if (imr.a2d[i, j] != refr2d[i][j])
                {
                    Console.WriteLine("i={0}, j={1}, imr.a2d[i,j] {2}!=refr2d[i][j] {3}", i, j, imr.a2d[i, j], refr2d[i][j]);
                    pass = false;
                }
            }
        }

        Console.WriteLine();
        Console.WriteLine("3D Array");
        Console.WriteLine("Testing inner product of one slice of two 3D matrices, size is {0}", size);
        Console.WriteLine("the matrices are members of Struct, matrix element stores random integer");

        ima = new ArrayStruct(size);
        imb = new ArrayStruct(size);
        imr = new ArrayStruct(size);
        for (int i = 0; i < size; i++)
        {
            for (int j = 0; j < size; j++)
            {
                imr.a3d[i, j, size - 2] = 1;
            }
        }

        int[][] refa3d = new int[size][];
        int[][] refb3d = new int[size][];
        int[][] refr3d = new int[size][];
        for (int k = 0; k < refa3d.Length; k++)
        {
            refa3d[k] = new int[size];
        }
        for (int k = 0; k < refb3d.Length; k++)
        {
            refb3d[k] = new int[size];
        }
        for (int k = 0; k < refr3d.Length; k++)
        {
            refr3d[k] = new int[size];
        }

        Init3DMatrix(ref ima, refa3d);
        Init3DMatrix(ref imb, refb3d);

        m = 0;
        n = 0;

        while (m < size)
        {
            n = 0;
            while (n < size)
            {
                InnerProduct3D(out imr.a3d[m, n, size - 2], ref ima, ref imb, m, n);
                InnerProduct3DRef(out refr3d[m][n], refa3d, refb3d, m, n);
                n++;
            }
            m++;
        }

        for (int i = 0; i < size; i++)
        {
            pass = true;
            for (int j = 0; j < size; j++)
            {
                if (imr.a3d[i, j, size - 2] != refr3d[i][j])
                {
                    Console.WriteLine("i={0}, j={1}, imr.a3d[i,j,size-2] {2}!=refr3d[i][j] {3}", i, j, imr.a3d[i, j, size - 2], refr3d[i][j]);
                    pass = false;
                }
            }
        }

        Console.WriteLine();

        if (pass)
        {
            Console.WriteLine("PASSED");
            return(100);
        }
        else
        {
            Console.WriteLine("FAILED");
            return(1);
        }
    }
}