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


C# AType.Select方法代码示例

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


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

示例1: 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

示例2: 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

示例3: ExtractEncodeInformation

        /// <summary>
        /// Type check, and extract data from left and right side.
        /// </summary>
        /// <param name="left"></param>
        /// <param name="right"></param>
        private EncodeInformation ExtractEncodeInformation(AType left, AType right)
        {
            // Error if the arguments are not numbers or Null
            if (!((left.IsNumber || left.Type == ATypes.ANull) && (right.IsNumber || right.Type == ATypes.ANull))) 
            {
                throw new Error.Type(TypeErrorText);
            }

            // Left argument must be a scalar or vector.
            if (left.Rank > 1)
            {
                throw new Error.Rank(RankErrorText);
            }

            double[] encodeKeys;
            if (left.IsArray)
            {
                encodeKeys = left.Select(item => item.asFloat).ToArray();
            }
            else
            {
                encodeKeys = new double[] { left.asFloat };
            }

            ATypes resultingType;
            if (left.Type == ATypes.AFloat || right.Type == ATypes.AFloat ||
                left.Type == ATypes.ANull || right.Type == ATypes.ANull)
            {
                resultingType = ATypes.AFloat;
            }
            else
            {
                resultingType = ATypes.AInteger;
            }

            List<double> encodeValues = new List<double>();
            ExtractItems(encodeValues, right);

            EncodeInformation arguments = new EncodeInformation(encodeKeys, encodeValues.ToArray(), resultingType);
            return arguments;
        }
开发者ID:sammoorhouse,项目名称:aplusdotnet,代码行数:46,代码来源:Encode.cs

示例4: ExtractDecodeInformation

        /// <summary>
        /// Extracts <see cref="DecodeInformation"/> from the arguments.
        /// </summary>
        /// <param name="left"></param>
        /// <param name="right"></param>
        /// <returns></returns>
        private DecodeInformation ExtractDecodeInformation(AType left, AType right)
        {
            // Error if the arguments are not numbers or Null
            if (!((left.IsNumber || left.Type == ATypes.ANull) && (right.IsNumber || right.Type == ATypes.ANull))) 
            {
                throw new Error.Type(TypeErrorText);
            }

            // righ side must be array
            if (!right.IsArray)
            {
                throw new Error.Rank(RankErrorText);
            }

            // left side must be scalar or vector
            if (left.Rank > 1)
            {
                throw new Error.Rank(RankErrorText);
            }

            ATypes resultType = 
                (left.Type == ATypes.AFloat || right.Type == ATypes.AFloat || right.Type == ATypes.ANull)
                ? ATypes.AFloat
                : ATypes.AInteger;

            double[] decodeValues;

            if (left.IsArray)
            {
                if (left.Length == 1)
                {
                    // one-element vector case, then we reshape it: (#x) rho y.
                    decodeValues = Enumerable.Repeat(left[0].asFloat, right.Length).ToArray();
                }
                else
                {
                    // left and right side length have to equal!
                    if (left.Length != right.Length)
                    {
                        throw new Error.Length(LengthErrorText);
                    }

                    decodeValues = left.Select(item => item.asFloat).ToArray();
                }
            }
            else
            {
                // scalar case, reshape it: (#x) rho y.
                decodeValues = Enumerable.Repeat(left.asFloat, right.Length).ToArray();
            }

            return new DecodeInformation(resultType, decodeValues);
        }
开发者ID:sammoorhouse,项目名称:aplusdotnet,代码行数:59,代码来源:Decode.cs

示例5: 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


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