コード例 #1
0
        public void TestMultiplyScalar()
        {
            var          array1   = new[] { 1.2, 2.3, 3.4, 4.5 };
            const double scalar   = 1.1;
            var          expected = new[] { 1.32, 2.53, 3.74, 4.95 };

            Assert.IsTrue(TestUtils.SequenceEquals(expected, WaveMath.Multiply(array1, scalar)));
        }
コード例 #2
0
        public void TestMultiplyArrays()
        {
            var array1   = new[] { 1.2, 2.3, 3.4, 4.5 };
            var array2   = new[] { 1.1, 2.2, 3.3, 1 };
            var expected = new[] { 1.32, 5.06, 11.22, 4.5 };

            Assert.IsTrue(TestUtils.SequenceEquals(expected, WaveMath.GetOperationFunction(WaveMath.OperationEnum.Multiply)(array1, array2)));
            Assert.IsTrue(TestUtils.SequenceEquals(expected, WaveMath.Multiply(array2, array1)));
            Assert.IsTrue(TestUtils.SequenceEquals(expected, WaveMath.Multiply(array1, array2.SubArray(3))));
        }
コード例 #3
0
ファイル: SignalExtension.cs プロジェクト: sheyfzh/envision
        /// <summary>
        /// Extends an array using the specified extension mode
        /// </summary>
        /// <param name="input">Array to extend</param>
        /// <param name="extensionMode">The extension mode</param>
        /// <param name="beforeSize">The extension size of the left side</param>
        /// <param name="afterSize">The extension size of right left side</param>
        /// <returns></returns>
        public static double[] Extend(double[] input, ExtensionMode extensionMode, int beforeSize, int afterSize)
        {
            if (input.Length == 0)
            {
                return(MemoryPool.Pool.New <double>(beforeSize + afterSize, true));
            }
            var pointsHalfLength = input.Length;

            while (beforeSize > input.Length || afterSize > input.Length)
            {
                input = Extend(input, extensionMode, pointsHalfLength);
                return(input);
            }
            var beforeExtension = MemoryPool.Pool.New <double>(beforeSize, true);
            var afterExtension  = MemoryPool.Pool.New <double>(afterSize, true);

            if (extensionMode != ExtensionMode.ZeroPadding)
            {
                if (extensionMode == ExtensionMode.SymmetricHalfPoint || extensionMode == ExtensionMode.AntisymmetricHalfPoint)
                {
                    if (beforeSize > 0)
                    {
                        Array.Copy(input, beforeExtension, beforeSize);
                        Array.Reverse(beforeExtension);
                    }
                    Array.Copy(input, input.Length - afterSize, afterExtension, 0, afterSize);
                    Array.Reverse(afterExtension);
                    if (extensionMode == ExtensionMode.AntisymmetricHalfPoint)
                    {
                        if (beforeSize > 0)
                        {
                            beforeExtension = WaveMath.Multiply(beforeExtension, -1);
                        }
                        afterExtension = WaveMath.Multiply(afterExtension, -1);
                    }
                }
                else if (extensionMode == ExtensionMode.SymmetricWholePoint)
                {
                    if (beforeSize > 0)
                    {
                        Array.Copy(input, input.Length > beforeSize ? 1 : 0, beforeExtension, 0, beforeSize);
                        Array.Reverse(beforeExtension);
                    }
                    Array.Copy(input, input.Length - afterSize - 1 < 0 ? 0 : input.Length - afterSize - 1, afterExtension, 0, afterSize);
                    Array.Reverse(afterExtension);
                }
                else if (extensionMode == ExtensionMode.AntisymmetricWholePoint)
                {
                    if (beforeSize > 0)
                    {
                        beforeExtension = GetAntisymmetricWholePointBefore(input, beforeSize);
                    }
                    afterExtension = GetAntisymmetricWholePointAfter(input, afterSize);
                }
                else if (extensionMode == ExtensionMode.PeriodicPadding)
                {
                    if (beforeSize > 0)
                    {
                        Array.Copy(input, input.Length - beforeSize, beforeExtension, 0, beforeSize);
                    }
                    Array.Copy(input, 0, afterExtension, 0, afterSize);
                }
                else if (extensionMode == ExtensionMode.SmoothPadding0)
                {
                    if (beforeSize > 0)
                    {
                        for (var i = 0; i < beforeExtension.Length; i++)
                        {
                            beforeExtension[i] = input[0];
                        }
                    }
                    for (var i = 0; i < afterExtension.Length; i++)
                    {
                        afterExtension[i] = input[input.Length - 1];
                    }
                }
                else if (extensionMode == ExtensionMode.SmoothPadding1)
                {
                    double previous;
                    if (beforeSize > 0)
                    {
                        var beforeDif = input[0] - input[1];
                        previous = input[0];
                        for (var i = beforeSize - 1; i >= 0; i--)
                        {
                            beforeExtension[i] = previous + beforeDif;
                            previous           = beforeExtension[i];
                        }
                    }
                    var afterDif = input[input.Length - 1] - input[input.Length - 2];
                    previous = input[input.Length - 1];
                    for (var i = 0; i < afterSize; i++)
                    {
                        afterExtension[i] = previous + afterDif;
                        previous          = afterExtension[i];
                    }
                }
            }

            var newPoints = MemoryPool.Pool.New <double>(beforeSize + input.Length + afterSize);

            if (beforeSize > 0)
            {
                beforeExtension.CopyTo(newPoints, 0);
            }
            input.CopyTo(newPoints, beforeSize);
            afterExtension.CopyTo(newPoints, beforeSize + input.Length);
            return(newPoints);
        }