public static byte[] Serialize(FloatTensor x) { x.Cpu(); if (x.shape.Length > 10) { throw new Exception("cannot serialize tensors with greater than 10 dimensions"); } var byteArray = new byte[10 * sizeof(int) + x.data.Length * sizeof(float)]; Buffer.BlockCopy(x.shape, 0, byteArray, 0, x.shape.Length * sizeof(int)); Buffer.BlockCopy(x.data, 0, byteArray, 10 * sizeof(int), x.data.Length * sizeof(float)); return(byteArray); }