//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testKroneckerProduct() public virtual void testKroneckerProduct() { Matrix m = ALGEBRA.kroneckerProduct(M3, M4); assertTrue(m is DoubleMatrix); assertMatrixEquals(m, DoubleMatrix.of(4, 4, 5, 6, 10, 12, 7, 8, 14, 16, 15, 18, 20, 24, 21, 24, 28, 32)); }
/// <summary> /// Finds the node sensitivity. /// </summary> /// <param name="pp"> the <seealso cref="PiecewisePolynomialResultsWithSensitivity"/> </param> /// <param name="xKey"> the key </param> /// <returns> Node sensitivity value at x=xKey </returns> public virtual DoubleArray nodeSensitivity(PiecewisePolynomialResultsWithSensitivity pp, double xKey) { ArgChecker.notNull(pp, "null pp"); ArgChecker.isFalse(double.IsNaN(xKey), "xKey containing NaN"); ArgChecker.isFalse(double.IsInfinity(xKey), "xKey containing Infinity"); if (pp.Dimensions > 1) { throw new System.NotSupportedException(); } DoubleArray knots = pp.Knots; int nKnots = knots.size(); int interval = FunctionUtils.getLowerBoundIndex(knots, xKey); if (interval == nKnots - 1) { interval--; // there is 1 less interval that knots } double s = xKey - knots.get(interval); DoubleMatrix a = pp.getCoefficientSensitivity(interval); int nCoefs = a.rowCount(); DoubleArray res = a.row(0); for (int i = 1; i < nCoefs; i++) { res = (DoubleArray)MA.scale(res, s); res = (DoubleArray)MA.add(res, a.row(i)); } return(res); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testGetters() public virtual void testGetters() { assertTrue(Arrays.Equals(A, M.DiagonalData)); assertTrue(Arrays.Equals(B, M.UpperSubDiagonalData)); assertTrue(Arrays.Equals(C, M.LowerSubDiagonalData)); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int n = A.length; int n = A.Length; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final com.opengamma.strata.collect.array.DoubleMatrix matrix = M.toDoubleMatrix(); DoubleMatrix matrix = M.toDoubleMatrix(); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i == j) { assertEquals(matrix.get(i, j), A[i], 0); } else if (j == i + 1) { assertEquals(matrix.get(i, j), B[j - 1], 0); } else if (j == i - 1) { assertEquals(matrix.get(i, j), C[j], 0); } else { assertEquals(matrix.get(i, j), 0, 0); } } } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testInvertIdentity() public virtual void testInvertIdentity() { const int n = 11; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final double[] a = new double[n]; double[] a = new double[n]; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final double[] b = new double[n - 1]; double[] b = new double[n - 1]; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final double[] c = new double[n - 1]; double[] c = new double[n - 1]; int i, j; for (i = 0; i < n; i++) { a[i] = 1.0; } //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final com.opengamma.strata.collect.array.DoubleMatrix res = CALCULATOR.apply(new TridiagonalMatrix(a, b, c)); DoubleMatrix res = CALCULATOR.apply(new TridiagonalMatrix(a, b, c)); for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { assertEquals((i == j ? 1.0 : 0.0), res.get(i, j), EPS); } } }
/// <summary> /// Adds two matrices. This operation can only be performed if the matrices are of the same type and dimensions. </summary> /// <param name="m1"> The first matrix, not null </param> /// <param name="m2"> The second matrix, not null </param> /// <returns> The sum of the two matrices </returns> /// <exception cref="IllegalArgumentException"> If the matrices are not of the same type, if the matrices are not the same shape. </exception> public virtual Matrix add(Matrix m1, Matrix m2) { ArgChecker.notNull(m1, "m1"); ArgChecker.notNull(m2, "m2"); if (m1 is DoubleArray) { if (m2 is DoubleArray) { DoubleArray array1 = (DoubleArray)m1; DoubleArray array2 = (DoubleArray)m2; return(array1.plus(array2)); } throw new System.ArgumentException("Tried to add a " + m1.GetType() + " and " + m2.GetType()); } else if (m1 is DoubleMatrix) { if (m2 is DoubleMatrix) { DoubleMatrix matrix1 = (DoubleMatrix)m1; DoubleMatrix matrix2 = (DoubleMatrix)m2; return(matrix1.plus(matrix2)); } throw new System.ArgumentException("Tried to add a " + m1.GetType() + " and " + m2.GetType()); } throw new System.NotSupportedException(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testRecoverOrginal() public virtual void testRecoverOrginal() { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final com.opengamma.strata.math.impl.matrix.MatrixAlgebra algebra = getAlgebra(); MatrixAlgebra algebra = Algebra; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final com.opengamma.strata.math.linearalgebra.DecompositionResult result = getSVD().apply(A); DecompositionResult result = SVD.apply(A); assertTrue(result is SVDecompositionResult); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final SVDecompositionResult svd_result = (SVDecompositionResult) result; SVDecompositionResult svd_result = (SVDecompositionResult)result; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final com.opengamma.strata.collect.array.DoubleMatrix u = svd_result.getU(); DoubleMatrix u = svd_result.U; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final com.opengamma.strata.collect.array.DoubleMatrix w = com.opengamma.strata.collect.array.DoubleMatrix.diagonal(com.opengamma.strata.collect.array.DoubleArray.copyOf(svd_result.getSingularValues())); DoubleMatrix w = DoubleMatrix.diagonal(DoubleArray.copyOf(svd_result.SingularValues)); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final com.opengamma.strata.collect.array.DoubleMatrix vt = svd_result.getVT(); DoubleMatrix vt = svd_result.VT; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final com.opengamma.strata.collect.array.DoubleMatrix a = (com.opengamma.strata.collect.array.DoubleMatrix) algebra.multiply(algebra.multiply(u, w), vt); DoubleMatrix a = (DoubleMatrix)algebra.multiply(algebra.multiply(u, w), vt); checkEquals(A, a); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testEquals() public virtual void testEquals() { LeastSquareResults ls1 = new LeastSquareResults(1.0, PARAMS, COVAR); LeastSquareResults ls2 = new LeastSquareResults(1.0, DoubleArray.of(1.0, 2.0), DoubleMatrix.copyOf(new double[][] { new double[] { 0.1, 0.2 }, new double[] { 0.2, 0.3 } })); assertEquals(ls1, ls2); ls2 = new LeastSquareResults(1.0, PARAMS, COVAR, null); assertEquals(ls1, ls2); ls2 = new LeastSquareResults(1.1, PARAMS, COVAR); assertFalse(ls1.Equals(ls2)); ls2 = new LeastSquareResults(1.0, DoubleArray.of(1.1, 2.0), DoubleMatrix.copyOf(new double[][] { new double[] { 0.1, 0.2 }, new double[] { 0.2, 0.3 } })); assertFalse(ls1.Equals(ls2)); ls2 = new LeastSquareResults(1.0, DoubleArray.of(1.0, 2.0), DoubleMatrix.copyOf(new double[][] { new double[] { 0.1, 0.2 }, new double[] { 0.2, 0.4 } })); assertFalse(ls1.Equals(ls2)); ls2 = new LeastSquareResults(1.0, PARAMS, COVAR, INV_JAC); assertFalse(ls1.Equals(ls2)); ls1 = new LeastSquareResults(1, PARAMS, COVAR, INV_JAC); ls2 = new LeastSquareResults(1, PARAMS, COVAR, COVAR); assertFalse(ls1.Equals(ls2)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test(expectedExceptions = IllegalArgumentException.class) public void testNotSquare1() public virtual void testNotSquare1() { new LeastSquareResults(1, PARAMS, DoubleMatrix.copyOf(new double[][] { new double[] { 0.2, 0.3 } })); }
/// <summary> /// Gamma is in the form gamma^i_{j,k} =\partial^2y_j/\partial x_i \partial x_k, where i is the /// index of the matrix in the stack (3rd index of the tensor), and j,k are the individual /// matrix indices. We would like it in the form H^i_{j,k} =\partial^2y_i/\partial x_j \partial x_k, /// so that each matrix is a Hessian (for the dependent variable y_i), hence the reshaping below. /// </summary> /// <param name="gamma"> the rank 3 tensor </param> /// <returns> the reshaped rank 3 tensor </returns> private DoubleMatrix[] reshapeTensor(DoubleMatrix[] gamma) { int m = gamma.Length; int n = gamma[0].rowCount(); ArgChecker.isTrue(gamma[0].columnCount() == m, "tenor wrong size. Seond index is {}, should be {}", gamma[0].columnCount(), m); DoubleMatrix[] res = new DoubleMatrix[n]; for (int i = 0; i < n; i++) { //JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java: //ORIGINAL LINE: double[][] temp = new double[m][m]; double[][] temp = RectangularArrays.ReturnRectangularDoubleArray(m, m); for (int j = 0; j < m; j++) { DoubleMatrix gammaJ = gamma[j]; for (int k = j; k < m; k++) { temp[j][k] = gammaJ.get(i, k); } } for (int j = 0; j < m; j++) { for (int k = 0; k < j; k++) { temp[j][k] = temp[k][j]; } } res[i] = DoubleMatrix.copyOf(temp); } return(res); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testHashCode() public virtual void testHashCode() { LeastSquareResults ls1 = new LeastSquareResults(1.0, PARAMS, COVAR); LeastSquareResults ls2 = new LeastSquareResults(1.0, DoubleArray.of(1.0, 2.0), DoubleMatrix.copyOf(new double[][] { new double[] { 0.1, 0.2 }, new double[] { 0.2, 0.3 } })); assertEquals(ls1.GetHashCode(), ls2.GetHashCode(), 0); ls2 = new LeastSquareResults(1.0, DoubleArray.of(1.0, 2.0), DoubleMatrix.copyOf(new double[][] { new double[] { 0.1, 0.2 }, new double[] { 0.2, 0.3 } }), null); assertEquals(ls1.GetHashCode(), ls2.GetHashCode(), 0); ls1 = new LeastSquareResults(1.0, PARAMS, COVAR, INV_JAC); ls2 = new LeastSquareResults(1.0, DoubleArray.of(1.0, 2.0), DoubleMatrix.copyOf(new double[][] { new double[] { 0.1, 0.2 }, new double[] { 0.2, 0.3 } }), DoubleMatrix.copyOf(new double[][] { new double[] { 0.5, 0.6 }, new double[] { 0.7, 0.8 } })); assertEquals(ls1.GetHashCode(), ls2.GetHashCode(), 0); }
/// <summary> /// Compute $A^T A$, where A is a matrix. </summary> /// <param name="a"> The matrix </param> /// <returns> The result of $A^T A$ </returns> public virtual DoubleMatrix matrixTransposeMultiplyMatrix(DoubleMatrix a) { ArgChecker.notNull(a, "a"); int n = a.rowCount(); int m = a.columnCount(); //JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java: //ORIGINAL LINE: double[][] data = new double[m][m]; double[][] data = RectangularArrays.ReturnRectangularDoubleArray(m, m); for (int i = 0; i < m; i++) { double sum = 0d; for (int k = 0; k < n; k++) { sum += a.get(k, i) * a.get(k, i); } data[i][i] = sum; for (int j = i + 1; j < m; j++) { sum = 0d; for (int k = 0; k < n; k++) { sum += a.get(k, i) * a.get(k, j); } data[i][j] = sum; data[j][i] = sum; } } return(DoubleMatrix.ofUnsafe(data)); }
public override LeastSquaresRegressionResult regress(double[][] x, double[][] weights, double[] y, bool useIntercept) { if (weights == null) { throw new System.ArgumentException("Cannot perform GLS regression without an array of weights"); } checkData(x, weights, y); double[][] dep = addInterceptVariable(x, useIntercept); double[] indep = new double[y.Length]; //JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java: //ORIGINAL LINE: double[][] wArray = new double[y.Length][y.Length]; double[][] wArray = RectangularArrays.ReturnRectangularDoubleArray(y.Length, y.Length); for (int i = 0; i < y.Length; i++) { indep[i] = y[i]; for (int j = 0; j < y.Length; j++) { wArray[i][j] = weights[i][j]; } } DoubleMatrix matrix = DoubleMatrix.copyOf(dep); DoubleArray vector = DoubleArray.copyOf(indep); DoubleMatrix w = DoubleMatrix.copyOf(wArray); DoubleMatrix transpose = ALGEBRA.getTranspose(matrix); DoubleMatrix betasVector = (DoubleMatrix)ALGEBRA.multiply(ALGEBRA.multiply(ALGEBRA.multiply(ALGEBRA.getInverse(ALGEBRA.multiply(transpose, ALGEBRA.multiply(w, matrix))), transpose), w), vector); double[] yModel = base.writeArrayAsVector(((DoubleMatrix)ALGEBRA.multiply(matrix, betasVector)).toArray()); double[] betas = base.writeArrayAsVector(betasVector.toArray()); return(getResultWithStatistics(x, y, betas, yModel, useIntercept)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test(expectedExceptions = IllegalArgumentException.class) public void testOGMultiply4() public virtual void testOGMultiply4() { OG.multiply(DoubleMatrix.copyOf(new double[][] { new double[] { 1, 2, 3 }, new double[] { 4, 5, 6 } }), M3); }
/// <summary> /// Creates an instance. </summary> /// <param name="knots"> the knots </param> /// <param name="coefMatrix"> the coefMatrix </param> /// <param name="order"> the order </param> /// <param name="dim"> the dim </param> //JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET: //ORIGINAL LINE: public PiecewisePolynomialResult(final com.opengamma.strata.collect.array.DoubleArray knots, final com.opengamma.strata.collect.array.DoubleMatrix coefMatrix, final int order, final int dim) public PiecewisePolynomialResult(DoubleArray knots, DoubleMatrix coefMatrix, int order, int dim) { _knots = knots; _coefMatrix = coefMatrix; _nIntervals = knots.size() - 1; _order = order; _dim = dim; }
/// <param name="coefficients"> Coefficients {a_0, a_1, a_2 ...} of the polynomial a_0 + a_1 x^1 + a_2 x^2 + .... </param> /// <param name="rMatrix"> R-matrix of the QR decomposition used in PolynomialsLeastSquaresRegression </param> /// <param name="dof"> Degrees of freedom = Number of data points - (degrees of Polynomial + 1) </param> /// <param name="diffNorm"> Norm of the vector, "residuals," whose components are yData_i - f(xData_i) </param> /// <param name="meanAndStd"> Vector (mean , standard deviation) used in normalization </param> //JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET: //ORIGINAL LINE: public PolynomialsLeastSquaresFitterResult(final double[] coefficients, final com.opengamma.strata.collect.array.DoubleMatrix rMatrix, final int dof, final double diffNorm, final double[] meanAndStd) public PolynomialsLeastSquaresFitterResult(double[] coefficients, DoubleMatrix rMatrix, int dof, double diffNorm, double[] meanAndStd) { _coefficients = coefficients; _rMatrix = rMatrix; _dof = dof; _diffNorm = diffNorm; _meanAndStd = meanAndStd; }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testInverse() public virtual void testInverse() { assertMatrixEquals(COMMONS.getInverse(M3), DoubleMatrix.copyOf(new double[][] { new double[] { -0.3333333333333333, 0.6666666666666666 }, new double[] { 0.6666666666666666, -0.3333333333333333 } })); }
/// <summary> /// Interpolate. /// </summary> /// <param name="xValues"> the values </param> /// <param name="yValues"> the values </param> /// <param name="xMatrix"> the matrix </param> /// <returns> Values of the underlying cubic spline function at the values of x </returns> //JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET: //ORIGINAL LINE: public com.opengamma.strata.collect.array.DoubleMatrix interpolate(final double[] xValues, final double[] yValues, final double[][] xMatrix) public virtual DoubleMatrix interpolate(double[] xValues, double[] yValues, double[][] xMatrix) { ArgChecker.notNull(xMatrix, "xMatrix"); DoubleMatrix matrix = DoubleMatrix.copyOf(xMatrix); return(DoubleMatrix.ofArrayObjects(xMatrix.Length, xMatrix[0].Length, i => interpolate(xValues, yValues, matrix.rowArray(i)))); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test(expectedExceptions = IllegalArgumentException.class) public void testOGTrace2() public virtual void testOGTrace2() { OG.getTrace(DoubleMatrix.copyOf(new double[][] { new double[] { 1, 2, 3 }, new double[] { 4, 5, 6 } })); }
/// <summary> /// Creates an instance. /// </summary> /// <param name="qr"> The result of the QR decomposition, not null </param> public QRDecompositionCommonsResult(QRDecomposition qr) { ArgChecker.notNull(qr, "qr"); _q = CommonsMathWrapper.unwrap(qr.Q); _r = CommonsMathWrapper.unwrap(qr.R); _qTranspose = _q.transpose(); _solver = qr.Solver; }
public virtual LUDecompositionResult apply(DoubleMatrix x) { ArgChecker.notNull(x, "x"); RealMatrix temp = CommonsMathWrapper.wrap(x); LUDecomposition lu = new LUDecomposition(temp); return(new LUDecompositionCommonsResult(lu)); }
/// <summary> /// Constructor. </summary> /// <param name="ch"> The result of the Cholesky decomposition. </param> public CholeskyDecompositionCommonsResult(CholeskyDecomposition ch) { ArgChecker.notNull(ch, "Cholesky decomposition"); _determinant = ch.Determinant; _l = CommonsMathWrapper.unwrap(ch.L); _lt = CommonsMathWrapper.unwrap(ch.LT); _solver = ch.Solver; }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testOuterProduct() public virtual void testOuterProduct() { assertMatrixEquals(COMMONS.getOuterProduct(M1, M2), DoubleMatrix.copyOf(new double[][] { new double[] { 3, 4 }, new double[] { 6, 8 } })); }
public virtual SVDecompositionResult apply(DoubleMatrix x) { ArgChecker.notNull(x, "x"); MatrixValidate.notNaNOrInfinite(x); RealMatrix commonsMatrix = CommonsMathWrapper.wrap(x); SingularValueDecomposition svd = new SingularValueDecomposition(commonsMatrix); return(new SVDecompositionCommonsResult(svd)); }
/// /// <param name="knots"> the knots </param> /// <param name="coefMatrix"> the coefMatrix </param> /// <param name="order"> the order </param> /// <param name="dim"> the dim </param> /// <param name="coeffSense"> the sensitivity of the coefficients to the nodes (y-values) </param> //JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET: //ORIGINAL LINE: public PiecewisePolynomialResultsWithSensitivity(com.opengamma.strata.collect.array.DoubleArray knots, com.opengamma.strata.collect.array.DoubleMatrix coefMatrix, int order, int dim, final com.opengamma.strata.collect.array.DoubleMatrix[] coeffSense) public PiecewisePolynomialResultsWithSensitivity(DoubleArray knots, DoubleMatrix coefMatrix, int order, int dim, DoubleMatrix[] coeffSense) : base(knots, coefMatrix, order, dim) { if (dim != 1) { throw new System.NotSupportedException(); } ArgChecker.noNulls(coeffSense, "null coeffSense"); // coefficient _coeffSense = coeffSense; }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testPower() public virtual void testPower() { assertMatrixEquals(COMMONS.getPower(M3, 3), DoubleMatrix.copyOf(new double[][] { new double[] { 13, 14 }, new double[] { 14, 13 } })); assertMatrixEquals(COMMONS.getPower(M3, 3), COMMONS.multiply(M3, COMMONS.multiply(M3, M3))); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testMultiply() public virtual void testMultiply() { assertMatrixEquals(COMMONS.multiply(DoubleMatrix.identity(2), M3), M3); assertMatrixEquals(COMMONS.multiply(M3, M4), DoubleMatrix.copyOf(new double[][] { new double[] { 19, 22 }, new double[] { 17, 20 } })); }
/// <summary> /// Interpolate. /// </summary> /// <param name="xValues"> X values of data </param> /// <param name="yValues"> Y values of data </param> /// <param name="xKeys"> the keys </param> /// <returns> Values of the underlying cubic spline function at the values of x </returns> //JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET: //ORIGINAL LINE: public com.opengamma.strata.collect.array.DoubleArray interpolate(final double[] xValues, final double[] yValues, final double[] xKeys) public virtual DoubleArray interpolate(double[] xValues, double[] yValues, double[] xKeys) { ArgChecker.notNull(xKeys, "xKeys"); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int keyLength = xKeys.length; int keyLength = xKeys.Length; for (int i = 0; i < keyLength; ++i) { ArgChecker.isFalse(double.IsNaN(xKeys[i]), "xKeys containing NaN"); ArgChecker.isFalse(double.IsInfinity(xKeys[i]), "xKeys containing Infinity"); } //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final PiecewisePolynomialResult result = this.interpolate(xValues, yValues); PiecewisePolynomialResult result = this.interpolate(xValues, yValues); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final com.opengamma.strata.collect.array.DoubleArray knots = result.getKnots(); DoubleArray knots = result.Knots; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int nKnots = knots.size(); int nKnots = knots.size(); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final com.opengamma.strata.collect.array.DoubleMatrix coefMatrix = result.getCoefMatrix(); DoubleMatrix coefMatrix = result.CoefMatrix; double[] res = new double[keyLength]; for (int j = 0; j < keyLength; ++j) { int indicator = 0; if (xKeys[j] < knots.get(1)) { indicator = 0; } else { for (int i = 1; i < nKnots - 1; ++i) { if (knots.get(i) <= xKeys[j]) { indicator = i; } } } //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final com.opengamma.strata.collect.array.DoubleArray coefs = coefMatrix.row(indicator); DoubleArray coefs = coefMatrix.row(indicator); res[j] = getValue(coefs, xKeys[j], knots.get(indicator)); ArgChecker.isFalse(double.IsInfinity(res[j]), "Too large input"); ArgChecker.isFalse(double.IsNaN(res[j]), "Too large input"); } return(DoubleArray.copyOf(res)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testSubtract() public virtual void testSubtract() { Matrix m = ALGEBRA.subtract(M1, M2); assertTrue(m is DoubleArray); assertMatrixEquals(m, DoubleArray.of(-2, -2)); m = ALGEBRA.subtract(M3, M4); assertTrue(m is DoubleMatrix); assertMatrixEquals(m, DoubleMatrix.of(2, 2, -4d, -4d, -4d, -4d)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testAdd() public virtual void testAdd() { Matrix m = ALGEBRA.add(M1, M2); assertTrue(m is DoubleArray); assertMatrixEquals(m, DoubleArray.of(4, 6)); m = ALGEBRA.add(M3, M4); assertTrue(m is DoubleMatrix); assertMatrixEquals(m, DoubleMatrix.of(2, 2, 6d, 8d, 10d, 12d)); }
/// <summary> /// Interpolate. /// </summary> /// <param name="xValues"> the values </param> /// <param name="yValuesMatrix"> the matrix </param> /// <param name="x"> the s </param> /// <returns> Values of the underlying cubic spline functions interpolating {yValuesMatrix.RowVectors} at the values of x </returns> //JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET: //ORIGINAL LINE: public com.opengamma.strata.collect.array.DoubleMatrix interpolate(final double[] xValues, final double[][] yValuesMatrix, final double[] x) public virtual DoubleMatrix interpolate(double[] xValues, double[][] yValuesMatrix, double[] x) { ArgChecker.notNull(x, "x"); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final com.opengamma.strata.collect.array.DoubleMatrix matrix = com.opengamma.strata.collect.array.DoubleMatrix.copyOf(yValuesMatrix); DoubleMatrix matrix = DoubleMatrix.copyOf(yValuesMatrix); return(DoubleMatrix.ofArrayObjects(yValuesMatrix.Length, x.Length, i => interpolate(xValues, matrix.rowArray(i), x))); }