code: public static final DoubleMatrix1D zMult(final DoubleMatrix2D A, final DoubleMatrix1D a, final DoubleMatrix1D b, final double beta){
  
  		if(A.columns()!=a.size()){
  			throw new IllegalArgumentException("Wrong matrix dimensions. Number of columns must be " + a.size() + ", found: " + A.columns());
  		}
  
  		if(A.rows()!=b.size()){
  			throw new IllegalArgumentException("Wrong matrix dimensions. Number of rows must be " + b.size() + ", found: " + A.rows());
  		}
  
  		final DoubleMatrix1D ret = DoubleFactory1D.dense.make(A.rows());
  
  		if(A instanceof SparseDoubleMatrix2D){
  			//sparse matrix
  			A.forEachNonZero(new IntIntDoubleFunction() {
  				@Override
  				public double apply(int i, int j, double Aij) {
  					ret.setQuick(i, ret.getQuick(i) + Aij * a.getQuick(j));
  					return Aij;
  				}
  			});
  			for(int i=0; i<ret.size(); i++){
  				ret.setQuick(i, ret.getQuick(i) + beta * b.getQuick(i));
  			}
  		}else{
  			//dense matrix
  			for(int i=0; i<A.rows(); i++){
  				double vi = beta * b.getQuick(i);
  				for(int j=0; j<A.columns(); j++){
  					vi += A.getQuick(i, j) * a.getQuick(j);
  				}
  				ret.setQuick(i, vi);
  			}
  		}
  
  		return ret;
  	}
docs: Returns v = A.a + beta*b.
  Useful in avoiding the need of the copy() in the colt api.