protected Dictionary <string, INDArray> GetOwnSlice(IDictionary <string, INDArray> block) { Dictionary <string, INDArray> slicedBlock = new Dictionary <string, INDArray>(); foreach (string section in block.Keys) { INDArray sectionBlock = block[section]; long[] beginIndex = new long[sectionBlock.Rank]; long[] endIndex = new long[sectionBlock.Rank]; long beginRecordIndex = (long)(sectionBlock.Shape[0] * ShareOffset); long endRecordIndex = (long)Math.Ceiling(sectionBlock.Shape[0] * (ShareOffset + Share)); //slice is empty, return null to indicate as specified if (beginRecordIndex == endRecordIndex) { return(null); } beginIndex[0] = beginRecordIndex; endIndex[0] = endRecordIndex; for (int i = 1; i < sectionBlock.Rank; i++) { endIndex[i] = sectionBlock.Shape[i]; } slicedBlock.Add(section, sectionBlock.Slice(beginIndex, endIndex)); } return(slicedBlock); }
/// <inheritdoc /> public override Dictionary <string, INDArray> ExtractDirectFrom(object readData, int numberOfRecords, IComputationHandler handler) { Dictionary <string, INDArray> unprocessedNamedArrays = (Dictionary <string, INDArray>)readData; Dictionary <string, INDArray> processedNamedArrays = new Dictionary <string, INDArray>(); foreach (string sectionName in unprocessedNamedArrays.Keys) { INDArray processedArray = unprocessedNamedArrays[sectionName]; if (processedArray.Shape[0] != numberOfRecords) { long[] beginIndices = (long[])processedArray.Shape.Clone(); long[] endIndices = (long[])processedArray.Shape.Clone(); beginIndices = NDArrayUtils.GetSliceIndicesAlongDimension(0, 0, beginIndices, copyResultShape: false, sliceEndIndex: false); endIndices = NDArrayUtils.GetSliceIndicesAlongDimension(0, Math.Min(numberOfRecords, processedArray.Shape[0]), endIndices, copyResultShape: false, sliceEndIndex: true); processedArray = processedArray.Slice(beginIndices, endIndices); } if (ProcessedSectionNames == null || ProcessedSectionNames.Contains(sectionName)) { processedArray = ProcessDirect(processedArray, handler); } processedNamedArrays.Add(sectionName, processedArray); } return(processedNamedArrays); }