public MatrixXD Concat(MatrixXD other, ConcatType concatType) { switch (concatType) { case ConcatType.Horizontal: { var totalCols = Cols + other.Cols; double[] inputValues = new double[Rows * totalCols]; var matrixXD = new MatrixXD(inputValues, Rows, totalCols); for (int i = 0; i < Rows; i++) { for (int j = 0; j < Cols; j++) { matrixXD.Set(i, j, Get(i, j)); } } int otherCols = other.Cols; for (int i = 0; i < other.Rows; i++) { for (int j = 0; j < otherCols; j++) { matrixXD.Set(i, Cols + j, other.Get(i, j)); } } return(matrixXD); } case ConcatType.Vertical: default: { int totalRows = Rows + other.Rows; double[] inputValues = new double[totalRows * Cols]; MatrixXD matrixXD = new MatrixXD(inputValues, totalRows, Cols); for (int i = 0; i < Rows; i++) { for (int j = 0; j < Cols; j++) { matrixXD.Set(i, j, Get(i, j)); } } int otherRows = other.Rows; for (int i = 0; i < otherRows; i++) { for (int j = 0; j < Cols; j++) { matrixXD.Set(Rows + i, j, other.Get(i, j)); } } return(matrixXD); } } }
/// <summary> /// 连接表达式与运算 /// </summary> /// <typeparam name="T">参数</typeparam> /// <param name="one">原表达式</param> /// <param name="another">新的表达式</param> /// <param name="type">连接类型</param> /// <returns></returns> public static Expression <Func <T, bool> > Concat <T>(this Expression <Func <T, bool> > one, Expression <Func <T, bool> > another, ConcatType type) { //创建新参数 var newParameter = Expression.Parameter(typeof(T), "parameter"); var parameterReplacer = new ParameterReplaceVisitor(newParameter); var left = parameterReplacer.Visit(one.Body); var right = parameterReplacer.Visit(another.Body); BinaryExpression body; switch (type) { case ConcatType.And: body = Expression.And(left, right); break; case ConcatType.AndAlso: body = Expression.AndAlso(left, right); break; case ConcatType.Or: body = Expression.Or(left, right); break; case ConcatType.OrElse: body = Expression.OrElse(left, right); break; default: throw new ApplicationException($"未知的连接类型 {type}"); } return(Expression.Lambda <Func <T, bool> >(body, newParameter)); }