private GenTensor <SafeDivisionWrapper <T> > InnerGaussianEliminationSafeDivision(int n) { InitIfNotInitted(); var elemMatrix = GenTensor <SafeDivisionWrapper <T> > .CreateMatrix(n, n, (x, y) => new SafeDivisionWrapper <T>(ConstantsAndFunctions <T> .Forward(this.GetValueNoCheck(x, y))) ); for (int k = 1; k < n; k++) { for (int j = k; j < n; j++) { var m = ConstantsAndFunctions <SafeDivisionWrapper <T> > .Divide( elemMatrix.GetValueNoCheck(j, k - 1), elemMatrix.GetValueNoCheck(k - 1, k - 1) ); for (int i = 0; i < n; i++) { var curr = elemMatrix.GetValueNoCheck(j, i); elemMatrix.SetValueNoCheck(ConstantsAndFunctions <SafeDivisionWrapper <T> > .Subtract( curr, ConstantsAndFunctions <SafeDivisionWrapper <T> > .Multiply( m, elemMatrix.GetValueNoCheck(k - 1, i) ) ), j, i); } } } return(elemMatrix); }
public GenTensor <T> GaussianEliminationSafeDivision() { #if ALLOW_EXCEPTIONS if (!IsMatrix) { throw new InvalidShapeException("this should be matrix"); } if (Shape[0] != Shape[1]) { throw new InvalidShapeException("this should be square matrix"); } #endif var wrp = InnerGaussianEliminationSafeDivision(Shape[0]); return(GenTensor <T> .CreateMatrix(Shape[0], Shape[1], (x, y) => wrp.GetValueNoCheck(x, y).Count())); }