Example #1
0
        public bool TestMultDiv()
        {
            NcArray ones   = new NcArray(NcInt.Instance, new int[] { 10 }).Fill(1);
            NcArray twos   = ones * 2;
            NcArray threes = twos + 1;
            NcArray fours  = twos * 2;
            NcArray zeros  = ones * 0;


            Assert.True(threes.Equals(ones * threes));
            Assert.True(twos.Equals(fours / twos));
            Assert.True(twos.Equals(fours / 2));
            try {
                fours.Div(0);
                throw new AssertFailedException("Failed to throw DivideByZeroException");
            } catch (DivideByZeroException) {
            }

            NcArray buf = NcArray.Arange(NcDouble.Instance, 5);

            buf = buf * 10.0;
            int[]   shape   = new int[] { 1, 3, 5, 7 };
            NcArray uVector = NcArray.Arange(NcShort.Instance, 1 * 3 * 5 * 7).Reshape(shape);

            return(true);
        }
Example #2
0
        public bool TestAddSub()
        {
            NcArray ones   = new NcArray(NcInt.Instance, new int[] { 10 }).Fill(1);
            NcArray twos   = ones + 1;
            NcArray threes = ones + 2;
            NcArray fours  = twos + 2;

            Assert.True(threes.Equals(ones + twos));
            Assert.False(fours.Equals(ones + twos));
            Assert.True(fours.Equals(twos + twos));
            Assert.True(ones.Equals(threes - twos));
            Assert.True(twos.Equals(fours - twos));
            Assert.False(ones.Equals(fours - ones));


            double[] buf = new double[100];
            for (int i = 0; i < 100; i++)
            {
                buf[i] = (double)i;
            }
            NcArray wrapper = new NcArray(buf, NcDouble.Instance, new int[] { 100 });

            wrapper.Add(20.0);
            Assert.Equals(buf[0], 20.0);
            return(true);
        }
Example #3
0
        public bool TestAddSub() {
            NcArray ones = new NcArray(NcInt.Instance, new int[] { 10 }).Fill(1);
            NcArray twos = ones + 1;
            NcArray threes = ones + 2;
            NcArray fours = twos + 2;

            Assert.True(threes.Equals(ones + twos));
            Assert.False(fours.Equals(ones + twos));
            Assert.True(fours.Equals(twos + twos));
            Assert.True(ones.Equals(threes - twos));
            Assert.True(twos.Equals(fours - twos));
            Assert.False(ones.Equals(fours - ones));


            double[] buf = new double[100];
            for(int i=0;i<100;i++) buf[i] = (double)i;
            NcArray wrapper = new NcArray(buf, NcDouble.Instance, new int[] { 100 });
            wrapper.Add(20.0);
            Assert.Equals(buf[0], 20.0);
            return true;
        }
Example #4
0
        public bool TestPut()
        {
            NcFile file = null;

            try {
                file = TestHelper.NewFile(filePath);
                NcDim time = file.AddDim("time", 2);
                NcDim x    = file.AddDim("x", 2);
                NcDim y    = file.AddDim("y", 2);
                NcDim z    = file.AddDim("z", 4);
                NcVar u    = file.AddVar("u", NcFloat.Instance, new List <NcDim>()
                {
                    time, x, y, z
                });
                NcVar v = file.AddVar("v", NcFloat.Instance, new List <NcDim>()
                {
                    time, x, y, z
                });

                NcArray uArray = new NcArray(NcFloat.Instance, u.Shape);
                uArray.Fill(1);
                uArray.FillSlice(20, new int[] { 0, 0, 0, 3 }, new int[] { 2, 2, 2, 4 });
                NcArray vArray = new NcArray(NcFloat.Instance, v.Shape);
                vArray.Fill(100);

                u.PutVar(uArray);

                v.PutVar(vArray);

                NcArray outArray = u.GetVar();
                Assert.True(uArray.Equals(outArray));

                outArray = v.GetVar();
                Assert.True(vArray.Equals(outArray));
            } finally {
                file.Close();
            }
            CheckDelete(filePath);
            return(true);
        }
Example #5
0
        public bool TestPut() {
            NcFile file = null;
            try {
                file = TestHelper.NewFile(filePath);
                NcDim time = file.AddDim("time", 2);
                NcDim x = file.AddDim("x", 2);
                NcDim y = file.AddDim("y", 2);
                NcDim z = file.AddDim("z", 4);
                NcVar u = file.AddVar("u", NcFloat.Instance, new List<NcDim>() { time, x, y, z });
                NcVar v = file.AddVar("v", NcFloat.Instance, new List<NcDim>() { time, x, y, z });

                NcArray uArray = new NcArray(NcFloat.Instance, u.Shape);
                uArray.Fill(1);
                uArray.FillSlice(20, new int[] { 0, 0, 0, 3 }, new int[] { 2, 2, 2, 4});
                NcArray vArray = new NcArray(NcFloat.Instance, v.Shape);
                vArray.Fill(100);

                u.PutVar(uArray);

                v.PutVar(vArray);

                NcArray outArray = u.GetVar();
                Assert.True(uArray.Equals(outArray));
                
                outArray = v.GetVar();
                Assert.True(vArray.Equals(outArray));

                    

            } finally {
                file.Close();
            }
            CheckDelete(filePath);
            return true;
        }