当前位置: 首页>>代码示例>>C#>>正文


C# AType.MixedType方法代码示例

本文整理汇总了C#中AType.MixedType方法的典型用法代码示例。如果您正苦于以下问题:C# AType.MixedType方法的具体用法?C# AType.MixedType怎么用?C# AType.MixedType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AType的用法示例。


在下文中一共展示了AType.MixedType方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Compute

        private AType Compute(AType items, int desiredCount)
        {
            AType result = AArray.Create(items.Type);

            if (desiredCount > 0)
            {
                // Check how many we can copy from the right argument
                int count = (desiredCount <= items.Length) ? desiredCount : items.Length;
                int remainder = desiredCount - count;

                for (int i = 0; i < count; i++)
                {
                    result.AddWithNoUpdate(items[i].Clone());
                }

                // Check if there is some leftover we need to fill
                if (remainder > 0)
                {
                    AType filler = FillElement(items);

                    for (; remainder > 0; remainder--)
                    {
                        result.AddWithNoUpdate(filler.Clone());
                    }
                }
            }
            else
            {
                // set the start point, which is the difference between the length of the items and
                //  the count we want to take from the end of the list
                // NOTE: + is used because in this case the 'desiredCount' variable is a negative number
                int start = items.Length + desiredCount;

                if (start < 0)
                {
                    // This case we need to add fill elements to the start of the array

                    AType filler = FillElement(items);
                    for(;start < 0; start++)
                    {
                        result.AddWithNoUpdate(filler.Clone());
                    }
                    // Now the 'start' is 0
                }

                for (; start < items.Length; start++)
                {
                    result.AddWithNoUpdate(items[start].Clone());
                }
            }

            result.Length = Math.Abs(desiredCount);
            result.Shape = new List<int>() { result.Length };

            if (items.Rank > 1)
            {
                result.Shape.AddRange(items.Shape.GetRange(1, items.Shape.Count - 1));
            }
            result.Rank = items.Rank;

            if (desiredCount == 0)
            {
                result.Type = items.MixedType() ? ATypes.ANull : items.Type;
            }
            else
            {
                result.Type = result[0].Type;
            }

            return result;
        }
开发者ID:sammoorhouse,项目名称:aplusdotnet,代码行数:71,代码来源:Take.cs

示例2: ReStructure

        /// <summary>
        /// Change column represenation to row representation.
        /// </summary>
        /// <param name="columnItems"></param>
        /// <param name="originalItems"></param>
        /// <returns></returns>
        private static AType ReStructure(List<AType> columnItems, AType originalItems)
        {
            AType result = AArray.Create(ATypes.AArray);
            AType row;

            for (int i = 0; i < originalItems.Shape[0]; i++)
            {
                row = AArray.Create(ATypes.AArray);

                for (int j = 0; j < originalItems.Shape[1]; j++)
                {
                    row.AddWithNoUpdate(columnItems[j][i].Clone());
                }

                row.Length = originalItems.Shape[1];
                row.Shape = new List<int>() { row.Length };
                row.Rank = 1;
                row.Type = row.Length > 0 ? row[0].Type : (originalItems.MixedType() ? ATypes.ANull : originalItems.Type);

                result.AddWithNoUpdate(row);
            }

            result.Length = originalItems.Length;
            result.Shape = new List<int>() { result.Length };
            result.Shape.AddRange(originalItems.Shape.GetRange(1, originalItems.Shape.Count - 1));
            result.Rank = originalItems.Rank;
            result.Type = result.Length > 0 ? result[0].Type : (originalItems.MixedType() ? ATypes.ANull : originalItems.Type);

            return result;
        }
开发者ID:sammoorhouse,项目名称:aplusdotnet,代码行数:36,代码来源:Rotate.cs

