Beispiel #1
0
        public void Abs()
        {
            // arrange
            var srcArray = NdArray <int> .Linspace(HostDevice.Instance, -4, 4, 8);

            // action
            var newArray = ElementWiseMathFunction <int> .Abs(srcArray);

            // assert
            Assert.IsTrue(newArray[0].Value > 0);
        }
Beispiel #2
0
        public void Ceiling()
        {
            // arrange
            var srcArray = NdArray <double> .Linspace(HostDevice.Instance, -1, 1, 6);

            // action
            var newArray = ElementWiseMathFunction <double> .Ceiling(srcArray);

            // assert
            Assert.AreEqual(-1.0, newArray[0].Value);
            Assert.AreEqual(0.0, newArray[1].Value);
            Assert.AreEqual(1.0, newArray[4].Value);
        }
Beispiel #3
0
        public void Atan()
        {
            // arrange
            var srcArray = NdArray <double> .Linspace(HostDevice.Instance, -1, 1, 3);

            // action
            var newArray = ElementWiseMathFunction <double> .Atan(srcArray);

            // assert
            const double Epsilon = 1e-8;

            Assert.IsTrue(Math.Abs(newArray[0].Value - (-Math.PI / 4.0)) < Epsilon);
            Assert.IsTrue(Math.Abs(newArray[1].Value - 0.0) < Epsilon);
            Assert.IsTrue(Math.Abs(newArray[2].Value - (Math.PI / 4.0)) < Epsilon);
        }
Beispiel #4
0
        public void Minimum()
        {
            // arrange
            var srcArray1 = NdArray <double> .Zeros(HostDevice.Instance, new[] { 3 });

            var srcArray2 = NdArray <double> .Ones(HostDevice.Instance, new[] { 3 });

            // action
            var newArray = ElementWiseMathFunction <double> .Minimum(srcArray1, srcArray2);

            // assert
            Assert.AreEqual(0.0, newArray[0].Value);
            Assert.AreEqual(0.0, newArray[1].Value);
            Assert.AreEqual(0.0, newArray[2].Value);
        }
Beispiel #5
0
        public void Sqrt()
        {
            // arrange
            var srcArray = NdArray <double> .Zeros(HostDevice.Instance, new[] { 3 });

            srcArray[0].Value = 1.0;
            srcArray[1].Value = 4.0;
            srcArray[2].Value = 16.0;

            // action
            var newArray = ElementWiseMathFunction <double> .Sqrt(srcArray);

            // assert
            Assert.AreEqual(1.0, newArray[0].Value);
            Assert.AreEqual(2.0, newArray[1].Value);
            Assert.AreEqual(4.0, newArray[2].Value);
        }
Beispiel #6
0
        public void Tanh()
        {
            // arrange
            var srcArray = NdArray <double> .Zeros(HostDevice.Instance, new[] { 3 });

            srcArray[0].Value = -Math.PI / 2.0;
            srcArray[1].Value = 0.0;
            srcArray[2].Value = Math.PI / 2.0;

            // action
            var newArray = ElementWiseMathFunction <double> .Tanh(srcArray);

            // assert
            const double Epsilon = 1e-8;

            Assert.IsTrue(Math.Abs(newArray[0].Value - -0.91715234) < Epsilon);
            Assert.IsTrue(Math.Abs(newArray[1].Value - 0.0) < Epsilon);
            Assert.IsTrue(Math.Abs(newArray[2].Value - 0.91715234) < Epsilon);
        }
Beispiel #7
0
        public void Sign()
        {
            // arrange
            var src = NdArray <double> .Zeros(HostDevice.Instance, new[] { 4 });

            src[0].Value = -2.0;
            src[1].Value = -1.0;
            src[2].Value = 0.0;
            src[3].Value = 1.0;

            // action
            var newArray = ElementWiseMathFunction <double> .Sign(src);

            // assert
            Assert.AreEqual(-1.0, newArray[0].Value);
            Assert.AreEqual(-1.0, newArray[1].Value);
            Assert.AreEqual(0.0, newArray[2].Value);
            Assert.AreEqual(1.0, newArray[3].Value);
        }
Beispiel #8
0
        public void Log10()
        {
            // arrange
            var srcArray = NdArray <double> .Zeros(HostDevice.Instance, new[] { 3 });

            srcArray[0].Value = 1.00;
            srcArray[1].Value = 10.0;
            srcArray[2].Value = 100.0;

            // action
            var newArray = ElementWiseMathFunction <double> .Log10(srcArray);

            // assert
            const double Epsilon = 1e-8;

            Assert.IsTrue(Math.Abs(newArray[0].Value - 0.0) < Epsilon);
            Assert.IsTrue(Math.Abs(newArray[1].Value - 1.0) < Epsilon);
            Assert.IsTrue(Math.Abs(newArray[2].Value - 2.0) < Epsilon);
        }
Beispiel #9
0
        public void Exp()
        {
            // arrange
            var srcArray = NdArray <double> .Zeros(HostDevice.Instance, new[] { 4 });

            srcArray[0].Value = -1.0;
            srcArray[1].Value = 0.0;
            srcArray[2].Value = 1.0;
            srcArray[3].Value = 10.0;

            // action
            var newArray = ElementWiseMathFunction <double> .Exp(srcArray);

            // assert
            const double Epsilon = 1e-8;

            Assert.IsTrue(Math.Abs(newArray[0].Value - 0.36787944117144233) < Epsilon);
            Assert.IsTrue(Math.Abs(newArray[1].Value - 1.0) < Epsilon);
            Assert.IsTrue(Math.Abs(newArray[2].Value - 2.718281828459045) < Epsilon);
            Assert.IsTrue(Math.Abs(newArray[3].Value - 22026.465794806718) < Epsilon);
        }
Beispiel #10
0
        public void Pow()
        {
            // arrange
            var lhs = NdArray <double> .Zeros(HostDevice.Instance, new[] { 3 });

            lhs[0].Value = 5.0;
            lhs[1].Value = 6.0;
            lhs[2].Value = 7.0;

            var rhs = NdArray <double> .Zeros(HostDevice.Instance, new[] { 3 });

            rhs[0].Value = 2.00;
            rhs[1].Value = 3.0;
            rhs[2].Value = 4.0;

            // action
            var newArray = ElementWiseMathFunction <double> .Pow(lhs, rhs);

            // assert
            Assert.AreEqual(25.0, newArray[0].Value);
            Assert.AreEqual(216.0, newArray[1].Value);
            Assert.AreEqual(2401.0, newArray[2].Value);
        }