public void Add_CheckResultWithExpected_EqualsExpected <T, TMonoid> ( T hack1, TMonoid hack2, IMatrix <T, TMonoid> matrix, List <List <T> > underlyingList) where TMonoid : IGroup <T>, new() { var result = matrix.Add(matrix); Assert.IsNotNull(result); Assert.IsFalse(Object.ReferenceEquals(matrix, result)); Assert.AreEqual(matrix.RowDimension, result.RowDimension); Assert.AreEqual(matrix.ColumnDimension, matrix.ColumnDimension); var group = new TMonoid(); for (Int32 i = 0; i < matrix.RowDimension; i++) { for (Int32 j = 0; j < matrix.ColumnDimension; j++) { var expected = group.Addition( underlyingList [i] [j], underlyingList [i] [j]); Assert.AreEqual(expected, result [(UInt32)i, (UInt32)j]); } } }
protected virtual void AddThirdBoundary(IMatrix A, double[] b, ThirdBoundaryEdge edge) { double[,] M = info.BoundaryBasis.MassMatrix; Func <double, double, double, double> ubetatime = edge.UBeta; Func <double, double, double> ubeta = (double x, double y) => ubetatime(x, y, 0); double beta = edge.Beta; Point p1 = info.Mesh.Points[edge[0]]; Point p2 = info.Mesh.Points[edge[edge.NodeCount - 1]]; double x0 = p1.X; double y0 = p1.Y; double x1 = p2.X; double y1 = p2.Y; double h = Point.Distance(p1, p2); for (int i = 0; i < info.BoundaryBasis.Size; i++) { b[edge[i]] += beta * h * Quadratures.NewtonCotes(0.0, 1.0, (double ksi) => ubeta(x0 + ksi * (x1 - x0), y0 + ksi * (y1 - y0)) * boundaryPsi[i](ksi)); } for (int i = 0; i < info.BoundaryBasis.Size; i++) { for (int j = 0; j < info.BoundaryBasis.Size; j++) { A.Add(edge[i], edge[j], beta * h * M[i, j]); } } }
protected override void _Activate(IContext context, IMatrix primary, IMatrix secondary) { var output = primary.Add(secondary); // default is to pass the error signal through, which is correct for addition _AddHistory(context, output, null); }
public void Build(IMatrix A, double[] b) { for (int q = 0; q < k; q++) { for (int s = 0; s < k; s++) { double value = 0.0; for (int i = 0; i < n; i++) { value += calc.CalculateFromOne(receivers[i], q) * calc.CalculateFromOne(receivers[i], s); } A.Add(q, s, value); } } for (int q = 0; q < k; q++) { double bvalue = 0.0; for (int i = 0; i < n; i++) { bvalue += calc.CalculateFromOne(receivers[i], q) * realG[i]; } b[q] = bvalue; A.Add(q, q, alpha); } for (int i = 0; i < k; i++) { foreach (var adjCell in Mesh.GetAdjacentCells(i, xCellCount, zCellCount)) { A.Add(i, adjCell, -(gamma[i] + gamma[adjCell])); A.Add(i, i, gamma[i] + gamma[adjCell]); } } }
private void AddLocalToGlobal(IMatrix A, double[] b, FiniteElement e) { for (int i = 0; i < info.Basis.Size; i++) { for (int j = 0; j < info.Basis.Size; j++) { A.Add(e[i], e[j], local[i, j]); } } for (int i = 0; i < info.Basis.Size; i++) { b[e[i]] += localb[i]; } }
private IMatrix GetMatrixToBeCalculated(IMatrix topHorizon) { //Constructs the base horizon by adding a scalar to all values from top horizon var baseHorizon = topHorizon.Add(BaseHorizonOffset * Constants.FeetsInMeter); //create horizon for fluid contact var fluidContact = matrixBuilder.Dense(topHorizon.RowCount, topHorizon.ColumnCount, FluidContactDepth * Constants.FeetsInMeter); //create another horizon by comparing the fluid with base and choosing the minimum. var thresholdSurface = fluidContact.PointwiseMinimum(baseHorizon); //create a matrix to hold the distances between top and the threshold, negative values will be ignored during calculating the volume var distanceBetweenSurfaces = thresholdSurface.Subtract(topHorizon); return(distanceBetweenSurfaces); }
void AddToGlobalMatrix(IMatrix A, FiniteElement e, double[,] local) { for (int i = 0; i < FEMParameters.BasisSize; i++) { for (int j = 0; j <= i; j++) { int iGlobal = e[i]; int jGlobal = e[j]; if (jGlobal > iGlobal) { (jGlobal, iGlobal) = (iGlobal, jGlobal); } A.Add(iGlobal, jGlobal, local[i, j]); } } }
public void Test1() { IMatrix <double> mat = new NMatrix(new double[, ] { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }); //IMatrix<double> mat2 = mat.Multiply(IdentityMatrix.CreateNew(3)); IMatrix <double> mat2 = mat.Multiply(mat); IMatrix <double> mat3 = mat2.Add(10); System.Console.WriteLine(mat); System.Console.WriteLine(); System.Console.WriteLine(mat2); System.Console.WriteLine(); System.Console.WriteLine(mat3); }
public void AddOperation_NegativeTestCases(IMatrix leftOperand, IMatrix rightOperand) => new Action(() => leftOperand.Add(rightOperand)).Should() .ThrowExactly <InvalidOperationException>() .WithMessage("The operands' size doesn't match.");
public void AddOperation_PositiveTestCases(IMatrix leftOperand, IMatrix rightOperand, IMatrix result) => MatricesAreEqual(leftOperand.Add(rightOperand), result).Should().BeTrue();