public void PowerLayer_Backward(double power, double scale, double shift)
        {
            var config = new PowerLayerConfiguration(power, scale, shift);
            var layer  = new PowerLayer(config);

            if (power != 0 && power != 1 && power != 2)
            {
                var minValue = -shift / scale;

                using (var bottomCpu = bottom.OnCpu())
                {
                    var bottomData = bottomCpu.Data;
                    for (int i = 0; i < bottom.Count; i++)
                    {
                        if (bottomData[i] < minValue)
                        {
                            bottomData[i] = minValue + (minValue - bottomData[i]);
                        }
                    }
                }
            }

            var checker = new GradientChecker(1e-2f, 1e-2f, 1701, 0.0d, 0.01f);

            checker.CheckEltwise(layer, bottom, top);
        }
        public void PowerLayer_Forward(double power, double scale, double shift)
        {
            var config = new PowerLayerConfiguration(power, scale, shift);
            var layer  = new PowerLayer(config);

            layer.Setup(bottom, top);
            layer.Forward(bottom, top);

            using (var topCpu = top.OnCpu())
                using (var bottomCpu = bottom.OnCpu())
                {
                    double minPrecision = 1e-5f;

                    // Now, check values
                    int count = bottomCpu.Data.Count;
                    for (int i = 0; i < count; i++)
                    {
                        var expectedValue = Math.Pow(shift + scale * bottomCpu.DataAt(i), power);
                        if (power == 0 || power == 1 || power == 2)
                        {
                            Assert.False(double.IsNaN(topCpu.DataAt(i)));
                        }

                        if (double.IsNaN(expectedValue))
                        {
                            Assert.True(double.IsNaN(topCpu.DataAt(i)));
                        }
                        else
                        {
                            double precision = Math.Max(Math.Abs(expectedValue * 1e-4f), minPrecision);
                            Assert.True(MathHelpers.Equality(expectedValue, topCpu.DataAt(i), precision));
                        }
                    }
                }
        }
        public void PowerLayer_Backward(double power, double scale, double shift)
        {
            var config = new PowerLayerConfiguration(power, scale, shift);
            var layer = new PowerLayer(config);

            if ( power != 0 && power != 1 && power != 2 )
            {
                var minValue = -shift / scale;

                using (var bottomCpu = bottom.OnCpu())
                {
                    var bottomData = bottomCpu.Data;
                    for (int i = 0; i < bottom.Count; i++)
                    {
                        if (bottomData[i] < minValue)
                            bottomData[i] = minValue + (minValue - bottomData[i]);
                    }
                }
            }

            var checker = new GradientChecker(1e-2f, 1e-2f, 1701, 0.0d, 0.01f);
            checker.CheckEltwise(layer, bottom, top);
        }
        public void PowerLayer_Forward(double power, double scale, double shift)
        {
            var config = new PowerLayerConfiguration(power, scale, shift);
            var layer = new PowerLayer(config);
            layer.Setup(bottom, top);
            layer.Forward(bottom, top);

            using (var topCpu = top.OnCpu())
            using (var bottomCpu = bottom.OnCpu())
            {
                double minPrecision = 1e-5f;

                // Now, check values
                int count = bottomCpu.Data.Count;
                for (int i = 0; i < count; i++)
                {
                    var expectedValue = Math.Pow(shift + scale * bottomCpu.DataAt(i), power);
                    if (power == 0 || power == 1 || power == 2)
                        Assert.False(double.IsNaN(topCpu.DataAt(i)));

                    if (double.IsNaN(expectedValue))
                        Assert.True(double.IsNaN(topCpu.DataAt(i)));
                    else
                    {
                        double precision = Math.Max(Math.Abs(expectedValue * 1e-4f), minPrecision);
                        Assert.True(MathHelpers.Equality(expectedValue, topCpu.DataAt(i), precision));
                    }
                }
            }
        }