示例3: Compute

        private AType Compute(AType items, int cutValue)
        {
            AType result;

            if (items.IsArray)
            {
                int absoluteCutValue = Math.Abs(cutValue);
                int firstAxisLength;

                // compute the first axis with corrpespond formula
                if (cutValue > 0)
                {
                    if (items.Length % cutValue != 0)
                    {
                        throw new Error.Length(LengthErrorText);
                    }

                    firstAxisLength = items.Length / cutValue;

                } // y <= 0
                else
                {
                    if (items.Length < absoluteCutValue - 1)
                    {
                        throw new Error.Length(LengthErrorText);
                    }

                    firstAxisLength = cutValue + items.Length + 1;
                }

                result = AArray.Create(ATypes.AType);

                if (items.Length > 0)
                {
                    int counter = 0;

                    for (int i = 0; i < firstAxisLength; i++)
                    {
                        AType item = AArray.Create(ATypes.AArray);

                        // select the correspond element if y > 0: get the following element else iota abs_y + i # items.
                        for (int j = 0; j < absoluteCutValue; j++)
                        {
                            item.AddWithNoUpdate(items[cutValue > 0 ? counter++ : i + j].Clone());
                        }

                        item.Length = absoluteCutValue;
                        item.Shape = new List<int>() { absoluteCutValue };
                        item.Shape.AddRange(items[0].Shape);
                        item.Rank = items.Rank;
                        item.Type = 
                            item.Length > 0 ? item[0].Type : (items.MixedType() ? ATypes.ANull : items.Type);

                        result.AddWithNoUpdate(item);
                    }
                }

                result.Length = firstAxisLength;
                result.Shape = new List<int>() { firstAxisLength };
                result.Shape.Add(absoluteCutValue);
                if (items.Rank > 1)
                {
                    result.Shape.AddRange(items.Shape.GetRange(1, items.Shape.Count - 1));
                }

                result.Rank = 1 + items.Rank;
                result.Type = 
                    result.Length > 0 ? result[0].Type : (items.MixedType() ? ATypes.ANull : items.Type);
            }
            else
            {
                result = AArray.Create(items.Type, items);
            }

            return result;
        }
开发者ID:sammoorhouse,项目名称:aplusdotnet,代码行数:76,代码来源:Restructure.cs

示例4: RotateArray

        /// <summary>
        /// Rotate the input array the correspond direction with number.
        /// </summary>
        /// <param name="number"></param>
        /// <param name="item"></param>
        /// <returns></returns>
        private static AType RotateArray(int number, AType item)
        {
            AType result;

            if (number == 0)
            {
                result = item;
            }
            else
            {
                result = AArray.Create(ATypes.AArray);

                if (item.Length > 0)
                {
                    if (item.Length <= Math.Abs(number))
                    {
                        number = number % item.Length;
                    }

                    if (number < 0)
                    {
                        number = item.Length + number;
                    }

                    for (int i = number; i <= item.Length - 1; i++)
                    {
                        result.AddWithNoUpdate(item[i]);
                    }

                    for (int i = 0; i < number; i++)
                    {
                        result.AddWithNoUpdate(item[i]);
                    }
                }

                result.Length = item.Length;
                result.Shape = new List<int>() { result.Length };
                result.Rank = 1;
                result.Type = result.Length > 0 ? result[0].Type : (item.MixedType() ? ATypes.ANull : item.Type);
            }

            return result;
        }
开发者ID:sammoorhouse,项目名称:aplusdotnet,代码行数:49,代码来源:Rotate.cs

示例5: Compute

        private AType Compute(AType right, int dropCounter)
        {
            if (right.IsArray && dropCounter == 0)
            {
                return right.Clone();
            }

            AType result = AArray.Create(ATypes.AType);

            if (right.IsArray)
            {
                if (right.Length - Math.Abs(dropCounter) > 0)
                {
                    if (dropCounter > 0)
                    {
                        for (int i = dropCounter; i < right.Length; i++)
                        {
                            result.AddWithNoUpdate(right[i].Clone());
                        }
                    }
                    else
                    {
                        for (int i = 0; i < right.Length + dropCounter; i++)
                        {
                            result.AddWithNoUpdate(right[i].Clone());
                        }
                    }
                    result.Length = right.Length - Math.Abs(dropCounter);
                    result.Shape = new List<int>() { result.Length };
                    
                    if (right.Rank > 1)
                    {
                        result.Shape.AddRange(right.Shape.GetRange(1, right.Shape.Count - 1));
                    }

                    result.Rank = right.Rank;
                    result.Type = result[0].Type;
                }
                else
                {
                    result.Type = right.MixedType() ? ATypes.ANull : right.Type;
                }
            }
            else
            {
                if (dropCounter == 0)
                {
                    result.Add(right.Clone());
                    result.Length = 1;
                    result.Shape = new List<int>() { 1 };
                    result.Type = right.Type;
                }
                else
                {
                    result.Type = right.MixedType() ? ATypes.ANull : right.Type;
                }
            }
            return result;
        }
