use memcpy instead of iterating to copy matrices