/// <summary>Computes the minimum norm solution to a real linear least squares problem /// </summary> /// <param name="A">left hand side (overwritten on exit)</param> /// <param name="B">right hand side</param> /// <param name="S"> /// The singular values of A in decreasing order. The condition number /// of A in the 2-norm = S(1)/S(min(m,n)) /// </param> /// <param name="rank"> /// an IntVector of size 1, on exit the first element contains the /// effective rank of A, i.e., the number of singular values which are /// greater than RCOND*S(1) /// </param> /// <param name="work">a work vector</param> /// <param name="workSize"> /// if -1 then workspace query is assumed and work[0] will contain the /// size of the optimal workspace /// </param> /// <returns> /// 0 success, <0 -ith argument had an error, >0 the algorithm for /// computing the SVD failed to converge; if INFO = i, i off-diagonal /// elements of an intermediate bidiagonal form did not converge to zero. /// </returns> public static int dgelss(fastmath.DoubleMatrix A, fastmath.DoubleMatrix B, fastmath.Vector S, fastmath.IntVector rank, fastmath.Vector work, int workSize) { System.Diagnostics.Debug.Assert(B.getRowCount() >= System.Math.max(A.getRowCount( ), A.getColCount()), "B.rows < max(A.rows,A.cols)"); System.Diagnostics.Debug.Assert(S.Count == System.Math.min(A.getRowCount(), A.getColCount ()), "S.length < min(A.rows,A.cols)"); System.Diagnostics.Debug.Assert(A.getRowIncrement() == 1, "A must be col major, 1 != rowIncrement = " + A.getRowIncrement()); // On entry, the M-by-N matrix A. On exit, the first min(m,n) rows of // A are overwritten with its right singular vectors, stored rowwise. throw new System.NotSupportedException("TODO"); }
/// <exception cref="fastmath.exceptions.NotInvertableException"/> public virtual fastmath.DoubleColMatrix invert() { fastmath.IntVector pivots = new fastmath.IntVector(getRowCount()); com.sun.jna.Pointer rowCount = newIntParam(getRowCount()); com.sun.jna.Pointer colCount = newIntParam(getColCount()); fastmath.IntVector output = new fastmath.IntVector(1); com.sun.jna.Pointer outBuffer = com.sun.jna.Native.getDirectBufferPointer(output. getBuffer()); com.sun.jna.Pointer pivotBuffer = com.sun.jna.Native.getDirectBufferPointer(pivots .getBuffer()); fastmath.LAPACK.instance.dgetrf_(rowCount, colCount, getPointer(), rowCount, pivotBuffer , outBuffer); if (output.elementAt(0) > 0) { throw new fastmath.exceptions.NotInvertableException(output.elementAt(0)); } else { if (output.elementAt(0) < 0) { throw new System.ArgumentException("the " + -output.elementAt(0) + "-th argument had an illegal value" ); } } fastmath.Vector workspace = new fastmath.Vector(1024); com.sun.jna.Pointer lwork = newIntParam(workspace.size); fastmath.LAPACK.instance.dgetri_(rowCount, getPointer(), rowCount, pivotBuffer, workspace .getPointer(), lwork, outBuffer); if (output.elementAt(0) > 0) { throw new fastmath.exceptions.NotInvertableException(output.elementAt(0)); } else { if (output.elementAt(0) < 0) { throw new System.ArgumentException("the " + -output.elementAt(0) + "-th argument had an illegal value" ); } } return(this); }
// Fastmath.instance.dcopy(X.size, X.getBuffer().asDoubleBuffer(), // X.getIncrement(), Y.getBuffer().asDoubleBuffer(), Y.getIncrement()); public static int dgetrf(fastmath.AbstractMatrix A, fastmath.IntVector ipiv) { return(dgetrf(A.isColMajor(), A.getRowCount(), A.getColCount(), A.getBuffer(), A. getOffset(0, 0), A.getRowCount(), ipiv.getBuffer())); }
private com.sun.jna.Pointer newIntParam(int rowCount) { fastmath.IntVector ib = new fastmath.IntVector(1); ib.setElementAt(0, rowCount); return(com.sun.jna.Native.getDirectBufferPointer(ib.getBuffer())); }