code: public static Matrix diag(Vec a)
      {
          DenseMatrix A = new DenseMatrix(a.length(), a.length());
          for(Iterator<IndexValue> iter = a.getNonZeroIterator(); iter.hasNext();)
          {
              IndexValue iv = iter.next();
              A.set(iv.getIndex(), iv.getIndex(), iv.getValue());
          }
              
          return A;
      }
docs: Returns a new dense square matrix such that the main diagonal contains
  the values given in <tt>a</tt>
  @param a the diagonal values of a matrix
  @return the diagonal matrix represent by <i>a</i>