开发者ID:sammoorhouse,项目名称:aplusdotnet,代码行数:59,代码来源:Drop.cs

示例6: Compute

        private AType Compute(AType items, byte[] expandVector)
        {
            AType result = AArray.Create(ATypes.AType);
            int index = 0;

            // get the filler element based on the right argument
            AType fillElementShape =
                items.Rank > 1 ? items.Shape.GetRange(1, items.Shape.Count - 1).ToAArray() : null;
            AType filler = Utils.FillElement(items.Type, fillElementShape);

            for (int i = 0; i < expandVector.Length; i++)
            {
                if (expandVector[i] == 1)
                {
                    result.AddWithNoUpdate(items[items.Length > 1 ? index++ : 0].Clone());
                }
                else
                {
                    result.AddWithNoUpdate(filler.Clone());
                }
            }

            result.Length = expandVector.Length;
            result.Shape = new List<int>() { expandVector.Length };

            if (items.Rank > 1)
            {
                result.Shape.AddRange(items.Shape.GetRange(1, items.Shape.Count - 1));
            }

            result.Rank = items.Rank;
            result.Type = result.Length > 0 ? result[0].Type : (items.MixedType() ? ATypes.ANull : items.Type);

            return result;
        }
开发者ID:sammoorhouse,项目名称:aplusdotnet,代码行数:35,代码来源:Expand.cs

示例7: CreateArray

        /// <summary>
        /// Create the result array with corrpesond shape.
        /// </summary>
        /// <param name="items"></param>
        /// <param name="shape"></param>
        /// <param name="pathVector"></param>
        /// <param name="transposeVector"></param>
        /// <returns></returns>
        private AType CreateArray(AType items, LinkedList<int> shape, List<int> pathVector, int[] transposeVector)
        {
            List<int> newPathVector;
            LinkedList<int> cutShape = null;
            AType result = AArray.Create(ATypes.AArray);

            for (int i = 0; i < shape.First(); i++)
            {
                newPathVector = new List<int>();
                newPathVector.AddRange(pathVector);
                newPathVector.Add(i);

                if (shape.Count > 1)
                {
                    cutShape = new LinkedList<int>(shape);
                    cutShape.RemoveFirst();
                    result.AddWithNoUpdate(CreateArray(items, cutShape, newPathVector, transposeVector));
                }
                else
                {
                    result.AddWithNoUpdate(GetItem(items, newPathVector, transposeVector));
                }
            }

            result.Length = shape.First();
            result.Shape = new List<int>() { result.Length };

            if (shape.Count > 1)
            {
                result.Shape.AddRange(cutShape.ToList());
            }

            result.Rank = result.Shape.Count;
            result.Type = 
                result.Length > 0 ? result[0].Type : (items.MixedType() ? ATypes.ANull : items.Type);

            return result;
        }
开发者ID:sammoorhouse,项目名称:aplusdotnet,代码行数:46,代码来源:TransposeAxes.cs

示例8: CreateEnclosedNull

        private static AType CreateEnclosedNull(AType inputItem)
        {
            AType result = AArray.Create(inputItem.MixedType() ? ATypes.ANull : inputItem.Type);

            result.Length = 0;
            result.Shape = new List<int>() { result.Length };

            if (inputItem.Rank > 1)
            {
                result.Shape.AddRange(inputItem.Shape.GetRange(1, inputItem.Shape.Count - 1));
            }

            result.Rank = inputItem.Rank;

            return ABox.Create(result);
        }
开发者ID:sammoorhouse,项目名称:aplusdotnet,代码行数:16,代码来源:Partition.cs


注:本文中的AType.MixedType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。