Esempio n. 1
0
        /// <summary>
        /// Serializes the specified array.
        /// </summary>
        /// <param name="array">The array.</param>
        /// <param name="stream">The stream.</param>
        public static void Serialize(SuperArray array, Stream stream)
        {
            using (var src = Helper.AsContiguous(array))
            {
                // Note: don't dispose writer - it does not own the stream's lifetime
                var writer = new System.IO.BinaryWriter(stream);

                // Can infer strides - src is contiguous
                writer.Write(array.DimensionCount); // int32
                writer.Write((int)array.ElementType);
                for (int i = 0; i < array.DimensionCount; ++i)
                {
                    writer.Write(array.Shape[i]);
                }

                var byteCount = src.ElementType.Size() * array.ElementCount();
                writer.Write(byteCount);
                WriteBytes(writer, src.Storage, src.StorageOffset, byteCount);

                writer.Flush();
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Repeats the specified tensor.
 /// </summary>
 /// <param name="x">The x.</param>
 /// <param name="reps">The reps.</param>
 /// <returns></returns>
 public SuperArray Repeat(SuperArray x, int reps)
 {
     x = x.View(x.ElementCount(), 1).Tile(reps);
     return(x.View(1, x.ElementCount()));
 }