本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}