Exemple #1
0
        public override NDArrayDict CreateState(int index, NDArray weight)
        {
            var state = new NDArrayDict("momentum", "prev_weight");

            if (Momentum == 0)
            {
                state["momentum"]    = null;
                state["prev_weight"] = weight.Copy();
            }
            else
            {
                state["momentum"]    = nd.Zeros(weight.Shape, weight.Context, weight.DataType);
                state["prev_weight"] = weight.Copy();
            }

            return(state);
        }
Exemple #2
0
        public void TestCopy()
        {
            NDArray nd = new NDArray("Car", "Teddy", "Ho");

            NDArray nd1 = nd.Copy();

            String s = nd[1];

            nd[1] = "Moo";

            String s1 = nd1[1];

            Assert.True(s1.Equals("Teddy"), "Arrays are not equal.");
        }
Exemple #3
0
        public void TestDeepCopy()
        {
            NDArray r1 = new NDArray(0, 1, 2);
            NDArray r2 = new NDArray(3, 4, 5);
            NDArray r3 = new NDArray(6, 7, 8);

            NDArray nd = new NDArray(r1, r2, r3);

            NDArray nd1 = nd.Copy();

            NDArray s = nd[1];

            nd[1] = new NDArray(0, 0, 0);

            NDArray s1 = nd1[1];

            Assert.True(s1.Equals(new NDArray(3, 4, 5)), "Arrays are not equal.");
        }
Exemple #4
0
        public static (NDArray, (bool, bool)) RandomFlip(NDArray src, float px = 0, float py = 0, bool copy = true)
        {
            var flip_y = FloatRnd.Uniform(0, 1 - py);
            var flip_x = FloatRnd.Uniform(0, 1 - px);

            if (flip_y > 0.5f)
            {
                src = nd.Flip(src, axis: 0);
            }

            if (flip_x > 0.5f)
            {
                src = nd.Flip(src, axis: 1);
            }

            if (copy)
            {
                src = src.Copy();
            }

            return(src, (flip_x > 0.5f, flip_y > 0.5f));
        }