コード例 #1
0
        public void TestDatasetFreeBlockSequential()
        {
            RedirectGlobalsToTempPath();

            string filename = $"test{nameof(TestDatasetFetchBlockSequential)}.dat";

            CreateCsvTempFile(filename);

            CsvRecordExtractor extractor = new CsvRecordReader(new FileSource(filename, Path.GetTempPath())).Extractor("inputs", 1, 2, "targets", 3);
            ExtractedDataset   dataset   = new ExtractedDataset(name: "name", blockSizeRecords: 1, recordExtractors: extractor);
            CpuFloat32Handler  handler   = new CpuFloat32Handler();

            dataset.FetchBlock(0, handler, false);
            dataset.FetchBlock(1, handler, false);
            dataset.FetchBlock(2, handler, false);

            Assert.AreEqual(3, dataset.ActiveBlockRegionCount);

            dataset.FreeBlock(1, handler);
            dataset.FreeBlock(2, handler);

            Assert.AreEqual(1, dataset.ActiveBlockRegionCount);

            var namedArrays = dataset.FetchBlock(0, handler, false);

            Assert.AreEqual(new[] { 3.5f, 1.4f }, namedArrays["inputs"].GetDataAs <float>().GetValuesArrayAs <float>(0, 2));

            namedArrays = dataset.FetchBlock(1, handler, false);
            Assert.AreEqual(new[] { 3.0f, 1.4f }, namedArrays["inputs"].GetDataAs <float>().GetValuesArrayAs <float>(0, 2));

            namedArrays = dataset.FetchBlock(2, handler, false);
            Assert.AreEqual(new[] { 3.2f, 1.3f }, namedArrays["inputs"].GetDataAs <float>().GetValuesArrayAs <float>(0, 2));

            dataset.Dispose();

            DeleteTempFile(filename);
        }
コード例 #2
0
        public async Task TestDatasetFetchAsync()
        {
            RedirectGlobalsToTempPath();

            string filename = $"test{nameof(TestDatasetFetchAsync)}.dat";

            CreateCsvTempFile(filename);

            CsvRecordExtractor extractor = new CsvRecordReader(new FileSource(filename, Path.GetTempPath())).Extractor("inputs", 1, 2, "targets", 3);
            ExtractedDataset   dataset   = new ExtractedDataset(name: "name", blockSizeRecords: 1, recordExtractors: extractor);
            CpuFloat32Handler  handler   = new CpuFloat32Handler();

            var block0 = dataset.FetchBlockAsync(0, handler);
            var block2 = dataset.FetchBlockAsync(2, handler);
            var block1 = dataset.FetchBlockAsync(1, handler);

            //mock a free block request to freak out the dataset controller
            dataset.FreeBlock(1, handler);

            IDictionary <string, INDArray> namedArrays0 = await block0;
            IDictionary <string, INDArray> namedArrays1 = await block1;
            IDictionary <string, INDArray> namedArrays2 = await block2;

            Assert.IsNotNull(namedArrays1);
            Assert.AreEqual(new[] { 3.0f, 1.4f }, namedArrays1["inputs"].GetDataAs <float>().GetValuesArrayAs <float>(0, 2));

            Assert.IsNotNull(namedArrays2);
            Assert.AreEqual(new[] { 3.2f, 1.3f }, namedArrays2["inputs"].GetDataAs <float>().GetValuesArrayAs <float>(0, 2));

            Assert.IsNotNull(namedArrays0);
            Assert.AreEqual(new[] { 3.5f, 1.4f }, namedArrays0["inputs"].GetDataAs <float>().GetValuesArrayAs <float>(0, 2));

            dataset.Dispose();

            DeleteTempFile(filename);
        }