public void TestDatasetBlockwiseSliceCreate() { RedirectGlobalsToTempPath(); string filename = nameof(TestDatasetBlockwiseSliceCreate) + "test.dat"; CreateCsvTempFile(filename); CsvRecordExtractor extractor = new CsvRecordReader(new FileSource(filename)).Extractor("inputs", 1, 2, "targets", 3); ExtractedDataset dataset = new ExtractedDataset("name", ExtractedDataset.BlockSizeAuto, extractor); Assert.Throws <ArgumentNullException>(() => new DatasetBlockwiseSlice(null, 0, 0, 1)); Assert.Throws <ArgumentException>(() => new DatasetBlockwiseSlice(dataset, 0, 0, 0)); Assert.Throws <ArgumentException>(() => new DatasetBlockwiseSlice(dataset, -1, 0, 1)); Assert.Throws <ArgumentException>(() => new DatasetBlockwiseSlice(dataset, 0, -1, 1)); Assert.Throws <ArgumentException>(() => new DatasetBlockwiseSlice(dataset, 1, 0, 1)); Assert.Throws <ArgumentException>(() => new DatasetBlockwiseSlice(dataset, 0, 2, 2)); DatasetBlockwiseSlice slice = new DatasetBlockwiseSlice(dataset, 0, 1, 3); Assert.AreSame(dataset, slice.UnderlyingDataset); Assert.AreEqual(0, slice.SplitBeginIndex); Assert.AreEqual(1, slice.SplitEndIndex); Assert.AreEqual(2, slice.SplitSize); Assert.AreEqual(3, slice.SplitInterval); Assert.AreEqual(dataset.Name, slice.Name); Assert.AreEqual(dataset.TargetBlockSizeRecords, slice.TargetBlockSizeRecords); Assert.AreEqual(dataset.SectionNames, slice.SectionNames); DeleteTempFile(filename); }
public void TestDatasetBlockwiseSliceFetch() { RedirectGlobalsToTempPath(); string filename = nameof(TestDatasetBlockwiseSliceFetch) + "test.dat"; CreateCsvTempFile(filename); CsvRecordExtractor extractor = new CsvRecordReader(new FileSource(filename)).Extractor("inputs", 0, "targets", 3); ExtractedDataset dataset = new ExtractedDataset("name", 1, extractor); DatasetBlockwiseSlice slice = new DatasetBlockwiseSlice(dataset, 1, 2, 3); Assert.AreEqual(new float[] { 4.9f }, slice.FetchBlock(0, new CpuFloat32Handler())["inputs"].GetDataAs <float>().GetValuesArrayAs <float>(0, 1)); extractor.Reader?.Dispose(); dataset.Dispose(); DeleteTempFile(filename); }