IEnumerable <int[]> OffsetGenerator() { var offset = KernelShape.Select(x => 0).ToArray(); bool goodToGo = false; do { yield return(offset); goodToGo = false; for (int i = 0; i < KernelShape.Length; i++) { offset[i]++; if (offset[i] < KernelShape[i]) { goodToGo = true; break; } offset[i] = 0; } } while (goodToGo); }
IEnumerable <int[]> CornerGenerator() { int[] min = KernelShape.Select((v, i) => - Lowerpadding[i] - ((Padding[i]) ? -(v / 2) : 0)).ToArray(); int[] max = KernelShape.Select((v, i) => InputShape[i] + Upperpadding[i] - ((Padding[i]) ? ((v + 1) / 2) : v)).ToArray(); var offset = min.Select(i => i).ToArray(); // deep copy bool goodToGo = false; do { yield return(offset); goodToGo = false; for (int i = KernelShape.Length - 1; i >= 0; i--) { offset[i] += Stride[i]; if (offset[i] <= max[i]) { goodToGo = true; break; } offset[i] = min[i]; } } while (goodToGo); }