/// <summary> /// Solves A*X=B for X using a previously QR factored matrix. /// </summary> /// <param name="q">The Q matrix obtained by QR factor. This is only used for the managed provider and can be /// <c>null</c> for the native provider. The native provider uses the Q portion stored in the R matrix.</param> /// <param name="r">The R matrix obtained by calling <see cref="QRFactor(float[],int,int,float[],float[])"/>. </param> /// <param name="rowsR">The number of rows in the A matrix.</param> /// <param name="columnsR">The number of columns in the A matrix.</param> /// <param name="tau">Contains additional information on Q. Only used for the native solver /// and can be <c>null</c> for the managed provider.</param> /// <param name="b">On entry the B matrix; on exit the X matrix.</param> /// <param name="columnsB">The number of columns of B.</param> /// <param name="x">On exit, the solution matrix.</param> /// <param name="work">The work array - only used in the native provider. The array must have a length of at least N, /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal /// work size value.</param> /// <remarks>Rows must be greater or equal to columns.</remarks> public override void QRSolveFactored(float[] q, float[] r, int rowsR, int columnsR, float[] tau, float[] b, int columnsB, float[] x, float[] work) { if (r == null) { throw new ArgumentNullException("r"); } if (q == null) { throw new ArgumentNullException("q"); } if (b == null) { throw new ArgumentNullException("q"); } if (x == null) { throw new ArgumentNullException("q"); } if (work == null) { throw new ArgumentNullException("work"); } if (r.Length != rowsR * columnsR) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "r"); } if (q.Length != rowsR * rowsR) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "q"); } if (b.Length != rowsR * columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } if (x.Length != columnsR * columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "x"); } if (rowsR < columnsR) { throw new ArgumentException(Resources.RowsLessThanColumns); } if (work.Length < 1) { work[0] = rowsR * Control.BlockSize; throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } SafeNativeMethods.s_qr_solve_factored(rowsR, columnsR, columnsB, r, b, tau, x, work, work.Length); }
public override void QRSolveFactored(float[] q, float[] r, int rowsA, int columnsA, float[] tau, float[] b, int columnsB, float[] x, float[] work, QRMethod method = QRMethod.Full) { if (r == null) { throw new ArgumentNullException("r"); } if (q == null) { throw new ArgumentNullException("q"); } if (b == null) { throw new ArgumentNullException("q"); } if (x == null) { throw new ArgumentNullException("q"); } if (work == null) { throw new ArgumentNullException("work"); } int rowsQ, columnsQ, rowsR, columnsR; if (method == QRMethod.Full) { rowsQ = columnsQ = rowsR = rowsA; columnsR = columnsA; } else { rowsQ = rowsA; columnsQ = rowsR = columnsR = columnsA; } if (r.Length != rowsR * columnsR) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, rowsR * columnsR), "r"); } if (q.Length != rowsQ * columnsQ) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, rowsQ * columnsQ), "q"); } if (b.Length != rowsA * columnsB) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, rowsA * columnsB), "b"); } if (x.Length != columnsA * columnsB) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, columnsA * columnsB), "x"); } if (work.Length < 1) { work[0] = rowsA * Control.BlockSize; throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } if (method == QRMethod.Full) { SafeNativeMethods.s_qr_solve_factored(rowsA, columnsA, columnsB, r, b, tau, x, work, work.Length); } else { // we don't have access to the raw Q matrix any more(it is stored in R in the full QR), need to think about this. // let just call the managed version in the meantime. The heavy lifting has already been done. -marcus base.QRSolveFactored(q, r, rowsA, columnsA, tau, b, columnsB, x, QRMethod.Thin); } }