Example #1
0
        /// <summary>
        /// 添加Key-Value型索引
        /// </summary>
        /// <param name="index">索引ID,从0开始,每一组配置都可以添加多个索引。请保持索引ID尽量小</param>
        /// <param name="fn">取索引Key的函数</param>
        /// <returns>自身</returns>
        public ExcelConfigSet AddKVIndex(int index, IndexFunction fn)
        {
            if (index < 0)
            {
                throw new ArgumentException("index must not be negetive");
            }

            if (null == fn)
            {
                throw new ArgumentNullException("IndexFunction");
            }

            while (kvIndex.Count <= index)
            {
                KVIndexData obj = new KVIndexData();
                obj.Handle = null;
                obj.Index  = new Dictionary <Key, DynamicMessage>();
                kvIndex.Add(obj);
            }

            KVIndexData index_set = kvIndex[index];

            index_set.Handle = fn;

            foreach (var data_item in datas)
            {
                index_set.Index[index_set.Handle(data_item)] = data_item;
            }
            return(this);
        }
        public void Find_NotFound_ThrowException()
        {
            // arrange
            var source = NdArray <int> .Arange(HostDevice.Instance, 1, 9, 1).Reshape(new[] { 2, 4 });

            // action
            var output = IndexFunction <int> .Find(10, source);
        }
        public void ArgMax()
        {
            // arrange
            var source = NdArray <int> .Arange(HostDevice.Instance, 1, 9, 1).Reshape(new[] { 2, 4 });

            // action
            var output = IndexFunction <int> .ArgMax(source);

            // assert
            CollectionAssert.AreEqual(new[] { 1, 3 }, output);
        }
        public void AllElements()
        {
            // arrange
            var source = NdArray <int> .Arange(HostDevice.Instance, 0, 9, 1).Reshape(new[] { 3, 3 });

            // action
            var output = IndexFunction <int> .AllElements(source);

            // assert
            CollectionAssert.AreEqual(Enumerable.Range(0, 9).ToArray(), output);
        }
        public void TryFind_NotFound()
        {
            // arrange
            var source = NdArray <int> .Arange(HostDevice.Instance, 1, 9, 1).Reshape(new[] { 2, 4 });

            // action
            var output = IndexFunction <int> .TryFind(10, source);

            // assert
            Assert.IsTrue(output.Length == 0);
        }
        public void ArgMinAxis()
        {
            // arrange
            var source = NdArray <int> .Arange(HostDevice.Instance, 1, 9, 1).Reshape(new[] { 2, 4 });

            // action
            var output = IndexFunction <int> .ArgMinAxis(1, source);

            // assert
            Assert.AreEqual(0, output[0].Value);
            Assert.AreEqual(0, output[1].Value);
        }
        public void FindAxis()
        {
            // arrange
            var source = NdArray <int> .Arange(HostDevice.Instance, 0, 8, 1).Reshape(new[] { 2, 4 });

            // action
            var output = IndexFunction <int> .FindAxis(2, 1, source);

            // assert
            Assert.AreEqual(2, output[0].Value);
            Assert.AreEqual(SpecialIdx.NotFound, output[1].Value);
        }
        public void TryFind()
        {
            // arrange
            var source = NdArray <int> .Arange(HostDevice.Instance, 1, 9, 1).Reshape(new[] { 2, 4 });

            source[new[] { 1, 3 }] = 2;

            // action
            var output = IndexFunction <int> .TryFind(2, source);

            // assert
            CollectionAssert.AreEqual(new[] { 0, 1 }, output);
        }
        public void AllIndex()
        {
            // arrange
            var source = NdArray <int> .Zeros(HostDevice.Instance, new[] { 2, 1, 3 });

            // action
            var output = IndexFunction <int> .AllIndex(source);

            // assert
            CollectionAssert.AreEqual(new[] { 0, 0, 0 }, output[0]);
            CollectionAssert.AreEqual(new[] { 0, 0, 1 }, output[1]);
            CollectionAssert.AreEqual(new[] { 0, 0, 2 }, output[2]);
            CollectionAssert.AreEqual(new[] { 1, 0, 0 }, output[3]);
            CollectionAssert.AreEqual(new[] { 1, 0, 1 }, output[4]);
            CollectionAssert.AreEqual(new[] { 1, 0, 2 }, output[5]);
        }
        public void CountTrue()
        {
            // arrange
            var source = NdArray <bool> .Zeros(HostDevice.Instance, new[] { 2, 4 });

            source[new[] { 0, 0 }] = true;
            source[new[] { 0, 2 }] = true;
            source[new[] { 1, 1 }] = true;
            source[new[] { 1, 2 }] = true;

            // action
            var output = IndexFunction <bool> .CountTrue(source);

            // assert
            Assert.AreEqual(4, output);
        }
Example #11
0
        /// <summary>
        /// 添加Key-List型索引
        /// </summary>
        /// <param name="index">索引ID,从0开始,每一组配置都可以添加多个索引。请保持索引ID尽量小</param>
        /// <param name="fn">取索引Key的函数</param>
        /// <returns>自身</returns>
        public ExcelConfigSet AddKLIndex(int index, IndexFunction fn)
        {
            if (index < 0)
            {
                throw new ArgumentException("index must not be negetive");
            }

            if (null == fn)
            {
                throw new ArgumentNullException("IndexFunction");
            }

            while (klIndex.Count <= index)
            {
                KLIndexData obj = new KLIndexData();
                obj.Handle   = null;
                obj.Index    = new Dictionary <Key, List <DynamicMessage> >();
                obj.SortRule = null;
                klIndex.Add(obj);
            }

            KLIndexData index_set = klIndex[index];

            index_set.Handle = fn;

            foreach (var data_item in datas)
            {
                Key key = index_set.Handle(data_item);
                List <DynamicMessage> ls;
                if (index_set.Index.TryGetValue(key, out ls))
                {
                    ls.Add(data_item);
                }
                else
                {
                    index_set.Index[key] = new List <DynamicMessage>()
                    {
                        data_item
                    };
                }
            }

            return(this);
        }
        public void TrueIndices()
        {
            // arrange
            var source = NdArray <bool> .Zeros(HostDevice.Instance, new[] { 2, 4 });

            source[new[] { 0, 0 }] = true;
            source[new[] { 0, 2 }] = true;
            source[new[] { 1, 1 }] = true;
            source[new[] { 1, 2 }] = true;

            // action
            var output = IndexFunction <bool> .TrueIndices(source);

            // assert
            Assert.AreEqual(0, output[new[] { 0, 0 }]);
            Assert.AreEqual(0, output[new[] { 0, 1 }]);
            Assert.AreEqual(0, output[new[] { 1, 0 }]);
            Assert.AreEqual(2, output[new[] { 1, 1 }]);
            Assert.AreEqual(1, output[new[] { 2, 0 }]);
            Assert.AreEqual(1, output[new[] { 2, 1 }]);
            Assert.AreEqual(1, output[new[] { 3, 0 }]);
            Assert.AreEqual(2, output[new[] { 3, 1 }]);
        }
Example #13
0
 /// <summary>
 /// 添加Key-Value型索引,索引ID为0
 /// </summary>
 /// <param name="fn">取索引Key的函数</param>
 /// <returns>自身</returns>
 public ExcelConfigSet AddKVIndex(IndexFunction fn)
 {
     return(AddKVIndex(0, fn));
 }