void add_vector(float * a, mat b, int dim){ petuum::RowAccessor row_acc; b.Get(0, &row_acc); const petuum::DenseRow<float>& r = row_acc.Get<petuum::DenseRow<float> >(); for(int i=0;i<dim;i++) a[i]+=r[i]; }
//multiplication W * a, size of W dim1 * dim2, assume a and b have been allocated void matrix_vector_multiply(mat W, float * a, float * b, int dim1, int dim2){ petuum::RowAccessor row_acc; for(int i=0;i<dim1;i++){ W.Get(i, &row_acc); const petuum::DenseRow<float>& r = row_acc.Get<petuum::DenseRow<float> >(); float sum=0; for(int j=0;j<dim2;j++) sum+=r[j]*a[j]; b[i]=sum; } }