Dont copy matrices of the same type element by element, use memcpy