public static int TransformFlatIndex(this RegularArrayInfo arrayInfo, int flatIndex, params Range[] ranges) { arrayInfo.ValidateRanges(ranges); int[] dimIndices = new int[arrayInfo.Rank]; RegularArrayInfo ai = new RegularArrayInfo(ranges.Select(r => new ArrayDimension(r.Count, r.Index)).ToArray()); ai.CalcDimIndices(flatIndex, dimIndices); return(arrayInfo.CalcFlatIndex(dimIndices)); }
public static IEnumerable <int> EnumerateFlatIndex(this RegularArrayInfo arrayInfo, params Range[] ranges) { arrayInfo.ValidateRanges(ranges); int[] dimIndices = new int[arrayInfo.Rank]; for (ArrayIndex ai = new ArrayIndex(new RegularArrayInfo(ranges.Select(r => new ArrayDimension(r.Count, r.Index)).ToArray())); ai.Carry == 0; ai++) { ai.GetDimIndices(dimIndices); yield return(arrayInfo.CalcFlatIndex(dimIndices)); } }