コード例 #1
0
 public DType Accept(TDouble type, string x)
 {
     if (double.TryParse(x, out var b))
     {
         return(DDouble.ValueOf(b));
     }
     else
     {
         throw new Exception($"{x} 不是double类型");
     }
 }
コード例 #2
0
        public DType Accept(TDouble type, ExcelStream x)
        {
            var d = x.Read();

            if (CheckNull(type.IsNullable, d))
            {
                return(null);
            }
            if (!double.TryParse(d.ToString(), out var v))
            {
                throw new InvalidExcelDataException($"{d} 不是 double 类型值");
            }
            return(DDouble.ValueOf(v));
        }
コード例 #3
0
ファイル: ExcelDataCreator.cs プロジェクト: zhangga/luban
        public DType Accept(TDouble type, object converter, ExcelStream x, DefAssembly ass)
        {
            var d = x.Read();

            if (CheckNull(type.IsNullable, d))
            {
                return(null);
            }
            if (!double.TryParse(d.ToString(), out var v))
            {
                throw new Exception($"{d} 不是 double 类型值");
            }
            return(new DDouble(v));
        }
コード例 #4
0
ファイル: CsJsonUmarshal.cs プロジェクト: zhangga/luban
 public string Accept(TDouble type, string json, string x)
 {
     return($"{x} = {json}.GetDouble();");
 }
コード例 #5
0
ファイル: CsConstValueVisitor.cs プロジェクト: zhangga/luban
 public string Accept(TDouble type, string x)
 {
     return(x);
 }
コード例 #6
0
 public string Accept(TDouble type)
 {
     return("readDouble");
 }
コード例 #7
0
 public string Accept(TDouble type)
 {
     return("DOUBLE");
 }
コード例 #8
0
 public virtual void Accept(TDouble type, T x)
 {
     DoAccept(type, x);
 }
コード例 #9
0
 public DType Accept(TDouble type, Sheet.NamedRow x, bool multirow, bool nullable)
 {
     throw new NotSupportedException();
 }
コード例 #10
0
 public string Accept(TDouble type, string fieldName, string tablesName)
 {
     throw new NotImplementedException();
 }
コード例 #11
0
ファイル: GoDeserializeVisitor.cs プロジェクト: zhangga/luban
 public string Accept(TDouble type, string bufName)
 {
     return($"{bufName}.ReadDouble()");
 }
コード例 #12
0
 public DType Accept(TDouble type, IEnumerable <ExcelStream> x, bool y, DefAssembly ass)
 {
     throw new NotImplementedException();
 }
コード例 #13
0
 public string Accept(TDouble type, string fieldName, string logType)
 {
     return($"{fieldName} = default;");
 }
コード例 #14
0
 public bool Accept(TDouble type, TType x, Dictionary <DefTypeBase, bool> y, HashSet <DefTypeBase> z)
 {
     return(true);
 }
コード例 #15
0
ファイル: JavaDefineTypeName.cs プロジェクト: zhangga/luban
 public virtual string Accept(TDouble type)
 {
     return(type.IsNullable ? "Double" : "double");
 }
コード例 #16
0
 public override string Accept(TDouble type)
 {
     return("Double");
 }
コード例 #17
0
 public string Accept(TDouble type, string json, string field)
 {
     return(DefaultLoad(json, field));
 }
コード例 #18
0
 public virtual TR Accept(TDouble type)
 {
     return DoAccept(type);
 }
コード例 #19
0
 public string Accept(TDouble type, string jsonVarName, string fieldName)
 {
     return($"{fieldName} = {jsonVarName}");
 }
コード例 #20
0
 public string Accept(TDouble type, string bufName, string fieldName)
 {
     return($"{bufName}.WriteDouble({fieldName});");
 }
コード例 #21
0
 public string Accept(TDouble type)
 {
     return("FJsonValueNumber");
 }
コード例 #22
0
 public virtual void Accept(TDouble type, T x)
 {
 }
コード例 #23
0
 public string Accept(TDouble type, string bufName, string fieldName)
 {
     return($"if(!{bufName}.readDouble({fieldName})) return false;");
 }
コード例 #24
0
 public string Accept(TDouble type)
 {
     return("writeDouble");
 }
コード例 #25
0
 public string Accept(TDouble type)
 {
     return("float64");
 }
