Exemplo n.º 1
0
        private Dictionary <Tuple <T1, T2>, int> CollectKeys2 <T1, T2>()
        {
            Debug.Assert(_keyColumns.Length == 2);

            var column1  = _dataMap[_keyColumns[0]].UnderlyingList;
            var column2  = _dataMap[_keyColumns[1]].UnderlyingList;
            var rowCount = _dataMap.MaxRowCount;
            var result   = new Dictionary <Tuple <T1, T2>, int>(rowCount);

            for (var i = 0; i < rowCount; ++i)
            {
                T1 k1 = i >= column1.Count ? TypeTrait <T1> .GetNaN() : (T1)column1[i];

                T2 k2 = i >= column2.Count ? TypeTrait <T2> .GetNaN() : (T2)column2[i];

                var key = Tuple.Create(k1, k2);
                try
                {
                    result.Add(key, i);
                }
                catch (ArgumentException ex)
                {
                    throw new ArgumentException($"Duplicate key values: {key}", ex);
                }
            }

            return(result);
        }
Exemplo n.º 2
0
        public static DataMap FromJagged <T>(T[][] source, string[] columnNames = null, bool transpose = false, IEqualityComparer <string> keyComparaer = null)
        {
            var result = new DataMap(keyComparaer);

            if (!transpose)
            {
                if (columnNames == null)
                {
                    var c = source[0].Length;
                    columnNames = new string[c];
                    for (var i = 0; i < c; ++i)
                    {
                        columnNames[i] = "Column" + i;
                    }
                }

                for (var i = 0; i < columnNames.Length; ++i)
                {
                    var data = new List <T>(source.Length);
                    result.Add(columnNames[i], data);
                    for (var j = 0; j < source.Length; ++j)
                    {
                        var row = source[j];
                        if (i < row.Length)
                        {
                            data.Add(row[i]);
                        }
                        else
                        {
                            data.Add(TypeTrait <T> .GetNaN());
                        }
                    }
                }
            }
            else
            {
                if (columnNames == null)
                {
                    var c = source.Length;
                    columnNames = new string[c];
                    for (var i = 0; i < c; ++i)
                    {
                        columnNames[i] = "Column" + i;
                    }
                }

                for (var i = 0; i < columnNames.Length; ++i)
                {
                    result.Add(columnNames[i], source[i]);
                }
            }

            return(result);
        }
Exemplo n.º 3
0
        private Dictionary <T1, int> CollectKeys1 <T1>()
        {
            Debug.Assert(_keyColumns.Length == 1);

            var column1  = _dataMap[_keyColumns[0]].UnderlyingList;
            var rowCount = _dataMap.MaxRowCount;
            var result   = new Dictionary <T1, int>(rowCount);

            for (var i = 0; i < rowCount; ++i)
            {
                T1 k1 = i >= column1.Count ? TypeTrait <T1> .GetNaN() : (T1)column1[i];

                result.Add(k1, i);
            }

            return(result);
        }
Exemplo n.º 4
0
        private Dictionary <Tuple <T1, T2, T3, T4, T5, T6>, int> CollectKeys6 <T1, T2, T3, T4, T5, T6>()
        {
            Debug.Assert(_keyColumns.Length == 6);

            var column1  = _dataMap[_keyColumns[0]].UnderlyingList;
            var column2  = _dataMap[_keyColumns[1]].UnderlyingList;
            var column3  = _dataMap[_keyColumns[2]].UnderlyingList;
            var column4  = _dataMap[_keyColumns[3]].UnderlyingList;
            var column5  = _dataMap[_keyColumns[4]].UnderlyingList;
            var column6  = _dataMap[_keyColumns[5]].UnderlyingList;
            var rowCount = _dataMap.MaxRowCount;
            var result   = new Dictionary <Tuple <T1, T2, T3, T4, T5, T6>, int>(rowCount);

            for (var i = 0; i < rowCount; ++i)
            {
                T1 k1 = i >= column1.Count ? TypeTrait <T1> .GetNaN() : (T1)column1[i];

                T2 k2 = i >= column2.Count ? TypeTrait <T2> .GetNaN() : (T2)column2[i];

                T3 k3 = i >= column3.Count ? TypeTrait <T3> .GetNaN() : (T3)column3[i];

                T4 k4 = i >= column4.Count ? TypeTrait <T4> .GetNaN() : (T4)column4[i];

                T5 k5 = i >= column5.Count ? TypeTrait <T5> .GetNaN() : (T5)column5[i];

                T6 k6 = i >= column6.Count ? TypeTrait <T6> .GetNaN() : (T6)column6[i];

                var key = Tuple.Create(k1, k2, k3, k4, k5, k6);
                try
                {
                    result.Add(key, i);
                }
                catch (ArgumentException ex)
                {
                    throw new ArgumentException($"Duplicate key values: {key}", ex);
                }
            }

            return(result);
        }
Exemplo n.º 5
0
        public static MetaNum Sum(this IList <MetaNum> self, bool skipNaN = true, int minCount = 0)
        {
            MetaNum sum   = (MetaNum)0.0;
            int     count = 0;

            foreach (var value in self)
            {
                if (skipNaN && TypeTrait <MetaNum> .IsNaN(value))
                {
                    continue;
                }
                sum += value;
                ++count;
            }

            if (count < minCount)
            {
                return(TypeTrait <MetaNum> .GetNaN());
            }

            return(sum);
        }
Exemplo n.º 6
0
        public static MetaNum Product(this IList <MetaNum> self, bool skipNaN = true, int minCount = 0)
        {
            MetaNum product = (MetaNum)1;
            int     count   = 0;

            foreach (var value in self)
            {
                if (skipNaN && TypeTrait <MetaNum> .IsNaN(value))
                {
                    continue;
                }
                product *= value;
                ++count;
            }

            if (count < minCount)
            {
                return(TypeTrait <MetaNum> .GetNaN());
            }

            return(product);
        }