示例#1
0
        private static Dictionary <string, object[]?> MatrixToDictionary(SymbolicExpression sexp)
        {
            RequireTrue(sexp.IsMatrix());

            switch (sexp.Type)
            {
            case SymbolicExpressionType.CharacterVector:
                var characterMatrix = sexp.AsCharacterMatrix();
                return(ArrayToDictionary <string, object>(characterMatrix.ToArray(), characterMatrix.ColumnNames));

            case SymbolicExpressionType.IntegerVector:
                var integerMatrix = sexp.AsIntegerMatrix();
                return(ArrayToDictionary <int, object>(integerMatrix.ToArray(), integerMatrix.ColumnNames));

            case SymbolicExpressionType.LogicalVector:
                var logicalMatrix = sexp.AsLogicalMatrix();
                return(ArrayToDictionary <bool, object>(logicalMatrix.ToArray(), logicalMatrix.ColumnNames));

            case SymbolicExpressionType.NumericVector:
                var numericMatrix = sexp.AsNumericMatrix();
                return(ArrayToDictionary <double, object>(numericMatrix.ToArray(), numericMatrix.ColumnNames));

            default: throw new InvalidOperationException($"Unsupported matrix type: {sexp.Type}");
            }
        }
示例#2
0
        private static IConverter ConvertFromIntegerVector(SymbolicExpression sexp)
        {
            if (sexp.IsMatrix())
            {
                if (sexp.IsDiffTime())
                {
                    return(new IntegerDiffTimeMatrixConverter(sexp.AsIntegerMatrix()));
                }

                return(new MatrixConverter <int>(sexp.AsIntegerMatrix()));
            }

            if (sexp.IsDiffTime())
            {
                return(new IntegerDiffTimeVectorConverter(sexp.AsInteger()));
            }

            return(new VectorConverter <int>(sexp.AsInteger()));
        }