示例#1
0
        public void WriteAndReadStorageIntsViaDiskFile()
        {
            const int size = 10;

            var file = new DiskFile("test17.dat", "rwb");

            Assert.NotNull(file);
            Assert.True(file.CanWrite);

            var storage0 = new IntTensor.IntStorage(size);

            for (var i = 0; i < size; ++i)
            {
                storage0[i] = i;
            }

            file.WriteInts(storage0);
            Assert.Equal(size * sizeof(int), file.Position);
            file.Seek(0);

            var storage1 = new IntTensor.IntStorage(size);
            var rd       = file.ReadInts(storage1);

            Assert.Equal(rd, size);
            Assert.Equal(size * sizeof(int), file.Position);

            for (var i = 0; i < rd; ++i)
            {
                Assert.Equal(storage0[i], storage1[i]);
            }

            file.Close();
            Assert.False(file.IsOpen);
        }
示例#2
0
 /// <summary>
 ///   Write ints to the file from the given storage.
 /// </summary>
 /// <param name="storage">A storage object fetch data from.</param>
 /// <returns>The number of ints written.</returns>
 public long WriteInts(IntTensor.IntStorage storage)
 {
     return(THFile_writeInt(this.handle, storage.handle));
 }
示例#3
0
 /// <summary>
 ///   Read ints from the file into the given storage.
 /// </summary>
 /// <param name="storage">A storage object to read data into.</param>
 /// <returns>The number of ints read.</returns>
 public long ReadInts(IntTensor.IntStorage storage)
 {
     return(THFile_readInt(this.handle, storage.handle));
 }