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


C# AType.TryFirstScalar方法代码示例

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


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

示例1: GetCutNumber

        private int GetCutNumber(AType right, AType left)
        {
            if (!(left.Type == ATypes.AFloat || left.Type == ATypes.AInteger || left.Type == ATypes.ANull))
            {
                throw new Error.Type(this.TypeErrorText);
            }
            
            AType scalar;
            int cutValue;

            // get the first scalar value with length check on
            if (!left.TryFirstScalar(out scalar, true))
            {
                throw new Error.Nonce(this.NonceErrorText);
            }

            // check if the scalar is a whole number and set the desired count of items
            if (!left.ConvertToRestrictedWholeNumber(out cutValue))
            {
                throw new Error.Type(this.TypeErrorText);
            }

            if (right.Rank > 8)
            {
                throw new Error.MaxRank(MaxRankErrorText);
            }

            if (right.Rank == 0 && cutValue != 1)
            {
                throw new Error.Rank(RankErrorText);
            }

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

示例2: GetDropCounter

        private int GetDropCounter(AType element)
        {
            if (element.Type == ATypes.AFloat || element.Type == ATypes.AInteger)
            {
                AType scalar;

                // Get the first scalar value with length check on
                if (!element.TryFirstScalar(out scalar, true))
                {
                    throw new Error.Nonce(this.NonceErrorText);
                }

                int dropCounter;
                // Check if the scalar is a whole number and set the drop counter
                if (!scalar.ConvertToRestrictedWholeNumber(out dropCounter))
                {
                    throw new Error.Type(this.TypeErrorText);
                }

                return dropCounter;
            }
            else if (element.Type == ATypes.ANull)
            {
                throw new Error.Nonce(this.NonceErrorText);
            }
            else
            {
                throw new Error.Type(this.TypeErrorText);
            }
        }
开发者ID:sammoorhouse,项目名称:aplusdotnet,代码行数:30,代码来源:Drop.cs

示例3: PrepareExpandVector

        private byte[] PrepareExpandVector(AType left)
        {
            // if the left side is User defined function, we throw Valence error.
            // this part belongs to Scan.
            if (left.Type == ATypes.AFunc)
            {
                throw new Error.Valence(ValenceErrorText);
            }

            if (!(left.Type == ATypes.AFloat || left.Type == ATypes.AInteger || left.Type == ATypes.ANull))
            {
                throw new Error.Type(TypeErrorText);
            }

            if (left.Rank > 1)
            {
                throw new Error.Rank(RankErrorText);
            }

            //int element;
            AType scalar;

            byte[] expandVector;

            if (left.TryFirstScalar(out scalar, true))
            {
                expandVector = new byte[] { ExtractExpandArgument(scalar) };
            }
            else
            {
                expandVector = left.Select(item => ExtractExpandArgument(item)).ToArray();
            }

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

示例4: GetLeadingAxesLength

        private static int GetLeadingAxesLength(AType argument)
        {
            if (!argument.IsNumber)
            {
                throw new Error.Type("Items");
            }

            AType result;
            if (!argument.TryFirstScalar(out result, true))
            {
                throw new Error.Length("Items");
            }


            int number;
            if (!result.ConvertToRestrictedWholeNumber(out number))
            {
                throw new Error.Type("Items");
            }

            if (number != -1 && number < 0)
            {
                throw new Error.Domain("Items");
            }

            return number;
        }
开发者ID:sammoorhouse,项目名称:aplusdotnet,代码行数:27,代码来源:Items.cs

示例5: PrepareRotateVector

        private int[] PrepareRotateVector(AType right, AType left)
        {
            if (!(left.Type == ATypes.AFloat || left.Type == ATypes.AInteger || left.Type == ATypes.ANull))
            {
                // Allowed types are: AFloat, AInteger and ANull
                // otherwise throw Type error
                throw new Error.Type(TypeErrorText);
            }

            AType scalar;
            List<int> rotateVector = new List<int>();

            if (left.TryFirstScalar(out scalar, true))
            {
                int result;

                if (!scalar.ConvertToRestrictedWholeNumber(out result))
                {
                    throw new Error.Type(TypeErrorText);
                }

                rotateVector.Add(result);
            }
            else
            {
                if (right.Rank > 0)
                {
                    if (left.Rank != right.Rank - 1)
                    {
                        throw new Error.Rank(RankErrorText);
                    }

                    if (!left.Shape.SequenceEqual(right.Shape.GetRange(1, right.Shape.Count - 1)))
                    {
                        throw new Error.Length(LengthErrorText);
                    }
                }

                // if the left is AArray and rank is bigger than 1, Ravel it
                AType leftvector = left.Rank > 1 ? MonadicFunctionInstance.Ravel.Execute(left) : left;

                int element;

                foreach (AType item in leftvector)
                {
                    if (!item.ConvertToRestrictedWholeNumber(out element))
                    {
                        throw new Error.Type(TypeErrorText);
                    }

                    rotateVector.Add(element);
                }
            }

            // if the right argument is scalar, we clone it!
            return rotateVector.ToArray();
        }
开发者ID:sammoorhouse,项目名称:aplusdotnet,代码行数:57,代码来源:Rotate.cs

示例6: ExtractString

        private static bool ExtractString(AType argument, out string message)
        {
            AType symbol;
            if (argument.Type == ATypes.ASymbol && argument.TryFirstScalar(out symbol))
            {
                message = symbol.asString;
                return true;
            }
            else if (argument.Type == ATypes.AChar)
            {
                message = MonadicFunctionInstance.Ravel.Execute(argument).ToString();
                return true;
            }

            message = "";
            return false;
        }
开发者ID:sammoorhouse,项目名称:aplusdotnet,代码行数:17,代码来源:Signal.cs

示例7: CreateReplicateJobInfo

        private ReplicateJobInfo CreateReplicateJobInfo(AType right, AType left)
        {
            if (!(left.Type == ATypes.AFloat || left.Type == ATypes.AInteger || left.Type == ATypes.ANull))
            {
                throw new Error.Type(TypeErrorText);
            }

            if (left.Rank > 1)
            {
                throw new Error.Rank(RankErrorText);
            }

            int[] replicateVector;
            AType scalar;

            if (left.TryFirstScalar(out scalar, true))
            {
                replicateVector = new int[] { ExtractInteger(scalar) };
            }
            else
            {
                if (left.Length > 0)
                {
                    replicateVector = left.Select(item => ExtractInteger(item)).ToArray();
                }
                else
                {
                    replicateVector = new int[] { 0 };
                }

                // lenght check should be the first than parse the left side,
                // but the A+ follow that order.
                if (right.Length != 1 && left.Length != right.Length)
                {
                    throw new Error.Length(LengthErrorText);
                }
            }

            ReplicateJobInfo info = new ReplicateJobInfo(
                replicateVector,
                right.IsArray ? right : AArray.Create(right.Type, right)
            );

            return info;
        }
开发者ID:sammoorhouse,项目名称:aplusdotnet,代码行数:45,代码来源:Replicate.cs

示例8: Execute

        public override AType Execute(AType right, AType left, Aplus environment)
        {
            // Environment is required!
            Assert.NotNull(environment);

            if (right.Type != ATypes.AChar)
            {
                throw new Error.Type(this.TypeErrorText);
            }

            if (right.Rank > 1)
            {
                throw new Error.Rank(this.RankErrorText);
            }

            string sourceCode = right.ToString();
            AType result;

            if(left.Type == ATypes.ASymbol)
            {
                AType symbol;
                if(left.TryFirstScalar(out symbol))
                {
                    result = ExecuteWithContextSwitch(environment, sourceCode, symbol.asString);
                }
                else
                {
                    result = ProtectedExecute(environment, sourceCode);
                }
            }
            else if (left.Type == ATypes.AInteger || left.Type == ATypes.ANull)
            {
                result = ProtectedExecute(environment, sourceCode);
            }
            else
            {
                throw new Error.Type(this.TypeErrorText);
            }

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

示例9: ExtractInteger

        /// <summary>
        /// Get integer from argument.
        /// </summary>
        /// <param name="argument"></param>
        /// <returns></returns>
        private int ExtractInteger(AType argument)
        {
            AType item;
            if (!argument.TryFirstScalar(out item, true))
            {
                throw new Error.Domain(DomainErrorText);
            }

            int number;
            if (!item.ConvertToRestrictedWholeNumber(out number))
            {
                throw new Error.Type(TypeErrorText);
            }

            if (number < 0)
            {
                throw new Error.Domain(DomainErrorText);
            }

            return number;
        }
开发者ID:sammoorhouse,项目名称:aplusdotnet,代码行数:26,代码来源:Deal.cs

示例10: Exit

        internal static AType Exit(Aplus environment, AType argument)
        {
            AType result;
            bool isFirstScalar = argument.TryFirstScalar(out result, true);

            if (isFirstScalar && !result.IsTolerablyWholeNumber || 
                !(argument.Type == ATypes.AInteger || argument.Type == ATypes.AFloat))
            {
                throw new Error.Type("_exit");
            }

            if (!isFirstScalar)
            {
                throw new Error.Length("_exit");
            }

            Environment.Exit(result.asInteger);

            // unreachable code
            return argument;
        }
开发者ID:sammoorhouse,项目名称:aplusdotnet,代码行数:21,代码来源:Exit.cs

示例11: Execute

        public override AType Execute(AType right, AType left, Aplus environment = null)
        {
            // type check
            if (left.Type != ATypes.ASymbol)
            {
                throw new Error.Domain(DomainErrorText);
            }

            AType scalar;

            // get the first scalar value with length check on
            if (!left.TryFirstScalar(out scalar, true))
            {
                throw new Error.Domain(DomainErrorText);
            }

            AType result;

            // select the correspond function for convert
            switch (scalar.asString)
            {
                case "int":
                    result = IntegerCase(right);
                    break;
                case "float":
                    result = FloatCase(right);
                    break;
                case "sym":
                    result = SymbolCase(right);
                    break;
                case "char":
                    result = CharCase(right);
                    break;
                default:
                    throw new Error.Domain(DomainErrorText);
            }

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

示例12: PerformAssign

        internal static void PerformAssign(AType target, AType value)
        {
            if (!Utils.DifferentNumberType(target, value) && target.Type != value.Type)
            {
                // The target and value are not numbers and they are of a different type?
                throw new Error.Type("assign");
            }

            AType result;

            if (value.Length == 1 && value.TryFirstScalar(out result, true))
            {
                if (target.Length == 1)
                {
                    PerformIndexAssign(target, result);
                }
                else
                {
                    foreach (AType item in target)
                    {
                        PerformIndexAssign(item, result);
                    }
                }
            }
            else if (target.Length == value.Length)
            {
                for (int i = 0; i < target.Length; i++)
                {
                    PerformIndexAssign(target[i], value[i]);
                }
            }
            else if (target.Rank < value.Rank)
            {
                throw new Error.Rank("assign");
            }
            else
            {
                throw new Error.Length("assign");
            }
        }
开发者ID:sammoorhouse,项目名称:aplusdotnet,代码行数:40,代码来源:Utils.cs

示例13: NestedPathNumber2NestedArray

        /// <summary>
        /// CASE 6: Nested right argument and nested left argument.
        /// </summary>
        /// <param name="pathBox"></param>
        /// <param name="items"></param>
        /// <returns></returns>
        private AType NestedPathNumber2NestedArray(AType pathBox, AType items, Aplus environment)
        {
            AType path = MonadicFunctionInstance.Disclose.Execute(pathBox, environment);

            if (path.IsFunctionScalar)
            {
                throw new Error.Domain(DomainErrorText);
            }

            //Nested scalar or vector whose items are simple scalar or vector of integers.
            if (path.IsBox)
            {
                throw new Error.Type(TypeErrorText);
            }

            //Right argument is ().
            if (items.Type == ATypes.ANull)
            {
                throw new Error.Index(IndexErrorText);
            }

            if (path.Type == ATypes.ANull)
            {
                if (!items.IsBox)
                {
                    throw new Error.Domain(DomainErrorText);
                }

                AType result;

                if (!items.TryFirstScalar(out result, true))
                {
                    throw new Error.Domain(DomainErrorText);
                }

                return MonadicFunctionInstance.Disclose.Execute(result, environment);
            }
            else if (path.Type == ATypes.AInteger)
            {
                if (path.Rank > 1)
                {
                    throw new Error.Rank(RankErrorText);
                }

                if (path.Length == 1)
                {
                    // Case 5
                    return PathNumber2NestedVector(path.IsArray ? path[0] : path, items);
                }

                // The 'path' variable must be an AArray after this point.
                // so we treat it like that

                if (!items.IsBox)
                {
                    throw new Error.Domain(DomainErrorText);
                }

                //Length: 0
                if (path.Length != items.Rank || path.Length == 0)
                {
                    throw new Error.Rank(RankErrorText);
                }

                List<int> shape = items.Shape;
                int index;

                for (int i = 0; i < path.Length; i++)
                {
                    index = path[i].asInteger;

                    if (index < 0 || index >= shape[i])
                    {
                        throw new Error.Index(IndexErrorText);
                    }

                    items = items[index];
                }

                return MonadicFunctionInstance.Disclose.Execute(items, environment);
            }
            else if (path.Type == ATypes.ASymbol)
            {
                // Case 3
                return ItemSelectWalker(SymbolConstant2SlotFillerDelegate, path, items, environment);
            }
            else if (path.Type == ATypes.AChar)
            {
                throw new Error.Domain(DomainErrorText);
            }
            else
            {
                throw new Error.Type(TypeErrorText);
            }
//.........这里部分代码省略.........
开发者ID:sammoorhouse,项目名称:aplusdotnet,代码行数:101,代码来源:Pick.cs

示例14: SolveEquation

        private AType SolveEquation(AType constants, AType equations)
        {
            AType lhs;
            AType rhs;

            if (constants.TryFirstScalar(out lhs, true) && equations.TryFirstScalar(out rhs, true))
            {
                // both left and right values are one element arrays.
                return AFloat.Create(lhs.asFloat / rhs.asFloat);
            }

            Matrix constantsArray = new SimpleMatrix(ExtractConstants(constants));
            Matrix originalEquations = new SimpleMatrix(FloatFromAType(equations));
            int[] rowsSequence;
            Matrix eliminatedConstants;
            GaussianElimination(originalEquations, constantsArray, out rowsSequence, out eliminatedConstants);

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

            if (equations.Shape[0] == equations.Shape[1])
            {
                // square equation
                if (constants.Rank > 1)
                {
                    foreach (int item in rowsSequence)
                    {
                        AType subArray = AArray.Create(ATypes.AFloat);

                        for (int i = 0; i < eliminatedConstants.Columns; i++)
                        {
                            subArray.Add(AFloat.Create(eliminatedConstants[item, i]));
                        }

                        result.Add(subArray);
                    }
                }
                else
                {
                    foreach (int item in rowsSequence)
                    {
                        result.Add(AFloat.Create(eliminatedConstants[item, 0]));
                    }
                }
            }
            else
            {
                double[][] independentConstants = BuildIndependentConstants(rowsSequence, eliminatedConstants);
                double[] beta;
                double[] actualconstants;

                if (constants.Rank == 1)
                {
                    beta = independentConstants.Select(item => item[0]).ToArray();
                    actualconstants = constants.Select(item => item.asFloat).ToArray();

                    double[] solution = OverDeterminedEquationSolve(beta, actualconstants, originalEquations);

                    foreach (double item in solution)
                    {
                        result.Add(AFloat.Create(item));
                    }
                }
                else
                {
                    for (int objective = 0; objective < constants.Shape[1]; objective++)
                    {
                        beta = independentConstants.Select(item => item[objective]).ToArray();
                        actualconstants = constants.Select(item => item[objective].asFloat).ToArray();

                        double[] solution = OverDeterminedEquationSolve(beta, actualconstants, originalEquations);
                        AType solutionArray = AArray.Create(ATypes.AFloat);

                        foreach (double item in solution)
                        {
                            solutionArray.Add(AFloat.Create(item));
                        }

                        result.Add(solutionArray);
                    }
                }
            }

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

示例15: PathVector2NestedVector

        /// <summary>
        /// CASE 5: Nested vector right argument and simple path vector left argument.
        /// </summary>
        /// <param name="path"></param>
        /// <param name="items"></param>
        /// <returns></returns>
        private AType PathVector2NestedVector(AType path, AType items, out bool resultFromBox)
        {
            AType result;
            AType element;

            if (path.TryFirstScalar(out element, true))
            {
                result = PathNumber2NestedVector(element, items);
            }
            else
            {
                if (path.Rank > 1)
                {
                    throw new Error.Rank(RankErrorText);
                }

                result = items;

                // Case 0
                if (path.Type == ATypes.ANull || path.Length == 0)
                {
                    resultFromBox = false;
                }
                else
                {    
                    resultFromBox = true;
                    foreach (AType item in path)
                    {
                        result = PathNumber2NestedVector(item, result);
                    }
                }
            }
            resultFromBox = true;

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


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