Exemplo n.º 1
0
        public void CalculateGroupsTest2()
        {
            double[] bytes = new[] { 1.0, 2.0, 3.0, 4.0 };
            DataRow target = new DataRow(bytes);
            int level = 2;
            List<DataGroup> expected = new List<DataGroup>() { new DataGroup() { 5.0 }, new DataGroup() { -2.0 }, new DataGroup() { -1.0 }, new DataGroup() { 0.0 } };
            List<DataGroup> actual = target.CalculateTransformedGroups(level);

            for (int i = 0; i < expected.Count; i++)
            {
                Assert.IsTrue(actual[i] != expected[i]);
            }
        }
Exemplo n.º 2
0
        public void CalculateGroupsTestPerformace()
        {
            var bytes = Enumerable.Repeat(128.0, 800).ToList();
            var levels = Math.Log(800, 2.0);
            var rowLen = this.CalculateRowLength(levels);
            while (bytes.Count() < rowLen)
            {
                bytes.Add(0x00);
            }

            var target = new DataRow(bytes.ToArray());

            var sw = Stopwatch.StartNew();
            target.CalculateTransformedGroups(Convert.ToInt32(levels));
            sw.Stop();
            Assert.IsTrue(sw.Elapsed < TimeSpan.FromSeconds(1));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Retransforms this instance.
        /// </summary>
        /// <returns></returns>
        public DataMatrix Retransform(int levelCount)
        {
            var matrix = new DataMatrix(MatrixType.Retransformed, this.ColumnCount);

            foreach (DataRow row in this.Rows)
            {
                int halfGroupCount = this.ColumnCount;

                var tmpRow = row.RowValues.ToArray();
                for (int currentLevel = 0; currentLevel < levelCount; currentLevel++)
                {
                    halfGroupCount = halfGroupCount / 2;
                    int groupLen = Convert.ToInt32(Math.Pow(2.0, currentLevel));
                    for (int j = 0; j < halfGroupCount; j++)
                    {
                        var r = tmpRow.ToList().ToArray();
                        var s = tmpRow.ToList().ToArray();

                        var groupOffset = (this.ColumnCount * j) / halfGroupCount;
                        for (int i = 0; i < groupLen; i++)
                        {
                            var a = tmpRow[groupOffset + i];
                            var d = tmpRow[groupOffset + groupLen + i];

                            r[i] = (a + d) / Math.Sqrt(2.0);
                            s[i] = (a - d) / Math.Sqrt(2.0);

                            // r[i] = (tmpRow[p + i] + tmpRow[p + h + i]) / Math.Sqrt(2.0);
                            // s[i] = (tmpRow[p + i] - tmpRow[p + h + i]) / Math.Sqrt(2.0);
                        }

                        for (int i = 0; i < groupLen; i++)
                        {
                            tmpRow[groupOffset + (2 * i)] = r[i];
                            tmpRow[groupOffset + (2 * i) + 1] = s[i];
                        }

                    }
                }

                for (int i = 0; i < tmpRow.Count(); i++)
                {
                    tmpRow[i] = Math.Round(tmpRow[i], 0);
                }

                var nr = new DataRow(tmpRow);
                matrix.Rows.Add(nr);
            }

            return matrix;
        }