Changed Mat serialisation with a unified one that also supports non-contiguous matrices