public static Array CreateArray <T>(this RegularArrayLongInfo arrayInfo, ICollection <T> coll) { if (arrayInfo == null) { throw new ArgumentNullException("arrayInfo"); } if (coll == null) { throw new ArgumentNullException("coll"); } if (coll.Count != arrayInfo.Length) { throw new ArgumentException("Invalid collection length", "coll"); } var indices = new long[arrayInfo.Rank]; var array = arrayInfo.CreateArray <T>(); coll.ForEach((t, i) => { arrayInfo.CalcDimIndices(i, indices); arrayInfo.SetValue(array, t, indices); }); return(array); }
public static long TransformFlatIndex(this RegularArrayLongInfo arrayInfo, long flatIndex, params LongRange[] ranges) { arrayInfo.ValidateRanges(ranges); long[] dimIndices = new long[arrayInfo.Rank]; RegularArrayLongInfo ai = new RegularArrayLongInfo(ranges.Select(r => new ArrayLongDimension(r.Count, r.Index)).ToArray()); ai.CalcDimIndices(flatIndex, dimIndices); return(arrayInfo.CalcFlatIndex(dimIndices)); }
public static IEnumerable <long> EnumerateFlatIndex(this RegularArrayLongInfo arrayInfo, params LongRange[] ranges) { arrayInfo.ValidateRanges(ranges); long[] dimIndices = new long[arrayInfo.Rank]; for (ArrayLongIndex ai = new ArrayLongIndex(new RegularArrayLongInfo(ranges.Select(r => new ArrayLongDimension(r.Count, r.Index)).ToArray())); ai.Carry == 0; ai++) { ai.GetDimIndices(dimIndices); yield return(arrayInfo.CalcFlatIndex(dimIndices)); } }
public static void ValidateRanges(this RegularArrayLongInfo arrayInfo, params LongRange[] ranges) { if (arrayInfo == null) { throw new ArgumentNullException("arrayInfo"); } if (ranges == null) { throw new ArgumentNullException("ranges"); } if (ranges.Length != arrayInfo.Rank) { throw new ArgumentException("Invalid array length", "ranges"); } if (Enumerable.Range(0, ranges.Length) .Any(i => ranges[i].Index <arrayInfo.LowerBounds[i] || ranges[i].Index + ranges[i].Count> arrayInfo.LowerBounds[i] + arrayInfo.Lengths[i])) { throw new ArgumentException("Out of range dimension exists"); } //return new RegularArrayLongInfo (ranges.Select(r => new ArrayLongDimension(r.Count, r.Index)).ToArray()); }