コード例 #26
0
 public void Accept(TDouble type, Dictionary <string, DefTypeBase> x)
 {
 }
コード例 #27
0
 public void Accept(TDouble type, HashSet <DefTypeBase> x)
 {
 }
コード例 #28
0
        public bool TryEvaluateExpression(Entry value, Store context, out Entry result)
        {
            //list
            if (value.Type == TermType.Function && value.ArgsCount == 1 && value.Text == "list")
            {
                Entry arg1 = Computation.Preprocessing(value.Items[0], context);

                TNumber tmp = Computation.NumericCalculation(arg1, context);
                TDouble n   = (TDouble)tmp.obj;
                //List<string> vector = new List<string>(Utilites.EntryMatrix2ArrStr(tmp.obj));
                //vector.RemoveAt(vector.Count - 1);
                //vector.RemoveAt(vector.Count - 1);
                //List<string> distinct = vector.Distinct().ToList();

                List <Term> answer = new List <Term>();
                if (n.D <= 0)
                {
                    answer.AddRange(TermsConverter.ToTerms(0.ToString()));
                }
                else
                {
                    for (int i = 0; i < n.D; i++)
                    {
                        answer.AddRange(TermsConverter.ToTerms("0"));
                    }

                    answer.AddRange(TermsConverter.ToTerms(n.D.ToString()));
                }

                answer.AddRange(TermsConverter.ToTerms(1.ToString()));
                answer.Add(new Term(Functions.Mat, TermType.Function, 2 + (int)n.D));

                result = Entry.Create(answer.ToArray());
                return(true);
            }

            //listLength
            if (value.Type == TermType.Function && value.ArgsCount == 1 && value.Text == "listLength")
            {
                Entry arg1 = Computation.Preprocessing(value.Items[0], context);

                List <string> vector = new List <string>(Utilites.EntryMatrix2ArrStr(arg1));

                List <Term> answer = new List <Term>();

                if (vector.Count <= 2)
                {
                    answer.AddRange(TermsConverter.ToTerms("0"));
                }
                else
                {
                    answer.AddRange(TermsConverter.ToTerms(vector[vector.Count - 2]));
                }

                result = Entry.Create(answer.ToArray());
                return(true);
            }

            //listDistinct
            if (value.Type == TermType.Function && value.ArgsCount == 1 && value.Text == "listDistinct")
            {
                Entry arg1 = Computation.Preprocessing(value.Items[0], context);

                TNumber tmp = Computation.NumericCalculation(arg1, context);

                List <string> vector = new List <string>(Utilites.EntryMatrix2ArrStr(tmp.obj));
                //vector.RemoveAt(vector.Count - 1);
                //vector.RemoveAt(vector.Count - 1);
                List <string> distinct = vector.Distinct().ToList();

                List <Term> answer = new List <Term>();
                foreach (string item in distinct)
                {
                    answer.AddRange(TermsConverter.ToTerms(item));
                }

                answer.AddRange(TermsConverter.ToTerms(distinct.Count.ToString()));
                answer.AddRange(TermsConverter.ToTerms(1.ToString()));
                answer.Add(new Term(Functions.Mat, TermType.Function, 2 + distinct.Count));

                result = Entry.Create(answer.ToArray());
                return(true);
            }

            //listSortAsText
            if (value.Type == TermType.Function && value.ArgsCount == 1 && value.Text == "listSortAsText")
            {
                Entry arg1 = Computation.Preprocessing(value.Items[0], context);

                TNumber tmp = Computation.NumericCalculation(arg1, context);

                BaseEntry be  = tmp.obj;
                Term[]    res = be.ToTerms(16, 16, FractionsType.Decimal, true);

                tmp = Computation.NumericCalculation(Entry.Create(res), context);

                List <string> vector = new List <string>(Utilites.EntryMatrix2ArrStr(tmp.obj));
                if (be.Type == BaseEntryType.Matrix)
                {
                    vector.RemoveAt(vector.Count - 1);
                    vector.RemoveAt(vector.Count - 1);
                    vector.Sort();
                }

                List <Term> answer = new List <Term>();
                foreach (string item in vector)
                {
                    answer.AddRange(TermsConverter.ToTerms(item));
                }

                answer.AddRange(TermsConverter.ToTerms(vector.Count.ToString()));
                answer.AddRange(TermsConverter.ToTerms(1.ToString()));
                answer.Add(new Term(Functions.Mat, TermType.Function, 2 + vector.Count));

                result = Entry.Create(answer.ToArray());
                return(true);
            }

            //listAdd
            if (value.Type == TermType.Function && value.ArgsCount == 2 && value.Text == "listAdd")
            {
                Entry arg1 = Computation.Preprocessing(value.Items[0], context);
                Entry arg2 = Computation.Preprocessing(value.Items[1], context);

                TNumber tmp, tmp1;
                TMatrix m;
                try
                {
                    tmp  = Computation.NumericCalculation(arg1, context);
                    tmp1 = Computation.NumericCalculation(arg2, context);
                    TNumber count = tmp.Rows();
                    m = tmp.Stack(new TNumber[] { new TNumber(0, 1) });
                    m[count.ToInt32(), 0] = tmp1;
                }
                catch
                {
                    tmp1    = Computation.NumericCalculation(arg2, context);
                    m       = new TMatrix(new TNumber[, ] {
                    });
                    m[0, 0] = tmp1;
                }

                result = Entry.Create(m.ToTerms());

                return(true);
            }

            //listNonZeros
            if (value.Type == TermType.Function && value.ArgsCount == 1 && value.Text == "listNonZeros")
            {
                Entry arg1 = Computation.Preprocessing(value.Items[0], context);

                TNumber tmp = Computation.NumericCalculation(arg1, context);

                List <string> vector = new List <string>(Utilites.EntryMatrix2ArrStr(tmp.obj));
                vector.RemoveAt(vector.Count - 1);
                vector.RemoveAt(vector.Count - 1);
                IEnumerable <string> select = from t in vector // определяем каждый объект из teams как t
                                              where t != "0"   //фильтрация по критерию
                                              select t;        // выбираем объект
                List <string> nonZeros = new List <string>(select);
                List <Term>   answer   = new List <Term>();
                foreach (string item in nonZeros)
                {
                    answer.AddRange(TermsConverter.ToTerms(item));
                }

                answer.AddRange(TermsConverter.ToTerms(nonZeros.Count.ToString()));
                answer.AddRange(TermsConverter.ToTerms(1.ToString()));
                answer.Add(new Term(Functions.Mat, TermType.Function, 2 + nonZeros.Count));

                result = Entry.Create(answer.ToArray());
                return(true);
            }

            //if (value.Type == TermType.Function && value.ArgsCount == 2 && value.Text == "listDistinct")
            //{
            //   Entry arg1 = Computation.Preprocessing(value.Items[0], context);
            //   Entry arg2 = Computation.Preprocessing(value.Items[1], context);

            //   int dir = Utilites.Entry2Int(arg2);
            //   TNumber tmp = Computation.NumericCalculation(arg1, context);

            //   List<string> vector = new List<string>(Utilites.EntryMatrix2ArrStr(tmp.obj));
            //   vector.RemoveAt(vector.Count - 1);
            //   vector.RemoveAt(vector.Count - 1);
            //   List<string> distinct = vector.Distinct().ToList();

            //   //string res = "null";

            //   List<Term> answer = new List<Term>();
            //   foreach (string item in distinct)
            //   {
            //      answer.AddRange(TermsConverter.ToTerms(item));
            //   }

            //   if (dir==0)
            //   {
            //      answer.AddRange(TermsConverter.ToTerms(distinct.Count.ToString()));
            //      answer.AddRange(TermsConverter.ToTerms(1.ToString()));
            //      answer.Add(new Term(Functions.Mat, TermType.Function, 2 + distinct.Count));
            //   }
            //   else
            //   {
            //      answer.AddRange(TermsConverter.ToTerms(1.ToString()));
            //      answer.AddRange(TermsConverter.ToTerms(distinct.Count.ToString()));
            //      answer.Add(new Term(Functions.Mat, TermType.Function, 2 + distinct.Count));
            //   }

            //   result = Entry.Create(answer.ToArray());
            //   return true;
            //}

            if (value.Type == TermType.Function && value.ArgsCount == 2 && value.Text == "listRemoveAt")
            {
                Entry arg1 = Computation.Preprocessing(value.Items[0], context);
                Entry arg2 = Computation.Preprocessing(value.Items[1], context);

                TNumber tmp1 = Computation.NumericCalculation(arg1, context);
                TNumber tmp2 = Computation.NumericCalculation(arg2, context);

                BaseEntry be1 = tmp1.obj;
                BaseEntry be2 = tmp2.obj;

                List <string> vector = new List <string>(Utilites.EntryMatrix2ArrStr(be1));
                if (be1.Type == BaseEntryType.Matrix)
                {
                    vector.RemoveAt(vector.Count - 1);
                    vector.RemoveAt(vector.Count - 1);
                    vector.RemoveAt((int)be2.ToDouble() - 1);
                }

                List <Term> answer = new List <Term>();
                foreach (string item in vector)
                {
                    answer.AddRange(TermsConverter.ToTerms(item));
                }

                answer.AddRange(TermsConverter.ToTerms(vector.Count.ToString()));
                answer.AddRange(TermsConverter.ToTerms(1.ToString()));
                answer.Add(new Term(Functions.Mat, TermType.Function, 2 + vector.Count));

                result = Entry.Create(answer.ToArray());
                return(true);
            }

            if (value.Type == TermType.Function && value.ArgsCount == 3 && value.Text == "listRemoveRange")
            {
                Entry arg1 = Computation.Preprocessing(value.Items[0], context);
                Entry arg2 = Computation.Preprocessing(value.Items[1], context);
                Entry arg3 = Computation.Preprocessing(value.Items[2], context);

                TNumber tmp1 = Computation.NumericCalculation(arg1, context);
                TNumber tmp2 = Computation.NumericCalculation(arg2, context);
                TNumber tmp3 = Computation.NumericCalculation(arg3, context);

                BaseEntry be1 = tmp1.obj;
                BaseEntry be2 = tmp2.obj;
                BaseEntry be3 = tmp3.obj;

                List <string> vector = new List <string>(Utilites.EntryMatrix2ArrStr(be1));
                if (be1.Type == BaseEntryType.Matrix)
                {
                    vector.RemoveAt(vector.Count - 1);
                    vector.RemoveAt(vector.Count - 1);
                    vector.RemoveRange((int)be2.ToDouble() - 1, (int)be3.ToDouble());
                }

                List <Term> answer = new List <Term>();
                foreach (string item in vector)
                {
                    answer.AddRange(TermsConverter.ToTerms(item));
                }

                answer.AddRange(TermsConverter.ToTerms(vector.Count.ToString()));
                answer.AddRange(TermsConverter.ToTerms(1.ToString()));
                answer.Add(new Term(Functions.Mat, TermType.Function, 2 + vector.Count));

                result = Entry.Create(answer.ToArray());
                return(true);
            }

            if (value.Type == TermType.Function && value.ArgsCount == 3 && value.Text == "listInsert")
            {
                Entry arg1 = Computation.Preprocessing(value.Items[0], context);
                Entry arg2 = Computation.Preprocessing(value.Items[1], context);
                Entry arg3 = Computation.Preprocessing(value.Items[2], context);

                TNumber tmp1 = Computation.NumericCalculation(arg1, context);
                TNumber tmp2 = Computation.NumericCalculation(arg2, context);
                TNumber tmp3 = Computation.NumericCalculation(arg3, context);

                BaseEntry be1 = tmp1.obj;
                BaseEntry be2 = tmp2.obj;
                BaseEntry be3 = tmp3.obj;

                List <string> vector = new List <string>(Utilites.EntryMatrix2ArrStr(be1));

                if (be1.Type == BaseEntryType.Matrix)
                {
                    vector.RemoveAt(vector.Count - 1);
                    vector.RemoveAt(vector.Count - 1);
                    vector.Insert((int)be2.ToDouble() - 1, be3.ToString());
                }

                List <Term> answer = new List <Term>();
                foreach (string item in vector)
                {
                    answer.AddRange(TermsConverter.ToTerms(item));
                }

                answer.AddRange(TermsConverter.ToTerms(vector.Count.ToString()));
                answer.AddRange(TermsConverter.ToTerms(1.ToString()));
                answer.Add(new Term(Functions.Mat, TermType.Function, 2 + vector.Count));

                result = Entry.Create(answer.ToArray());
                return(true);
            }

            if (value.Type == TermType.Function && value.ArgsCount == 3 && value.Text == "listInsertRange")
            {
                Entry arg1 = Computation.Preprocessing(value.Items[0], context);
                Entry arg2 = Computation.Preprocessing(value.Items[1], context);
                Entry arg3 = Computation.Preprocessing(value.Items[2], context);

                TNumber tmp1 = Computation.NumericCalculation(arg1, context);
                TNumber tmp2 = Computation.NumericCalculation(arg2, context);
                TNumber tmp3 = Computation.NumericCalculation(arg3, context);

                BaseEntry be1 = tmp1.obj;
                BaseEntry be2 = tmp2.obj;
                BaseEntry be3 = tmp3.obj;

                List <string> vector  = new List <string>(Utilites.EntryMatrix2ArrStr(be1));
                List <string> vector1 = new List <string>(Utilites.EntryMatrix2ArrStr(be3));
                if (be1.Type == BaseEntryType.Matrix)
                {
                    vector.RemoveAt(vector.Count - 1);
                    vector.RemoveAt(vector.Count - 1);
                    vector1.RemoveAt(vector.Count - 1);
                    vector1.RemoveAt(vector.Count - 1);
                    vector.InsertRange((int)be2.ToDouble() - 1, vector1);
                }

                List <Term> answer = new List <Term>();
                foreach (string item in vector)
                {
                    answer.AddRange(TermsConverter.ToTerms(item));
                }

                answer.AddRange(TermsConverter.ToTerms(vector.Count.ToString()));
                answer.AddRange(TermsConverter.ToTerms(1.ToString()));
                answer.Add(new Term(Functions.Mat, TermType.Function, 2 + vector.Count));

                result = Entry.Create(answer.ToArray());
                return(true);
            }

            if (value.Type == TermType.Function && value.ArgsCount == 3 && value.Text == "insertRows")
            {
                Entry arg1 = Computation.Preprocessing(value.Items[0], context);
                Entry arg2 = Computation.Preprocessing(value.Items[1], context);
                Entry arg3 = Computation.Preprocessing(value.Items[2], context);

                TNumber tmp1 = Computation.NumericCalculation(arg1, context);
                TNumber tmp2 = Computation.NumericCalculation(arg2, context);
                TNumber tmp3 = Computation.NumericCalculation(arg3, context);

                MatrixL <TNumber> matrixL = Utilites.TMatrixToMatrixL(tmp1);
                for (int i = 0; i < tmp3.ToInt32(); i++)
                {
                    matrixL.InsertRow(tmp2.ToInt32() - 1);
                }

                TMatrix m = Utilites.MatrixLToTMatrix(matrixL);

                result = Entry.Create(m.ToTerms());
                return(true);
            }

            if (value.Type == TermType.Function && value.ArgsCount == 3 && value.Text == "insertRow")
            {
                Entry arg1 = Computation.Preprocessing(value.Items[0], context);
                Entry arg2 = Computation.Preprocessing(value.Items[1], context);
                Entry arg3 = Computation.Preprocessing(value.Items[2], context);

                TNumber tmp1 = Computation.NumericCalculation(arg1, context);
                TNumber tmp2 = Computation.NumericCalculation(arg2, context);
                TNumber tmp3 = Computation.NumericCalculation(arg3, context);

                MatrixL <TNumber> matrixL = Utilites.TMatrixToMatrixL(tmp1);
                List <TNumber>    vectorL = Utilites.TMatrixToMatrixL(tmp3).ToList();
                matrixL.InsertRow(tmp2.ToInt32() - 1, vectorL);
                TMatrix m = Utilites.MatrixLToTMatrix(matrixL);

                result = Entry.Create(m.ToTerms());
                return(true);
            }

            if (value.Type == TermType.Function && value.ArgsCount == 3 && value.Text == "insertCols")
            {
                Entry arg1 = Computation.Preprocessing(value.Items[0], context);
                Entry arg2 = Computation.Preprocessing(value.Items[1], context);
                Entry arg3 = Computation.Preprocessing(value.Items[2], context);

                TNumber tmp1 = Computation.NumericCalculation(arg1, context);
                TNumber tmp2 = Computation.NumericCalculation(arg2, context);
                TNumber tmp3 = Computation.NumericCalculation(arg3, context);

                MatrixL <TNumber> matrixL = Utilites.TMatrixToMatrixL(tmp1);
                for (int i = 0; i < tmp3.ToInt32(); i++)
                {
                    matrixL.InsertCol(tmp2.ToInt32() - 1);
                }
                TMatrix m = Utilites.MatrixLToTMatrix(matrixL);

                result = Entry.Create(m.ToTerms());
                return(true);
            }

            if (value.Type == TermType.Function && value.ArgsCount == 3 && value.Text == "insertCol")
            {
                Entry arg1 = Computation.Preprocessing(value.Items[0], context);
                Entry arg2 = Computation.Preprocessing(value.Items[1], context);
                Entry arg3 = Computation.Preprocessing(value.Items[2], context);

                TNumber tmp1 = Computation.NumericCalculation(arg1, context);
                TNumber tmp2 = Computation.NumericCalculation(arg2, context);
                TNumber tmp3 = Computation.NumericCalculation(arg3, context);

                MatrixL <TNumber> matrixL = Utilites.TMatrixToMatrixL(tmp1);
                List <TNumber>    vectorL = Utilites.TMatrixToMatrixL(tmp3).ToList();
                matrixL.InsertCol(tmp2.ToInt32() - 1, vectorL);
                TMatrix m = Utilites.MatrixLToTMatrix(matrixL);

                result = Entry.Create(m.ToTerms());
                return(true);
            }


            if (value.Type == TermType.Function && value.ArgsCount == 3 && value.Text == "removeRows")
            {
                Entry arg1 = Computation.Preprocessing(value.Items[0], context);
                Entry arg2 = Computation.Preprocessing(value.Items[1], context);
                Entry arg3 = Computation.Preprocessing(value.Items[2], context);

                TNumber tmp1 = Computation.NumericCalculation(arg1, context);
                TNumber tmp2 = Computation.NumericCalculation(arg2, context);
                TNumber tmp3 = Computation.NumericCalculation(arg3, context);

                MatrixL <TNumber> matrixL = Utilites.TMatrixToMatrixL(tmp1);
                for (int i = 0; i < tmp3.ToInt32(); i++)
                {
                    matrixL.RemoveRowAt(tmp2.ToInt32() - 1);
                }
                TMatrix m = Utilites.MatrixLToTMatrix(matrixL);

                result = Entry.Create(m.ToTerms());
                return(true);
            }


            if (value.Type == TermType.Function && value.ArgsCount == 3 && value.Text == "removeCols")
            {
                Entry arg1 = Computation.Preprocessing(value.Items[0], context);
                Entry arg2 = Computation.Preprocessing(value.Items[1], context);
                Entry arg3 = Computation.Preprocessing(value.Items[2], context);

                TNumber tmp1 = Computation.NumericCalculation(arg1, context);
                TNumber tmp2 = Computation.NumericCalculation(arg2, context);
                TNumber tmp3 = Computation.NumericCalculation(arg3, context);

                MatrixL <TNumber> matrixL = Utilites.TMatrixToMatrixL(tmp1);
                for (int i = 0; i < tmp3.ToInt32(); i++)
                {
                    matrixL.RemoveColAt(tmp2.ToInt32() - 1);
                }
                TMatrix m = Utilites.MatrixLToTMatrix(matrixL);

                result = Entry.Create(m.ToTerms());
                return(true);
            }


            if (value.Type == TermType.Function && value.ArgsCount == 1 && value.Text == "nonZerosRows")
            {
                Entry arg1 = Computation.Preprocessing(value.Items[0], context);

                TNumber tmp1 = Computation.NumericCalculation(arg1, context);

                MatrixL <TNumber> matrixL = Utilites.TMatrixToMatrixL(tmp1);
                List <int>        indexes = new List <int>(matrixL.R);
                List <TNumber>    row;
                List <double>     rowD;
                int j = 0;
                for (int i = 0; i < matrixL.R; i++)
                {
                    row  = matrixL.Row(i);
                    rowD = new List <double>(matrixL.C);
                    foreach (TNumber item in row)
                    {
                        if (item.obj.Type != BaseEntryType.Double)
                        {
                            break;
                        }
                        //if (item.obj.ToDouble() != 0) break;
                        try
                        {
                            rowD.Add(item.obj.ToDouble());
                        }
                        catch
                        {
                            break;
                        }
                    }
                    rowD = rowD.Distinct().ToList();
                    if (rowD.Count == 1 && rowD[0] == 0)
                    {
                        indexes.Add(i - j);
                        j++;
                    }
                }
                if (indexes.Count > 0)
                {
                    foreach (int item in indexes)
                    {
                        matrixL.RemoveRowAt(item);
                    }
                }
                TMatrix m = Utilites.MatrixLToTMatrix(matrixL);

                result = Entry.Create(m.ToTerms());
                return(true);
            }

            if (value.Type == TermType.Function && value.ArgsCount == 1 && value.Text == "nonZerosRowsCols")
            {
                Entry arg1 = Computation.Preprocessing(value.Items[0], context);

                TNumber tmp1 = Computation.NumericCalculation(arg1, context);

                MatrixL <TNumber> matrixL = Utilites.TMatrixToMatrixL(tmp1);
                List <int>        indexes = new List <int>(matrixL.R);
                List <TNumber>    row;
                List <double>     rowD;
                int j = 0;
                for (int i = 0; i < matrixL.R; i++)
                {
                    row  = matrixL.Row(i);
                    rowD = new List <double>(matrixL.C);
                    foreach (TNumber item in row)
                    {
                        if (item.obj.Type != BaseEntryType.Double)
                        {
                            break;
                        }
                        //if (item.obj.ToDouble() != 0) break;
                        try
                        {
                            rowD.Add(item.obj.ToDouble());
                        }
                        catch
                        {
                            break;
                        }
                    }
                    rowD = rowD.Distinct().ToList();
                    if (rowD.Count == 1 && rowD[0] == 0)
                    {
                        indexes.Add(i - j);
                        j++;
                    }
                }
                if (indexes.Count > 0)
                {
                    foreach (int item in indexes)
                    {
                        matrixL.RemoveRowAt(item);
                    }
                }

                indexes = new List <int>(matrixL.C);
                List <TNumber> col;
                List <double>  colD;
                j = 0;
                for (int i = 0; i < matrixL.C; i++)
                {
                    col  = matrixL.Col(i);
                    colD = new List <double>(matrixL.R);
                    foreach (TNumber item in col)
                    {
                        if (item.obj.Type != BaseEntryType.Double)
                        {
                            break;
                        }
                        //if (item.obj.ToDouble() != 0) break;
                        try
                        {
                            colD.Add(item.obj.ToDouble());
                        }
                        catch
                        {
                            break;
                        }
                    }
                    colD = colD.Distinct().ToList();
                    if (colD.Count == 1 && colD[0] == 0)
                    {
                        indexes.Add(i - j);
                        j++;
                    }
                }
                if (indexes.Count > 0)
                {
                    foreach (int item in indexes)
                    {
                        matrixL.RemoveColAt(item);
                    }
                }
                TMatrix m = Utilites.MatrixLToTMatrix(matrixL);

                result = Entry.Create(m.ToTerms());
                return(true);
            }

            if (value.Type == TermType.Function && value.ArgsCount == 1 && value.Text == "nonZerosCols")
            {
                Entry arg1 = Computation.Preprocessing(value.Items[0], context);

                TNumber tmp1 = Computation.NumericCalculation(arg1, context);

                MatrixL <TNumber> matrixL = Utilites.TMatrixToMatrixL(tmp1);
                List <int>        indexes = new List <int>(matrixL.C);
                List <TNumber>    col;
                List <double>     colD;
                int j = 0;
                for (int i = 0; i < matrixL.C; i++)
                {
                    col  = matrixL.Col(i);
                    colD = new List <double>(matrixL.R);
                    foreach (TNumber item in col)
                    {
                        if (item.obj.Type != BaseEntryType.Double)
                        {
                            break;
                        }
                        //if (item.obj.ToDouble() != 0) break;
                        try
                        {
                            colD.Add(item.obj.ToDouble());
                        }
                        catch
                        {
                            break;
                        }
                    }
                    colD = colD.Distinct().ToList();
                    if (colD.Count == 1 && colD[0] == 0)
                    {
                        indexes.Add(i - j);
                        j++;
                    }
                }
                if (indexes.Count > 0)
                {
                    foreach (int item in indexes)
                    {
                        matrixL.RemoveColAt(item);
                    }
                }
                TMatrix m = Utilites.MatrixLToTMatrix(matrixL);

                result = Entry.Create(m.ToTerms());
                return(true);
            }


            if (value.Type == TermType.Function && value.ArgsCount == 4 && value.Text == "putMatrix")
            {
                Entry arg1 = Computation.Preprocessing(value.Items[0], context);
                Entry arg2 = Computation.Preprocessing(value.Items[1], context);
                Entry arg3 = Computation.Preprocessing(value.Items[2], context);
                Entry arg4 = Computation.Preprocessing(value.Items[3], context);

                TNumber tmp1 = Computation.NumericCalculation(arg1, context);
                TNumber tmp2 = Computation.NumericCalculation(arg2, context);
                TNumber tmp3 = Computation.NumericCalculation(arg3, context);
                TNumber tmp4 = Computation.NumericCalculation(arg4, context);

                if (tmp3.ToInt32() < 1 || tmp4.ToInt32() < 1)
                {
                    throw new ArgumentException("Неверно задана индексация");
                }

                int adressR = tmp3.ToInt32() - 1;
                int adressC = tmp4.ToInt32() - 1;

                MatrixL <TNumber> matrixL1 = Utilites.TMatrixToMatrixL(tmp1);
                MatrixL <TNumber> matrixL2 = Utilites.TMatrixToMatrixL(tmp2);

                int n = matrixL1.R - adressR;
                int m = matrixL1.C - adressC;
                if (n > matrixL2.R)
                {
                    n = matrixL2.R;
                }
                if (m > matrixL2.C)
                {
                    m = matrixL2.C;
                }

                for (int i = 0; i < n; i++)
                {
                    for (int j = 0; j < m; j++)
                    {
                        matrixL1[adressR + i, adressC + j] = matrixL2[i, j];
                    }
                }

                TMatrix mat = Utilites.MatrixLToTMatrix(matrixL1);

                result = Entry.Create(mat.ToTerms());
                return(true);
            }


            if (value.Type == TermType.Function && value.ArgsCount == 4 && value.Text == "insertMatrix")
            {
                Entry arg1 = Computation.Preprocessing(value.Items[0], context);
                Entry arg2 = Computation.Preprocessing(value.Items[1], context);
                Entry arg3 = Computation.Preprocessing(value.Items[2], context);
                Entry arg4 = Computation.Preprocessing(value.Items[3], context);

                TNumber tmp1 = Computation.NumericCalculation(arg1, context);
                TNumber tmp2 = Computation.NumericCalculation(arg2, context);
                TNumber tmp3 = Computation.NumericCalculation(arg3, context);
                TNumber tmp4 = Computation.NumericCalculation(arg4, context);

                if (tmp3.ToInt32() < 1 || tmp4.ToInt32() < 1)
                {
                    throw new ArgumentException("Неверно задана индексация");
                }

                int adressR = tmp3.ToInt32() - 1;
                int adressC = tmp4.ToInt32() - 1;

                MatrixL <TNumber> matrixL1 = Utilites.TMatrixToMatrixL(tmp1);
                MatrixL <TNumber> matrixL2 = Utilites.TMatrixToMatrixL(tmp2);

                for (int i = 0; i < matrixL2.R; i++)
                {
                    matrixL1.InsertRow(adressR);
                }
                for (int i = 0; i < matrixL2.C; i++)
                {
                    matrixL1.InsertCol(adressC);
                }

                int n = matrixL1.R - adressR;
                int m = matrixL1.C - adressC;
                if (n > matrixL2.R)
                {
                    n = matrixL2.R;
                }
                if (m > matrixL2.C)
                {
                    m = matrixL2.C;
                }

                for (int i = 0; i < n; i++)
                {
                    for (int j = 0; j < m; j++)
                    {
                        matrixL1[adressR + i, adressC + j] = matrixL2[i, j];
                    }
                }

                TMatrix mat = Utilites.MatrixLToTMatrix(matrixL1);

                result = Entry.Create(mat.ToTerms());
                return(true);
            }


            result = null;
            return(false);
        }
コード例 #29
0
 public string Accept(TDouble type, string bufName, string fieldName)
 {
     return($"{fieldName} = {bufName}.ReadDouble();");
 }
コード例 #30
0
 public DType Accept(TDouble type, XElement x, DefAssembly ass)
 {
     return(DDouble.ValueOf(double.Parse(x.Value.Trim())));
 }