fast implementation of the matrix assembly