Dlaset.java

package org.mklab.sdpj.gpack.lapackwrap;

import org.mklab.nfc.matrix.ComplexNumericalMatrix;
import org.mklab.nfc.matrix.RealNumericalMatrix;
import org.mklab.nfc.scalar.ComplexNumericalScalar;
import org.mklab.nfc.scalar.RealNumericalScalar;
import org.mklab.sdpj.gpack.blaswrap.BLAS;


/**
 * @author koga
 * @version $Revision$, 2009/04/25
   * @param <RS> type of real scalar
   * @param <RM> type of real matrix
   * @param <CS> type of complex scalar
   * @param <CM> type of complex Matrix
 */
public class Dlaset<RS extends RealNumericalScalar<RS, RM, CS, CM>, RM extends RealNumericalMatrix<RS, RM, CS, CM>, CS extends ComplexNumericalScalar<RS, RM, CS, CM>, CM extends ComplexNumericalMatrix<RS, RM, CS, CM>> {

  /*  -- LAPACK auxiliary routine (version 3.0) --   
  Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,   
  Courant Institute, Argonne National Lab, and Rice University   
  October 31, 1992   


  Purpose   
  =======   

  DLASET initializes an m-by-n matrix A to BETA on the diagonal and   
  ALPHA on the offdiagonals.   

  Arguments   
  =========   

  UPLO    (input) CHARACTER*1   
       Specifies the part of the matrix A to be set.   
       = 'U':      Upper triangular part is set; the strictly lower   
                   triangular part of A is not changed.   
       = 'L':      Lower triangular part is set; the strictly upper   
                   triangular part of A is not changed.   
       Otherwise:  All of the matrix A is set.   

  M       (input) INTEGER   
       The number of rows of the matrix A.  M >= 0.   

  N       (input) INTEGER   
       The number of columns of the matrix A.  N >= 0.   

  ALPHA   (input) DOUBLE PRECISION   
       The constant to which the offdiagonal elements are to be set.   

  BETA    (input) DOUBLE PRECISION   
       The constant to which the diagonal elements are to be set.   

  A       (input/output) DOUBLE PRECISION array, dimension (LDA,N)   
       On exit, the leading m-by-n submatrix of A is set as follows:   

       if UPLO = 'U', A(i,j) = ALPHA, 1<=i<=j-1, 1<=j<=n,   
       if UPLO = 'L', A(i,j) = ALPHA, j+1<=i<=m, 1<=j<=n,   
       otherwise,     A(i,j) = ALPHA, 1<=i<=m, 1<=j<=n, i.ne.j,   

       and, for all UPLO, A(i,i) = BETA, 1<=i<=min(m,n).   

  LDA     (input) INTEGER   
       The leading dimension of the array A.  LDA >= max(1,M).   

  =====================================================================   
  */
  /**
   * Subroutine
   * 
   * @param uplo uplo
   * @param m m
   * @param n n
   * @param alpha alpha
   * @param beta beta
   * @param a a
   * @param lda lda
   * @return result
   */
  int execute(String uplo, int m, int n, RS alpha, RS beta, RS[] a, int lda) {
    int a_dim1 = lda;
    int a_offset = 1 + a_dim1 * 1;
    int pointer_a = -a_offset;

    if (BLAS.lsame(uplo, "U")) { //$NON-NLS-1$
      // Set the strictly upper triangular or trapezoidal part of the array to ALPHA.
      for (int j = 2; j <= n; ++j) {
        for (int i = 1; i <= Math.min(j - 1, m); ++i) {
          a[(j) * a_dim1 + i + pointer_a] = alpha;
        }
      }
    } else if (BLAS.lsame(uplo, "L")) { //$NON-NLS-1$
      // Set the strictly lower triangular or trapezoidal part of the array to ALPHA.
      for (int j = 1; j <= Math.min(m, n); ++j) {
        for (int i = j + 1; i <= m; ++i) {
          a[(j) * a_dim1 + i + pointer_a] = alpha;
        }
      }
    } else {
      // Set the leading m-by-n submatrix to ALPHA.
      for (int j = 1; j <= n; ++j) {
        for (int i = 1; i <= m; ++i) {
          a[(j) * a_dim1 + i + pointer_a] = alpha;
        }
      }
    }

    // Set the first min(M,N) diagonal elements to BETA.
    for (int i = 1; i <= Math.min(m, n); ++i) {
      a[(i) * a_dim1 + i + pointer_a] = beta;
    }

    return 0;
  }
}